Mock ASharedMemory_create on non-Android platforms only if NNAPI is loaded

This ensures identical behaviour on platforms which use full
nnapi_implementation.cc, but don't have libneuralnetworks.so library, and
platforms which use nnapi_implementation_disabled.cc stub.

PiperOrigin-RevId: 262387219
This commit is contained in:
A. Unique TensorFlower 2019-08-08 10:46:17 -07:00 committed by TensorFlower Gardener
parent 934c284867
commit f71f815048
2 changed files with 8 additions and 2 deletions

View File

@ -178,7 +178,13 @@ const NnApi LoadNnApi() {
}
}
#else
nnapi.ASharedMemory_create = ASharedMemory_create;
// Mock ASharedMemory_create only if libneuralnetworks.so was successfully
// loaded. This ensures identical behaviour on platforms which use this
// implementation, but don't have libneuralnetworks.so library, and
// platforms which use nnapi_implementation_disabled.cc stub.
if (libneuralnetworks != nullptr) {
nnapi.ASharedMemory_create = ASharedMemory_create;
}
#endif // __ANDROID__
// API 28 (NN 1.1) methods.

View File

@ -116,7 +116,7 @@ TEST(NnapiLibTest, NnApiImplementation) {
EXPECT_EQ(nnapi->ANeuralNetworksExecution_startCompute, nullptr);
EXPECT_EQ(nnapi->ANeuralNetworksEvent_wait, nullptr);
EXPECT_EQ(nnapi->ANeuralNetworksEvent_free, nullptr);
EXPECT_NE(nnapi->ASharedMemory_create, nullptr);
EXPECT_EQ(nnapi->ASharedMemory_create, nullptr);
EXPECT_EQ(nnapi->ANeuralNetworks_getDeviceCount, nullptr);
EXPECT_EQ(nnapi->ANeuralNetworks_getDevice, nullptr);
EXPECT_EQ(nnapi->ANeuralNetworksDevice_getName, nullptr);