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

Method to

imperative/python/megengine/tensor.py:198–208  ·  view source on GitHub ↗

r"""Copy self :class:`~.Tensor` to specified device. See :func:`~.copy`

(self, device, *, _borrow=False)

Source from the content-addressed store, hash-verified

196 self *= 0
197
198 def to(self, device, *, _borrow=False):
199 r"""Copy self :class:`~.Tensor` to specified device. See :func:`~.copy`"""
200 if isinstance(device, str) and not _valid_device(device):
201 raise ValueError(
202 "invalid device name {}. For the correct format of the device name, please refer to the instruction of megengine.device.set_default_device()".format(
203 device
204 )
205 )
206 cn = as_device(device).to_c()
207 op = Borrow(comp_node=cn) if _borrow else Copy(comp_node=cn)
208 return apply(op, self)[0]
209
210 @property
211 def requires_grad(self):

Callers 13

__dlpack__Method · 0.95
test_PoissonRNGFunction · 0.95
test_MultinomialRNGFunction · 0.95
test_ExponentialRNGFunction · 0.95
test_borrowFunction · 0.95
test_stream_memFunction · 0.95
forwardMethod · 0.45
convert_params_to_xlaMethod · 0.45
executeMethod · 0.45
fwdFunction · 0.45

Calls 6

_valid_deviceFunction · 0.85
as_deviceFunction · 0.85
to_cMethod · 0.80
CopyClass · 0.50
applyFunction · 0.50
formatMethod · 0.45

Tested by 8

test_PoissonRNGFunction · 0.76
test_MultinomialRNGFunction · 0.76
test_ExponentialRNGFunction · 0.76
test_borrowFunction · 0.76
test_stream_memFunction · 0.76
fwdFunction · 0.36
copy_testFunction · 0.36