Return NNAPI device handle with the provided null-terminated device name. If no matching device could be found, nullptr will be returned.
| 315 | // Return NNAPI device handle with the provided null-terminated device name. If |
| 316 | // no matching device could be found, nullptr will be returned. |
| 317 | ANeuralNetworksDevice* GetDeviceHandle(TfLiteContext* context, |
| 318 | const char* device_name_ptr) { |
| 319 | if (!device_name_ptr) return nullptr; |
| 320 | ANeuralNetworksDevice* device_handle = nullptr; |
| 321 | std::string device_name(device_name_ptr); |
| 322 | uint32_t num_devices = 0; |
| 323 | NnApiImplementation()->ANeuralNetworks_getDeviceCount(&num_devices); |
| 324 | |
| 325 | std::vector<const char*> device_names; |
| 326 | for (uint32_t i = 0; i < num_devices; i++) { |
| 327 | ANeuralNetworksDevice* device = nullptr; |
| 328 | const char* buffer = nullptr; |
| 329 | NnApiImplementation()->ANeuralNetworks_getDevice(i, &device); |
| 330 | NnApiImplementation()->ANeuralNetworksDevice_getName(device, &buffer); |
| 331 | if (device_name == buffer) { |
| 332 | device_handle = device; |
| 333 | break; |
| 334 | } |
| 335 | device_names.push_back(buffer); |
| 336 | } |
| 337 | if (!device_handle) { |
| 338 | context->ReportError(context, |
| 339 | "Could not find the specified NNAPI accelerator: %s. " |
| 340 | "Must be one of: {%s}.", |
| 341 | device_name_ptr, |
| 342 | SimpleJoin(device_names, ",").c_str()); |
| 343 | } |
| 344 | return device_handle; |
| 345 | } |
| 346 | |
| 347 | // Compute the hash of a TfLiteIntArray. |
| 348 | uint64_t GetHash(const TfLiteIntArray* int_array) { |
no test coverage detected