hip._util.types#

class hip._util.types.Pointer(pyobj=None)#

Bases: object

Datatype for handling 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 additional Py_buffer object 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._ptr attribute to NULL.

  • ctypes.c_void_p:

    Takes the pointer address pyobj.value and writes it to self._ptr. Note that ctypes.c_void_p seems to be identified as Python buffer for unknown reasons. Therefore, it must be checked for this type first.

  • object that implements the Python buffer protocol:

    If the object represents a simple contiguous array, writes the Py_buffer associated with pyobj to self._py_buffer, sets the self._py_buffer_acquired flag to True, and writes self._py_buffer.buf to the data pointer self._ptr.

  • object that implements the CUDA Array Interface protocol:

    Takes the integer-valued pointer address, i.e. the first entry of the data tuple from pyobj’s member __cuda_array_interface__ and writes it to self._ptr.

  • Pointer:

    Copies pyobj._ptr to self._ptr. Py_buffer object ownership is not transferred!

  • int:

    Interprets the integer value as pointer address and writes it to self._ptr.

  • object that has as_c_void_p(self) method:

    Takes the pointer address pyobj.as_c_void_p().value and writes it to self._ptr.

Type checks are performed in the above order.

Note:

When initializing Pointer instances 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 a Pointer instance still has acquired it, the buffer data will not be freed until the Pointer instance 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.

__getitem__()#

Returns a new Pointer whose pointer is this instance’s pointer offsetted by offset.

Args:

offset (int): Offset (in bytes) to add to this instance’s pointer.

__init__()#

Constructor.

Args:
pyobj (object):

See the class description Pointer for information about accepted types for pyobj. Defaults to None.

Raises:

TypeError: If the input object pyobj is not of the right type.

as_c_void_p(self)#

Data pointer as ctypes.c_void_p.

createRef(self) Pointer#

Creates are reference to this pointer.

Returns a Pointer that stores the address of this `~.Pointer’s data pointer.

Note:

No ownership information is transferred.

static fromObj(pyobj)#

Creates a Pointer from the given object.

In case pyobj is itself a Pointer instance, this method returns it directly. No new Pointer is created.

is_ptr_null#

If data pointer is NULL.

class hip._util.types.CStr(pyobj)#

Bases: Pointer

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 str in cases where it is returned by a function. Hence, the __getitem__, __repr__ and __str__ implementation of this class decode the underlying data as UTF-8 string. 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 bytes or to other array types or memory views that can deal with Python buffers.

Warning:

When using this type as adapter, be aware that bytes and str objects passed to the constructor of this class might get garbage collected. If the called C library stores pointers to the data of these Python objects into a library-managed data structure and the latter is then used outside of the original scope, you might experience memory errors.

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:

  • ctypes.c_void_p:

    Takes the pointer address pyobj.value and writes it to self._ptr. Length information is obtained via strlen in this case. Note that ctypes.c_void_p seems to be identified as Python buffer for unknown reasons. Therefore, it must be checked for this type first.

  • object that implements the Python buffer protocol:

    If the object represents a simple contiguous array, writes the Py_buffer associated with pyobj to self._py_buffer, sets the self._py_buffer_acquired flag to True, and writes self._py_buffer.buf to the data pointer self._ptr.

  • object that is accepted as input by __init__.

Type checks are performed in the above order.

C Attributes:
_ptr (void *, protected):

See Pointer for 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 Pointer for more information.

_py_buffer_acquired (bool, protected):

See Pointer for more information.

__getitem__()#

Get individual chars or slice the underlying chars.

Note:

Copies into a temporary str object if subscript is a slice.

__init__()#

Constructor.

Args:
pyobj (object):

See the class description CStr for information about accepted types for pyobj.

Raises:

TypeError: If the input object pyobj is not of the right type.

as_c_void_p(self)#

Data pointer as ctypes.c_void_p.

createRef(self) Pointer#

Creates are reference to this pointer.

Returns a Pointer that stores the address of this `~.Pointer’s data pointer.

