dpnp.ndarray.to_device

method

ndarray.to_device(device, /, *, stream=None)

Transfers this array to specified target device.

Parameters:
  • device ({string, SyclDevice, SyclQueue}) -- Array API concept of target device. It can be an OneAPI filter selector string, an instance of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, or a dpctl.tensor.Device object returned by dpnp.dpnp_array.dpnp_array.device property.

  • stream ({SyclQueue, None}, optional) -- Execution queue to synchronize with. If None, synchronization is not performed. Default: None.

Returns:

out -- A view if data copy is not required, and a copy otherwise. If copying is required, it is done by copying from the original allocation device to the host, followed by copying from host to the target device.

Return type:

dpnp.ndarray

Examples

>>> import dpnp as np, dpctl
>>> x = np.full(100, 2, dtype=np.int64)
>>> q_prof = dpctl.SyclQueue(x.sycl_device, property="enable_profiling")
>>> # return a view with profile-enabled queue
>>> y = x.to_device(q_prof)
>>> timer = dpctl.SyclTimer()
>>> with timer(q_prof):
...     z = y * y
>>> print(timer.dt)