Loading neuralnetworks/utils/service/include/nnapi/hal/Service.h +1 −8 Original line number Original line Diff line number Diff line Loading @@ -24,23 +24,16 @@ namespace android::hardware::neuralnetworks::service { namespace android::hardware::neuralnetworks::service { struct SharedDeviceAndUpdatability { nn::SharedDevice device; bool isDeviceUpdatable = false; }; /** /** * @brief Get the NNAPI sAIDL and HIDL services declared in the VINTF. * @brief Get the NNAPI sAIDL and HIDL services declared in the VINTF. * * * @pre maxFeatureLevelAllowed >= Version::Level::FEATURE_LEVEL_5 * @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 * @param maxFeatureLevelAllowed Maximum version of driver allowed to be used. Any driver version * exceeding this must be clamped to `maxFeatureLevelAllowed`. * exceeding this must be clamped to `maxFeatureLevelAllowed`. * @return A list of devices and whether each device is updatable or not. * @return A list of devices and whether each device is updatable or not. */ */ std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers, std::vector<nn::SharedDevice> getDevices(nn::Version::Level maxFeatureLevelAllowed); nn::Version::Level maxFeatureLevelAllowed); } // namespace android::hardware::neuralnetworks::service } // namespace android::hardware::neuralnetworks::service Loading neuralnetworks/utils/service/src/Service.cpp +8 −18 Original line number Original line Diff line number Diff line Loading @@ -51,7 +51,7 @@ namespace aidl_hal = ::aidl::android::hardware::neuralnetworks; using getDeviceFn = std::add_pointer_t<nn::GeneralResult<nn::SharedDevice>(const std::string&)>; using getDeviceFn = std::add_pointer_t<nn::GeneralResult<nn::SharedDevice>(const std::string&)>; void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevice, void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevice, std::vector<SharedDeviceAndUpdatability>* devices, std::vector<nn::SharedDevice>* devices, std::unordered_set<std::string>* registeredDevices) { std::unordered_set<std::string>* registeredDevices) { CHECK(devices != nullptr); CHECK(devices != nullptr); CHECK(registeredDevices != nullptr); CHECK(registeredDevices != nullptr); Loading @@ -63,7 +63,7 @@ void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevi if (maybeDevice.has_value()) { if (maybeDevice.has_value()) { auto device = std::move(maybeDevice).value(); auto device = std::move(maybeDevice).value(); CHECK(device != nullptr); CHECK(device != nullptr); devices->push_back({.device = std::move(device)}); devices->push_back(std::move(device)); } else { } else { LOG(ERROR) << "getDevice(" << name << ") failed with " << maybeDevice.error().code LOG(ERROR) << "getDevice(" << name << ") failed with " << maybeDevice.error().code << ": " << maybeDevice.error().message; << ": " << maybeDevice.error().message; Loading @@ -72,9 +72,9 @@ void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevi } } } } void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, void getAidlDevices(std::vector<nn::SharedDevice>* devices, std::unordered_set<std::string>* registeredDevices, std::unordered_set<std::string>* registeredDevices, bool includeUpdatableDrivers, nn::Version::Level maxFeatureLevelAllowed) { nn::Version::Level maxFeatureLevelAllowed) { CHECK(devices != nullptr); CHECK(devices != nullptr); CHECK(registeredDevices != nullptr); CHECK(registeredDevices != nullptr); Loading @@ -91,21 +91,12 @@ void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, } } for (const auto& name : names) { for (const auto& name : names) { bool isDeviceUpdatable = false; if (__builtin_available(android __NNAPI_AIDL_MIN_ANDROID_API__, *)) { const auto instance = std::string(aidl_hal::IDevice::descriptor) + '/' + name; isDeviceUpdatable = AServiceManager_isUpdatableViaApex(instance.c_str()); } if (isDeviceUpdatable && !includeUpdatableDrivers) { continue; } if (const auto [it, unregistered] = registeredDevices->insert(name); unregistered) { if (const auto [it, unregistered] = registeredDevices->insert(name); unregistered) { auto maybeDevice = aidl_hal::utils::getDevice(name, maxFeatureLevelAllowed); auto maybeDevice = aidl_hal::utils::getDevice(name, maxFeatureLevelAllowed); if (maybeDevice.has_value()) { if (maybeDevice.has_value()) { auto device = std::move(maybeDevice).value(); auto device = std::move(maybeDevice).value(); CHECK(device != nullptr); CHECK(device != nullptr); devices->push_back( devices->push_back(std::move(device)); {.device = std::move(device), .isDeviceUpdatable = isDeviceUpdatable}); } else { } else { LOG(ERROR) << "getDevice(" << name << ") failed with " << maybeDevice.error().code LOG(ERROR) << "getDevice(" << name << ") failed with " << maybeDevice.error().code << ": " << maybeDevice.error().message; << ": " << maybeDevice.error().message; Loading @@ -116,14 +107,13 @@ void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, } // namespace } // namespace std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers, std::vector<nn::SharedDevice> getDevices(nn::Version::Level maxFeatureLevelAllowed) { nn::Version::Level maxFeatureLevelAllowed) { std::vector<nn::SharedDevice> devices; std::vector<SharedDeviceAndUpdatability> devices; std::unordered_set<std::string> registeredDevices; std::unordered_set<std::string> registeredDevices; CHECK_GE(maxFeatureLevelAllowed, nn::Version::Level::FEATURE_LEVEL_5); CHECK_GE(maxFeatureLevelAllowed, nn::Version::Level::FEATURE_LEVEL_5); getAidlDevices(&devices, ®isteredDevices, includeUpdatableDrivers, maxFeatureLevelAllowed); getAidlDevices(&devices, ®isteredDevices, maxFeatureLevelAllowed); getHidlDevicesForVersion(V1_3::IDevice::descriptor, &V1_3::utils::getDevice, &devices, getHidlDevicesForVersion(V1_3::IDevice::descriptor, &V1_3::utils::getDevice, &devices, ®isteredDevices); ®isteredDevices); Loading Loading
neuralnetworks/utils/service/include/nnapi/hal/Service.h +1 −8 Original line number Original line Diff line number Diff line Loading @@ -24,23 +24,16 @@ namespace android::hardware::neuralnetworks::service { namespace android::hardware::neuralnetworks::service { struct SharedDeviceAndUpdatability { nn::SharedDevice device; bool isDeviceUpdatable = false; }; /** /** * @brief Get the NNAPI sAIDL and HIDL services declared in the VINTF. * @brief Get the NNAPI sAIDL and HIDL services declared in the VINTF. * * * @pre maxFeatureLevelAllowed >= Version::Level::FEATURE_LEVEL_5 * @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 * @param maxFeatureLevelAllowed Maximum version of driver allowed to be used. Any driver version * exceeding this must be clamped to `maxFeatureLevelAllowed`. * exceeding this must be clamped to `maxFeatureLevelAllowed`. * @return A list of devices and whether each device is updatable or not. * @return A list of devices and whether each device is updatable or not. */ */ std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers, std::vector<nn::SharedDevice> getDevices(nn::Version::Level maxFeatureLevelAllowed); nn::Version::Level maxFeatureLevelAllowed); } // namespace android::hardware::neuralnetworks::service } // namespace android::hardware::neuralnetworks::service Loading
neuralnetworks/utils/service/src/Service.cpp +8 −18 Original line number Original line Diff line number Diff line Loading @@ -51,7 +51,7 @@ namespace aidl_hal = ::aidl::android::hardware::neuralnetworks; using getDeviceFn = std::add_pointer_t<nn::GeneralResult<nn::SharedDevice>(const std::string&)>; using getDeviceFn = std::add_pointer_t<nn::GeneralResult<nn::SharedDevice>(const std::string&)>; void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevice, void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevice, std::vector<SharedDeviceAndUpdatability>* devices, std::vector<nn::SharedDevice>* devices, std::unordered_set<std::string>* registeredDevices) { std::unordered_set<std::string>* registeredDevices) { CHECK(devices != nullptr); CHECK(devices != nullptr); CHECK(registeredDevices != nullptr); CHECK(registeredDevices != nullptr); Loading @@ -63,7 +63,7 @@ void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevi if (maybeDevice.has_value()) { if (maybeDevice.has_value()) { auto device = std::move(maybeDevice).value(); auto device = std::move(maybeDevice).value(); CHECK(device != nullptr); CHECK(device != nullptr); devices->push_back({.device = std::move(device)}); devices->push_back(std::move(device)); } else { } else { LOG(ERROR) << "getDevice(" << name << ") failed with " << maybeDevice.error().code LOG(ERROR) << "getDevice(" << name << ") failed with " << maybeDevice.error().code << ": " << maybeDevice.error().message; << ": " << maybeDevice.error().message; Loading @@ -72,9 +72,9 @@ void getHidlDevicesForVersion(const std::string& descriptor, getDeviceFn getDevi } } } } void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, void getAidlDevices(std::vector<nn::SharedDevice>* devices, std::unordered_set<std::string>* registeredDevices, std::unordered_set<std::string>* registeredDevices, bool includeUpdatableDrivers, nn::Version::Level maxFeatureLevelAllowed) { nn::Version::Level maxFeatureLevelAllowed) { CHECK(devices != nullptr); CHECK(devices != nullptr); CHECK(registeredDevices != nullptr); CHECK(registeredDevices != nullptr); Loading @@ -91,21 +91,12 @@ void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, } } for (const auto& name : names) { for (const auto& name : names) { bool isDeviceUpdatable = false; if (__builtin_available(android __NNAPI_AIDL_MIN_ANDROID_API__, *)) { const auto instance = std::string(aidl_hal::IDevice::descriptor) + '/' + name; isDeviceUpdatable = AServiceManager_isUpdatableViaApex(instance.c_str()); } if (isDeviceUpdatable && !includeUpdatableDrivers) { continue; } if (const auto [it, unregistered] = registeredDevices->insert(name); unregistered) { if (const auto [it, unregistered] = registeredDevices->insert(name); unregistered) { auto maybeDevice = aidl_hal::utils::getDevice(name, maxFeatureLevelAllowed); auto maybeDevice = aidl_hal::utils::getDevice(name, maxFeatureLevelAllowed); if (maybeDevice.has_value()) { if (maybeDevice.has_value()) { auto device = std::move(maybeDevice).value(); auto device = std::move(maybeDevice).value(); CHECK(device != nullptr); CHECK(device != nullptr); devices->push_back( devices->push_back(std::move(device)); {.device = std::move(device), .isDeviceUpdatable = isDeviceUpdatable}); } else { } else { LOG(ERROR) << "getDevice(" << name << ") failed with " << maybeDevice.error().code LOG(ERROR) << "getDevice(" << name << ") failed with " << maybeDevice.error().code << ": " << maybeDevice.error().message; << ": " << maybeDevice.error().message; Loading @@ -116,14 +107,13 @@ void getAidlDevices(std::vector<SharedDeviceAndUpdatability>* devices, } // namespace } // namespace std::vector<SharedDeviceAndUpdatability> getDevices(bool includeUpdatableDrivers, std::vector<nn::SharedDevice> getDevices(nn::Version::Level maxFeatureLevelAllowed) { nn::Version::Level maxFeatureLevelAllowed) { std::vector<nn::SharedDevice> devices; std::vector<SharedDeviceAndUpdatability> devices; std::unordered_set<std::string> registeredDevices; std::unordered_set<std::string> registeredDevices; CHECK_GE(maxFeatureLevelAllowed, nn::Version::Level::FEATURE_LEVEL_5); CHECK_GE(maxFeatureLevelAllowed, nn::Version::Level::FEATURE_LEVEL_5); getAidlDevices(&devices, ®isteredDevices, includeUpdatableDrivers, maxFeatureLevelAllowed); getAidlDevices(&devices, ®isteredDevices, maxFeatureLevelAllowed); getHidlDevicesForVersion(V1_3::IDevice::descriptor, &V1_3::utils::getDevice, &devices, getHidlDevicesForVersion(V1_3::IDevice::descriptor, &V1_3::utils::getDevice, &devices, ®isteredDevices); ®isteredDevices); Loading