Note:

No ownership information is transferred.

decode(self, /, encoding='utf-8', errors='strict')#

Return a str object with respect to the enconding.

See:

bytes.decode

encode(self, /, encoding='utf-8', errors='strict')#

Return a bytes object with respect to the encoding.

See:

str.encode

free(self) void#

Free dynamically allocated data.

Note:

Simply returns if the data pointer is NULL.

Note:

Throws RuntimeError if this instance does not own the data that ought to be freed.

Note:

Unsets the _is_ptr_owner flag.

static fromObj(pyobj)#

Creates a CStr from the given object.

In case pyobj is itself a CStr instance, this method returns it directly. No new CStr is created.

is_ptr_null#

If data pointer is NULL.

malloc(self, Py_ssize_t size_bytes) void#

Dynamically allocate a buffer of bytes for this CStr.

Args:

size_bytes (Py_ssize_t): The number of bytes to allocate.

Note:

Throws RuntimeError if the data pointer is not NULL as this indicates that this instance handles external data.

Note:

Sets the _is_ptr_owner flag.

class hip._util.types.ImmortalCStr(pyobj)#

Bases: CStr

Immortal version of CStr that sets the reference count of itself 1 initially, which prevents it from getting garbage collected. Furthermore, increases the reference count of wrapped bytes

Note:

Class name and implementation inspired from: https://peps.python.org/pep-0683

__getitem__()#

Get individual chars or slice the underlying chars.

Note:

Copies into a temporary str object if subscript is a slice.

__init__()#

Constructor.

as_c_void_p(self)#

Data pointer as ctypes.c_void_p.

createRef(self) Pointer#

Creates are reference to this pointer.

