Copy an EagerTensor to the current device if it's not on `device_name`.
(tensor, device_name)
| 47 | |
| 48 | |
| 49 | def _maybe_copy_to_context_device(tensor, device_name): |
| 50 | """Copy an EagerTensor to the current device if it's not on `device_name`.""" |
| 51 | in_device = tensor.backing_device |
| 52 | if device_name == in_device: |
| 53 | return tensor |
| 54 | else: |
| 55 | # Note that EagerTensor._copy bypasses the placer and copies to the context |
| 56 | # device, which means e.g. int32 Tensors which would normally be forced onto |
| 57 | # the CPU can instead be placed on the GPU. This is necessary so that the |
| 58 | # PyFunc kernel always returns Tensors on the device it's executing on. |
| 59 | return tensor._copy() # pylint: disable=protected-access |
| 60 | |
| 61 | |
| 62 | class EagerFunc(object): |