NNAPI SL Benchmark - Add option to specify vendor [1/n]. am: 27de3f2169 am: ddd35c3056 am: be3a6408c2
Original change: https://android-review.googlesource.com/c/platform/test/mlts/benchmark/+/2096394
Change-Id: Id9001d55b3ace20ce79d07d4543623cd1fb86e78
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/nn/benchmark/app/AcceleratorSpecificTestSupport.java b/src/com/android/nn/benchmark/app/AcceleratorSpecificTestSupport.java
index 0bdac1f..83875d6 100644
--- a/src/com/android/nn/benchmark/app/AcceleratorSpecificTestSupport.java
+++ b/src/com/android/nn/benchmark/app/AcceleratorSpecificTestSupport.java
@@ -166,6 +166,7 @@
mProcessor.setNnApiAcceleratorName(acceleratorName);
mProcessor.setUseNnApiSupportLibrary(NNTestBase.shouldUseNnApiSupportLibrary());
mProcessor.setExtractNnApiSupportLibrary(NNTestBase.shouldExtractNnApiSupportLibrary());
+ mProcessor.setNnApiSupportLibraryVendor(NNTestBase.getNnApiSupportLibraryVendor());
mTestModelEntry = testModelEntry;
}
diff --git a/src/com/android/nn/benchmark/app/BenchmarkTestBase.java b/src/com/android/nn/benchmark/app/BenchmarkTestBase.java
index 294e439..10c4254 100644
--- a/src/com/android/nn/benchmark/app/BenchmarkTestBase.java
+++ b/src/com/android/nn/benchmark/app/BenchmarkTestBase.java
@@ -95,9 +95,11 @@
if (useNNApi) {
final boolean useNnApiSupportLibrary = NNTestBase.shouldUseNnApiSupportLibrary();
final boolean extractNnApiSupportLibrary = NNTestBase.shouldExtractNnApiSupportLibrary();
+ final String nnApiSupportLibraryVendor = NNTestBase.getNnApiSupportLibraryVendor();
Log.i(NNBenchmark.TAG, "Configuring usage of NNAPI SL to " + useNnApiSupportLibrary);
mActivity.setUseNnApiSupportLibrary(useNnApiSupportLibrary);
mActivity.setExtractNnApiSupportLibrary(extractNnApiSupportLibrary);
+ mActivity.setNnApiSupportLibraryVendor(nnApiSupportLibraryVendor);
}
}
diff --git a/src/com/android/nn/benchmark/app/NNBenchmark.java b/src/com/android/nn/benchmark/app/NNBenchmark.java
index a0e6f28..93c1ec8 100644
--- a/src/com/android/nn/benchmark/app/NNBenchmark.java
+++ b/src/com/android/nn/benchmark/app/NNBenchmark.java
@@ -50,6 +50,7 @@
private boolean mUseNnApiSupportLibrary = false;
private boolean mExtractNnApiSupportLibrary = false;
+ private String mNnApiSupportLibraryVendor = "";
private Processor mProcessor;
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
@@ -85,6 +86,11 @@
mProcessor.setUseNnApiSupportLibrary(mUseNnApiSupportLibrary);
}
+ public void setNnApiSupportLibraryVendor(String value) {
+ mNnApiSupportLibraryVendor = value;
+ mProcessor.setNnApiSupportLibraryVendor(mNnApiSupportLibraryVendor);
+ }
+
public void setExtractNnApiSupportLibrary(boolean value) {
mExtractNnApiSupportLibrary = value;
mProcessor.setExtractNnApiSupportLibrary(value);
@@ -145,6 +151,7 @@
mProcessor.setTfLiteBackend(!i.getBooleanExtra(EXTRA_DISABLE_NNAPI, false) ? TfLiteBackend.NNAPI : TfLiteBackend.CPU);
mProcessor.setMaxRunIterations(i.getIntExtra(EXTRA_MAX_ITERATIONS, 0));
mProcessor.setUseNnApiSupportLibrary(mUseNnApiSupportLibrary);
+ mProcessor.setNnApiSupportLibraryVendor(mNnApiSupportLibraryVendor);
mProcessor.setExtractNnApiSupportLibrary(mExtractNnApiSupportLibrary);
executorService.submit(mProcessor);
} else {
diff --git a/src/com/android/nn/benchmark/core/NNTestBase.java b/src/com/android/nn/benchmark/core/NNTestBase.java
index fe0bddd..169572a 100644
--- a/src/com/android/nn/benchmark/core/NNTestBase.java
+++ b/src/com/android/nn/benchmark/core/NNTestBase.java
@@ -150,9 +150,11 @@
// from the library.
private boolean mUseNnApiSupportLibrary = false;
private boolean mExtractNnApiSupportLibrary = false;
+ private String mNnApiSupportLibraryVendor = "";
static final String USE_NNAPI_SL_PROPERTY = "useNnApiSupportLibrary";
static final String EXTRACT_NNAPI_SL_PROPERTY = "extractNnApiSupportLibrary";
+ static final String NNAPI_SL_VENDOR = "nnApiSupportLibraryVendor";
private static boolean getBooleanTestParameter(String key, boolean defaultValue) {
// All instrumentation arguments are passed as String so I have to convert the value here.
@@ -168,6 +170,10 @@
return getBooleanTestParameter(EXTRACT_NNAPI_SL_PROPERTY, false);
}
+ public static String getNnApiSupportLibraryVendor() {
+ return InstrumentationRegistry.getArguments().getString(NNAPI_SL_VENDOR);
+ }
+
public NNTestBase(String modelName, String modelFile, int[] inputShape,
InferenceInOutSequence.FromAssets[] inputOutputAssets,
InferenceInOutSequence.FromDataset[] inputOutputDatasets,
@@ -210,6 +216,7 @@
public void setUseNnApiSupportLibrary(boolean value) {mUseNnApiSupportLibrary = value;}
public void setExtractNnApiSupportLibrary(boolean value) {mExtractNnApiSupportLibrary = value;}
+ public void setNnApiSupportLibraryVendor(String value) {mNnApiSupportLibraryVendor = value;}
public void setNNApiDeviceName(String value) {
if (mTfLiteBackend != TfLiteBackend.NNAPI) {
diff --git a/src/com/android/nn/benchmark/core/Processor.java b/src/com/android/nn/benchmark/core/Processor.java
index 87a4455..1955b26 100644
--- a/src/com/android/nn/benchmark/core/Processor.java
+++ b/src/com/android/nn/benchmark/core/Processor.java
@@ -77,6 +77,7 @@
private boolean mUseNnApiSupportLibrary;
private boolean mExtractNnApiSupportLibrary;
+ private String mNnApiSupportLibraryVendor;
public Processor(Context context, Processor.Callback callback, int[] testList) {
mContext = context;
@@ -94,6 +95,7 @@
mModelFilterRegex = null;
mUseNnApiSupportLibrary = false;
mExtractNnApiSupportLibrary = false;
+ mNnApiSupportLibraryVendor = "";
}
public void setUseNNApi(boolean useNNApi) {
@@ -142,6 +144,7 @@
public void setUseNnApiSupportLibrary(boolean value) { mUseNnApiSupportLibrary = value; }
public void setExtractNnApiSupportLibrary(boolean value) { mExtractNnApiSupportLibrary = value; }
+ public void setNnApiSupportLibraryVendor(String value) { mNnApiSupportLibraryVendor = value; }
public void enableCompilationCachingBenchmarks(
float warmupTimeSeconds, float runTimeSeconds, int maxIterations) {
@@ -183,7 +186,8 @@
/*enableIntermediateTensorsDump=*/false,
/*mmapModel=*/ false,
NNTestBase.shouldUseNnApiSupportLibrary(),
- NNTestBase.shouldExtractNnApiSupportLibrary()
+ NNTestBase.shouldExtractNnApiSupportLibrary(),
+ NNTestBase.getNnApiSupportLibraryVendor()
)) {
tb.setNNApiDeviceName(acceleratorName);
return tb.setupModel(context);
@@ -210,7 +214,7 @@
oldTestBase.destroy();
}
NNTestBase tb = t.createNNTestBase(mBackend, /*enableIntermediateTensorsDump=*/false,
- mMmapModel, mUseNnApiSupportLibrary, mExtractNnApiSupportLibrary);
+ mMmapModel, mUseNnApiSupportLibrary, mExtractNnApiSupportLibrary, mNnApiSupportLibraryVendor);
if (mBackend == TfLiteBackend.NNAPI) {
tb.setNNApiDeviceName(mAcceleratorName);
}
diff --git a/src/com/android/nn/benchmark/core/TestModels.java b/src/com/android/nn/benchmark/core/TestModels.java
index d91e013..99eac1b 100644
--- a/src/com/android/nn/benchmark/core/TestModels.java
+++ b/src/com/android/nn/benchmark/core/TestModels.java
@@ -82,24 +82,25 @@
public NNTestBase createNNTestBase(TfLiteBackend tfLiteBackend, boolean enableIntermediateTensorsDump) {
return createNNTestBase(tfLiteBackend, enableIntermediateTensorsDump, /*mmapModel=*/false,
- /*useNnApiSl=*/false, /*extractNnApiSl=*/false);
+ /*useNnApiSl=*/false, /*extractNnApiSl=*/false, /*nnApiSlVendor=*/"");
}
// Used by CTS tests.
public NNTestBase createNNTestBase(boolean useNNAPI, boolean enableIntermediateTensorsDump) {
TfLiteBackend tfLiteBackend = useNNAPI ? TfLiteBackend.NNAPI : TfLiteBackend.CPU;
return createNNTestBase(tfLiteBackend, enableIntermediateTensorsDump,
- /*mmapModel=*/false, /*useNnApiSl=*/false, /*extractNnApiSl=*/false);
+ /*mmapModel=*/false, /*useNnApiSl=*/false, /*extractNnApiSl=*/false, /*nnApiSlVendor=*/"");
}
public NNTestBase createNNTestBase(TfLiteBackend tfLiteBackend, boolean enableIntermediateTensorsDump,
- boolean mmapModel, boolean useNnApiSl, boolean extractNnApiSl) {
+ boolean mmapModel, boolean useNnApiSl, boolean extractNnApiSl, String nnApiSlVendor) {
NNTestBase test = createNNTestBase();
test.setTfLiteBackend(tfLiteBackend);
test.enableIntermediateTensorsDump(enableIntermediateTensorsDump);
test.setMmapModel(mmapModel);
test.setUseNnApiSupportLibrary(useNnApiSl);
test.setExtractNnApiSupportLibrary(extractNnApiSl);
+ test.setNnApiSupportLibraryVendor(nnApiSlVendor);
return test;
}
diff --git a/src/com/android/nn/benchmark/util/DumpIntermediateTensors.java b/src/com/android/nn/benchmark/util/DumpIntermediateTensors.java
index 438384a..22d7f16 100644
--- a/src/com/android/nn/benchmark/util/DumpIntermediateTensors.java
+++ b/src/com/android/nn/benchmark/util/DumpIntermediateTensors.java
@@ -96,7 +96,8 @@
try (NNTestBase testBase = modelEntry.createNNTestBase(
backend, /*enableIntermediateTensorsDump*/true, /*mmapModel*/false,
NNTestBase.shouldUseNnApiSupportLibrary(),
- NNTestBase.shouldExtractNnApiSupportLibrary())) {
+ NNTestBase.shouldExtractNnApiSupportLibrary(),
+ NNTestBase.getNnApiSupportLibraryVendor())) {
testBase.setupModel(this);
File outputDir = new File(getFilesDir() + "/" + DUMP_DIR +
"/" + modelName, useNNAPIDir);