Returns a Pointer that stores the address of this `~.Pointer’s data pointer.

Note:

No ownership information is transferred.

decode(self, /, encoding='utf-8', errors='strict')#

Return a str object with respect to the enconding.

See:

bytes.decode

encode(self, /, encoding='utf-8', errors='strict')#

Return a bytes object with respect to the encoding.

See:

str.encode

free(self) void#

Free dynamically allocated data.

Note:

Simply returns if the data pointer is NULL.

Note:

Throws RuntimeError if this instance does not own the data that ought to be freed.

Note:

Unsets the _is_ptr_owner flag.

static fromObj(pyobj)#

Creates an ImmortalCStr from the given object.

In case pyobj is itself a ImmortalCStr instance, this method returns it directly. No new ImmortalCStr is created.

is_ptr_null#

If data pointer is NULL.

malloc(self, Py_ssize_t size_bytes) void#

Dynamically allocate a buffer of bytes for this CStr.

Args:

size_bytes (Py_ssize_t): The number of bytes to allocate.

Note:

Throws RuntimeError if the data pointer is not NULL as this indicates that this instance handles external data.

Note:

Sets the _is_ptr_owner flag.

class hip._util.types.DeviceArray#

Bases: NDBuffer

Datatype for handling device buffers.

Datatype for handling device buffers returned by hipMalloc and 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._ptr attribute to NULL. No shape and type information is available in this case!

  • object that is accepted as input by __init__:

    In this case, init code from Pointer is used. Py_buffer object ownership is not transferred See __init__ for more information. 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.value and writes it to self._ptr. No shape and type information is available in this case!

  • object with __cuda_array_interface__ member:

    Takes the integer-valued pointer address, i.e. the first entry of the data tuple from pyobj’s member __cuda_array_interface__ and writes it to self._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 configure member function. be aware that you might need to pass the _force=True keyword argument — in particular if your instance was created from a type that does not implement the CUDA Array Interface protocol.

See:

configure

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.

__dict__ (dict, protected):

Dict with member __cuda_array_interface__.

static DeviceArray(pyobj)#

Creates a NDBuffer from the given object.

In case pyobj is itself a NDBuffer instance, this method returns it directly. No new NDBuffer is created.

NUMPY_CHAR_CODES = ('?', '=?', '<?', '>?', 'bool', 'bool_', 'bool8', 'uint8', 'u1', '=u1', '<u1', '>u1', 'uint16', 'u2', '=u2', '<u2', '>u2', 'uint32', 'u4', '=u4', '<u4', '>u4', 'uint64', 'u8', '=u8', '<u8', '>u8', 'int8', 'i1', '=i1', '<i1', '>i1', 'int16', 'i2', '=i2', '<i2', '>i2', 'int32', 'i4', '=i4', '<i4', '>i4', 'int64', 'i8', '=i8', '<i8', '>i8', 'float16', 'f2', '=f2', '<f2', '>f2', 'float32', 'f4', '=f4', '<f4', '>f4', 'float64', 'f8', '=f8', '<f8', '>f8', 'complex64', 'c8', '=c8', '<c8', '>c8', 'complex128', 'c16', '=c16', '<c16', '>c16', 'byte', 'b', '=b', '<b', '>b', 'short', 'h', '=h', '<h', '>h', 'intc', 'i', '=i', '<i', '>i', 'intp', 'int0', 'p', '=p', '<p', '>p', 'long', 'int', 'int_', 'l', '=l', '<l', '>l', 'longlong', 'q', '=q', '<q', '>q', 'ubyte', 'B', '=B', '<B', '>B', 'ushort', 'H', '=H', '<H', '>H', 'uintc', 'I', '=I', '<I', '>I', 'uintp', 'uint0', 'P', '=P', '<P', '>P', 'ulong', 'uint', 'L', '=L', '<L', '>L', 'ulonglong', 'Q', '=Q', '<Q', '>Q', 'half', 'e', '=e', '<e', '>e', 'single', 'f', '=f', '<f', '>f', 'double', 'float', 'float_', 'd', '=d', '<d', '>d', 'longdouble', 'longfloat', 'g', '=g', '<g', '>g', 'csingle', 'singlecomplex', 'F', '=F', '<F', '>F', 'cdouble', 'complex', 'complex_', 'cfloat', 'D', '=D', '<D', '>D', 'clongdouble', 'clongfloat', 'longcomplex', 'G', '=G', '<G', '>G', 'str', 'str_', 'str0', 'unicode', 'unicode_', 'U', '=U', '<U', '>U', 'bytes', 'bytes_', 'bytes0', 'S', '=S', '<S', '>S', 'void', 'void0', 'V', '=V', '<V', '>V', 'object', 'object_', 'O', '=O', '<O', '>O', 'datetime64', '=datetime64', '<datetime64', '>datetime64', 'datetime64[Y]', '=datetime64[Y]', '<datetime64[Y]', '>datetime64[Y]', 'datetime64[M]', '=datetime64[M]', '<datetime64[M]', '>datetime64[M]', 'datetime64[W]', '=datetime64[W]', '<datetime64[W]', '>datetime64[W]', 'datetime64[D]', '=datetime64[D]', '<datetime64[D]', '>datetime64[D]', 'datetime64[h]', '=datetime64[h]', '<datetime64[h]', '>datetime64[h]', 'datetime64[m]', '=datetime64[m]', '<datetime64[m]', '>datetime64[m]', 'datetime64[s]', '=datetime64[s]', '<datetime64[s]', '>datetime64[s]', 'datetime64[ms]', '=datetime64[ms]', '<datetime64[ms]', '>datetime64[ms]', 'datetime64[us]', '=datetime64[us]', '<datetime64[us]', '>datetime64[us]', 'datetime64[ns]', '=datetime64[ns]', '<datetime64[ns]', '>datetime64[ns]', 'datetime64[ps]', '=datetime64[ps]', '<datetime64[ps]', '>datetime64[ps]', 'datetime64[fs]', '=datetime64[fs]', '<datetime64[fs]', '>datetime64[fs]', 'datetime64[as]', '=datetime64[as]', '<datetime64[as]', '>datetime64[as]', 'M', '=M', '<M', '>M', 'M8', '=M8', '<M8', '>M8', 'M8[Y]', '=M8[Y]', '<M8[Y]', '>M8[Y]', 'M8[M]', '=M8[M]', '<M8[M]', '>M8[M]', 'M8[W]', '=M8[W]', '<M8[W]', '>M8[W]', 'M8[D]', '=M8[D]', '<M8[D]', '>M8[D]', 'M8[h]', '=M8[h]', '<M8[h]', '>M8[h]', 'M8[m]', '=M8[m]', '<M8[m]', '>M8[m]', 'M8[s]', '=M8[s]', '<M8[s]', '>M8[s]', 'M8[ms]', '=M8[ms]', '<M8[ms]', '>M8[ms]', 'M8[us]', '=M8[us]', '<M8[us]', '>M8[us]', 'M8[ns]', '=M8[ns]', '<M8[ns]', '>M8[ns]', 'M8[ps]', '=M8[ps]', '<M8[ps]', '>M8[ps]', 'M8[fs]', '=M8[fs]', '<M8[fs]', '>M8[fs]', 'M8[as]', '=M8[as]', '<M8[as]', '>M8[as]', 'timedelta64', '=timedelta64', '<timedelta64', '>timedelta64', 'timedelta64[Y]', '=timedelta64[Y]', '<timedelta64[Y]', '>timedelta64[Y]', 'timedelta64[M]', '=timedelta64[M]', '<timedelta64[M]', '>timedelta64[M]', 'timedelta64[W]', '=timedelta64[W]', '<timedelta64[W]', '>timedelta64[W]', 'timedelta64[D]', '=timedelta64[D]', '<timedelta64[D]', '>timedelta64[D]', 'timedelta64[h]', '=timedelta64[h]', '<timedelta64[h]', '>timedelta64[h]', 'timedelta64[m]', '=timedelta64[m]', '<timedelta64[m]', '>timedelta64[m]', 'timedelta64[s]', '=timedelta64[s]', '<timedelta64[s]', '>timedelta64[s]', 'timedelta64[ms]', '=timedelta64[ms]', '<timedelta64[ms]', '>timedelta64[ms]', 'timedelta64[us]', '=timedelta64[us]', '<timedelta64[us]', '>timedelta64[us]', 'timedelta64[ns]', '=timedelta64[ns]', '<timedelta64[ns]', '>timedelta64[ns]', 'timedelta64[ps]', '=timedelta64[ps]', '<timedelta64[ps]', '>timedelta64[ps]', 'timedelta64[fs]', '=timedelta64[fs]', '<timedelta64[fs]', '>timedelta64[fs]', 'timedelta64[as]', '=timedelta64[as]', '<timedelta64[as]', '>timedelta64[as]', 'm', '=m', '<m', '>m', 'm8', '=m8', '<m8', '>m8', 'm8[Y]', '=m8[Y]', '<m8[Y]', '>m8[Y]', 'm8[M]', '=m8[M]', '<m8[M]', '>m8[M]', 'm8[W]', '=m8[W]', '<m8[W]', '>m8[W]', 'm8[D]', '=m8[D]', '<m8[D]', '>m8[D]', 'm8[h]', '=m8[h]', '<m8[h]', '>m8[h]', 'm8[m]', '=m8[m]', '<m8[m]', '>m8[m]', 'm8[s]', '=m8[s]', '<m8[s]', '>m8[s]', 'm8[ms]', '=m8[ms]', '<m8[ms]', '>m8[ms]', 'm8[us]', '=m8[us]', '<m8[us]', '>m8[us]', 'm8[ns]', '=m8[ns]', '<m8[ns]', '>m8[ns]', 'm8[ps]', '=m8[ps]', '<m8[ps]', '>m8[ps]', 'm8[fs]', '=m8[fs]', '<m8[fs]', '>m8[fs]', 'm8[as]', '=m8[as]', '<m8[as]', '>m8[as]')#
__getitem__()#

Returns a contiguous subarray according to the subscript expression.

Returns a contiguous subarray according to the subscript expression.

Args:
subscript (int/slice/tuple):

Either an integer, a slice, or a tuple of slices and integers.

Note:

If the subscript is a single integer, e.g. [i], the subarray [i,:,:,...,:] is returned. A KeyError is raised if the extent of axis 0 is surpassed. This behavior is identical to that of numpy.

Raises:

TypeError: If the subscript types are not ‘int’, ‘slice’ or a ‘tuple’ thereof. ValueError: If the subscripts do not yield an contiguous subarray. A single array element is regarded as contiguous array of size 1.

__init__()#

Constructor.

Args:
pyobj (object):

See the class description NDBuffer for information about accepted types for pyobj.

Raises:

TypeError: If the input object pyobj is not of the right type.

Note:

Shape and type information and other metadata can be modified or overwritten after creation via the configure member function. be aware that you might need to pass the _force=True keyword argument — in particular if your instance was created from a type that does not implement the CUDA Array Interface protocol.

See:

configure

as_c_void_p(self)#

Data pointer as ctypes.c_void_p.

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 RuntimeException is 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 (int or None):

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):

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

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 specify itemsize additionally when dealing with other datatypes than bytes (typestr: 'b').

createRef(self) Pointer#

Creates are reference to this pointer.

Returns a Pointer that stores the address of this `~.Pointer’s data pointer.

