Make NNAPI Memory type more structured
This CL makes NNAPI memory more structured by replacing the pervasive
use of NativeHandle with the new, more specific memory types "Ashmem"
and "MmapFd". It changes the Memory type to be a std::variant of Ashmem
and MmapFd, in addition to (a cleaned up) HardwareBuffer. Finally, the
Memory type also continues to hold the alternative type "NativeHandle"
(now as an "Unknown" memory type) to ensure all previous types of
memory could still be held.
This change also updates the utility and testing code to account for the
changes to the Memory type.
Bug: 183118727
Test: mma
Test: NeuralNetworksTest_static
Change-Id: I7e2fea015a18b5e00d56bef924ebca4449d5b6dd
Merged-In: I7e2fea015a18b5e00d56bef924ebca4449d5b6dd
(cherry picked from commit d6496953292ba60c357417e7c9673ba31d9f84f5)
diff --git a/runtime/Memory.cpp b/runtime/Memory.cpp
index 7b46cf1..33f3ab7 100644
--- a/runtime/Memory.cpp
+++ b/runtime/Memory.cpp
@@ -182,7 +182,7 @@
RuntimeMemory::RuntimeMemory(SharedMemory memory) : kMemory(std::move(memory)) {
CHECK(kMemory != nullptr);
- mValidator = std::make_unique<SizedMemoryValidator>(kMemory->size);
+ mValidator = std::make_unique<SizedMemoryValidator>(nn::getSize(kMemory));
}
RuntimeMemory::RuntimeMemory(SharedMemory memory, std::unique_ptr<MemoryValidatorBase> validator)
@@ -548,8 +548,8 @@
}
std::unique_ptr<MemoryValidatorBase> validator;
- if (memory.value()->name == "hardware_buffer_blob") {
- validator = std::make_unique<SizedMemoryValidator>(memory.value()->size);
+ if (isAhwbBlob(memory.value())) {
+ validator = std::make_unique<SizedMemoryValidator>(nn::getSize(memory.value()));
} else {
validator = std::make_unique<AHardwareBufferNonBlobValidator>();
}