diff --git a/tensorflow/lite/tools/benchmark/benchmark_performance_options.cc b/tensorflow/lite/tools/benchmark/benchmark_performance_options.cc index 32c1b873b32..e286b7c9b0c 100644 --- a/tensorflow/lite/tools/benchmark/benchmark_performance_options.cc +++ b/tensorflow/lite/tools/benchmark/benchmark_performance_options.cc @@ -33,6 +33,11 @@ limitations under the License. #include "tensorflow/lite/tools/benchmark/logging.h" #include "tensorflow/lite/tools/command_line_flags.h" +#if (defined(ANDROID) || defined(__ANDROID__)) && \ + (defined(__arm__) || defined(__aarch64__)) +#define TFLITE_ENABLE_HEXAGON +#endif + namespace tflite { namespace benchmark { @@ -62,6 +67,13 @@ void MultiRunStatsRecorder::OnBenchmarkStart(const BenchmarkParams& params) { return; } +#if defined(TFLITE_ENABLE_HEXAGON) + if (params.Get("use_hexagon")) { + current_run_name_ = "dsp w/ hexagon"; + return; + } +#endif + // Handle cases run on CPU // Note: could use std::to_string to convert an integer to string but it // requires C++11. @@ -202,7 +214,12 @@ bool BenchmarkPerformanceOptions::ParsePerfOptions() { std::vector BenchmarkPerformanceOptions::GetValidPerfOptions() const { - return {"all", "cpu", "gpu", "nnapi", "none"}; + std::vector valid_options = {"all", "cpu", "gpu", "nnapi", + "none"}; +#if defined(TFLITE_ENABLE_HEXAGON) + valid_options.emplace_back("dsp"); +#endif + return valid_options; } bool BenchmarkPerformanceOptions::HasOption(const std::string& option) const { @@ -218,20 +235,25 @@ void BenchmarkPerformanceOptions::ResetPerformanceOptions() { single_option_run_params_->Set("use_nnapi", false); single_option_run_params_->Set("nnapi_accelerator_name", ""); #endif +#if defined(TFLITE_ENABLE_HEXAGON) + single_option_run_params_->Set("use_hexagon", false); +#endif } void BenchmarkPerformanceOptions::CreatePerformanceOptions() { TFLITE_LOG(INFO) << "The list of TFLite runtime options to be benchmarked: [" << params_.Get("perf_options_list") << "]"; - const bool benchmark_all = HasOption("all"); - if (HasOption("none")) { // Just add an empty BenchmarkParams instance. BenchmarkParams params; all_run_params_.emplace_back(std::move(params)); + // As 'none' is exclusive to others, simply return here. + return; } + const bool benchmark_all = HasOption("all"); + if (benchmark_all || HasOption("cpu")) { const std::vector num_threads = {1, 2, 4}; for (const int count : num_threads) { @@ -280,6 +302,14 @@ void BenchmarkPerformanceOptions::CreatePerformanceOptions() { all_run_params_.emplace_back(std::move(params)); } #endif + +#if defined(TFLITE_ENABLE_HEXAGON) + if (benchmark_all || HasOption("dsp")) { + BenchmarkParams params; + params.AddParam("use_hexagon", BenchmarkParam::Create(true)); + all_run_params_.emplace_back(std::move(params)); + } +#endif } void BenchmarkPerformanceOptions::Run() {