Note:

No ownership information is transferred.

static fromObj(pyobj)#

Creates a NDBuffer from the given object.

In case pyobj is itself a NDBuffer instance, this method returns it directly. No new NDBuffer is created.

is_ptr_null#

If data pointer is NULL.

is_read_only#

If the data is read only, i.e. must not be modified.

itemsize#

Number of bytes required to store a single element of the array.

rank#

Rank of the underlying data.

See:

set_bounds

shape#

A tuple of int (or long) representing the size of each dimension.

size#

Product of the shape entries.

stream_as_int#

Returns the stream address as integer value.

typestr#

The type string (see CUDA Array Interface specification).

class hip._util.types.ListOfBytes(pyobj)#

Bases: Pointer

Datatype for handling Python list or tuple objects with entries of type bytes or CStr.

Datatype for handling Python list and tuple objects with entries of type bytes that need to be converted to a pointer type when passed to the underlying C function.

The type can be initialized from the following Python objects:

  • list / tuple of bytes / `~.CStr:

    A list or tuple of bytes or CStr objects. In this case, this type allocates an array of const char* pointers wherein it stores the addresses from the list/ tuple entries. Furthermore, the instance’s self._is_ptr_owner C attribute is set to True in this case.

  • object that is accepted as input by __init__:

    In this case, init code from Pointer is used and the C attribute self._is_ptr_owner remains unchanged. See __init__ for more information.

Note:

Type checks are performed in the above order.

C Attributes:
_ptr (void *, protected):

See Pointer for more information.

_py_buffer (Py_buffer, protected):

See Pointer for more information.

_py_buffer_acquired (bool, protected):

See Pointer for more information.

_is_ptr_owner (bint, protected):

If this object is the owner of the allocated buffer. Defaults to False.

__getitem__()#

Returns a new Pointer whose pointer is this instance’s pointer offsetted by offset.

Args:

offset (int): Offset (in bytes) to add to this instance’s pointer.

__init__()#

Constructor.

Args:
pyobj (object):

See the class description ListOfBytes for information about accepted types for pyobj.

Raises:

TypeError: If the input object pyobj is not of the right type.

as_c_void_p(self)#

Data pointer as ctypes.c_void_p.

createRef(self) Pointer#

Creates are reference to this pointer.

Returns a Pointer that stores the address of this `~.Pointer’s data pointer.

