aboutsummaryrefslogtreecommitdiff
path: root/shim/sl/scripts/NeuralNetworks.patch
blob: c33177e0811f7680e572502e550d428e3c9599e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
diff --git a/common/SharedMemoryAndroid.cpp b/common/SharedMemoryAndroid.cpp
index 4730de36b..896d643e7 100644
--- a/common/SharedMemoryAndroid.cpp
+++ b/common/SharedMemoryAndroid.cpp
@@ -160,8 +160,19 @@ GeneralResult<SharedMemory> allocateSharedMemory(size_t size) {
     return createSharedMemoryFromUniqueFd(size, prot, std::move(fd), offset);
 }
 
-GeneralResult<Mapping> map(const Memory::Ashmem& /*memory*/) {
-    return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) << "Cannot map ashmem memory";
+GeneralResult<Mapping> map(const Memory::Ashmem& memory) {
+    constexpr off64_t offset = 0;
+    constexpr int prot = PROT_READ | PROT_WRITE;
+    std::shared_ptr<base::MappedFile> mapping =
+            base::MappedFile::FromFd(memory.fd, offset, memory.size, prot);
+    if (mapping == nullptr || mapping->data() == nullptr) {
+        return NN_ERROR() << "Can't mmap the file descriptor.";
+    }
+    return Mapping{
+            .pointer = mapping->data(),
+            .size = memory.size,
+            .context = std::move(mapping),
+    };
 }
 
 #endif  // NN_COMPATIBILITY_LIBRARY_BUILD
diff --git a/runtime/NeuralNetworks.cpp b/runtime/NeuralNetworks.cpp
index b91d3ce45..8977dac68 100644
--- a/runtime/NeuralNetworks.cpp
+++ b/runtime/NeuralNetworks.cpp
@@ -1859,7 +1859,7 @@ int SL_ANeuralNetworksDevice_forEachVendorExtensionOperandTypeInformation(
 #define NNCL_FUNC(symbol) .symbol = symbol
 
 NnApiSLDriverImplFL5 slDriverImpl{
-        .base{.implFeatureLevel = ANEURALNETWORKS_FEATURE_LEVEL_5},
+        .base={.implFeatureLevel = ANEURALNETWORKS_FEATURE_LEVEL_5},
         NNCL_FUNC(ANeuralNetworksBurst_create),
         NNCL_FUNC(ANeuralNetworksBurst_free),
         NNCL_FUNC(ANeuralNetworksCompilation_createForDevices),