numba_dpex.core.targets.kernel_target module

class numba_dpex.core.targets.kernel_target.DpexCallConv(context)

Bases: MinimalCallConv

Custom calling convention class used by numba-dpex.

numba_dpex’s calling convention derives from numba.core.callconv import MinimalCallConv. The DpexCallConv overriddes call_function().

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

Call the Numba-compiled callee.

class numba_dpex.core.targets.kernel_target.DpexKernelTargetContext(typingctx, target='SyclDevice')

Bases: BaseContext

A target context inheriting Numba’s BaseContext that is customized for generating SYCL kernels.

A customized target context for generating SPIR-V kernels. The class defines helper functions to generates SPIR-V kernels as LLVM IR using the required calling conventions and metadata. The class also registers OpenCL math and API functions, helper functions for inserting LLVM address space cast instructions, and other functionalities used by the compiler to generate SPIR-V kernels.

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.ir.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.

Parameters

ufunc_key : NumPy ufunc

Returns

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_depx’s target context.

To make sure we are calling supported OpenCL math functions, we replace the dpnp functions that default to NUMBA’s NumPy ufunc with OpenCL intrinsics that are equivalent to those functions. The replacement is done after the OpenCL functions have been registered into the target context.

mangler(name, argtypes, abi_tags=(), uid=None)

Perform name mangling.

mark_ocl_device(func)
prepare_ocl_kernel(func, argtypes)
replace_dpnp_ufunc_with_ocl_intrinsics()
property target_data
class numba_dpex.core.targets.kernel_target.DpexKernelTypingContext

Bases: BaseContext

Custom typing context to support kernel compilation.

The customized typing context provides two features required to compile Python functions decorated by the kernel decorator: An overridden resolve_argument_type() that changes all npytypes.Array to numba_depx.core.types.Array. 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 numba_dpex.core.types.Array 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.core.targets.kernel_target.SyclDevice

Bases: GPU

Mark the hardware target as SYCL Device.