Note:

No ownership information is transferred.

static fromObj(pyobj)#

Creates a ListOfBytes from the given object.

In case pyobj is itself an ListOfBytes instance, this method returns it directly. No new ListOfBytes is created.

is_ptr_null#

If data pointer is NULL.

class hip._util.types.ListOfPointer(pyobj)#

Bases: Pointer

Datatype for handling Python list or tuple objects with entries that can be converted to type Pointer.

Datatype for handling Python list and tuple objects with entries that can be converted to type Pointer. Such entries might be of type None, 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 / tuple of bytes:

    A list or tuple of types that can be converted to Pointer. In this case, this type allocates an array of void * pointers wherein it stores the addresses obtained from the list/tuple entries. Furthermore, the instance’s self._is_ptr_owner C attribute is set to True in this case.

  • object that is accepted as input by __init__:

    In this case, init code from Pointer is used and the C attribute self._is_ptr_owner remains unchanged. See __init__ for more information.

Note:

Type checks are performed in the above order.

C Attributes:
_ptr (void *, protected):

See Pointer for more information.

_py_buffer (Py_buffer, protected):

See Pointer for more information.

_py_buffer_acquired (bool, protected):

See Pointer for more information.

_is_ptr_owner (bint, protected):

If this object is the owner of the allocated buffer. Defaults to False.

