MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / copy

Function copy

imperative/python/megengine/functional/tensor.py:1209–1230  ·  view source on GitHub ↗

r"""Copies tensor to another device. Args: inp: input tensor. device: destination device. Examples: >>> import numpy as np >>> x = Tensor([1, 2, 3], np.int32) >>> F.copy(x, 'cpu1') Tensor([1 2 3], dtype=int32, device=cpu1:0) >>> F.

(inp, device=None)

Source from the content-addressed store, hash-verified

1207
1208
1209def copy(inp, device=None):
1210 r"""Copies tensor to another device.
1211
1212 Args:
1213 inp: input tensor.
1214 device: destination device.
1215
1216 Examples:
1217
1218 >>> import numpy as np
1219 >>> x = Tensor([1, 2, 3], np.int32)
1220
1221 >>> F.copy(x, 'cpu1')
1222 Tensor([1 2 3], dtype=int32, device=cpu1:0)
1223
1224 >>> F.copy(x, 'xpu0')
1225 Tensor([1 2 3], dtype=int32, device=xpu0:0)
1226
1227 """
1228 if device is None:
1229 return apply(Identity(), inp)[0]
1230 return apply(Copy(comp_node=as_device(device).to_c()), inp)[0]
1231
1232
1233def roll(

Callers 15

concatFunction · 0.70
stackFunction · 0.70
forwardMethod · 0.50
quantizeFunction · 0.50
quantize_qatFunction · 0.50
_flushMethod · 0.50
_load_cacheMethod · 0.50
device_waitMethod · 0.50
create_layoutFunction · 0.50
write_tupleFunction · 0.50
command_hashFunction · 0.50

Calls 5

as_deviceFunction · 0.85
to_cMethod · 0.80
applyFunction · 0.50
IdentityClass · 0.50
CopyClass · 0.50

Tested by 5

write_tupleFunction · 0.40
mavi_iter_data_valueFunction · 0.40
mesh_indexing_implFunction · 0.40
TESTFunction · 0.40
test_multibatchsizeFunction · 0.40