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

Function GetDeviceForInput

tensorflow/core/common_runtime/eager/execute.cc:347–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345}
346
347Status GetDeviceForInput(const EagerContext* ctx, TensorHandle* tensor_handle,
348 Device** result) {
349 Device* cpu_device = ctx->HostCPU();
350 string device_name;
351 if (tensor_handle->IsRemote()) {
352 Device* device = tensor_handle->device();
353 device_name = device != nullptr ? device->name() : cpu_device->name();
354 *result = (device == nullptr ? cpu_device : device);
355 } else if (tensor_handle->dtype == DT_RESOURCE) {
356 // Use the resource's actual device because it is the device that will
357 // influence partitioning the multi-device function.
358 const Tensor* tensor;
359 TF_RETURN_IF_ERROR(tensor_handle->Tensor(&tensor));
360 const ResourceHandle& handle = tensor->flat<ResourceHandle>()(0);
361 device_name = handle.device();
362
363 Device* input_device;
364 TF_RETURN_IF_ERROR(
365 ctx->FindDeviceFromName(device_name.c_str(), &input_device));
366 *result = input_device;
367 } else if (MTypeFromDType(tensor_handle->dtype) == HOST_MEMORY) {
368 *result = cpu_device;
369 } else {
370 Device* device = tensor_handle->device();
371 device_name = device != nullptr ? device->name() : cpu_device->name();
372 *result = (device == nullptr ? cpu_device : device);
373 }
374 return Status::OK();
375}
376
377// Appends a TensorShape object to Fprint128 hash.
378// For best performance, we would like to avoid dynamic memory allocation in

Callers 1

EagerLocalExecuteFunction · 0.85

Calls 8

MTypeFromDTypeFunction · 0.85
HostCPUMethod · 0.80
IsRemoteMethod · 0.80
FindDeviceFromNameMethod · 0.80
c_strMethod · 0.80
nameMethod · 0.65
deviceMethod · 0.45
TensorMethod · 0.45

Tested by

no test coverage detected