__getitem__()#

Returns a new Pointer whose pointer is this instance’s pointer offsetted by offset.

Args:

offset (int): Offset (in bytes) to add to this instance’s pointer.

__init__()#

Constructor.

Args:
pyobj (object):

See the class description ListOfPointer for information about accepted types for pyobj.

Raises:

TypeError: If the input object pyobj is not of the right type.

as_c_void_p(self)#

Data pointer as ctypes.c_void_p.

createRef(self) Pointer#

Creates are reference to this pointer.

Returns a Pointer that stores the address of this `~.Pointer’s data pointer.

Note:

No ownership information is transferred.

static fromObj(pyobj)#

Creates a ListOfPointer from the given object.

In case pyobj is itself a ListOfPointer instance, this method returns it directly. No new ListOfPointer is created.

is_ptr_null#

If data pointer is NULL.

class hip._util.types.ListOfInt(pyobj)#

Bases: Pointer

Datatype for handling Python list or tuple objects with entries that can be converted to C type int.

Datatype for handling Python list and tuple objects with entries that can be converted to C type int. Such entries might be of Python type None, int, or of any ctypes integer type.

The type can be initialized from the following Python objects:

  • list / tuple of types that can be converted to C type int:

    A list or tuple of types that can be converted to C type int. In this case, this type allocates an array of C int values wherein it stores the values obtained from the list/tuple entries. Furthermore, the instance’s self._is_ptr_owner C attribute is set to True in this case.

  • object that is accepted as input by __init__:

    In this case, init code from Pointer is used and the C attribute self._is_ptr_owner remains unchanged. See Pointer for more information.

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 Pointer for more information.

_py_buffer (Py_buffer, protected):

See Pointer for more information.

_py_buffer_acquired (bool, protected):

See Pointer for more information.

_is_ptr_owner (bint, protected):

If this object is the owner of the allocated buffer. Defaults to False.

__getitem__()#

Returns a new Pointer whose pointer is this instance’s pointer offsetted by offset.

Args:

offset (int): Offset (in bytes) to add to this instance’s pointer.

__init__()#

Constructor.

Args:
pyobj (object):

See the class description ListOfInt for information about accepted types for pyobj.

Raises:

TypeError: If the input object pyobj is not of the right type.

as_c_void_p(self)#

Data pointer as ctypes.c_void_p.

createRef(self) Pointer#

Creates are reference to this pointer.

Returns a Pointer that stores the address of this `~.Pointer’s data pointer.

Note:

No ownership information is transferred.

static fromObj(pyobj)#

Creates a ListOfInt from the given object.

In case pyobj is itself a ListOfInt instance, this method returns it directly. No new ListOfInt is created.

is_ptr_null#

If data pointer is NULL.

