Loading neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Service.h +2 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,8 @@ namespace aidl::android::hardware::neuralnetworks::utils { ::android::nn::GeneralResult<::android::nn::SharedDevice> getDevice(const std::string& name); ::android::nn::GeneralResult<::android::nn::SharedDevice> getDevice( const std::string& name, ::android::nn::Version::Level maxFeatureLevelAllowed); } // namespace aidl::android::hardware::neuralnetworks::utils Loading neuralnetworks/aidl/utils/src/Service.cpp +6 −4 Original line number Diff line number Diff line Loading @@ -55,11 +55,12 @@ nn::GeneralResult<nn::Version> getAidlServiceFeatureLevel(IDevice* service) { } // namespace nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) { nn::GeneralResult<nn::SharedDevice> getDevice( const std::string& instanceName, ::android::nn::Version::Level maxFeatureLevelAllowed) { auto fullName = std::string(IDevice::descriptor) + "/" + instanceName; hal::utils::ResilientDevice::Factory makeDevice = [instanceName, name = std::move(fullName)](bool blocking) -> nn::GeneralResult<nn::SharedDevice> { [instanceName, name = std::move(fullName), maxFeatureLevelAllowed](bool blocking) -> nn::GeneralResult<nn::SharedDevice> { std::add_pointer_t<AIBinder*(const char*)> getService; if (blocking) { if (__builtin_available(android __NNAPI_AIDL_MIN_ANDROID_API__, *)) { Loading @@ -79,7 +80,8 @@ nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) { << " returned nullptr"; } ABinderProcess_startThreadPool(); const auto featureLevel = NN_TRY(getAidlServiceFeatureLevel(service.get())); auto featureLevel = NN_TRY(getAidlServiceFeatureLevel(service.get())); featureLevel.level = std::min(featureLevel.level, maxFeatureLevelAllowed); return Device::create(instanceName, std::move(service), featureLevel); }; Loading neuralnetworks/utils/service/include/nnapi/hal/Service.h +12 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,18 @@ struct SharedDeviceAndUpdatability { bool isDeviceUpdatable = false; }; std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers); /** * @brief Get the NNAPI sAIDL and HIDL services declared in the VINTF. * * @pre maxFeatureLevelAllowed >= Version::Level::FEATURE_LEVEL_5 * * @param includeUpdatableDrivers Allow updatable drivers to be used. * @param maxFeatureLevelAllowed Maximum version of driver allowed to be used. Any driver version * exceeding this must be clamped to `maxFeatureLevelAllowed`. * @return A list of devices and whether each device is updatable or not. */ std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers, nn::Version::Level maxFeatureLevelAllowed); } // namespace android::hardware::neuralnetworks::service Loading neuralnetworks/utils/service/src/Service.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevi void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, std::unordered_set<std::string>* registeredDevices, bool includeUpdatableDrivers) { bool includeUpdatableDrivers, nn::Version::Level maxFeatureLevelAllowed) { CHECK(devices != nullptr); CHECK(registeredDevices != nullptr); Loading @@ -100,7 +100,7 @@ void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, continue; } if (const auto [it, unregistered] = registeredDevices->insert(name); unregistered) { auto maybeDevice = aidl_hal::utils::getDevice(name); auto maybeDevice = aidl_hal::utils::getDevice(name, maxFeatureLevelAllowed); if (maybeDevice.has_value()) { auto device = std::move(maybeDevice).value(); CHECK(device != nullptr); Loading @@ -116,11 +116,14 @@ void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, } // namespace std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers) { std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers, nn::Version::Level maxFeatureLevelAllowed) { std::vector<SharedDeviceAndUpdatability> devices; std::unordered_set<std::string> registeredDevices; getAidlDevices(&devices, ®isteredDevices, includeUpdatableDrivers); CHECK_GE(maxFeatureLevelAllowed, nn::Version::Level::FEATURE_LEVEL_5); getAidlDevices(&devices, ®isteredDevices, includeUpdatableDrivers, maxFeatureLevelAllowed); getHidlDevicesForVersion(V1_3::IDevice::descriptor, &V1_3::utils::getDevice, &devices, ®isteredDevices); Loading Loading
neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Service.h +2 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,8 @@ namespace aidl::android::hardware::neuralnetworks::utils { ::android::nn::GeneralResult<::android::nn::SharedDevice> getDevice(const std::string& name); ::android::nn::GeneralResult<::android::nn::SharedDevice> getDevice( const std::string& name, ::android::nn::Version::Level maxFeatureLevelAllowed); } // namespace aidl::android::hardware::neuralnetworks::utils Loading
neuralnetworks/aidl/utils/src/Service.cpp +6 −4 Original line number Diff line number Diff line Loading @@ -55,11 +55,12 @@ nn::GeneralResult<nn::Version> getAidlServiceFeatureLevel(IDevice* service) { } // namespace nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) { nn::GeneralResult<nn::SharedDevice> getDevice( const std::string& instanceName, ::android::nn::Version::Level maxFeatureLevelAllowed) { auto fullName = std::string(IDevice::descriptor) + "/" + instanceName; hal::utils::ResilientDevice::Factory makeDevice = [instanceName, name = std::move(fullName)](bool blocking) -> nn::GeneralResult<nn::SharedDevice> { [instanceName, name = std::move(fullName), maxFeatureLevelAllowed](bool blocking) -> nn::GeneralResult<nn::SharedDevice> { std::add_pointer_t<AIBinder*(const char*)> getService; if (blocking) { if (__builtin_available(android __NNAPI_AIDL_MIN_ANDROID_API__, *)) { Loading @@ -79,7 +80,8 @@ nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) { << " returned nullptr"; } ABinderProcess_startThreadPool(); const auto featureLevel = NN_TRY(getAidlServiceFeatureLevel(service.get())); auto featureLevel = NN_TRY(getAidlServiceFeatureLevel(service.get())); featureLevel.level = std::min(featureLevel.level, maxFeatureLevelAllowed); return Device::create(instanceName, std::move(service), featureLevel); }; Loading
neuralnetworks/utils/service/include/nnapi/hal/Service.h +12 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,18 @@ struct SharedDeviceAndUpdatability { bool isDeviceUpdatable = false; }; std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers); /** * @brief Get the NNAPI sAIDL and HIDL services declared in the VINTF. * * @pre maxFeatureLevelAllowed >= Version::Level::FEATURE_LEVEL_5 * * @param includeUpdatableDrivers Allow updatable drivers to be used. * @param maxFeatureLevelAllowed Maximum version of driver allowed to be used. Any driver version * exceeding this must be clamped to `maxFeatureLevelAllowed`. * @return A list of devices and whether each device is updatable or not. */ std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers, nn::Version::Level maxFeatureLevelAllowed); } // namespace android::hardware::neuralnetworks::service Loading
neuralnetworks/utils/service/src/Service.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevi void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, std::unordered_set<std::string>* registeredDevices, bool includeUpdatableDrivers) { bool includeUpdatableDrivers, nn::Version::Level maxFeatureLevelAllowed) { CHECK(devices != nullptr); CHECK(registeredDevices != nullptr); Loading @@ -100,7 +100,7 @@ void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, continue; } if (const auto [it, unregistered] = registeredDevices->insert(name); unregistered) { auto maybeDevice = aidl_hal::utils::getDevice(name); auto maybeDevice = aidl_hal::utils::getDevice(name, maxFeatureLevelAllowed); if (maybeDevice.has_value()) { auto device = std::move(maybeDevice).value(); CHECK(device != nullptr); Loading @@ -116,11 +116,14 @@ void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, } // namespace std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers) { std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers, nn::Version::Level maxFeatureLevelAllowed) { std::vector<SharedDeviceAndUpdatability> devices; std::unordered_set<std::string> registeredDevices; getAidlDevices(&devices, ®isteredDevices, includeUpdatableDrivers); CHECK_GE(maxFeatureLevelAllowed, nn::Version::Level::FEATURE_LEVEL_5); getAidlDevices(&devices, ®isteredDevices, includeUpdatableDrivers, maxFeatureLevelAllowed); getHidlDevicesForVersion(V1_3::IDevice::descriptor, &V1_3::utils::getDevice, &devices, ®isteredDevices); Loading