NNAPI Burst -- runtime and CTS
The NNAPI is introducing the notion of an "Execution Burst" object (or
more simply a "Burst" object), which is similar to an
ANeuralNetworksExecution, but is intended to be reused across multiple
executions and has lower IPC overheads. It achieves this low IPC
overhead by replacing HIDL HwBinder calls with FMQ messages.
This CL implements the NDK burst functions, implements the path through
the partitioner/scheduler, and creates CTS tests using the burst object.
Bug: 119570067
Test: mma
Test: NeuralNetworksTest_static
Change-Id: I1d2414f454910ad3ba4b2af728ab95ef8b609c9c
Merged-In: I1d2414f454910ad3ba4b2af728ab95ef8b609c9c
(cherry picked from commit 78adc2154eba664bb286b4d21c67caa65b051cc2)
diff --git a/runtime/NeuralNetworks.cpp b/runtime/NeuralNetworks.cpp
index 80ecb99..c02e780 100644
--- a/runtime/NeuralNetworks.cpp
+++ b/runtime/NeuralNetworks.cpp
@@ -22,6 +22,7 @@
#include "NeuralNetworks.h"
+#include "BurstBuilder.h"
#include "Callbacks.h"
#include "CompilationBuilder.h"
#include "ExecutionBuilder.h"
@@ -546,15 +547,18 @@
return ANEURALNETWORKS_UNEXPECTED_NULL;
}
- // TODO in subsequent CL
- return ANEURALNETWORKS_NO_ERROR;
+ CompilationBuilder* c = reinterpret_cast<CompilationBuilder*>(compilation);
+ BurstBuilder* b = nullptr;
+ int result = c->createBurst(&b);
+ *burst = reinterpret_cast<ANeuralNetworksBurst*>(b);
+ return result;
}
void ANeuralNetworksBurst_free(ANeuralNetworksBurst* burst) {
NNTRACE_RT(NNTRACE_PHASE_TERMINATION, "ANeuralNetworksBurst_free");
// No validation. Free of nullptr is valid.
- (void)burst;
- // TODO in subsequent CL
+ BurstBuilder* b = reinterpret_cast<BurstBuilder*>(burst);
+ delete b;
}
int ANeuralNetworksExecution_burstCompute(ANeuralNetworksExecution* execution,
@@ -565,8 +569,27 @@
return ANEURALNETWORKS_UNEXPECTED_NULL;
}
- // TODO in subsequent CL
- return ANEURALNETWORKS_NO_ERROR;
+ ExecutionBuilder* r = reinterpret_cast<ExecutionBuilder*>(execution);
+ BurstBuilder* b = reinterpret_cast<BurstBuilder*>(burst);
+
+ if (r->getCompilation() != b->getCompilation()) {
+ LOG(ERROR) << "ANeuralNetworksBurst and ANeuralNetworksExecution "
+ "used in ANeuralNetworksExecution_burstCompute must "
+ "originate from the same ANeuralNetworksCompilation";
+ return ANEURALNETWORKS_BAD_DATA;
+ }
+
+ const bool locked = b->tryLock();
+ if (!locked) {
+ LOG(ERROR) << "ANeuralNetworksBurst is already being used in another "
+ "call to ANeuralNetworksExecution_burstCompute";
+ return ANEURALNETWORKS_BAD_STATE;
+ }
+
+ const int n = r->burstCompute(b);
+ b->unlock();
+
+ return n;
}
int ANeuralNetworksMemory_createFromFd(size_t size, int prot, int fd, size_t offset,