File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -487,16 +487,19 @@ will mean duplicating the memory. Do not do this for very large arrays:
487487
488488.. note ::
489489
490- Note that GPU tensors can't be converted to NumPy arrays since NumPy doesn't
491- support GPU devices:
490+ GPU tensors cannot be directly zero-copy converted to NumPy arrays since
491+ NumPy does not support GPU devices. However, since DLPack v1, cross-device
492+ copy is supported via the ``device `` parameter:
492493
493494 >>> x_torch = torch.arange(5 , device = ' cuda' )
494- >>> np.from_dlpack(x_torch)
495+ >>> np.from_dlpack(x_torch) # fails: implicit device=None means same device
495496 Traceback (most recent call last):
496497 File "<stdin>", line 1, in <module>
497498 RuntimeError: Unsupported device in DLTensor.
499+ >>> np.from_dlpack(x_torch, device = ' cpu' ) # works: explicit copy to CPU
500+ array([0, 1, 2, 3, 4])
498501
499- But, if both libraries support the device the data buffer is on, it is
502+ If both libraries support the device the data buffer is on, it is
500503 possible to use the ``__dlpack__ `` protocol (e.g. PyTorch _ and CuPy _):
501504
502505 >>> x_torch = torch.arange(5 , device = ' cuda' )
You can’t perform that action at this time.
0 commit comments