ml_benchmark: Pass driver configuration as a string.

BUG=b:163096945
TEST=emerge-chell chromeos-base/ml_benchmark
TEST=Execute SoDA benchmark on device with new config.

Change-Id: Idab8a660bfbab860fb2369a4c40ab45cc8a3ec92
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2344549
Tested-by: Stuart Langley <slangley@chromium.org>
Commit-Queue: Stuart Langley <slangley@chromium.org>
Reviewed-by: Franklin He <franklinh@chromium.org>
diff --git a/ml_benchmark/main.cc b/ml_benchmark/main.cc
index 7208dc8..01249b3 100644
--- a/ml_benchmark/main.cc
+++ b/ml_benchmark/main.cc
@@ -5,6 +5,7 @@
 #include <string>
 
 #include <base/files/file_path.h>
+#include <base/files/file_util.h>
 #include <base/logging.h>
 #include <brillo/flag_helper.h>
 #include <brillo/proto_file_io.h>
@@ -13,6 +14,7 @@
 #include "ml_benchmark/shared_library_benchmark_functions.h"
 #include "proto/benchmark_config.pb.h"
 
+using chrome::ml_benchmark::AccelerationMode;
 using chrome::ml_benchmark::CrOSBenchmarkConfig;
 using chrome::ml_benchmark::SodaBenchmarkConfig;
 using chrome::ml_benchmark::BenchmarkResults;
@@ -21,9 +23,6 @@
 
 namespace {
 
-constexpr char kSodaDriverName[] = "SoDA";
-constexpr char kSodaDriverPath[] = "libsoda_benchmark_driver.so";
-
 void benchmark_and_report_results(const std::string& driver_name,
                                   const base::FilePath& driver_file_path,
                                   const CrOSBenchmarkConfig& config) {
@@ -44,6 +43,9 @@
   if (results.status() == chrome::ml_benchmark::OK) {
     LOG(INFO) << driver_name << " finished";
     LOG(INFO) << results.results_message();
+    LOG(INFO) << "Accuracy: " << results.total_accuracy();
+    LOG(INFO) << "Average Latency: " << results.average_latency_in_us()
+              << " usec";
   } else {
     LOG(ERROR) << driver_name << " Encountered an error";
     LOG(ERROR) << "Reason: " << results.results_message();
@@ -56,6 +58,9 @@
   DEFINE_string(workspace_path, ".", "Path to the driver workspace.");
   DEFINE_string(config_file_name, "benchmark.config",
       "Name of the driver configuration file.");
+  DEFINE_string(driver_library_path, "libsoda_benchmark_driver.so",
+      "Path to the driver shared library.");
+  DEFINE_bool(use_nnapi, false, "Use NNAPI delegate.");
 
   brillo::FlagHelper::Init(argc, argv, "ML Benchmark runner");
 
@@ -64,24 +69,19 @@
 
   CrOSBenchmarkConfig benchmark_config;
 
-  CHECK(brillo::ReadTextProtobuf(workspace_config_path, &benchmark_config))
+  if (FLAGS_use_nnapi) {
+    benchmark_config.set_acceleration_mode(AccelerationMode::NNAPI);
+  }
+
+  CHECK(base::ReadFileToString(workspace_config_path,
+                               benchmark_config.mutable_driver_config()))
       << "Could not read the benchmark config file: " << workspace_config_path;
 
-  // Execute benchmarks
-  if (benchmark_config.has_soda_config()) {
-    const auto& soda_config = benchmark_config.soda_config();
+  base::FilePath driver_library(FLAGS_driver_library_path);
 
-    base::FilePath soda_path;
-    if (soda_config.soda_driver_path().empty()) {
-      soda_path = base::FilePath(kSodaDriverPath);
-    } else {
-      soda_path = base::FilePath(soda_config.soda_driver_path());
-    }
-
-    benchmark_and_report_results(kSodaDriverName,
-        soda_path,
-        benchmark_config);
-  }
+  benchmark_and_report_results(FLAGS_driver_library_path,
+                               driver_library,
+                               benchmark_config);
 
   LOG(INFO) << "Benchmark finished, exiting";
 }
diff --git a/ml_benchmark/proto/benchmark_config.proto b/ml_benchmark/proto/benchmark_config.proto
index 5f2f816..57bf59b 100644
--- a/ml_benchmark/proto/benchmark_config.proto
+++ b/ml_benchmark/proto/benchmark_config.proto
@@ -11,9 +11,13 @@
 // Refer to the CrOS ML Benchmarking Suite Design Document
 // at go/cros-ml-benchmark-suite
 message CrOSBenchmarkConfig {
+  reserved 2, 3;
+
   AccelerationMode acceleration_mode = 1;
-  // benchmark-specific configurations
-  SodaBenchmarkConfig soda_config = 2;
+
+  // String representation of the driver proto configuration, to be decoded by
+  // the benchmark driver implementation.
+  string driver_config = 4;
 }
 
 // Benchmark-specific configurations