dpctl.tensor.usm_ndarray
- class dpctl.tensor.usm_ndarray(shape, dtype=None, strides=None, buffer='device', offset=0, order='C', buffer_ctor_kwargs=dict(), array_namespace=None)
An array object represents a multidimensional tensor of numeric elements stored in a USM allocation on a SYCL device.
- Arg:
- shape (int, tuple):
Shape of the array to be created.
- dtype (str, dtype):
Array data type, i.e. the type of array elements. If
dtype
has the valueNone
, it is determined by default floating point type supported by target device. The supported types arebool
boolean type
int8
,int16
,int32
,int64
,signed integer types
uint8
,uint16
,uint32
,uint64
,unsigned integer types
float16
half-precision floating type, supported if target device’s property
has_aspect_fp16
isTrue
float32
,complex64
single-precision real and complex floating types
float64
,complex128
double-precision real and complex floating types, supported if target device’s property
has_aspect_fp64
isTrue
.
Default:
None
.- strides (tuple, optional):
Strides of the array to be created in elements. If
strides
has the valueNone
, it is determined by theshape
of the array and the requestedorder
. Default:None
.- buffer (str, object, optional):
A string corresponding to the type of USM allocation to make, or a Python object representing a USM memory allocation, i.e.
dpctl.memory.MemoryUSMDevice
,dpctl.memory.MemoryUSMShared
, ordpctl.memory.MemoryUSMHost
. Recognized strings are"device"
,"shared"
, or"host"
. Additional arguments to the USM memory alloctors can be passed in a dictionary specified viabuffer_ctor_kwrds
keyword parameter. Default:"device"
.- offset (int, optional):
Offset of the array element with all zero indexes relative to the start of the provided buffer in elements. The argument is ignored if the
buffer
value is a string and the memory is allocated by the constructor. Default:0
.- order ({“C”, “F”}, optional):
The memory layout of the array when constructing using a new allocation. Value
"C"
corresponds to C-contiguous, or row-major memory layout, while value"F"
corresponds to F-contiguous, or column-major layout. Default:"C"
.- buffer_ctor_kwargs (dict, optional):
Dictionary with keyword parameters to use when creating a new USM memory allocation. See
dpctl.memory.MemoryUSMShared
for supported keyword arguments.- array_namespace (module, optional):
Array namespace module associated with this array. Default:
None
.
buffer
can be"shared"
,"host"
,"device"
to allocate new device memory by calling respective constructor with the specifiedbuffer_ctor_kwrds
;buffer
can be an instance ofdpctl.memory.MemoryUSMShared
,dpctl.memory.MemoryUSMDevice
, ordpctl.memory.MemoryUSMHost
;buffer
can also be anotherdpctl.tensor.usm_ndarray
instance, in which case its underlyingMemoryUSM*
buffer is used.Attributes:
Returns transposed array for 2D array, raises ValueError otherwise.
Returns data-API object representing residence of the array data.
Returns NumPy's dtype corresponding to the type of the array elements.
Returns
dpctl.tensor._flags
object.Returns imaginary component for arrays with complex data-types and returns zero array for all other data-types.
Size of array element in bytes.
Returns array where the last two dimensions are transposed.
Total bytes consumed by the elements of the array.
Gives the number of indices needed to address elements of this array.
Returns real component for arrays with complex data-types and returns itself for all other data-types.
Elements of the shape tuple give the lengths of the respective array dimensions.
Number of elements in the array.
Returns memory displacement in array elements, upon unit change of respective index.
Returns
dpctl.SyclContext
object to which USM data is bound.Returns
dpctl.SyclDevice
object on which USM data was allocated.Returns
dpctl.SyclQueue
object associated with USM data.Gives USM memory object underlying usm_array instance.
USM type of underlying memory.
Public methods:
to_device
(target_device)Transfers this array to specified target device.
Private methods:
_set_namespace
(mod)Sets array namespace to given module mod.
Attributes
- usm_ndarray.T
Returns transposed array for 2D array, raises ValueError otherwise.
- usm_ndarray._byte_bounds
Returns a 2-tuple with pointers to the end-points of the array
- usm_ndarray._element_offset
Returns the offset of the zero-index element of the array, in elements, relative to the start of memory allocation
- usm_ndarray._pointer
Returns USM pointer for data allocation encoded as integer
- usm_ndarray.device
Returns data-API object representing residence of the array data.
- usm_ndarray.dtype
Returns NumPy’s dtype corresponding to the type of the array elements.
- usm_ndarray.flags
Returns
dpctl.tensor._flags
object.
- usm_ndarray.imag
Returns imaginary component for arrays with complex data-types and returns zero array for all other data-types.
- usm_ndarray.itemsize
Size of array element in bytes.
- usm_ndarray.mT
Returns array where the last two dimensions are transposed.
- usm_ndarray.nbytes
Total bytes consumed by the elements of the array.
- usm_ndarray.ndim
Gives the number of indices needed to address elements of this array.
- usm_ndarray.real
Returns real component for arrays with complex data-types and returns itself for all other data-types.
- usm_ndarray.shape
Elements of the shape tuple give the lengths of the respective array dimensions.
- usm_ndarray.size
Number of elements in the array.
- usm_ndarray.strides
Returns memory displacement in array elements, upon unit change of respective index.
E.g. for strides (s1, s2, s3) and multi-index (i1, i2, i3)
a[i1, i2, i3] == (&a[0,0,0])[ s1*s1 + s2*i2 + s3*i3]
- usm_ndarray.sycl_context
Returns
dpctl.SyclContext
object to which USM data is bound.
- usm_ndarray.sycl_device
Returns
dpctl.SyclDevice
object on which USM data was allocated.
- usm_ndarray.sycl_queue
Returns
dpctl.SyclQueue
object associated with USM data.
- usm_ndarray.usm_data
Gives USM memory object underlying usm_array instance.
- usm_ndarray.usm_type
USM type of underlying memory. Can be
"device"
,"shared"
, or"host"
.See: https://docs.oneapi.com/versions/latest/dpcpp/iface/usm.html
Public methods
- dpctl.tensor.usm_ndarray.to_device(target_device)
Transfers this array to specified target device.
- Example:
import dpctl import dpctl.tensor as dpt x = dpt.full(10**6, 2, dtype="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)
- Parameters:
target_device (object) – Array API concept of target device. It can be a oneAPI filter selector string, an instance of
dpctl.SyclDevice
corresponding to a non-partitioned SYCL device, an instance ofdpctl.SyclQueue
, or adpctl.tensor.Device
object returned bydpctl.tensor.usm_array.device
.- Returns:
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:
Private methods
- dpctl.tensor.usm_ndarray._set_namespace(self, mod)
Sets array namespace to given module mod.