dpctl.memory

Subpackage dpctl.memory exposes Unified Shared Memory (USM) operations.

Unified Shared Memory is a pointer-based memory management in SYCL guaranteeing that the host and all devices use a unified address space. As described in the SYCL specification:

Pointer values in the unified address space will always refer to the same location in memory. The unified address space encompasses the host and one or more devices. Note that this does not require addresses in the unified address space to be accessible on all devices, just that pointer values will be consistent.

Three types of USM allocations are supported:

USM allocation type

Description

"device"

Allocations in device memory accessible by the device but not by the host

"shared"

Allocations in device memory accessible by both the host and the device

"host"

Allocations in host memory accessible by both the host and the device

Python classes representing USM allocations

MemoryUSMDevice

Class representing allocation of SYCL USM-device memory.

MemoryUSMShared

An object representing allocation of SYCL USM-shared memory.

MemoryUSMHost

An object representing allocation of SYCL USM-host memory.

Python objects representing USM allocations provide __sycl_usm_array_interface__ attribute. A Python object can be converted to one of these classes using the following function:

as_usm_memory

Converts Python object with __sycl_usm_array_interface__ property to one of MemoryUSMShared, MemoryUSMDevice, or MemoryUSMHost instances depending on the type of USM allocation they represent.

Should the USM allocation fail, the following Python exception will be raised:

USMAllocationError

An exception raised when Universal Shared Memory (USM) allocation call returns a null pointer, signaling a failure to perform the allocation.