Sadik Armagan | 8f397a1 | 2022-06-17 15:38:22 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #define LOG_TAG "ArmnnDriver" |
| 7 | |
| 8 | #include <android-base/logging.h> |
| 9 | #include <android-base/scopeguard.h> |
| 10 | #include <dlfcn.h> |
| 11 | |
| 12 | #include "NeuralNetworksShim.h" |
| 13 | #include "SupportLibrarySymbols.h" |
| 14 | |
| 15 | #include <string> |
| 16 | |
| 17 | using namespace std; |
| 18 | |
| 19 | int main() |
| 20 | { |
| 21 | /// The platform shim allows use of the armnn support library driver (arm-armnn-sl) to create a |
| 22 | /// binderized vendor service (arm-armnn-shim) that is started at device startup |
| 23 | |
| 24 | NnApiSLDriverImpl* impl = ANeuralNetworks_getSLDriverImpl(); |
| 25 | if (impl == nullptr) |
| 26 | { |
| 27 | LOG(ERROR) << "ArmnnDriver: ANeuralNetworks_getSLDriverImpl returned nullptr!!!"; |
| 28 | return EXIT_FAILURE; |
| 29 | } |
| 30 | |
| 31 | ANeuralNetworksShimDeviceInfo* deviceInfo; |
| 32 | ANeuralNetworksShimDeviceInfo_create(&deviceInfo, |
| 33 | /*deviceName=*/"arm-armnn-sl", |
| 34 | /*serviceName=*/"arm-armnn-shim"); |
| 35 | const auto guardDeviceInfo = android::base::make_scope_guard( |
| 36 | [deviceInfo] { ANeuralNetworksShimDeviceInfo_free(deviceInfo); }); |
| 37 | |
| 38 | ANeuralNetworksShimRegistrationParams* params; |
| 39 | ANeuralNetworksShimRegistrationParams_create(impl, ¶ms); |
| 40 | const auto guardParams = android::base::make_scope_guard( |
| 41 | [params] { ANeuralNetworksShimRegistrationParams_free(params); }); |
| 42 | ANeuralNetworksShimRegistrationParams_addDeviceInfo(params, deviceInfo); |
| 43 | ANeuralNetworksShimRegistrationParams_setNumberOfListenerThreads(params, 15); |
| 44 | ANeuralNetworksShimRegistrationParams_registerAsLazyService(params, false); |
| 45 | ANeuralNetworksShimRegistrationParams_fallbackToMinimumSupportDevice(params, false); |
| 46 | |
| 47 | auto result = ANeuralNetworksShim_registerSupportLibraryService(params); |
| 48 | LOG(ERROR) << "ArmnnDriver: ANeuralNetworksShim_registerSupportLibraryService returned error status: " << result; |
| 49 | |
| 50 | return EXIT_FAILURE; |
| 51 | } |