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

Function _maybe_copy_to_context_device

tensorflow/python/ops/script_ops.py:49–59  ·  view source on GitHub ↗

Copy an EagerTensor to the current device if it's not on `device_name`.

(tensor, device_name)

Source from the content-addressed store, hash-verified

47
48
49def _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
62class EagerFunc(object):

Callers 1

__call__Method · 0.85

Calls 1

_copyMethod · 0.80

Tested by

no test coverage detected