numba_dpex.core.targets.kernel_target module
- class numba_dpex.core.targets.kernel_target.DpexCallConv(context)
Bases:
MinimalCallConvCustom calling convention class used by numba-dpex.
numba_dpex’s calling convention derives from
numba.core.callconv import MinimalCallConv. TheDpexCallConvoverriddescall_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:
BaseContextA target context inheriting Numba’s
BaseContextthat 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
NotImplementedErrorexception. Subclasses should implement this method.
- declare_function(module, fndesc)
Create the LLVM function from a
numba_dpex.kerneldecorated 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
NotImplementedErrorexception. Subclasses may raiseKeyErrorto signal that the givenufunc_keyis 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:
BaseContextCustom 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 allnpytypes.Arraytonumba_depx.core.types.Array. An overriddenload_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.BaseContextto handle the special case ofnumba.core.types.npytypes.Array. Whenever a NumPy ndarray argument is encountered as an argument to akernelfunction, it is converted to anumba_dpex.core.types.Arraytype.- Args:
- valA Python value that is passed as an argument to a
kernel function.
- valA Python value that is passed as an argument to a
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:
GPUMark the hardware target as SYCL Device.