diff options
author | Michael Butler <butlermichael@google.com> | 2021-10-28 01:54:26 +0000 |
---|---|---|
committer | Michael Butler <butlermichael@google.com> | 2021-10-29 14:28:45 -0700 |
commit | abc86918aece7623019da6964350bb7f349d8f70 (patch) | |
tree | d0c42004930a03e2cc3f5219ca3e403405fdb3b5 /neuralnetworks/aidl/utils/src/Service.cpp | |
parent | 1f5c57c965c85ae1f642e1408db17c598ed2d1b7 (diff) |
Revert^2 "Provide explicitly versioned NNAPI AIDL utils libs -- HAL."
Reason for revert: rollforward fix of this topic
This change is a revert of I3d3ac4745, which itself is a revert of
I74f1798e8.
This CL modifies the AIDL utils libraries to be explicitly
versioned. Currently, we only have two versions: v1 and "current".
Specifically, the following changes are made:
- Remove AIDL dependencies from neuralnetworks_utils_hal_common
- Create explicitly versioned libs of neuralnetworks_utils_hal_aidl*
This is needed because it is not allowed for a build target to
link against multiple versions of the same AIDL lirary.
The canonical driver will report ANDROID_S for AIDL v1, and FL6 for v2.
Reverted Changes:
I2aefa0023:Revert "Use explicitly versioned NNAPI HAL util li...
Ia7df07ab9:Revert "Add neuralnetworks_utils_hal_aidl_v2 to al...
Iadd823460:Revert "Provide explicitly version NNAPI AIDL util...
I3d3ac4745:Revert "Provide explicitly versioned NNAPI AIDL ut...
Bug: 202405342
Test: NNT_static
Test: CtsNNAPITestCases
Test: VtsHalNeuralnetworksTargetTest
Change-Id: Ib3b732aa406f6d37e8f941082807c9232720c909
Merged-In: Ib3b732aa406f6d37e8f941082807c9232720c909
(cherry picked from commit 478a78ea77fccf332b04d5ad25309428d0f96eaf)
Diffstat (limited to 'neuralnetworks/aidl/utils/src/Service.cpp')
-rw-r--r-- | neuralnetworks/aidl/utils/src/Service.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/neuralnetworks/aidl/utils/src/Service.cpp b/neuralnetworks/aidl/utils/src/Service.cpp index ac182a205e..01772eed53 100644 --- a/neuralnetworks/aidl/utils/src/Service.cpp +++ b/neuralnetworks/aidl/utils/src/Service.cpp @@ -17,6 +17,7 @@ #include "Service.h" #include <AndroidVersionUtil.h> +#include <aidl/android/hardware/neuralnetworks/IDevice.h> #include <android/binder_auto_utils.h> #include <android/binder_manager.h> #include <android/binder_process.h> @@ -28,8 +29,33 @@ #include <string> #include "Device.h" +#include "Utils.h" namespace aidl::android::hardware::neuralnetworks::utils { +namespace { + +// Map the AIDL version of an IDevice to NNAPI canonical feature level. +nn::GeneralResult<nn::Version> getAidlServiceFeatureLevel(IDevice* service) { + CHECK(service != nullptr); + int aidlVersion; + const auto ret = service->getInterfaceVersion(&aidlVersion); + HANDLE_ASTATUS(ret) << "getInterfaceVersion failed"; + + // For service AIDL versions greater than or equal to the AIDL library version that the runtime + // was built against, clamp it to the runtime AIDL library version. + aidlVersion = std::min(aidlVersion, IDevice::version); + + // Map stable AIDL versions to canonical versions. + switch (aidlVersion) { + case 1: + return nn::Version::ANDROID_S; + case 2: + return nn::Version::FEATURE_LEVEL_6; + } + return NN_ERROR() << "Unknown AIDL service version: " << aidlVersion; +} + +} // namespace nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) { auto fullName = std::string(IDevice::descriptor) + "/" + instanceName; @@ -55,7 +81,8 @@ nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) { << " returned nullptr"; } ABinderProcess_startThreadPool(); - return Device::create(instanceName, std::move(service)); + const auto featureLevel = NN_TRY(getAidlServiceFeatureLevel(service.get())); + return Device::create(instanceName, std::move(service), featureLevel); }; return hal::utils::ResilientDevice::create(std::move(makeDevice)); |