numba_vulkan.mathimpl#
Lowering of the math module onto GLSL.std.450 via LLVM intrinsics.
Attributes#
Functions#
|
Call an LLVM floating point intrinsic. |
|
Decide whether a |
|
|
|
Call a libclc math function, or this package's replacement for it. |
|
The low and high 32-bit words of a |
|
The |
|
Lower |
|
Lower |
|
Lower |
|
Lower |
|
Select this package's implementation of an integer-exponent power. |
Module Contents#
- numba_vulkan.mathimpl.registry#
- numba_vulkan.mathimpl.lower#
- numba_vulkan.mathimpl.call_intrinsic(builder, name, args)#
Call an LLVM floating point intrinsic.
- Parameters:
- Returns:
The result, of the same type as the arguments.
- Return type:
llvmlite.ir.Value
Notes
The SPIR-V backend maps these intrinsics to GLSL.std.450 extended instructions.
- numba_vulkan.mathimpl.libclc_name(context, pyfn, ty)#
Decide whether a
mathfunction is taken from libclc.libclc is preferred: its functions are accurate to the last digit or two, give the same results on every device, and exist in double precision. With
fastmath, float32 functions use the device’s built-in versions instead, which are faster but less accurate and differ between drivers. float64 has no built-in alternative.- Parameters:
context (VulkanTargetContext) – The target context; its
fast_mathflag is consulted.pyfn (callable) – The
mathfunction.ty (numba.types.Float) – Type the function is evaluated in.
- Returns:
The libclc name to call, or
Noneto use another implementation.- Return type:
str or None
- numba_vulkan.mathimpl.reduced_exp(builder, x, scale=0)#
expof adouble, reduced here before calling libclc.libclc’s own
float64exploses precision as the argument grows on some devices (up to 673 ulp on llvmpipe and 208 on Intel’s UHD 630 near 700, 1 ulp on NVIDIA), while it is accurate everywhere for small arguments. Soxis split intok ln 2 + rwith|r| <= ln(2)/2and exact arithmetic, libclc computesexp(r), and the result is scaled by2**k, built from its bit pattern in two factors so that neither overflows near the ends of the range.- Parameters:
builder (llvmlite.ir.IRBuilder) – Builder positioned where the code is emitted.
x (llvmlite.ir.Value) – The argument, a
double.scale (int, optional) – Power of two to multiply the result by, exactly;
-1givesexp(x) / 2without overflowing where that is finite.
- Returns:
exp(x) * 2**scaleas adouble.- Return type:
llvmlite.ir.Value
Notes
Arguments beyond about 746 in magnitude, infinities and NaN go to libclc unreduced; the result is then infinite, zero or NaN anyway.
- numba_vulkan.mathimpl.call_libclc(builder, name, args, ty)#
Call a libclc math function, or this package’s replacement for it.
- Parameters:
- Returns:
The result, of type ty.
- Return type:
llvmlite.ir.Value
- numba_vulkan.mathimpl.double_words(builder, value)#
The low and high 32-bit words of a
double.Working on words instead of a 64-bit integer keeps bit manipulation of
float64values intact when a kernel computes with 32-bit integers (see numba_vulkan.narrowing).- Returns:
low, high –
i32values.- Return type:
llvmlite.ir.Value
- numba_vulkan.mathimpl.words_double(builder, low, high)#
The
doublewith the given low and high words.
- numba_vulkan.mathimpl.lower_copysign(context, builder, sig, args)#
Lower
math.copysignby combining bit patterns.The SPIR-V backend cannot select
llvm.copysign.- Parameters:
context (VulkanTargetContext) – The target context.
builder (llvmlite.ir.IRBuilder) – Builder positioned where the code is emitted.
sig (numba.core.typing.Signature) – Signature the call was typed with.
args (sequence of llvmlite.ir.Value) – Argument values, in the types of
sig.args.
- Returns:
The magnitude of the first argument with the sign of the second.
- Return type:
llvmlite.ir.Value
- numba_vulkan.mathimpl.lower_fmod(context, builder, sig, args)#
Lower
math.fmod: the remainder with the sign of the dividend.- Parameters:
context (VulkanTargetContext) – The target context.
builder (llvmlite.ir.IRBuilder) – Builder positioned where the code is emitted.
sig (numba.core.typing.Signature) – Signature the call was typed with.
args (sequence of llvmlite.ir.Value) – Argument values, in the types of
sig.args.
- Returns:
The remainder, as a value of the return type.
- Return type:
llvmlite.ir.Value
- numba_vulkan.mathimpl.float_int_power(context, builder, sig, args)#
Lower
float ** intandpow(float, int).A negative exponent gives the reciprocal of the positive power.
- Parameters:
context (VulkanTargetContext) – The target context.
builder (llvmlite.ir.IRBuilder) – Builder positioned where the code is emitted.
sig (numba.core.typing.Signature) – Signature the call was typed with.
args (sequence of llvmlite.ir.Value) – Argument values, in the types of
sig.args.
- Returns:
The power, as a value of the return type.
- Return type:
llvmlite.ir.Value
Notes
Numba’s implementation contains a float64
powfallback for large exponents, which Vulkan lacks; this one only multiplies.
- numba_vulkan.mathimpl.int_int_power(context, builder, sig, args)#
Lower
int ** intandpow(int, int).As in Numba, a negative exponent gives 0 unless the base is 1 or -1. Unlike Numba,
0 ** negativegives 0 instead of raising.- Parameters:
context (VulkanTargetContext) – The target context.
builder (llvmlite.ir.IRBuilder) – Builder positioned where the code is emitted.
sig (numba.core.typing.Signature) – Signature the call was typed with.
args (sequence of llvmlite.ir.Value) – Argument values, in the types of
sig.args.
- Returns:
The power, as a value of the return type.
- Return type:
llvmlite.ir.Value
- numba_vulkan.mathimpl.power_override(fn, sig)#
Select this package’s implementation of an integer-exponent power.
Numba registers its implementations per concrete type, which entries in a lowering registry cannot outrank, so VulkanTargetContext.get_function asks this function first.
- Parameters:
fn (callable or numba.types.Function) – The function being resolved.
sig (numba.core.typing.Signature) – Signature of the call.
- Returns:
float_int_power or int_int_power for powers with a non-literal integer exponent, otherwise
None.- Return type:
callable or None