USM array object

The array object represents a multi-dimensional tensor of uniform elemental datatype allocated on a Device. The tensor in stored in a USM allocation, which can be accessed via usm_ndarray.base attribute.

Implementation of usm_ndarray conforms to Array API standard specification.

usm_ndarray(shape[, dtype, strides, buffer, ...])

An array object represents a multidimensional tensor of numeric elements stored in a USM allocation on a SYCL device.

Use usm_ndarray.to_device() to migrate array to different device

Migrate array to a different device
    from dpctl import tensor

    a = tensor.zeros(100, device="cpu")
    b = a.to_device("gpu")

Use usm_ndarray.device() to specify placement of new array

Create a USM-device empty array on the same device as another array
    from dpctl import tensor

    d = tensor.eye(100)
    u = tensor.full(d.shape, fill_value=0.5, usm_type="device", device=d.device)

Use usm_ndarray.mT() to transpose matrices in a array thought of as a stack of matrices

Transpose an array
    from dpctl import tensor

    # create stack of matrices
    proto = tensor.asarray([[2, 1], [3, 4]])
    ar = tensor.tile(proto, (5, 10, 10))

    # transpose each matrix in the stack
    arT = ar.mT