mindspore.ops.move_to

View Source On Gitee
mindspore.ops.move_to(input, to='CPU', blocking=True)[source]

Copy tensor to target device synchronously or asynchronously, default synchronously.

Note

This interface currently only supports Graph mode with jit_level of O0 or O1.

Parameters
  • input (Union[Tensor, list[int], tuple[int]]) – The input tensor. When the input is list and tuple, it will be converted to tensor before copying.

  • to (str, optional) – Specify the target device, with optional values of "Ascend" and "CPU". Default "CPU" .

  • blocking (bool, optional) – Whether use synchronous copying. Default True.

Returns

A new tensor on target device.

Supported Platforms:

Ascend CPU

Examples

>>> import mindspore
>>> from mindspore import nn, ops, Tensor
>>> mindspore.set_context(mode=mindspore.GRAPH_MODE)
>>> class MoveToNet(nn.Cell):
...     def __init__(self):
...         super().__init__()
...
...     def construct(self, x):
...         cpu_x = ops.move_to(x, "CPU")
...         npu_x = ops.move_to(cpu_x, "Ascend")
...         return npu_x
...
>>> net = MoveToNet()
>>> x = Tensor([1, 2, 3], mindspore.int64)
>>> y = net(x)
>>> print(y)
[1 2 3]