class hip._util.types.ListOfUnsigned(pyobj)#

Bases: Pointer

Datatype for handling Python list or tuple objects with entries that can be converted to C type unsigned.

Datatype for handling Python list and tuple objects with entries that can be converted to C type unsigned. Such entries might be of Python type None, int, or of any ctypes integer type.

The type can be initialized from the following Python objects:

  • list / tuple of types that can be converted to C type unsigned:

    A list or tuple of types that can be converted to C type unsigned. In this case, this type allocates an array of C unsigned values wherein it stores the values obtained from the list/tuple entries. Furthermore, the instance’s self._is_ptr_owner C attribute is set to True in this case.

  • object that is accepted as input by __init__:

    In this case, init code from Pointer is used and the C attribute self._is_ptr_owner remains unchanged. See Pointer for more information.

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 Pointer for more information.

_py_buffer (Py_buffer, protected):

See Pointer for more information.

_py_buffer_acquired (bool, protected):

See Pointer for more information.

_is_ptr_owner (bint, protected):

If this object is the owner of the allocated buffer. Defaults to False.

__getitem__()#

Returns a new Pointer whose pointer is this instance’s pointer offsetted by offset.

Args:

offset (int): Offset (in bytes) to add to this instance’s pointer.

__init__()#

Constructor.

Args:
pyobj (object):

See the class description ListOfUnsigned for information about accepted types for pyobj.

Raises:

TypeError: If the input object pyobj is not of the right type.

as_c_void_p(self)#

Data pointer as ctypes.c_void_p.

createRef(self) Pointer#

Creates are reference to this pointer.

Returns a Pointer that stores the address of this `~.Pointer’s data pointer.

Note:

No ownership information is transferred.

static fromObj(pyobj)#

Creates a ListOfUnsigned from the given object.

In case pyobj is itself an ListOfUnsigned instance, this method returns it directly. No new ListOfUnsigned is created.

is_ptr_null#

If data pointer is NULL.

class hip._util.types.ListOfUnsignedLong(pyobj)#

Bases: Pointer

Datatype for handling Python list or tuple objects with entries that can be converted to C type unsigned long.

Datatype for handling Python list and tuple objects with entries that can be converted to C type unsigned long. Such entries might be of Python type None, int, or of any ctypes integer type.

The type can be initialized from the following Python objects:

  • list / tuple of types that can be converted to C type unsigned long:

    A list or tuple of types that can be converted to C type unsigned long. In this case, this type allocates an array of C unsigned long values wherein it stores the values obtained from the list/tuple entries. Furthermore, the instance’s self._is_ptr_owner C attribute is set to True in this case.

  • object that is accepted as input by __init__:

    In this case, init code from Pointer is used and the C attribute self._is_ptr_owner remains unchanged. See Pointer for more information.

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 Pointer for more information.

_py_buffer (Py_buffer, protected):

See Pointer for more information.

_py_buffer_acquired (bool, protected):

See Pointer for more information.

_is_ptr_owner (bint, protected):

If this object is the owner of the allocated buffer. Defaults to False.

__getitem__()#

Returns a new Pointer whose pointer is this instance’s pointer offsetted by offset.

Args:

offset (int): Offset (in bytes) to add to this instance’s pointer.

__init__()#

Constructor.

Args:
pyobj (object):

See the class description ListOfUnsigned for information about accepted types for pyobj.

Raises:

TypeError: If the input object pyobj is not of the right type.

as_c_void_p(self)#

Data pointer as ctypes.c_void_p.

createRef(self) Pointer#

Creates are reference to this pointer.

Returns a Pointer that stores the address of this `~.Pointer’s data pointer.

Note:

No ownership information is transferred.

static fromObj(pyobj)#

Creates a ListOfUnsignedLong from the given object.

In case pyobj is itself an ListOfUnsignedLong instance, this method returns it directly. No new ListOfUnsignedLong is created.

is_ptr_null#

If data pointer is NULL.