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 value None, it is determined by default floating point type supported by target device. The supported types are

bool:

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 is True

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 is True.

Default: None.

strides (tuple, optional):

Strides of the array to be created in elements. If strides has the value None, it is determined by the shape of the array and the requested order. 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, or dpctl.memory.MemoryUSMHost. Recognized strings are "device", "shared", or "host". Additional arguments to the USM memory allocators can be passed in a dictionary specified via buffer_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 specified buffer_ctor_kwrds; buffer can be an instance of dpctl.memory.MemoryUSMShared, dpctl.memory.MemoryUSMDevice, or dpctl.memory.MemoryUSMHost; buffer can also be another dpctl.tensor.usm_ndarray instance, in which case its underlying MemoryUSM* buffer is used.

Methods

to_device(target_device)

Transfers this array to specified target device.

Attributes

T

Returns transposed array for 2D array, raises ValueError otherwise.

device

Returns dpctl.tensor.Device object representing residence of the array data.

dtype

Returns NumPy's dtype corresponding to the type of the array elements.

flags

Returns dpctl.tensor._flags.Flags object.

imag

Returns view into imaginary component for arrays with complex data-types and returns new zero array for all other data-types.

itemsize

Size of array element in bytes.

mT

Returns array (a view) where the last two dimensions are transposed.

nbytes

Total bytes consumed by the elements of the array.

ndim

Gives the number of indices needed to address elements of this array.

real

Returns view into real component for arrays with complex data-types and returns itself for all other data-types.

shape

Elements of the shape tuple give the lengths of the respective array dimensions.

size

Number of elements in the array.

strides

Returns memory displacement in array elements, upon unit change of respective index.

sycl_context

Returns dpctl.SyclContext object to which USM data is bound.

sycl_device

Returns dpctl.SyclDevice object on which USM data was allocated.

sycl_queue

Returns dpctl.SyclQueue object associated with USM data.

usm_data

Gives USM memory object underlying usm_ndarray instance.

usm_type

USM type of underlying memory.

Special attributes

__dlpack_device__()

Gives a tuple (device_type, device_id) corresponding to DLDevice entry in DLTensor in DLPack protocol.

__dlpack__(*[, stream, max_version, ...])

Produces DLPack capsule.

__sycl_usm_array_interface__

Gives __sycl_usm_array_interface__ dictionary describing the array.

_pointer

Returns USM pointer to the start of array (element with zero multi-index) encoded as integer.

_element_offset

Returns the offset of the zero-index element of the array, in elements, relative to the start of memory allocation

_byte_bounds

Returns a 2-tuple with pointers to the end-points of the array