numba-cuda 0.19.1__py3-none-any.whl → 0.20.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of numba-cuda might be problematic. Click here for more details.
- numba_cuda/VERSION +1 -1
- numba_cuda/numba/cuda/__init__.py +1 -1
- numba_cuda/numba/cuda/_internal/cuda_bf16.py +12706 -1470
- numba_cuda/numba/cuda/_internal/cuda_fp16.py +2653 -8769
- numba_cuda/numba/cuda/api.py +6 -1
- numba_cuda/numba/cuda/bf16.py +285 -2
- numba_cuda/numba/cuda/cgutils.py +2 -2
- numba_cuda/numba/cuda/cloudpickle/__init__.py +21 -0
- numba_cuda/numba/cuda/cloudpickle/cloudpickle.py +1598 -0
- numba_cuda/numba/cuda/cloudpickle/cloudpickle_fast.py +17 -0
- numba_cuda/numba/cuda/codegen.py +1 -1
- numba_cuda/numba/cuda/compiler.py +373 -30
- numba_cuda/numba/cuda/core/analysis.py +319 -0
- numba_cuda/numba/cuda/core/annotations/__init__.py +0 -0
- numba_cuda/numba/cuda/core/annotations/type_annotations.py +304 -0
- numba_cuda/numba/cuda/core/base.py +1289 -0
- numba_cuda/numba/cuda/core/bytecode.py +727 -0
- numba_cuda/numba/cuda/core/caching.py +2 -2
- numba_cuda/numba/cuda/core/compiler.py +6 -14
- numba_cuda/numba/cuda/core/compiler_machinery.py +497 -0
- numba_cuda/numba/cuda/core/config.py +747 -0
- numba_cuda/numba/cuda/core/consts.py +124 -0
- numba_cuda/numba/cuda/core/cpu.py +370 -0
- numba_cuda/numba/cuda/core/environment.py +68 -0
- numba_cuda/numba/cuda/core/event.py +511 -0
- numba_cuda/numba/cuda/core/funcdesc.py +330 -0
- numba_cuda/numba/cuda/core/inline_closurecall.py +1889 -0
- numba_cuda/numba/cuda/core/interpreter.py +48 -26
- numba_cuda/numba/cuda/core/ir_utils.py +15 -26
- numba_cuda/numba/cuda/core/options.py +262 -0
- numba_cuda/numba/cuda/core/postproc.py +249 -0
- numba_cuda/numba/cuda/core/pythonapi.py +1868 -0
- numba_cuda/numba/cuda/core/rewrites/__init__.py +26 -0
- numba_cuda/numba/cuda/core/rewrites/ir_print.py +90 -0
- numba_cuda/numba/cuda/core/rewrites/registry.py +104 -0
- numba_cuda/numba/cuda/core/rewrites/static_binop.py +40 -0
- numba_cuda/numba/cuda/core/rewrites/static_getitem.py +187 -0
- numba_cuda/numba/cuda/core/rewrites/static_raise.py +98 -0
- numba_cuda/numba/cuda/core/ssa.py +496 -0
- numba_cuda/numba/cuda/core/targetconfig.py +329 -0
- numba_cuda/numba/cuda/core/tracing.py +231 -0
- numba_cuda/numba/cuda/core/transforms.py +952 -0
- numba_cuda/numba/cuda/core/typed_passes.py +738 -7
- numba_cuda/numba/cuda/core/typeinfer.py +1948 -0
- numba_cuda/numba/cuda/core/unsafe/__init__.py +0 -0
- numba_cuda/numba/cuda/core/unsafe/bytes.py +67 -0
- numba_cuda/numba/cuda/core/unsafe/eh.py +66 -0
- numba_cuda/numba/cuda/core/unsafe/refcount.py +98 -0
- numba_cuda/numba/cuda/core/untyped_passes.py +1983 -0
- numba_cuda/numba/cuda/cpython/cmathimpl.py +560 -0
- numba_cuda/numba/cuda/cpython/mathimpl.py +499 -0
- numba_cuda/numba/cuda/cpython/numbers.py +1474 -0
- numba_cuda/numba/cuda/cuda_paths.py +422 -246
- numba_cuda/numba/cuda/cudadecl.py +1 -1
- numba_cuda/numba/cuda/cudadrv/__init__.py +1 -1
- numba_cuda/numba/cuda/cudadrv/devicearray.py +2 -1
- numba_cuda/numba/cuda/cudadrv/driver.py +11 -140
- numba_cuda/numba/cuda/cudadrv/dummyarray.py +111 -24
- numba_cuda/numba/cuda/cudadrv/libs.py +5 -5
- numba_cuda/numba/cuda/cudadrv/mappings.py +1 -1
- numba_cuda/numba/cuda/cudadrv/nvrtc.py +19 -8
- numba_cuda/numba/cuda/cudadrv/nvvm.py +1 -4
- numba_cuda/numba/cuda/cudadrv/runtime.py +1 -1
- numba_cuda/numba/cuda/cudaimpl.py +5 -1
- numba_cuda/numba/cuda/debuginfo.py +85 -2
- numba_cuda/numba/cuda/decorators.py +3 -3
- numba_cuda/numba/cuda/descriptor.py +3 -4
- numba_cuda/numba/cuda/deviceufunc.py +66 -2
- numba_cuda/numba/cuda/dispatcher.py +18 -39
- numba_cuda/numba/cuda/flags.py +141 -1
- numba_cuda/numba/cuda/fp16.py +0 -2
- numba_cuda/numba/cuda/include/13/cuda_bf16.h +5118 -0
- numba_cuda/numba/cuda/include/13/cuda_bf16.hpp +3865 -0
- numba_cuda/numba/cuda/include/13/cuda_fp16.h +5363 -0
- numba_cuda/numba/cuda/include/13/cuda_fp16.hpp +3483 -0
- numba_cuda/numba/cuda/lowering.py +7 -144
- numba_cuda/numba/cuda/mathimpl.py +2 -1
- numba_cuda/numba/cuda/memory_management/nrt.py +43 -17
- numba_cuda/numba/cuda/misc/findlib.py +75 -0
- numba_cuda/numba/cuda/models.py +9 -1
- numba_cuda/numba/cuda/np/npdatetime_helpers.py +217 -0
- numba_cuda/numba/cuda/np/npyfuncs.py +1807 -0
- numba_cuda/numba/cuda/np/numpy_support.py +553 -0
- numba_cuda/numba/cuda/np/ufunc/ufuncbuilder.py +59 -0
- numba_cuda/numba/cuda/nvvmutils.py +1 -1
- numba_cuda/numba/cuda/printimpl.py +12 -1
- numba_cuda/numba/cuda/random.py +1 -1
- numba_cuda/numba/cuda/serialize.py +1 -1
- numba_cuda/numba/cuda/simulator/__init__.py +1 -1
- numba_cuda/numba/cuda/simulator/api.py +1 -1
- numba_cuda/numba/cuda/simulator/compiler.py +4 -0
- numba_cuda/numba/cuda/simulator/cudadrv/devicearray.py +1 -1
- numba_cuda/numba/cuda/simulator/kernelapi.py +1 -1
- numba_cuda/numba/cuda/simulator/memory_management/nrt.py +14 -2
- numba_cuda/numba/cuda/target.py +35 -17
- numba_cuda/numba/cuda/testing.py +7 -19
- numba_cuda/numba/cuda/tests/__init__.py +1 -1
- numba_cuda/numba/cuda/tests/cloudpickle_main_class.py +9 -0
- numba_cuda/numba/cuda/tests/core/test_serialize.py +4 -4
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py +1 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_libraries.py +1 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py +1 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_detect.py +6 -3
- numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py +1 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_linker.py +18 -2
- numba_cuda/numba/cuda/tests/cudadrv/test_module_callbacks.py +2 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_nvjitlink.py +1 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_ptds.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/extensions_usecases.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_array.py +2 -1
- numba_cuda/numba/cuda/tests/cudapy/test_atomics.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_bfloat16.py +539 -2
- numba_cuda/numba/cuda/tests/cudapy/test_bfloat16_bindings.py +81 -1
- numba_cuda/numba/cuda/tests/cudapy/test_caching.py +1 -3
- numba_cuda/numba/cuda/tests/cudapy/test_complex.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_constmem.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_cooperative_groups.py +2 -3
- numba_cuda/numba/cuda/tests/cudapy/test_copy_propagate.py +130 -0
- numba_cuda/numba/cuda/tests/cudapy/test_datetime.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_debug.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py +293 -4
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo_types.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_dispatcher.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_errors.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_exception.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_extending.py +2 -1
- numba_cuda/numba/cuda/tests/cudapy/test_inline.py +18 -8
- numba_cuda/numba/cuda/tests/cudapy/test_intrinsics.py +23 -21
- numba_cuda/numba/cuda/tests/cudapy/test_ir_utils.py +10 -37
- numba_cuda/numba/cuda/tests/cudapy/test_laplace.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_math.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_matmul.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_operator.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_print.py +20 -0
- numba_cuda/numba/cuda/tests/cudapy/test_record_dtype.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_reduction.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_serialize.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_sm.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_ssa.py +453 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sync.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_typeinfer.py +538 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ufuncs.py +263 -2
- numba_cuda/numba/cuda/tests/cudapy/test_userexc.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_vector_type.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_decor.py +112 -6
- numba_cuda/numba/cuda/tests/cudapy/test_warning.py +1 -1
- numba_cuda/numba/cuda/tests/cudapy/test_warp_ops.py +1 -1
- numba_cuda/numba/cuda/tests/doc_examples/test_cg.py +0 -2
- numba_cuda/numba/cuda/tests/doc_examples/test_ffi.py +3 -2
- numba_cuda/numba/cuda/tests/doc_examples/test_laplace.py +0 -2
- numba_cuda/numba/cuda/tests/doc_examples/test_sessionize.py +0 -2
- numba_cuda/numba/cuda/tests/nocuda/test_import.py +3 -1
- numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +24 -12
- numba_cuda/numba/cuda/tests/nrt/test_nrt.py +2 -1
- numba_cuda/numba/cuda/tests/support.py +55 -15
- numba_cuda/numba/cuda/tests/test_tracing.py +200 -0
- numba_cuda/numba/cuda/types.py +56 -0
- numba_cuda/numba/cuda/typing/__init__.py +9 -1
- numba_cuda/numba/cuda/typing/cffi_utils.py +55 -0
- numba_cuda/numba/cuda/typing/context.py +751 -0
- numba_cuda/numba/cuda/typing/enumdecl.py +74 -0
- numba_cuda/numba/cuda/typing/npydecl.py +658 -0
- numba_cuda/numba/cuda/typing/templates.py +7 -6
- numba_cuda/numba/cuda/ufuncs.py +3 -3
- numba_cuda/numba/cuda/utils.py +6 -112
- {numba_cuda-0.19.1.dist-info → numba_cuda-0.20.1.dist-info}/METADATA +4 -3
- {numba_cuda-0.19.1.dist-info → numba_cuda-0.20.1.dist-info}/RECORD +171 -116
- numba_cuda/numba/cuda/tests/cudadrv/test_mvc.py +0 -60
- {numba_cuda-0.19.1.dist-info → numba_cuda-0.20.1.dist-info}/WHEEL +0 -0
- {numba_cuda-0.19.1.dist-info → numba_cuda-0.20.1.dist-info}/licenses/LICENSE +0 -0
- {numba_cuda-0.19.1.dist-info → numba_cuda-0.20.1.dist-info}/licenses/LICENSE.numba +0 -0
- {numba_cuda-0.19.1.dist-info → numba_cuda-0.20.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Provide math calls that uses intrinsics or libc math functions.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import math
|
|
9
|
+
import operator
|
|
10
|
+
import sys
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
import llvmlite.ir
|
|
14
|
+
from llvmlite.ir import Constant
|
|
15
|
+
|
|
16
|
+
from numba.core.imputils import impl_ret_untracked, Registry
|
|
17
|
+
from numba.core import types
|
|
18
|
+
from numba.cuda.core import config
|
|
19
|
+
from numba.core.extending import overload
|
|
20
|
+
from numba.core.typing import signature
|
|
21
|
+
from numba.cpython.unsafe.numbers import trailing_zeros
|
|
22
|
+
from numba.cuda import cgutils
|
|
23
|
+
|
|
24
|
+
registry = Registry("mathimpl")
|
|
25
|
+
lower = registry.lower
|
|
26
|
+
|
|
27
|
+
# Helpers, shared with cmathimpl.
|
|
28
|
+
_NP_FLT_FINFO = np.finfo(np.dtype("float32"))
|
|
29
|
+
FLT_MAX = _NP_FLT_FINFO.max
|
|
30
|
+
FLT_MIN = _NP_FLT_FINFO.tiny
|
|
31
|
+
|
|
32
|
+
_NP_DBL_FINFO = np.finfo(np.dtype("float64"))
|
|
33
|
+
DBL_MAX = _NP_DBL_FINFO.max
|
|
34
|
+
DBL_MIN = _NP_DBL_FINFO.tiny
|
|
35
|
+
|
|
36
|
+
FLOAT_ABS_MASK = 0x7FFFFFFF
|
|
37
|
+
FLOAT_SIGN_MASK = 0x80000000
|
|
38
|
+
DOUBLE_ABS_MASK = 0x7FFFFFFFFFFFFFFF
|
|
39
|
+
DOUBLE_SIGN_MASK = 0x8000000000000000
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def is_nan(builder, val):
|
|
43
|
+
"""
|
|
44
|
+
Return a condition testing whether *val* is a NaN.
|
|
45
|
+
"""
|
|
46
|
+
return builder.fcmp_unordered("uno", val, val)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def is_inf(builder, val):
|
|
50
|
+
"""
|
|
51
|
+
Return a condition testing whether *val* is an infinite.
|
|
52
|
+
"""
|
|
53
|
+
pos_inf = Constant(val.type, float("+inf"))
|
|
54
|
+
neg_inf = Constant(val.type, float("-inf"))
|
|
55
|
+
isposinf = builder.fcmp_ordered("==", val, pos_inf)
|
|
56
|
+
isneginf = builder.fcmp_ordered("==", val, neg_inf)
|
|
57
|
+
return builder.or_(isposinf, isneginf)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def is_finite(builder, val):
|
|
61
|
+
"""
|
|
62
|
+
Return a condition testing whether *val* is a finite.
|
|
63
|
+
"""
|
|
64
|
+
# is_finite(x) <=> x - x != NaN
|
|
65
|
+
val_minus_val = builder.fsub(val, val)
|
|
66
|
+
return builder.fcmp_ordered("ord", val_minus_val, val_minus_val)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def f64_as_int64(builder, val):
|
|
70
|
+
"""
|
|
71
|
+
Bitcast a double into a 64-bit integer.
|
|
72
|
+
"""
|
|
73
|
+
assert val.type == llvmlite.ir.DoubleType()
|
|
74
|
+
return builder.bitcast(val, llvmlite.ir.IntType(64))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def int64_as_f64(builder, val):
|
|
78
|
+
"""
|
|
79
|
+
Bitcast a 64-bit integer into a double.
|
|
80
|
+
"""
|
|
81
|
+
assert val.type == llvmlite.ir.IntType(64)
|
|
82
|
+
return builder.bitcast(val, llvmlite.ir.DoubleType())
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def f32_as_int32(builder, val):
|
|
86
|
+
"""
|
|
87
|
+
Bitcast a float into a 32-bit integer.
|
|
88
|
+
"""
|
|
89
|
+
assert val.type == llvmlite.ir.FloatType()
|
|
90
|
+
return builder.bitcast(val, llvmlite.ir.IntType(32))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def int32_as_f32(builder, val):
|
|
94
|
+
"""
|
|
95
|
+
Bitcast a 32-bit integer into a float.
|
|
96
|
+
"""
|
|
97
|
+
assert val.type == llvmlite.ir.IntType(32)
|
|
98
|
+
return builder.bitcast(val, llvmlite.ir.FloatType())
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def negate_real(builder, val):
|
|
102
|
+
"""
|
|
103
|
+
Negate real number *val*, with proper handling of zeros.
|
|
104
|
+
"""
|
|
105
|
+
# The negative zero forces LLVM to handle signed zeros properly.
|
|
106
|
+
return builder.fsub(Constant(val.type, -0.0), val)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def call_fp_intrinsic(builder, name, args):
|
|
110
|
+
"""
|
|
111
|
+
Call a LLVM intrinsic floating-point operation.
|
|
112
|
+
"""
|
|
113
|
+
mod = builder.module
|
|
114
|
+
intr = mod.declare_intrinsic(name, [a.type for a in args])
|
|
115
|
+
return builder.call(intr, args)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _unary_int_input_wrapper_impl(wrapped_impl):
|
|
119
|
+
"""
|
|
120
|
+
Return an implementation factory to convert the single integral input
|
|
121
|
+
argument to a float64, then defer to the *wrapped_impl*.
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
def implementer(context, builder, sig, args):
|
|
125
|
+
(val,) = args
|
|
126
|
+
input_type = sig.args[0]
|
|
127
|
+
fpval = context.cast(builder, val, input_type, types.float64)
|
|
128
|
+
inner_sig = signature(types.float64, types.float64)
|
|
129
|
+
res = wrapped_impl(context, builder, inner_sig, (fpval,))
|
|
130
|
+
return context.cast(builder, res, types.float64, sig.return_type)
|
|
131
|
+
|
|
132
|
+
return implementer
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def unary_math_int_impl(fn, float_impl):
|
|
136
|
+
impl = _unary_int_input_wrapper_impl(float_impl)
|
|
137
|
+
lower(fn, types.Integer)(impl)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def unary_math_intr(fn, intrcode):
|
|
141
|
+
"""
|
|
142
|
+
Implement the math function *fn* using the LLVM intrinsic *intrcode*.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
@lower(fn, types.Float)
|
|
146
|
+
def float_impl(context, builder, sig, args):
|
|
147
|
+
res = call_fp_intrinsic(builder, intrcode, args)
|
|
148
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
149
|
+
|
|
150
|
+
unary_math_int_impl(fn, float_impl)
|
|
151
|
+
return float_impl
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def unary_math_extern(fn, f32extern, f64extern, int_restype=False):
|
|
155
|
+
"""
|
|
156
|
+
Register implementations of Python function *fn* using the
|
|
157
|
+
external function named *f32extern* and *f64extern* (for float32
|
|
158
|
+
and float64 inputs, respectively).
|
|
159
|
+
If *int_restype* is true, then the function's return value should be
|
|
160
|
+
integral, otherwise floating-point.
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
def float_impl(context, builder, sig, args):
|
|
164
|
+
"""
|
|
165
|
+
Implement *fn* for a types.Float input.
|
|
166
|
+
"""
|
|
167
|
+
[val] = args
|
|
168
|
+
input_type = sig.args[0]
|
|
169
|
+
lty = context.get_value_type(input_type)
|
|
170
|
+
func_name = {
|
|
171
|
+
types.float32: f32extern,
|
|
172
|
+
types.float64: f64extern,
|
|
173
|
+
}[input_type]
|
|
174
|
+
fnty = llvmlite.ir.FunctionType(lty, [lty])
|
|
175
|
+
fn = cgutils.insert_pure_function(builder.module, fnty, name=func_name)
|
|
176
|
+
res = builder.call(fn, (val,))
|
|
177
|
+
res = context.cast(builder, res, input_type, sig.return_type)
|
|
178
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
179
|
+
|
|
180
|
+
lower(fn, types.Float)(float_impl)
|
|
181
|
+
|
|
182
|
+
# Implement wrapper for integer inputs
|
|
183
|
+
unary_math_int_impl(fn, float_impl)
|
|
184
|
+
|
|
185
|
+
return float_impl
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
unary_math_intr(math.fabs, "llvm.fabs")
|
|
189
|
+
exp_impl = unary_math_intr(math.exp, "llvm.exp")
|
|
190
|
+
log_impl = unary_math_intr(math.log, "llvm.log")
|
|
191
|
+
log10_impl = unary_math_intr(math.log10, "llvm.log10")
|
|
192
|
+
log2_impl = unary_math_intr(math.log2, "llvm.log2")
|
|
193
|
+
sin_impl = unary_math_intr(math.sin, "llvm.sin")
|
|
194
|
+
cos_impl = unary_math_intr(math.cos, "llvm.cos")
|
|
195
|
+
|
|
196
|
+
log1p_impl = unary_math_extern(math.log1p, "log1pf", "log1p")
|
|
197
|
+
expm1_impl = unary_math_extern(math.expm1, "expm1f", "expm1")
|
|
198
|
+
erf_impl = unary_math_extern(math.erf, "erff", "erf")
|
|
199
|
+
erfc_impl = unary_math_extern(math.erfc, "erfcf", "erfc")
|
|
200
|
+
|
|
201
|
+
tan_impl = unary_math_extern(math.tan, "tanf", "tan")
|
|
202
|
+
asin_impl = unary_math_extern(math.asin, "asinf", "asin")
|
|
203
|
+
acos_impl = unary_math_extern(math.acos, "acosf", "acos")
|
|
204
|
+
atan_impl = unary_math_extern(math.atan, "atanf", "atan")
|
|
205
|
+
|
|
206
|
+
asinh_impl = unary_math_extern(math.asinh, "asinhf", "asinh")
|
|
207
|
+
acosh_impl = unary_math_extern(math.acosh, "acoshf", "acosh")
|
|
208
|
+
atanh_impl = unary_math_extern(math.atanh, "atanhf", "atanh")
|
|
209
|
+
sinh_impl = unary_math_extern(math.sinh, "sinhf", "sinh")
|
|
210
|
+
cosh_impl = unary_math_extern(math.cosh, "coshf", "cosh")
|
|
211
|
+
tanh_impl = unary_math_extern(math.tanh, "tanhf", "tanh")
|
|
212
|
+
|
|
213
|
+
log2_impl = unary_math_extern(math.log2, "log2f", "log2")
|
|
214
|
+
ceil_impl = unary_math_extern(math.ceil, "ceilf", "ceil", True)
|
|
215
|
+
floor_impl = unary_math_extern(math.floor, "floorf", "floor", True)
|
|
216
|
+
|
|
217
|
+
gamma_impl = unary_math_extern(
|
|
218
|
+
math.gamma, "numba_gammaf", "numba_gamma"
|
|
219
|
+
) # work-around
|
|
220
|
+
sqrt_impl = unary_math_extern(math.sqrt, "sqrtf", "sqrt")
|
|
221
|
+
trunc_impl = unary_math_extern(math.trunc, "truncf", "trunc", True)
|
|
222
|
+
lgamma_impl = unary_math_extern(math.lgamma, "lgammaf", "lgamma")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
@lower(math.isnan, types.Float)
|
|
226
|
+
def isnan_float_impl(context, builder, sig, args):
|
|
227
|
+
[val] = args
|
|
228
|
+
res = is_nan(builder, val)
|
|
229
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
@lower(math.isnan, types.Integer)
|
|
233
|
+
def isnan_int_impl(context, builder, sig, args):
|
|
234
|
+
res = cgutils.false_bit
|
|
235
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@lower(math.isinf, types.Float)
|
|
239
|
+
def isinf_float_impl(context, builder, sig, args):
|
|
240
|
+
[val] = args
|
|
241
|
+
res = is_inf(builder, val)
|
|
242
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
@lower(math.isinf, types.Integer)
|
|
246
|
+
def isinf_int_impl(context, builder, sig, args):
|
|
247
|
+
res = cgutils.false_bit
|
|
248
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
@lower(math.isfinite, types.Float)
|
|
252
|
+
def isfinite_float_impl(context, builder, sig, args):
|
|
253
|
+
[val] = args
|
|
254
|
+
res = is_finite(builder, val)
|
|
255
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
@lower(math.isfinite, types.Integer)
|
|
259
|
+
def isfinite_int_impl(context, builder, sig, args):
|
|
260
|
+
res = cgutils.true_bit
|
|
261
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
@lower(math.copysign, types.Float, types.Float)
|
|
265
|
+
def copysign_float_impl(context, builder, sig, args):
|
|
266
|
+
lty = args[0].type
|
|
267
|
+
mod = builder.module
|
|
268
|
+
fn = cgutils.get_or_insert_function(
|
|
269
|
+
mod,
|
|
270
|
+
llvmlite.ir.FunctionType(lty, (lty, lty)),
|
|
271
|
+
"llvm.copysign.%s" % lty.intrinsic_name,
|
|
272
|
+
)
|
|
273
|
+
res = builder.call(fn, args)
|
|
274
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
# -----------------------------------------------------------------------------
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
@lower(math.frexp, types.Float)
|
|
281
|
+
def frexp_impl(context, builder, sig, args):
|
|
282
|
+
(val,) = args
|
|
283
|
+
fltty = context.get_data_type(sig.args[0])
|
|
284
|
+
intty = context.get_data_type(sig.return_type[1])
|
|
285
|
+
expptr = cgutils.alloca_once(builder, intty, name="exp")
|
|
286
|
+
fnty = llvmlite.ir.FunctionType(
|
|
287
|
+
fltty, (fltty, llvmlite.ir.PointerType(intty))
|
|
288
|
+
)
|
|
289
|
+
fname = {
|
|
290
|
+
"float": "numba_frexpf",
|
|
291
|
+
"double": "numba_frexp",
|
|
292
|
+
}[str(fltty)]
|
|
293
|
+
fn = cgutils.get_or_insert_function(builder.module, fnty, fname)
|
|
294
|
+
res = builder.call(fn, (val, expptr))
|
|
295
|
+
res = cgutils.make_anonymous_struct(builder, (res, builder.load(expptr)))
|
|
296
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
@lower(math.ldexp, types.Float, types.intc)
|
|
300
|
+
def ldexp_impl(context, builder, sig, args):
|
|
301
|
+
val, exp = args
|
|
302
|
+
fltty, intty = map(context.get_data_type, sig.args)
|
|
303
|
+
fnty = llvmlite.ir.FunctionType(fltty, (fltty, intty))
|
|
304
|
+
fname = {
|
|
305
|
+
"float": "numba_ldexpf",
|
|
306
|
+
"double": "numba_ldexp",
|
|
307
|
+
}[str(fltty)]
|
|
308
|
+
fn = cgutils.insert_pure_function(builder.module, fnty, name=fname)
|
|
309
|
+
res = builder.call(fn, (val, exp))
|
|
310
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
# -----------------------------------------------------------------------------
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
@lower(math.atan2, types.int64, types.int64)
|
|
317
|
+
def atan2_s64_impl(context, builder, sig, args):
|
|
318
|
+
[y, x] = args
|
|
319
|
+
y = builder.sitofp(y, llvmlite.ir.DoubleType())
|
|
320
|
+
x = builder.sitofp(x, llvmlite.ir.DoubleType())
|
|
321
|
+
fsig = signature(types.float64, types.float64, types.float64)
|
|
322
|
+
return atan2_float_impl(context, builder, fsig, (y, x))
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
@lower(math.atan2, types.uint64, types.uint64)
|
|
326
|
+
def atan2_u64_impl(context, builder, sig, args):
|
|
327
|
+
[y, x] = args
|
|
328
|
+
y = builder.uitofp(y, llvmlite.ir.DoubleType())
|
|
329
|
+
x = builder.uitofp(x, llvmlite.ir.DoubleType())
|
|
330
|
+
fsig = signature(types.float64, types.float64, types.float64)
|
|
331
|
+
return atan2_float_impl(context, builder, fsig, (y, x))
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
@lower(math.atan2, types.Float, types.Float)
|
|
335
|
+
def atan2_float_impl(context, builder, sig, args):
|
|
336
|
+
assert len(args) == 2
|
|
337
|
+
ty = sig.args[0]
|
|
338
|
+
lty = context.get_value_type(ty)
|
|
339
|
+
func_name = {types.float32: "atan2f", types.float64: "atan2"}[ty]
|
|
340
|
+
fnty = llvmlite.ir.FunctionType(lty, (lty, lty))
|
|
341
|
+
fn = cgutils.insert_pure_function(builder.module, fnty, name=func_name)
|
|
342
|
+
res = builder.call(fn, args)
|
|
343
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
# -----------------------------------------------------------------------------
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
@lower(math.hypot, types.int64, types.int64)
|
|
350
|
+
def hypot_s64_impl(context, builder, sig, args):
|
|
351
|
+
[x, y] = args
|
|
352
|
+
y = builder.sitofp(y, llvmlite.ir.DoubleType())
|
|
353
|
+
x = builder.sitofp(x, llvmlite.ir.DoubleType())
|
|
354
|
+
fsig = signature(types.float64, types.float64, types.float64)
|
|
355
|
+
res = hypot_float_impl(context, builder, fsig, (x, y))
|
|
356
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
@lower(math.hypot, types.uint64, types.uint64)
|
|
360
|
+
def hypot_u64_impl(context, builder, sig, args):
|
|
361
|
+
[x, y] = args
|
|
362
|
+
y = builder.sitofp(y, llvmlite.ir.DoubleType())
|
|
363
|
+
x = builder.sitofp(x, llvmlite.ir.DoubleType())
|
|
364
|
+
fsig = signature(types.float64, types.float64, types.float64)
|
|
365
|
+
res = hypot_float_impl(context, builder, fsig, (x, y))
|
|
366
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
@lower(math.hypot, types.Float, types.Float)
|
|
370
|
+
def hypot_float_impl(context, builder, sig, args):
|
|
371
|
+
xty, yty = sig.args
|
|
372
|
+
assert xty == yty == sig.return_type
|
|
373
|
+
x, y = args
|
|
374
|
+
|
|
375
|
+
# Windows has alternate names for hypot/hypotf, see
|
|
376
|
+
# https://msdn.microsoft.com/fr-fr/library/a9yb3dbt%28v=vs.80%29.aspx
|
|
377
|
+
fname = {
|
|
378
|
+
types.float32: "_hypotf" if sys.platform == "win32" else "hypotf",
|
|
379
|
+
types.float64: "_hypot" if sys.platform == "win32" else "hypot",
|
|
380
|
+
}[xty]
|
|
381
|
+
plat_hypot = types.ExternalFunction(fname, sig)
|
|
382
|
+
|
|
383
|
+
if sys.platform == "win32" and config.MACHINE_BITS == 32:
|
|
384
|
+
inf = xty(float("inf"))
|
|
385
|
+
|
|
386
|
+
def hypot_impl(x, y):
|
|
387
|
+
if math.isinf(x) or math.isinf(y):
|
|
388
|
+
return inf
|
|
389
|
+
return plat_hypot(x, y)
|
|
390
|
+
else:
|
|
391
|
+
|
|
392
|
+
def hypot_impl(x, y):
|
|
393
|
+
return plat_hypot(x, y)
|
|
394
|
+
|
|
395
|
+
res = context.compile_internal(builder, hypot_impl, sig, args)
|
|
396
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
# -----------------------------------------------------------------------------
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
@lower(math.radians, types.Float)
|
|
403
|
+
def radians_float_impl(context, builder, sig, args):
|
|
404
|
+
[x] = args
|
|
405
|
+
coef = context.get_constant(sig.return_type, math.pi / 180)
|
|
406
|
+
res = builder.fmul(x, coef)
|
|
407
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
unary_math_int_impl(math.radians, radians_float_impl)
|
|
411
|
+
|
|
412
|
+
# -----------------------------------------------------------------------------
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
@lower(math.degrees, types.Float)
|
|
416
|
+
def degrees_float_impl(context, builder, sig, args):
|
|
417
|
+
[x] = args
|
|
418
|
+
coef = context.get_constant(sig.return_type, 180 / math.pi)
|
|
419
|
+
res = builder.fmul(x, coef)
|
|
420
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
unary_math_int_impl(math.degrees, degrees_float_impl)
|
|
424
|
+
|
|
425
|
+
# -----------------------------------------------------------------------------
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
@lower(math.pow, types.Float, types.Float)
|
|
429
|
+
@lower(math.pow, types.Float, types.Integer)
|
|
430
|
+
def pow_impl(context, builder, sig, args):
|
|
431
|
+
impl = context.get_function(operator.pow, sig)
|
|
432
|
+
return impl(builder, args)
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
# -----------------------------------------------------------------------------
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
@lower(math.nextafter, types.Float, types.Float)
|
|
439
|
+
def nextafter_impl(context, builder, sig, args):
|
|
440
|
+
assert len(args) == 2
|
|
441
|
+
ty = sig.args[0]
|
|
442
|
+
lty = context.get_value_type(ty)
|
|
443
|
+
func_name = {types.float32: "nextafterf", types.float64: "nextafter"}[ty]
|
|
444
|
+
fnty = llvmlite.ir.FunctionType(lty, (lty, lty))
|
|
445
|
+
fn = cgutils.insert_pure_function(builder.module, fnty, name=func_name)
|
|
446
|
+
res = builder.call(fn, args)
|
|
447
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
# -----------------------------------------------------------------------------
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def _unsigned(T):
|
|
454
|
+
"""Convert integer to unsigned integer of equivalent width."""
|
|
455
|
+
pass
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
@overload(_unsigned, target="cuda")
|
|
459
|
+
def _unsigned_impl(T):
|
|
460
|
+
if T in types.unsigned_domain:
|
|
461
|
+
return lambda T: T
|
|
462
|
+
elif T in types.signed_domain:
|
|
463
|
+
newT = getattr(types, "uint{}".format(T.bitwidth))
|
|
464
|
+
return lambda T: newT(T)
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def gcd_impl(context, builder, sig, args):
|
|
468
|
+
xty, yty = sig.args
|
|
469
|
+
assert xty == yty == sig.return_type
|
|
470
|
+
x, y = args
|
|
471
|
+
|
|
472
|
+
def gcd(a, b):
|
|
473
|
+
"""
|
|
474
|
+
Stein's algorithm, heavily cribbed from Julia implementation.
|
|
475
|
+
"""
|
|
476
|
+
T = type(a)
|
|
477
|
+
if a == 0:
|
|
478
|
+
return abs(b)
|
|
479
|
+
if b == 0:
|
|
480
|
+
return abs(a)
|
|
481
|
+
za = trailing_zeros(a)
|
|
482
|
+
zb = trailing_zeros(b)
|
|
483
|
+
k = min(za, zb)
|
|
484
|
+
# Uses np.*_shift instead of operators due to return types
|
|
485
|
+
u = _unsigned(abs(np.right_shift(a, za)))
|
|
486
|
+
v = _unsigned(abs(np.right_shift(b, zb)))
|
|
487
|
+
while u != v:
|
|
488
|
+
if u > v:
|
|
489
|
+
u, v = v, u
|
|
490
|
+
v -= u
|
|
491
|
+
v = np.right_shift(v, trailing_zeros(v))
|
|
492
|
+
r = np.left_shift(T(u), k)
|
|
493
|
+
return r
|
|
494
|
+
|
|
495
|
+
res = context.compile_internal(builder, gcd, sig, args)
|
|
496
|
+
return impl_ret_untracked(context, builder, sig.return_type, res)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
lower(math.gcd, types.Integer, types.Integer)(gcd_impl)
|