numba_dpex.target module

class numba_dpex.target.DPPYCallConv(context)

Bases: numba.core.callconv.MinimalCallConv

Custom calling convention class used by numba-dpex.

numba-dpex’s calling convention derives from numba.core.callconv import MinimalCallConv. The DPPYCallConv overriddes call_function().

call_function(builder, callee, resty, argtys, args, env=None)

Call the Numba-compiled callee.

class numba_dpex.target.DPPYTargetContext(typingctx, target='SyclDevice')

Bases: numba.core.base.BaseContext

A numba_dpex-specific target context inheriting Numba’s BaseContext.

DPPYTargetContext is a customized target context that inherits from Numba’s numba.core.base.BaseContext class. The class defines helper functions to mark LLVM functions as SPIR-V kernels. The class also registers OpenCL math and API functions, helper functions for inserting LLVM address space cast instructions, and other functionalities used by numba_dpex’s compiler passes.

addrspacecast(builder, src, addrspace)

Insert an LLVM addressspace cast instruction into the module.

FIXME: Move this function into utils.

property call_conv
codegen()
create_module(name)

Create a LLVM module

The default implementation in BaseContext always raises a NotImplementedError exception. Subclasses should implement this method.

declare_function(module, fndesc)

Create the LLVM function from a numba_dpex.kernel decorated function.

Args:
module (llvmlite.llvmpy.core.Module)The LLVM module into which

the kernel function will be inserted.

fndesc (numba.core.funcdesc.PythonFunctionDescriptor)The

signature of the function.

Returns:
llvmlite.ir.values.Function: The reference to the LLVM Function

that was inserted into the module.

get_ufunc_info(ufunc_key)

Get the ufunc implementation for a given ufunc object.

The default implementation in BaseContext always raises a NotImplementedError exception. Subclasses may raise KeyError to signal that the given ufunc_key is not available.

ufunc_key : NumPy ufunc

resdict[str, callable]

A mapping of a NumPy ufunc type signature to a lower-level implementation.

implement_powi_as_math_call = True
init()

For subclasses to add initializer

insert_const_string(mod, string)

Create a global string from the passed in string argument and return a void* in the GENERIC address space pointing to that string.

Args:

mod: LLVM module where the global string value is to be inserted. string: A Python string that will be converted to a global constant

string and inserted into the module.

Returns: A LLVM Constant pointing to the global string value inserted

into the module.

load_additional_registries()

Register OpenCL functions into numba-dpex’s target context.

To make sure we are calling supported OpenCL math functions, we replace some of NUMBA’s NumPy ufunc with OpenCL versions of those functions. The replacement is done after the OpenCL functions have been registered into the target context.

mangler(name, argtypes, abi_tags=())

Perform name mangling.

mark_ocl_device(func)
prepare_ocl_kernel(func, argtypes)
replace_numpy_ufunc_with_opencl_supported_functions()
property target_data
class numba_dpex.target.DPPYTypingContext

Bases: numba.core.typing.context.BaseContext

A numba_dpex-specific typing context inheriting Numba’s BaseContext.

DPPYTypingContext is a customized typing context that inherits from Numba’s typing.BaseContext class. We add two specific functionalities to the basic Numba typing context features: An overridden resolve_argument_type() that changes all npytypes.Array to numba-dpex’s dppy_array_type.DppyArray. An overridden load_additional_registries() that registers OpenCL math and other functions to the typing context.

load_additional_registries()

Register the OpenCL API and math and other functions.

resolve_argument_type(val)

Return the Numba type of a Python value used as a function argument.

Overrides the implementation of numba.core.typing.BaseContext to handle the special case of numba.core.types.npytypes.Array. Whenever a NumPy ndarray argument is encountered as an argument to a kernel function, it is converted to a DPPYArray type.

Args:
valA Python value that is passed as an argument to a kernel

function.

Returns: The Numba type corresponding to the Python value.

Raises:

ValueError: If the type of the Python value is not supported.

class numba_dpex.target.GenericPointerModel(dmm, fe_type)

Bases: numba.core.datamodel.models.PrimitiveModel

class numba_dpex.target.SyclDevice

Bases: numba.core.target_extension.GPU

Mark the hardware target as SYCL Device.