MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GetDeviceHandle

Function GetDeviceHandle

tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:317–345  ·  view source on GitHub ↗

Return NNAPI device handle with the provided null-terminated device name. If no matching device could be found, nullptr will be returned.

Source from the content-addressed store, hash-verified

315// Return NNAPI device handle with the provided null-terminated device name. If
316// no matching device could be found, nullptr will be returned.
317ANeuralNetworksDevice* 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.
348uint64_t GetHash(const TfLiteIntArray* int_array) {

Callers 2

InitMethod · 0.85
DoPrepareMethod · 0.85

Calls 5

SimpleJoinFunction · 0.85
c_strMethod · 0.80
NnApiImplementationFunction · 0.50
push_backMethod · 0.45
ReportErrorMethod · 0.45

Tested by

no test coverage detected