Skip to content

Commit 29bc97d

Browse files
Merge pull request #990 from IntelPython/expand-to_device-docstring
Expanded doc-string of dpctl.tensor.usm_ndarray.to_device
2 parents ea4e009 + 335afd5 commit 29bc97d

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

dpctl/tensor/_usmarray.pyx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,43 @@ cdef class usm_ndarray:
638638
res.array_namespace_ = self.array_namespace_
639639
return res
640640

641-
def to_device(self, target_device):
641+
def to_device(self, target):
642642
"""
643-
Transfer array to target device
643+
Transfers this array to specified target device.
644+
645+
:Example:
646+
.. code-block:: python
647+
648+
import dpctl
649+
import dpctl.tensor as dpt
650+
651+
x = dpt.full(10**6, 2, dtype="int64")
652+
q_prof = dpctl.SyclQueue(
653+
x.sycl_device, property="enable_profiling")
654+
# return a view with profile-enabled queue
655+
y = x.to_device(q_prof)
656+
timer = dpctl.SyclTimer()
657+
with timer(q_prof):
658+
z = y * y
659+
print(timer.dt)
660+
661+
Args:
662+
target: array API concept of target device.
663+
It can be a oneAPI filter selector string,
664+
an instance of :class:`dpctl.SyclDevice` corresponding to a
665+
non-partitioned SYCL device, an instance of
666+
:class:`dpctl.SyclQueue`, or a :class:`dpctl.tensor.Device`
667+
object returned by :attr:`dpctl.tensor.usm_array.device`.
668+
669+
Returns:
670+
A view if data copy is not required, and a copy otherwise.
671+
If copying is required, it is done by copying from the original
672+
allocation device to the host, followed by copying from host
673+
to the target device.
644674
"""
645675
cdef c_dpctl.DPCTLSyclQueueRef QRef = NULL
646676
cdef c_dpmem._Memory arr_buf
647-
d = Device.create_device(target_device)
677+
d = Device.create_device(target)
648678
if (d.sycl_context == self.sycl_context):
649679
arr_buf = <c_dpmem._Memory> self.usm_data
650680
QRef = (<c_dpctl.SyclQueue> d.sycl_queue).get_queue_ref()

0 commit comments

Comments
 (0)