copy

nvtripy.copy(input: Tensor, device: device) Tensor[source]

Copies the input tensor to the specified device.

Caution

This function cannot be used in a compiled function or nvtripy.Module because it depends on evaluating its inputs, which is not allowed during compilation.

Parameters:
  • input (Tensor) – [dtype=T1] Input tensor.

  • device (device) – The target device to copy the tensor to.

Returns:

[dtype=T1] A new tensor on the specified device.

Raises:

TripyException – If the input tensor is already on the specified device, as performing copies within the same device is currently not supported.

Return type:

Tensor

DATA TYPE CONSTRAINTS:
Example: Copying To CPU
1input = tp.Tensor([1, 2, 3], device=tp.device("gpu"))
2output = tp.copy(input, device=tp.device("cpu"))
Local Variables
>>> input
tensor([1, 2, 3], dtype=int32, loc=gpu:0, shape=(3,))

>>> output
tensor([1, 2, 3], dtype=int32, loc=cpu:0, shape=(3,))
Example: Copying To GPU
1input = tp.Tensor([1, 2, 3])
2output = tp.copy(input, device=tp.device("gpu"))
Local Variables
>>> input
tensor([1, 2, 3], dtype=int32, loc=cpu:0, shape=(3,))

>>> output
tensor([1, 2, 3], dtype=int32, loc=gpu:0, shape=(3,))