numba_dpex.utils package
Submodules
Module contents
Various utility functions and classes to aid LLVM IR building.
- class numba_dpex.utils.LLVMTypes
Bases:
objectA helper class to get LLVM Values for integer C types.
- byte_ptr_ptr_t = <<class 'llvmlite.ir.types.PointerType'> i8**>
- byte_ptr_t = <<class 'llvmlite.ir.types.PointerType'> i8*>
- byte_t = <<class 'llvmlite.ir.types.IntType'> i8>
- int32_ptr_t = <<class 'llvmlite.ir.types.PointerType'> i32*>
- int32_t = <<class 'llvmlite.ir.types.IntType'> i32>
- int64_ptr_t = <<class 'llvmlite.ir.types.PointerType'> i64*>
- int64_t = <<class 'llvmlite.ir.types.IntType'> i64>
- void_t = <<class 'llvmlite.ir.types.VoidType'> void>
- class numba_dpex.utils.address_space
Bases:
objectThe address space values supported by numba_dpex.
Address space
Value
PRIVATE
0
GLOBAL
1
CONSTANT
2
LOCAL
3
GENERIC
4
- CONSTANT = 2
- GENERIC = 4
- GLOBAL = 1
- LOCAL = 3
- PRIVATE = 0
- numba_dpex.utils.as_usm_obj(obj, queue=None, usm_type='shared', copy=True)
Determine and return a SYCL device accessible object.
We try to determine if the provided object defines a valid __sycl_usm_array_interface__ dictionary. If not, we create a USM memory of
usm_typeand try to copy the dataobjholds. Only numpy.ndarray is supported currently as obj if the object is not already allocated using USM.- Args:
obj: Object to be tested and data copied from. usm_type: USM type used in case obj is not already allocated using USM. queue (dpctl.SyclQueue): SYCL queue to be used to allocate USM memory in case obj is not already USM allocated. copy (bool): Flag to determine if we copy data from obj.
- Returns:
A Python object allocated using USM memory.
- Raises:
- TypeError:
If obj is not allocated on USM memory or is not of type numpy.ndarray, TypeError is raised.
If queue is not of type dpctl.SyclQueue.
- ValueError:
In case obj is not USM allocated, users need to pass the SYCL queue to be used for creating new memory. ValueError is raised if queue argument is not provided.
If usm_type is not valid.
If dtype of the passed ndarray(obj) is not supported.
- class numba_dpex.utils.calling_conv
Bases:
object- CC_SPIR_FUNC = 'spir_func'
- CC_SPIR_KERNEL = 'spir_kernel'
- numba_dpex.utils.copy_from_numpy_to_usm_obj(usm_allocated, obj)
Copy from supported objects to USM allocated data.
This function copies the data of a supported Python type (only numpy.ndarray is supported at this point) into object that defines a
__sycl_usm_array_interface__attribute. For more information please refer to the specification of__sycl_usm_array_interface__: https://github.com/IntelPython/dpctl/wiki/Zero-copy-data-exchange-using-SYCL-USM#sycl-usm-array-interface- Args:
usm_allocated: An object that should define a
__sycl_usm_array_interface__dictionary. A TypeError is thrown if the object does not have such an attribute. obj (numpy.ndarray): Numpy ndarray, the data will be copied into.- Raises:
- TypeError:
If any argument is not of permitted type.
- ValueError:
If size of data does not match.
If obj is not C-contiguous.
- numba_dpex.utils.copy_to_numpy_from_usm_obj(usm_allocated, obj)
Copy from USM allocated data to supported objects.
- Args:
usm_allocated: An object that should define a __sycl_usm_array_interface__ dictionary. A TypeError is thrown if the object does not have such an attribute. obj (numpy.ndarray): Numpy ndarray, the data will be copied into.
- Raises:
- TypeError:
If any argument is not of permitted type.
- ValueError:
If size of data does not match.
- numba_dpex.utils.create_null_ptr(builder, context)
Allocates a new LLVM Value storing a
void*and returns the Value to caller.- Args:
builder: The LLVM IR builder to be used for code generation. context: The LLVM IR builder context.
Returns: An LLVM value storing a null pointer
- numba_dpex.utils.get_llvm_ptr_type(type)
Returns an LLVM pointer type for a give LLVM type object.
- Args:
type: An LLVM type for which we need the corresponding pointer type.
Returns: An LLVM pointer type object corresponding to the input LLVM type.
- numba_dpex.utils.get_llvm_type(context, type)
Returns the LLVM Value corresponding to a Numba type.
- Args:
context: The LLVM context or the execution state of the current IR generator. type: A Numba type object.
- Returns: An Python object wrapping an LLVM Value corresponding to the
specified Numba type.
- numba_dpex.utils.get_one(context)
Returns an LLVM Constant storing a 64 bit representation for one.
- Args:
context: The LLVM IR builder context.
Returns: An LLVM Constant Value storing one.
- numba_dpex.utils.get_zero(context)
Returns an LLVM Constant storing a 64 bit representation for zero.
- Args:
context: The LLVM IR builder context.
Returns: An LLVM Constant Value storing zero.
- numba_dpex.utils.has_usm_memory(obj)
Determine and return a SYCL device accessible object.
as_usm_memory() converts Python object with __sycl_usm_array_interface__ property to one of
MemoryUSMShared,MemoryUSMDevice, orMemoryUSMHostinstances. For more information please refer: https://github.com/IntelPython/dpctl/blob/0.8.0/dpctl/memory/_memory.pyx#L673- Args:
obj: Object to be tested and data copied from.
- Returns:
A Python object allocated using USM memory if argument is already allocated using USM (zero-copy), None otherwise.