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

Method __dlpack__

imperative/python/megengine/tensor.py:265–279  ·  view source on GitHub ↗
(self, stream=None)

Source from the content-addressed store, hash-verified

263 self._qparams = qparams
264
265 def __dlpack__(self, stream=None):
266 if stream is not None and not isinstance(stream, int):
267 raise TypeError("stream must be ``int`` or ``none``")
268 elif stream is not None and stream != -1:
269 mdevice, mrank, mstream = self.device.physical_locator
270 if mdevice == "gpu":
271 if mstream != stream:
272 device = "gpu{}:{}".format(mrank, mstream)
273 self.to(device, _borrow=True)
274 elif mdevice == "cpu":
275 device = "cpu{}:{}".format(mrank, mstream)
276 self.to(device, _borrow=True)
277 else:
278 raise ValueError("dlpack not support this device: {}!".format(mdevice))
279 return _to_dlpack(self)
280
281
282set_py_tensor_type(Tensor)

Callers 1

to_dlpackFunction · 0.80

Calls 2

toMethod · 0.95
formatMethod · 0.45

Tested by

no test coverage detected