Enable burst to be used in NNAPI compat lib
This CL includes the following changes:
* Changes std::shared_ptr<ExecutionBurstController> to SharedBurst
* Removes the NN_NO_BURST preprocessor guard
* Changes the mechanics (but not the behavior) of how a cached resource
in a burst object is released
Bug: 180492058
Test: mma
Test: NeuralNetworksTest_static
Change-Id: Ib4b0242b6e34a37fda63a414194ec1938bb533d7
Merged-In: Ib4b0242b6e34a37fda63a414194ec1938bb533d7
(cherry picked from commit 5c4d93fac64e7d419cb160fdbf4b9b58f7c56bd4)
diff --git a/runtime/Memory.cpp b/runtime/Memory.cpp
index 9e93581..c078292 100644
--- a/runtime/Memory.cpp
+++ b/runtime/Memory.cpp
@@ -19,10 +19,10 @@
#include "Memory.h"
#include <CpuExecutor.h>
-#include <ExecutionBurstController.h>
#include <LegacyUtils.h>
#include <android-base/scopeguard.h>
#include <android/hardware_buffer.h>
+#include <nnapi/IBurst.h>
#include <nnapi/SharedMemory.h>
#include <nnapi/TypeUtils.h>
#include <nnapi/Types.h>
@@ -192,16 +192,6 @@
RuntimeMemory::RuntimeMemory(SharedBuffer buffer) : kBuffer(std::move(buffer)) {}
-RuntimeMemory::~RuntimeMemory() {
-#ifndef NN_NO_BURST
- for (const auto& [ptr, weakBurst] : mUsedBy) {
- if (const std::shared_ptr<ExecutionBurstController> burst = weakBurst.lock()) {
- burst->freeMemory(getKey());
- }
- }
-#endif // NN_NO_BURST
-}
-
Request::MemoryPool RuntimeMemory::getMemoryPool() const {
if (kBuffer != nullptr) {
return kBuffer->getToken();
@@ -218,13 +208,11 @@
return mCachedRunTimePoolInfo;
}
-intptr_t RuntimeMemory::getKey() const {
- return reinterpret_cast<intptr_t>(this);
-}
-
-void RuntimeMemory::usedBy(const std::shared_ptr<ExecutionBurstController>& burst) const {
- std::lock_guard<std::mutex> guard(mMutex);
- mUsedBy.emplace(burst.get(), burst);
+void RuntimeMemory::hold(const IBurst::OptionalCacheHold& cacheHold) const {
+ if (cacheHold != nullptr) {
+ std::lock_guard<std::mutex> guard(mMutex);
+ mHold.insert(cacheHold);
+ }
}
static int copyHidlMemories(const std::optional<RunTimePoolInfo>& src,