summaryrefslogtreecommitdiff
path: root/nn/runtime/test/TestNeuralNetworksWrapper.h
diff options
context:
space:
mode:
authorDavid Gross <dgross@google.com>2018-11-15 21:10:05 -0800
committerLev Proleev <levp@google.com>2018-11-29 18:41:21 +0000
commitfeb475d4a7464c64f9eb89193f19d06f0438f973 (patch)
tree458b8e82276941f7f9a2b6756689a37a1b6dd84c /nn/runtime/test/TestNeuralNetworksWrapper.h
parent61d241218842776a80e6572cb15cc6540daf63e2 (diff)
downloadml-feb475d4a7464c64f9eb89193f19d06f0438f973.tar.gz
Implement ANeuralNetworksExecution_compute() and add related properties.
Change wrapper::Execution::compute() to use ANeuralNetworksExecution_compute() rather than simulating it using ANeuralNetworksExecution_startCompute(). Change test_wrapper::Execution::compute() the same way by default, but to permit simulation by setting global state using test_wrapper::Execution::setComputeUsesSynchronousAPI(). Setting the new property debug.nn.syncexec-runtime to 1 makes ANeuralNetworksExecution_startCompute() behave synchronously (i.e., it will not return until the work is complete). In this case, the runtime itself will not spawn a thread to do the work. This simulates using ANeuralNetworksExecution_compute(). Setting the new property debug.nn.syncexec-cpu to 1 instructs the runtime not to spawn a thread to do CPU execution. Remove the execution path that was under the control of preprocessor symbol DISABLE_PARTITIONED_EXECUTION. Modify NeuralNetworksTest so that instead of iterating over {useCpuOnly=no, useCpuOnly=yes} it instead iterates over {useCpuOnly=no, useCpuOnly=yes} x {computeUsesSynchronousAPI=no, computeUsesSynchronousAPI=yes} Bug: 115920643 Bug: 119272497 Test: NeuralNetworksTest_static (and verify from logcat that we're getting correct threading behavior according to API choices and property settings) Test: cts -m CtsNNAPITestCases Change-Id: I9723aa502197a8d48a95a3ae5d7f053d381001da Merged-In: I9723aa502197a8d48a95a3ae5d7f053d381001da (cherry picked from commit c97068abfcb2174f6ffa6cb477250b5ccdca1a82)
Diffstat (limited to 'nn/runtime/test/TestNeuralNetworksWrapper.h')
-rw-r--r--nn/runtime/test/TestNeuralNetworksWrapper.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/nn/runtime/test/TestNeuralNetworksWrapper.h b/nn/runtime/test/TestNeuralNetworksWrapper.h
index 27097a65f..84ef3be0c 100644
--- a/nn/runtime/test/TestNeuralNetworksWrapper.h
+++ b/nn/runtime/test/TestNeuralNetworksWrapper.h
@@ -36,6 +36,9 @@ enum class Type {
TENSOR_FLOAT32 = ANEURALNETWORKS_TENSOR_FLOAT32,
TENSOR_INT32 = ANEURALNETWORKS_TENSOR_INT32,
TENSOR_QUANT8_ASYMM = ANEURALNETWORKS_TENSOR_QUANT8_ASYMM,
+ BOOL = ANEURALNETWORKS_BOOL,
+ TENSOR_QUANT16_SYMM = ANEURALNETWORKS_TENSOR_QUANT16_SYMM,
+ TENSOR_FLOAT16 = ANEURALNETWORKS_TENSOR_FLOAT16,
};
enum class ExecutePreference {
@@ -355,21 +358,34 @@ class Execution {
}
Result compute() {
- ANeuralNetworksEvent* event = nullptr;
- Result result =
- static_cast<Result>(ANeuralNetworksExecution_startCompute(mExecution, &event));
- if (result != Result::NO_ERROR) {
+ if (!mComputeUsesSychronousAPI) {
+ ANeuralNetworksEvent* event = nullptr;
+ Result result =
+ static_cast<Result>(ANeuralNetworksExecution_startCompute(mExecution, &event));
+ if (result != Result::NO_ERROR) {
+ return result;
+ }
+ // TODO how to manage the lifetime of events when multiple waiters is not
+ // clear.
+ result = static_cast<Result>(ANeuralNetworksEvent_wait(event));
+ ANeuralNetworksEvent_free(event);
return result;
}
- // TODO how to manage the lifetime of events when multiple waiters is not
- // clear.
- result = static_cast<Result>(ANeuralNetworksEvent_wait(event));
- ANeuralNetworksEvent_free(event);
- return result;
+
+ return static_cast<Result>(ANeuralNetworksExecution_compute(mExecution));
}
+ // By default, compute() uses the synchronous API.
+ // setComputeUsesSynchronousAPI() can be used to change the behavior of
+ // compute() to instead use the asynchronous API and then wait for
+ // computation to complete.
+ static void setComputeUsesSynchronousAPI(bool val) { mComputeUsesSychronousAPI = val; }
+
private:
ANeuralNetworksExecution* mExecution = nullptr;
+
+ // Initialized to true in TestNeuralNetworksWrapper.cpp.
+ static bool mComputeUsesSychronousAPI;
};
} // namespace test_wrapper