| 345 | } |
| 346 | |
| 347 | Status 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 |
no test coverage detected