dpctl.memory¶
Data Parallel Control Memory
dpctl.memory provides Python objects for untyped USM memory container of bytes for each kind of USM pointers: shared pointers, device pointers and host pointers.
Shared and host pointers are accessible from both host and a device, while device pointers are only accessible from device.
Python objects corresponding to shared and host pointers implement Python simple buffer protocol. It is therefore possible to use these objects to maniputalate USM memory using NumPy or bytearray, memoryview, or array.array classes.
Classes¶
-
class
dpctl.memory.
MemoryUSMDevice
(nbytes, alignment=0, queue=None, copy=False)¶ allocates nbytes of USM device memory.
Non-positive alignments are not used (malloc_device is used instead). For the queue=None case the
dpctl.SyclQueue()
is used to allocate memory.MemoryUSMDevice(usm_obj) constructor create instance from usm_obj expected to implement __sycl_usm_array_interface__ protocol and exposing a contiguous block of USM device allocation. Use copy=True to perform a copy if USM type of the allocation represented by the argument is other than ‘device’.
-
copy_from_device
()¶ Copy SYCL memory underlying the argument object into the memory of the instance
-
copy_from_host
()¶ Copy content of Python buffer provided by obj to instance memory.
-
copy_to_host
()¶ Copy content of instance’s memory into memory of
obj
, or allocate NumPy array ofobj
isNone
.
-
get_usm_type
(syclobj=None)¶ Returns the type of USM allocation using Sycl context carried by syclobj keyword argument. Value of None is understood to query against self.sycl_context - the context used to create the allocation.
-
nbytes
¶ Extent of this USM buffer in bytes.
-
reference_obj
¶ Reference to the Python object owning this USM buffer.
-
size
¶ Extent of this USM buffer in bytes.
-
sycl_context
¶ dpctl.SyclContext
the USM pointer is bound to.
-
sycl_device
¶ dpctl.SyclDevice
the USM pointer is bound to.
-
tobytes
()¶ Constructs bytes object populated with copy of USM memory.
-
-
class
dpctl.memory.
MemoryUSMHost
(nbytes, alignment=0, queue=None, copy=False)¶ allocates nbytes of USM host memory.
Non-positive alignments are not used (malloc_host is used instead). For the queue=None case the
dpctl.SyclQueue()
is used to allocate memory.MemoryUSMDevice(usm_obj) constructor create instance from usm_obj expected to implement __sycl_usm_array_interface__ protocol and to expose a contiguous block of USM host allocation. Use copy=True to perform a copy if USM type of the allocation represented by the argument is other than ‘host’.
-
copy_from_device
()¶ Copy SYCL memory underlying the argument object into the memory of the instance
-
copy_from_host
()¶ Copy content of Python buffer provided by obj to instance memory.
-
copy_to_host
()¶ Copy content of instance’s memory into memory of
obj
, or allocate NumPy array ofobj
isNone
.
-
get_usm_type
(syclobj=None)¶ Returns the type of USM allocation using Sycl context carried by syclobj keyword argument. Value of None is understood to query against self.sycl_context - the context used to create the allocation.
-
nbytes
¶ Extent of this USM buffer in bytes.
-
reference_obj
¶ Reference to the Python object owning this USM buffer.
-
size
¶ Extent of this USM buffer in bytes.
-
sycl_context
¶ dpctl.SyclContext
the USM pointer is bound to.
-
sycl_device
¶ dpctl.SyclDevice
the USM pointer is bound to.
-
tobytes
()¶ Constructs bytes object populated with copy of USM memory.
-
allocates nbytes of USM shared memory.
Non-positive alignments are not used (malloc_shared is used instead). For the queue=None case the
dpctl.SyclQueue()
is used to allocate memory.MemoryUSMShared(usm_obj) constructor creates instance from usm_obj expected to implement __sycl_usm_array_interface__ protocol and to expose a contiguous block of USM shared allocation. Use copy=True to perform a copy if USM type of the allocation represented by the argument is other than ‘shared’.
Copy SYCL memory underlying the argument object into the memory of the instance
Copy content of Python buffer provided by obj to instance memory.
Copy content of instance’s memory into memory of
obj
, or allocate NumPy array ofobj
isNone
.
Returns the type of USM allocation using Sycl context carried by syclobj keyword argument. Value of None is understood to query against self.sycl_context - the context used to create the allocation.
Extent of this USM buffer in bytes.
Reference to the Python object owning this USM buffer.
Extent of this USM buffer in bytes.
dpctl.SyclContext
the USM pointer is bound to.
dpctl.SyclDevice
the USM pointer is bound to.
Constructs bytes object populated with copy of USM memory.
Functions¶
-
dpctl.memory.
as_usm_memory
(obj)¶ Converts Python object with __sycl_usm_array_interface__ property to one of
MemoryUSMShared
,MemoryUSMDevice
, orMemoryUSMHost
instances depending on the type of USM allocation they represent.- Raises
ValueError – When object does not expose the __sycl_usm_array_interface__, or it is malformed
TypeError – When unexpected types of entries in the interface are encountered
SyclQueueCreationError – When a
dpctl.SyclQueue
could not be created from the information given by the interface