rocm.bindings.util.types#
2026-09-24
41 min read time
Advanced Micro Devices, Inc.
Classes#
CStr(pyobj) |
|
Datatype for handling device buffers. |
|
ListOfBytes(pyobj) |
|
ListOfInt(pyobj) |
|
ListOfInt64(pyobj) |
|
ListOfLong(pyobj) |
|
ListOfPointer(pyobj) |
|
ListOfUInt64(pyobj) |
|
ListOfUnsigned(pyobj) |
|
ListOfUnsignedLong(pyobj) |
|
NDBuffer(pyobj) |
|
Pointer(pyobj=None) |
|
PointerToInt(pyobj) |
|
PointerToInt64(pyobj) |
|
PointerToLong(pyobj) |
|
PointerToUInt64(pyobj) |
|
PointerToUnsigned(pyobj) |
|
PointerToUnsignedLong(pyobj) |
Module Contents#
- class rocm.bindings.util.types.CStr(pyobj)#
Bases:
PointerCStr(pyobj)
Datatype for handling C strings (
char *and related).Datatype for handling C strings (
char *). Cython’s parameter autoconversion creates duplicates of C strings and hence loses the original data’s address, which can be an issue.This implementation assumes that this type is mainly used like a Python
strin cases where it is returned by a function. Hence, the__getitem__,__repr__and__str__implementation of this class decode the underlying data asUTF-8string. ASCII is a subset of UTF-8. Note that this design choice is irrelevant for the case where the type is used as adapter to convert Python arguments to a C string.This datatype implements the Python buffer protocol. Therefore, different decoding of the underlying data can be achieved by passing this type to the constructor of
bytesor to other array types or memory views that can deal with Python buffers.- Pinning of
strandbytesinputs: strandbytesarguments are interned in the_retained_inputsclass dict for the lifetime of the program, so the C pointer handed to the backend remains valid even after the wrapper instance is collected and even if the backend retains the pointer past the call’s return (the COMGR compile cache reached viahiprtcis one such backend). Repeated calls with logically equal content reuse the same canonical bytes object and therefore the same C pointer, which preserves backend caches keyed on pointer identity. The intern table only grows with the number of distinct string contents ever passed.- Warning:
The program-lifetime pin above only applies to
strandbytesinputs. When the wrapper is constructed from another buffer-protocol object (bytearray,numpy.ndarray,memoryview, …) the source is pinned only for the wrapper instance’s lifetime viaPy_bufferacquisition. If the called C library stores the pointer into a library-managed structure and the wrapper then goes out of scope, memory errors are possible — pass abytes/str(which is interned) or hold a Python-side reference to the source for as long as the backend may dereference it.- Limitation:
This class is only designed for handling strings that encode each character with 8 bits (ASCII and UTF-8). Smaller or larger symbols are not supported.
The type can be initialized from the following Python objects:
-
Takes the pointer address
pyobj.valueand writes it toself._ptr. If needed, length information must be obtained viastrlenin this case. Note thatctypes.c_void_pseems to be identified as Python buffer for unknown reasons. Therefore, it must be checked for this type first. str:UTF-8 encoded, then interned via
CStr._retained_inputs.setdefault(b, b).self._ptrpoints into the canonical bytes object and is valid for the program’s lifetime.-
Interned via
CStr._retained_inputs.setdefault(pyobj, pyobj).self._ptrpoints into the canonical bytes object and is valid for the program’s lifetime. objectthat implements the Python buffer protocol:Note that
bytesalso implements the buffer protocol but is intercepted by the dedicated branch above so it takes the intern path instead ofPy_bufferacquisition. This branch therefore handlesbytearray,numpy.ndarray,memoryview, and similar mutable / typed buffers.If the object represents a simple contiguous array, writes the
Py_bufferassociated withpyobjtoself._py_buffer, sets theself._py_buffer_acquiredflag toTrue, and writesself._py_buffer.bufto the data pointerself._ptr. The source is pinned only for the wrapper’s lifetime (see Warning above).objectthat is accepted as input by__init__.
Type checks are performed in the above order.
- C Attributes:
- _ptr (
void *, protected): See
Pointerfor more information.- _shape (
Py_size_t[1], protected): Size of the wrapped zero-terminated C char, stored into first array element.
- _py_buffer (
Py_buffer, protected): See
Pointerfor more information.- _py_buffer_acquired (
bool, protected): See
Pointerfor more information.
- _ptr (
- decode(encoding=..., errors=...) Any#
CStr.decode(self, /, encoding=’utf-8’, errors=’strict’)
Return a
strobject with respect to the enconding.- See:
- encode(encoding=..., errors=...) Any#
CStr.encode(self, /, encoding=’utf-8’, errors=’strict’)
Return a
bytesobject with respect to the encoding.- See:
- free() void#
CStr.free(self) -> void
Free dynamically allocated data.
- Note:
Simply returns if the data pointer is NULL.
- Note:
Throws
RuntimeErrorif this instance does not own the data that ought to be freed.- Note:
Unsets the _is_ptr_owner flag.
- static fromObj(pyobj) Any#
CStr.fromObj(pyobj)
Creates a CStr from the given object.
In case
pyobjis itself aCStrinstance, this method returns it directly. No newCStris created.
- malloc(Py_ssize_tcontent_len) void#
CStr.malloc(self, Py_ssize_t content_len) -> void
Allocate a zeroed buffer with room for
content_lenchars plus a NUL terminator.Allocates
content_len + 1bytes and zero-fills them, so the buffer is always NUL-terminated: even a C callee that writes allcontent_lenbytes without terminating leaves the appended trailing byte as the terminator, keepingstrlen-based length reporting in-bounds.- Args:
- content_len (
Py_ssize_t): Number of content (non-terminator) bytes to reserve. The actual allocation is
content_len + 1to hold the appended NUL terminator.
- content_len (
- Note:
mallocappends a NUL terminator byte; pass the buffer capacity the C callee will be told about (e.g. HIP’slen), notlen + 1.- Note:
Throws
RuntimeErrorif the data pointer is not NULL as this indicates that this instance handles external data.- Note:
Sets the _is_ptr_owner flag.
- Pinning of
- class rocm.bindings.util.types.DeviceArray(*args, **kwargs)#
Bases:
NDBufferDatatype for handling device buffers.
Datatype for handling device buffers returned by
hipMallocand related device memory allocation routines.This type implements the CUDA array interface protocol.
It can be initialized from the following Python objects:
None:This will set the
self._ptrattribute toNULL. No shape and type information is available in this case!
int:Interprets the integer value as pointer address and writes it to
self._ptr. No shape and type information is available in this case!
ctypes.c_void_p:Takes the pointer address
pyobj.valueand writes it toself._ptr. No shape and type information is available in this case!
objectwith__cuda_array_interface__member:Takes the integer-valued pointer address, i.e. the first entry of the
datatuple frompyobj’s member__cuda_array_interface__and writes it toself._ptr. Copies shape and type information.
- Note:
Type checks are performed in the above order.
- Note:
Shape and type information and other metadata can be modified or overwritten after creation via the
configuremember function. be aware that you might need to pass the_force=Truekeyword argument — in particular if your instance was created from a type that does not implement the CUDA array interface protocol.- See:
- C Attributes:
- _ptr (
void *, protected): Stores a pointer to the data of the original Python object.
- _py_buffer (
Py_buffer, protected): Stores a pointer to the data of the original Python object.
- _py_buffer_acquired (
bool, protected): Stores a pointer to the data of the original Python object.
- _itemsize (
size_t, protected): Stores the itemsize.
- _cuda_array_interface (
dict, protected): The CUDA array interface metadata, handed out as a copy by
__cuda_array_interface__.- _pybuffer_obj (
object, protected): Keeps the exporter of a wrapped
Py_bufferalive.- _typestr_bytes (
bytes, protected): NUL-terminated format string handed to consumers of this Python buffer. Must stay alive as long as any view exists.
- _ptr (
- static DeviceArray(pyobj) Any#
DeviceArray.DeviceArray(pyobj)
Creates a NDBuffer from the given object.
In case
pyobjis itself aNDBufferinstance, this method returns it directly. No newNDBufferis created.
- class rocm.bindings.util.types.ListOfBytes(pyobj)#
Bases:
PointerListOfBytes(pyobj)
Handler for
list/tuplewhose entries arebytes,str, orCStr.Datatype for handling Python
listandtupleobjects with entries of typebytes,str, orCStrthat need to be converted to a pointer type when passed to the underlying C function.strentries are UTF-8 encoded transparently.The type can be initialized from the following Python objects:
list/tupleofbytes,str, orCStr:A
listortupleofbytes,str, orCStrobjects. In this case, this type allocates an array ofconst char*pointers wherein it stores the addresses from thelist/tupleentries.strentries are UTF-8 encoded;bytesand the encoded form ofstrentries are interned in theListOfBytes._retained_inputsclass dict for the program’s lifetime so the C pointers remain valid even if the backend retains them. Furthermore, the instance’sself._is_ptr_ownerC attribute is set toTrue.The interning covers the strings, not the array around them: the
const char**array lives exactly as long as this instance, which frees it in__dealloc__. Generated wrappers bind the adapter to a local variable, so the array is alive for the whole C call. If a C function retains the array pointer past its return, the caller must keep the adapter alive too — passListOfBytes([...])and hold that object, rather than a barelist.objectthat is accepted as input by__init__:
- Note:
Type checks are performed in the above order.
- C Attributes:
- _ptr (
void *, protected): See
Pointerfor more information.- _py_buffer (
Py_buffer, protected): See
Pointerfor more information.- _py_buffer_acquired (
bool, protected): See
Pointerfor more information.- _is_ptr_owner (
bint, protected): If this object is the owner of the allocated buffer. Defaults to
False.
- _ptr (
- static allocate(Py_ssize_tcount) Any#
ListOfBytes.allocate(Py_ssize_t count)
Allocate an owned, zero-initialized array of
countchar *slots.The returned
ListOfBytesowns the buffer (freed on garbage collection) and has a known length, so it is indexable, iterable, and convertible viato_list/to_tuple.
- static fromObj(pyobj) Any#
ListOfBytes.fromObj(pyobj)
Creates a ListOfBytes from the given object.
In case
pyobjis itself anListOfBytesinstance, this method returns it directly. No newListOfBytesis created.
- class rocm.bindings.util.types.ListOfInt(pyobj)#
Bases:
PointerListOfInt(pyobj)
Handler for
list/tuplewhose entries can be converted to C typeintDatatype for handling Python
listandtupleobjects with entries that can be converted to C typeint. Such entries might be of Python typeNone,int, or of anyctypesinteger type.The type can be initialized from the following Python objects:
list/tupleof types that can be converted to C typeint:A
listortupleof types that can be converted to C typeint. In this case, this type allocates an array of Cintvalues wherein it stores the values obtained from thelist/tupleentries. Furthermore, the instance’sself._is_ptr_ownerC attribute is set toTruein this case.The array lives exactly as long as this instance, which frees it in
__dealloc__. Generated wrappers bind the adapter to a local variable, so the array is alive for the whole C call. If a C function retains the pointer past its return, the caller must keep the adapter alive too — passListOfInt([...])and hold that object, rather than a barelist.objectthat is accepted as input by__init__:
- Note:
Type checks are performed in the above order.
- Note:
Simple, contiguous numpy and Python 3 array types can be passed directly to this routine as they implement the Python buffer protocol.
- C Attributes:
- _ptr (
void *, protected): See
Pointerfor more information.- _py_buffer (
Py_buffer, protected): See
Pointerfor more information.- _py_buffer_acquired (
bool, protected): See
Pointerfor more information.- _is_ptr_owner (
bint, protected): If this object is the owner of the allocated buffer. Defaults to
False.
- _ptr (
- static allocate(Py_ssize_tcount) Any#
ListOfInt.allocate(Py_ssize_t count)
Allocate an owned, zero-initialized array of
countCintslots.The returned
ListOfIntowns the buffer (freed on garbage collection) and has a known length, so it is indexable, iterable, and convertible viato_list/to_tuple.
- static fromObj(pyobj) Any#
ListOfInt.fromObj(pyobj)
Creates a ListOfInt from the given object.
In case
pyobjis itself aListOfIntinstance, this method returns it directly. No newListOfIntis created.
- class rocm.bindings.util.types.ListOfInt64(pyobj)#
Bases:
PointerListOfInt64(pyobj)
Handler for
list/tuplewhose entries can be converted to Cint64_tDatatype for handling Python
listandtupleobjects with entries that can be converted to C typeint64_t. Such entries might be of Python typeNone,int, or of anyctypesinteger type.Unlike
ListOfLong, the element width does not depend on the data model of the platform:int64_tis 64 bits on LP64 (Linux) and LLP64 (Windows) alike, while Clongis 64 bits on the former and 32 bits on the latter. This is the handler for parameters whose declaration pins the width –int64_t,ssize_t,ptrdiff_t,intptr_tand library typedefs aliased to them.The type can be initialized from the following Python objects:
list/tupleof types that can be converted to C typeint64_t:A
listortupleof types that can be converted to C typeint64_t. In this case, this type allocates an array of Cint64_tvalues wherein it stores the values obtained from thelist/tupleentries. Furthermore, the instance’sself._is_ptr_ownerC attribute is set toTruein this case.The array lives exactly as long as this instance, which frees it in
__dealloc__. Generated wrappers bind the adapter to a local variable, so the array is alive for the whole C call. If a C function retains the pointer past its return, the caller must keep the adapter alive too — passListOfInt64([...])and hold that object, rather than a barelist.objectthat is accepted as input by__init__:
- Note:
Type checks are performed in the above order.
- Note:
Simple, contiguous numpy and Python 3 array types can be passed directly to this routine as they implement the Python buffer protocol.
- C Attributes:
- _ptr (
void *, protected): See
Pointerfor more information.- _py_buffer (
Py_buffer, protected): See
Pointerfor more information.- _py_buffer_acquired (
bool, protected): See
Pointerfor more information.- _is_ptr_owner (
bint, protected): If this object is the owner of the allocated buffer. Defaults to
False.
- _ptr (
- static allocate(Py_ssize_tcount) Any#
ListOfInt64.allocate(Py_ssize_t count)
Allocate an owned, zero-initialized array of
countCint64_tslots.The returned
ListOfInt64owns the buffer (freed on garbage collection) and has a known length, so it is indexable, iterable, and convertible viato_list/to_tuple.
- static fromObj(pyobj) Any#
ListOfInt64.fromObj(pyobj)
Creates a ListOfInt64 from the given object.
In case
pyobjis itself aListOfInt64instance, this method returns it directly. No newListOfInt64is created.
- class rocm.bindings.util.types.ListOfLong(pyobj)#
Bases:
PointerListOfLong(pyobj)
Handler for
list/tuplewhose entries can be converted to C typelongDatatype for handling Python
listandtupleobjects with entries that can be converted to C typelong. Such entries might be of Python typeNone,int, or of anyctypesinteger type.The type can be initialized from the following Python objects:
list/tupleof types that can be converted to C typelong:A
listortupleof types that can be converted to C typelong. In this case, this type allocates an array of Clongvalues wherein it stores the values obtained from thelist/tupleentries. Furthermore, the instance’sself._is_ptr_ownerC attribute is set toTruein this case.The array lives exactly as long as this instance, which frees it in
__dealloc__. Generated wrappers bind the adapter to a local variable, so the array is alive for the whole C call. If a C function retains the pointer past its return, the caller must keep the adapter alive too — passListOfLong([...])and hold that object, rather than a barelist.objectthat is accepted as input by__init__:
- Note:
Type checks are performed in the above order.
- Note:
Simple, contiguous numpy and Python 3 array types can be passed directly to this routine as they implement the Python buffer protocol.
- C Attributes:
- _ptr (
void *, protected): See
Pointerfor more information.- _py_buffer (
Py_buffer, protected): See
Pointerfor more information.- _py_buffer_acquired (
bool, protected): See
Pointerfor more information.- _is_ptr_owner (
bint, protected): If this object is the owner of the allocated buffer. Defaults to
False.
- _ptr (
- static allocate(Py_ssize_tcount) Any#
ListOfLong.allocate(Py_ssize_t count)
Allocate an owned, zero-initialized array of
countClongslots.The returned
ListOfLongowns the buffer (freed on garbage collection) and has a known length, so it is indexable, iterable, and convertible viato_list/to_tuple.
- static fromObj(pyobj) Any#
ListOfLong.fromObj(pyobj)
Creates a ListOfLong from the given object.
In case
pyobjis itself aListOfLonginstance, this method returns it directly. No newListOfLongis created.
- class rocm.bindings.util.types.ListOfPointer(pyobj)#
Bases:
PointerListOfPointer(pyobj)
Handler for Python
list/tuplewhose entries can be converted toPointerDatatype for handling Python
listandtupleobjects with entries that can be converted to typePointer. Such entries might be of typeNone,int,ctypes.c_void_p, Python buffer interface implementors, CUDA array interface implementors,Pointer, subclasses of Pointer.The type can be initialized from the following Python objects:
list/tupleof types that can be converted toPointer:A
listortupleof types that can be converted toPointer. In this case, this type allocates an array ofvoid *pointers wherein it stores the addresses obtained from thelist/tupleentries. Furthermore, the instance’sself._is_ptr_ownerC attribute is set toTruein this case.The array lives exactly as long as this instance, which frees it in
__dealloc__. Generated wrappers bind the adapter to a local variable, so the array is alive for the whole C call. If a C function retains the pointer past its return, the caller must keep the adapter alive too — passListOfPointer([...])and hold that object, rather than a barelist. Note also that this type stores addresses without holding references to the objects they belong to, so those objects must be kept alive independently for as long as the C side may dereference them.objectthat is accepted as input by__init__:In this case, init code from
Pointeris used and the C attributeself._is_ptr_ownerremains unchanged. See__init__for more information.
- Note:
Type checks are performed in the above order.
- C Attributes:
- _ptr (
void *, protected): See
Pointerfor more information.- _py_buffer (
Py_buffer, protected): See
Pointerfor more information.- _py_buffer_acquired (
bool, protected): See
Pointerfor more information.- _is_ptr_owner (
bint, protected): If this object is the owner of the allocated buffer. Defaults to
False.
- _ptr (
- static allocate(Py_ssize_tcount) Any#
ListOfPointer.allocate(Py_ssize_t count)
Allocate an owned, zero-initialized array of
countvoid *slots.The returned
ListOfPointerowns the buffer (freed on garbage collection) and has a known length, so it is indexable, iterable, and convertible viato_list/to_tuple. Each element is returned as aPointer.
- static fromObj(pyobj) Any#
ListOfPointer.fromObj(pyobj)
Creates a ListOfPointer from the given object.
In case
pyobjis itself aListOfPointerinstance, this method returns it directly. No newListOfPointeris created.
- class rocm.bindings.util.types.ListOfUInt64(pyobj)#
Bases:
PointerListOfUInt64(pyobj)
Handler for
list/tuplewhose entries can be converted to Cuint64_tDatatype for handling Python
listandtupleobjects with entries that can be converted to C typeuint64_t. Such entries might be of Python typeNone,int, or of anyctypesinteger type.Unlike
ListOfUnsignedLong, the element width does not depend on the data model of the platform:uint64_tis 64 bits on LP64 (Linux) and LLP64 (Windows) alike, while Cunsigned longis 64 bits on the former and 32 bits on the latter. This is the handler for parameters whose declaration pins the width –uint64_t,size_t,uintptr_tand library typedefs aliased to them.The type can be initialized from the following Python objects:
list/tupleof types that can be converted to C typeuint64_t:A
listortupleof types that can be converted to C typeuint64_t. In this case, this type allocates an array of Cuint64_tvalues wherein it stores the values obtained from thelist/tupleentries. Furthermore, the instance’sself._is_ptr_ownerC attribute is set toTruein this case.The array lives exactly as long as this instance, which frees it in
__dealloc__. Generated wrappers bind the adapter to a local variable, so the array is alive for the whole C call. If a C function retains the pointer past its return, the caller must keep the adapter alive too — passListOfUInt64([...])and hold that object, rather than a barelist.objectthat is accepted as input by__init__:
- Note:
Type checks are performed in the above order.
- Note:
Simple, contiguous numpy and Python 3 array types can be passed directly to this routine as they implement the Python buffer protocol.
- C Attributes:
- _ptr (
void *, protected): See
Pointerfor more information.- _py_buffer (
Py_buffer, protected): See
Pointerfor more information.- _py_buffer_acquired (
bool, protected): See
Pointerfor more information.- _is_ptr_owner (
bint, protected): If this object is the owner of the allocated buffer. Defaults to
False.
- _ptr (
- static allocate(Py_ssize_tcount) Any#
ListOfUInt64.allocate(Py_ssize_t count)
Allocate an owned, zero-initialized array of
countCuint64_tslots.The returned
ListOfUInt64owns the buffer (freed on garbage collection) and has a known length, so it is indexable, iterable, and convertible viato_list/to_tuple.
- static fromObj(pyobj) Any#
ListOfUInt64.fromObj(pyobj)
Creates a ListOfUInt64 from the given object.
In case
pyobjis itself aListOfUInt64instance, this method returns it directly. No newListOfUInt64is created.
- class rocm.bindings.util.types.ListOfUnsigned(pyobj)#
Bases:
PointerListOfUnsigned(pyobj)
Handler for
list/tuplewhose entries can be converted to CunsignedDatatype for handling Python
listandtupleobjects with entries that can be converted to C typeunsigned. Such entries might be of Python typeNone,int, or of anyctypesinteger type.The type can be initialized from the following Python objects:
list/tupleof types that can be converted to C typeunsigned:A
listortupleof types that can be converted to C typeunsigned. In this case, this type allocates an array of Cunsignedvalues wherein it stores the values obtained from thelist/tupleentries. Furthermore, the instance’sself._is_ptr_ownerC attribute is set toTruein this case.The array lives exactly as long as this instance, which frees it in
__dealloc__. Generated wrappers bind the adapter to a local variable, so the array is alive for the whole C call. If a C function retains the pointer past its return, the caller must keep the adapter alive too — passListOfUnsigned([...])and hold that object, rather than a barelist.objectthat is accepted as input by__init__:
- Note:
Type checks are performed in the above order.
- Note:
Simple, contiguous numpy and Python 3 array types can be passed directly to this routine as they implement the Python buffer protocol.
- C Attributes:
- _ptr (
void *, protected): See
Pointerfor more information.- _py_buffer (
Py_buffer, protected): See
Pointerfor more information.- _py_buffer_acquired (
bool, protected): See
Pointerfor more information.- _is_ptr_owner (
bint, protected): If this object is the owner of the allocated buffer. Defaults to
False.
- _ptr (
- static allocate(Py_ssize_tcount) Any#
ListOfUnsigned.allocate(Py_ssize_t count)
Allocate an owned, zero-initialized array of
countCunsignedslots.The returned
ListOfUnsignedowns the buffer (freed on garbage collection) and has a known length, so it is indexable, iterable, and convertible viato_list/to_tuple.
- static fromObj(pyobj) Any#
ListOfUnsigned.fromObj(pyobj)
Creates a ListOfUnsigned from the given object.
In case
pyobjis itself anListOfUnsignedinstance, this method returns it directly. No newListOfUnsignedis created.
- class rocm.bindings.util.types.ListOfUnsignedLong(pyobj)#
Bases:
PointerListOfUnsignedLong(pyobj)
Handler for
list/tuplewhose entries can be converted to Cunsigned longDatatype for handling Python
listandtupleobjects with entries that can be converted to C typeunsigned long. Such entries might be of Python typeNone,int, or of anyctypesinteger type.The type can be initialized from the following Python objects:
list/tupleof types that can be converted to C typeunsigned long:A
listortupleof types that can be converted to C typeunsigned long. In this case, this type allocates an array of Cunsigned longvalues wherein it stores the values obtained from thelist/tupleentries. Furthermore, the instance’sself._is_ptr_ownerC attribute is set toTruein this case.The array lives exactly as long as this instance, which frees it in
__dealloc__. Generated wrappers bind the adapter to a local variable, so the array is alive for the whole C call. If a C function retains the pointer past its return, the caller must keep the adapter alive too — passListOfUnsignedLong([...])and hold that object, rather than a barelist.objectthat is accepted as input by__init__:
- Note:
Type checks are performed in the above order.
- Note:
Simple, contiguous numpy and Python 3 array types can be passed directly to this routine as they implement the Python buffer protocol.
- C Attributes:
- _ptr (
void *, protected): See
Pointerfor more information.- _py_buffer (
Py_buffer, protected): See
Pointerfor more information.- _py_buffer_acquired (
bool, protected): See
Pointerfor more information.- _is_ptr_owner (
bint, protected): If this object is the owner of the allocated buffer. Defaults to
False.
- _ptr (
- static allocate(Py_ssize_tcount) Any#
ListOfUnsignedLong.allocate(Py_ssize_t count)
Allocate an owned, zero-initialized array of
countCunsigned longslots.The returned
ListOfUnsignedLongowns the buffer (freed on garbage collection) and has a known length, so it is indexable, iterable, and convertible viato_list/to_tuple.
- static fromObj(pyobj) Any#
ListOfUnsignedLong.fromObj(pyobj)
Creates a ListOfUnsignedLong from the given object.
In case
pyobjis itself anListOfUnsignedLonginstance, this method returns it directly. No newListOfUnsignedLongis created.
- class rocm.bindings.util.types.NDBuffer(pyobj)#
Bases:
PointerNDBuffer(pyobj)
Handler for contiguous n-dimensional buffers of various element types
Datatype for handling contiguous n-dimensional buffers of various element types. The buffer can be reshaped via its
configuremethod.- Note:
This buffer does not provide any routines to read or write elements of the buffer. Instead, its
__getitem__operator is overloaded to returnNDBufferinstances pointing to contiguous subregions or single elements of the original buffer. If this buffer is wrapped around host data, users can convert it to types that allow access to the underlying data such asbytes,bytearrayor numpy array types as this type implements the Python buffer protocol.
This type implements the CUDA array interface protocol. Note, however that it is the user’s obligation to only pass this type to consumers of the CUDA array interface if and only if the underlying data is device data.
It can be initialized from the following Python objects:
-
Takes the pointer address
pyobj.valueand writes it toself._ptr. No length information can be obtained in this case. Note thatctypes.c_void_pseems to be identified as Python buffer for unknown reasons. Therefore, it must be checked for this type first. objectwith__cuda_array_interface__member:Takes the integer-valued pointer address, i.e. the first entry of the
datatuple frompyobj’s member__cuda_array_interface__and writes it toself._ptr. Copies shape and type information.
objectthat implements the Python buffer protocol:If the object represents a simple contiguous array, writes the
Py_bufferassociated withpyobjtoself._py_buffer, sets theself._py_buffer_acquiredflag toTrue, and writesself._py_buffer.bufto the data pointerself._ptr.objectthat is accepted as input by__init__:
- Note:
Type checks are performed in the above order.
- Note:
Shape and type information and other metadata can be modified or overwritten after creation via the
configuremember function. Be aware that you might need to pass the_force=Truekeyword argument — in particular if your instance was created from a type that does not implement the CUDA array interface protocol.- Note:
This type represents a dense, C-contiguous array; all of its addressing is derived from the shape and the itemsize. An input that implements the CUDA array interface protocol is therefore rejected if it carries a mask, a non-zero offset, or strides that describe a non-contiguous layout. Strides that spell out the contiguous layout the shape already implies are accepted.
- See:
- C Attributes:
- _ptr (
void *, protected): Stores a pointer to the data of the original Python object.
- _py_buffer (
Py_buffer, protected): Stores a pointer to the data of the original Python object.
- _py_buffer_acquired (
bool, protected): Stores a pointer to the data of the original Python object.
- _cuda_array_interface (
dict, protected): The CUDA array interface metadata, handed out as a copy by
__cuda_array_interface__.- _pybuffer_obj (
object, protected): Keeps the exporter of a wrapped
Py_bufferalive.- _typestr_bytes (
bytes, protected): NUL-terminated format string handed to consumers of this Python buffer. Must stay alive as long as any view exists.
- _itemsize (
size_t, protected): Stores the itemsize. The item size is not member of
__cuda_array_interface__.- _py_buffer_shape (
Py_Ssize_t*, private): A buffer to pass shape information to consumers of this Python buffer.
- _ptr (
- is_read_only: _typeshed.Incomplete#
- itemsize: _typeshed.Incomplete#
- rank: _typeshed.Incomplete#
- shape: _typeshed.Incomplete#
- size: _typeshed.Incomplete#
- stream_as_int: _typeshed.Incomplete#
- typestr: _typeshed.Incomplete#
- configure(**kwargs) Any#
NDBuffer.configure(self, **kwargs)
(Re-)configure this contiguous n-dimensional buffer.
- Warning:
When you reconfigure the buffer shape, previously acquired views on this NDBuffer via the Python buffer protocol might become invalid. Therefore, a
RuntimeExceptionis thrown if this method is called while the view count is greater than zero.- Keyword arguments:
- shape (
tuple): A tuple that describes the extent per dimension. The length of the tuple is the number of dimensions.
- typestr (
str): A numpy typestr, see the notes for more details.
- stream (
intorNone): The stream to synchronize before consuming this array. See first note for more details. Only makes sense if this buffer wraps device data.
- itemsize (
int): Size in bytes of each item. Defaults to 1. See the notes.
- read_only (
bool): NDBufferis read_only. Second entry of the CUDA array interface ‘data’ tuple. Defaults to False.- _force(
bool): Ignore changes in the total number of bytes when overriding shape, typestr, and/or itemsize.
- shape (
- Note:
More details on the keyword arguments can be found here: https://numba.readthedocs.io/en/stable/cuda/cuda_array_interface.html
- Note:
This method does not automatically map all existing numpy/numba typestr to appropriate number of bytes, i.e.
itemsize. Hence, you need to specifyitemsizeadditionally when dealing with other datatypes than bytes (typestr:'b').
- static fromObj(pyobj) Any#
NDBuffer.fromObj(pyobj)
Creates a NDBuffer from the given object.
In case
pyobjis itself aNDBufferinstance, this method returns it directly. No newNDBufferis created.
- class rocm.bindings.util.types.Pointer(pyobj=...)#
Pointer(pyobj=None)
Handler for Python arguments that need to be converted to a pointer type
Datatype for handling Python arguments that need to be converted to a pointer type when passed to an underlying C function.
This type stores a C
void *pointer to the original Python object’s data plus an additionalPy_bufferobject if the pointer has ben acquired from a Python object that implements the Python buffer protocol.This type can be constructed from input objects that are implementors of the CUDA array interface protocol.
In summary, the type can be initialized from the following Python objects:
None:This will set the
self._ptrattribute toNULL.-
Takes the pointer address
pyobj.valueand writes it toself._ptr. Note thatctypes.c_void_pseems to be identified as Python buffer for unknown reasons. Therefore, it must be checked for this type first. -
Takes the pointer address
pyobj.valueand writes it toself._ptr. Note thatctypes.c_void_pseems to be identified as Python buffer for unknown reasons. Therefore, it must be checked for this type first. objectthat implements the Python buffer protocol:If the object represents a simple contiguous array, writes the
Py_bufferassociated withpyobjtoself._py_buffer, sets theself._py_buffer_acquiredflag toTrue, and writesself._py_buffer.bufto the data pointerself._ptr.objectthat implements the CUDA array interface protocol:Takes the integer-valued pointer address, i.e. the first entry of the
datatuple frompyobj’s member__cuda_array_interface__and writes it toself._ptr.-
Copies
pyobj._ptrtoself._ptr.Py_bufferobject ownership is not transferred! int:Interprets the integer value as pointer address and writes it to
self._ptr.objectthat hasas_c_void_p(self)method:Takes the pointer address
pyobj.as_c_void_p().valueand writes it toself._ptr.
Type checks are performed in the above order.
- Note:
When initializing
Pointerinstances from a Python input object, buffer types are checked first by purpose. Acquiring/releasing a buffer typically implies that the reference count of the buffer is incremented/decremented. If the Python input object releases a buffer but aPointerinstance still has acquired it, the buffer data will not be freed until thePointerinstance is deleted.- C Attributes:
- _ptr (C type
void *, protected): Stores a pointer to the data of the original Python object.
- _py_buffer (C type ``Py_buffer`, protected):
Stores a pointer to the data of the original Python object.
- _py_buffer_acquired (C type
bint, protected): Stores a pointer to the data of the original Python object.
- _ptr (C type
- is_ptr_null: _typeshed.Incomplete#
- as_c_void_p() Any#
Pointer.as_c_void_p(self)
Data pointer as
ctypes.c_void_p.
- createRef() Pointer#
Pointer.createRef(self) -> Pointer
Creates are reference to this pointer.
Returns a
Pointerthat stores the address of this `~.Pointer’s data pointer.- Note:
No ownership information is transferred.
- static fromObj(pyobj) Any#
Pointer.fromObj(pyobj)
Creates a Pointer from the given object.
In case
pyobjis itself aPointerinstance, this method returns it directly. No newPointeris created.
- class rocm.bindings.util.types.PointerToInt(pyobj)#
Bases:
ListOfIntPointerToInt(pyobj)
Handler for a rank-0 pointer to a single C
int.A
PointerTo*is a length-1 specialization of the matchingListOf*(hereListOfInt): it wraps aT *that points at a single value rather than a sized buffer. Use it for a caller-allocated scalar pointer argument (anIN/INOUT/ caller-allocatedOUTint *parameter): allocate one slot, pass it to the C call, then read the result back throughvalue(orself[0]).Accepts the same inputs as
ListOfInt(alist/tuple, anotherListOfInt/PointerToInt, or any object accepted byPointer), except that alist/tupleinitializer must have exactly one element (aPointerTo*points at a single scalar);allocatedefaults to a single slot.- value: Any#
- static allocate(Py_ssize_tcount=...) Any#
PointerToInt.allocate(Py_ssize_t count=1)
Allocate an owned, zero-initialized array of
countCintslots.Defaults to a single slot (the rank-0
PointerTo*use case).
- static fromObj(pyobj) Any#
PointerToInt.fromObj(pyobj)
Creates a PointerToInt from the given object.
In case
pyobjis itself aPointerToIntinstance, this method returns it directly. No newPointerToIntis created.
- class rocm.bindings.util.types.PointerToInt64(pyobj)#
Bases:
ListOfInt64PointerToInt64(pyobj)
Handler for a rank-0 pointer to a single C
int64_t.A
PointerTo*is a length-1 specialization of the matchingListOf*(hereListOfInt64): it wraps aT *that points at a single value rather than a sized buffer. Use it for a caller-allocated scalar pointer argument whose declaration pins a signed 64-bit width (anIN/INOUT/ caller-allocatedOUTint64_t *,ssize_t *or aliasedhoff_t *parameter, e.g. hipFILE’s asyncbytes_read_p/bytes_written_p): allocate one slot, pass it to the C call, then read the result back throughvalue(orself[0]).Accepts the same inputs as
ListOfInt64(alist/tuple, anotherListOfInt64/PointerToInt64, or any object accepted byPointer), except that alist/tupleinitializer must have exactly one element (aPointerTo*points at a single scalar);allocatedefaults to a single slot.- value: Any#
- static allocate(Py_ssize_tcount=...) Any#
PointerToInt64.allocate(Py_ssize_t count=1)
Allocate an owned, zero-initialized array of
countCint64_tslots.Defaults to a single slot (the rank-0
PointerTo*use case).
- static fromObj(pyobj) Any#
PointerToInt64.fromObj(pyobj)
Creates a PointerToInt64 from the given object.
In case
pyobjis itself aPointerToInt64instance, this method returns it directly. No newPointerToInt64is created.
- class rocm.bindings.util.types.PointerToLong(pyobj)#
Bases:
ListOfLongPointerToLong(pyobj)
Handler for a rank-0 pointer to a single C
long.A
PointerTo*is a length-1 specialization of the matchingListOf*(hereListOfLong): it wraps aT *that points at a single value rather than a sized buffer. Use it for a caller-allocated scalar pointer argument (anIN/INOUT/ caller-allocatedOUTlong *parameter, e.g. hipFILE’s asyncbytes_read_p/bytes_written_p): allocate one slot, pass it to the C call, then read the result back throughvalue(orself[0]).Accepts the same inputs as
ListOfLong(alist/tuple, anotherListOfLong/PointerToLong, or any object accepted byPointer), except that alist/tupleinitializer must have exactly one element (aPointerTo*points at a single scalar);allocatedefaults to a single slot.- value: Any#
- static allocate(Py_ssize_tcount=...) Any#
PointerToLong.allocate(Py_ssize_t count=1)
Allocate an owned, zero-initialized array of
countClongslots.Defaults to a single slot (the rank-0
PointerTo*use case).
- static fromObj(pyobj) Any#
PointerToLong.fromObj(pyobj)
Creates a PointerToLong from the given object.
In case
pyobjis itself aPointerToLonginstance, this method returns it directly. No newPointerToLongis created.
- class rocm.bindings.util.types.PointerToUInt64(pyobj)#
Bases:
ListOfUInt64PointerToUInt64(pyobj)
Handler for a rank-0 pointer to a single C
uint64_t.A
PointerTo*is a length-1 specialization of the matchingListOf*(hereListOfUInt64): it wraps aT *that points at a single value rather than a sized buffer. Use it for a caller-allocated scalar pointer argument whose declaration pins an unsigned 64-bit width (anIN/INOUT/ caller-allocatedOUTuint64_t *orsize_t *parameter): allocate one slot, pass it to the C call, then read the result back throughvalue(orself[0]).Accepts the same inputs as
ListOfUInt64(alist/tuple, anotherListOfUInt64/PointerToUInt64, or any object accepted byPointer), except that alist/tupleinitializer must have exactly one element (aPointerTo*points at a single scalar);allocatedefaults to a single slot.- value: Any#
- static allocate(Py_ssize_tcount=...) Any#
PointerToUInt64.allocate(Py_ssize_t count=1)
Allocate an owned, zero-initialized array of
countCuint64_tslots.Defaults to a single slot (the rank-0
PointerTo*use case).
- static fromObj(pyobj) Any#
PointerToUInt64.fromObj(pyobj)
Creates a PointerToUInt64 from the given object.
In case
pyobjis itself aPointerToUInt64instance, this method returns it directly. No newPointerToUInt64is created.
- class rocm.bindings.util.types.PointerToUnsigned(pyobj)#
Bases:
ListOfUnsignedPointerToUnsigned(pyobj)
Handler for a rank-0 pointer to a single C
unsigned int.A
PointerTo*is a length-1 specialization of the matchingListOf*(hereListOfUnsigned): it wraps aT *that points at a single value rather than a sized buffer. Use it for a caller-allocated scalar pointer argument (anIN/INOUT/ caller-allocatedOUTunsigned int *parameter): allocate one slot, pass it to the C call, then read the result back throughvalue(orself[0]).Accepts the same inputs as
ListOfUnsigned(alist/tuple, anotherListOfUnsigned/PointerToUnsigned, or any object accepted byPointer), except that alist/tupleinitializer must have exactly one element (aPointerTo*points at a single scalar);allocatedefaults to a single slot.- value: Any#
- static allocate(Py_ssize_tcount=...) Any#
PointerToUnsigned.allocate(Py_ssize_t count=1)
Allocate an owned, zero-initialized array of
countCunsigned intslots.Defaults to a single slot (the rank-0
PointerTo*use case).
- static fromObj(pyobj) Any#
PointerToUnsigned.fromObj(pyobj)
Creates a PointerToUnsigned from the given object.
In case
pyobjis itself aPointerToUnsignedinstance, this method returns it directly. No newPointerToUnsignedis created.
- class rocm.bindings.util.types.PointerToUnsignedLong(pyobj)#
Bases:
ListOfUnsignedLongPointerToUnsignedLong(pyobj)
Handler for a rank-0 pointer to a single C
unsigned long.A
PointerTo*is a length-1 specialization of the matchingListOf*(hereListOfUnsignedLong): it wraps aT *that points at a single value rather than a sized buffer. Use it for a caller- allocated scalar pointer argument (anIN/INOUT/ caller-allocatedOUTunsigned long */size_t *parameter): allocate one slot, pass it to the C call, then read the result back throughvalue(orself[0]).Accepts the same inputs as
ListOfUnsignedLong(alist/tuple, anotherListOfUnsignedLong/PointerToUnsignedLong, or any object accepted byPointer), except that alist/tupleinitializer must have exactly one element (aPointerTo*points at a single scalar);allocatedefaults to a single slot.- value: Any#
- static allocate(Py_ssize_tcount=...) Any#
PointerToUnsignedLong.allocate(Py_ssize_t count=1)
Allocate an owned, zero-initialized array of
countCunsigned longslots.Defaults to a single slot (the rank-0
PointerTo*use case).
- static fromObj(pyobj) Any#
PointerToUnsignedLong.fromObj(pyobj)
Creates a PointerToUnsignedLong from the given object.
In case
pyobjis itself aPointerToUnsignedLonginstance, this method returns it directly. No newPointerToUnsignedLongis created.