numba-cuda 0.0.1__py3-none-any.whl → 0.0.13__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.
- _numba_cuda_redirector.pth +1 -0
- _numba_cuda_redirector.py +74 -0
- numba_cuda/VERSION +1 -0
- numba_cuda/__init__.py +5 -0
- numba_cuda/_version.py +19 -0
- numba_cuda/numba/cuda/__init__.py +22 -0
- numba_cuda/numba/cuda/api.py +526 -0
- numba_cuda/numba/cuda/api_util.py +30 -0
- numba_cuda/numba/cuda/args.py +77 -0
- numba_cuda/numba/cuda/cg.py +62 -0
- numba_cuda/numba/cuda/codegen.py +378 -0
- numba_cuda/numba/cuda/compiler.py +422 -0
- numba_cuda/numba/cuda/cpp_function_wrappers.cu +47 -0
- numba_cuda/numba/cuda/cuda_fp16.h +3631 -0
- numba_cuda/numba/cuda/cuda_fp16.hpp +2465 -0
- numba_cuda/numba/cuda/cuda_paths.py +258 -0
- numba_cuda/numba/cuda/cudadecl.py +806 -0
- numba_cuda/numba/cuda/cudadrv/__init__.py +9 -0
- numba_cuda/numba/cuda/cudadrv/devicearray.py +904 -0
- numba_cuda/numba/cuda/cudadrv/devices.py +248 -0
- numba_cuda/numba/cuda/cudadrv/driver.py +3201 -0
- numba_cuda/numba/cuda/cudadrv/drvapi.py +398 -0
- numba_cuda/numba/cuda/cudadrv/dummyarray.py +452 -0
- numba_cuda/numba/cuda/cudadrv/enums.py +607 -0
- numba_cuda/numba/cuda/cudadrv/error.py +36 -0
- numba_cuda/numba/cuda/cudadrv/libs.py +176 -0
- numba_cuda/numba/cuda/cudadrv/ndarray.py +20 -0
- numba_cuda/numba/cuda/cudadrv/nvrtc.py +260 -0
- numba_cuda/numba/cuda/cudadrv/nvvm.py +707 -0
- numba_cuda/numba/cuda/cudadrv/rtapi.py +10 -0
- numba_cuda/numba/cuda/cudadrv/runtime.py +142 -0
- numba_cuda/numba/cuda/cudaimpl.py +1055 -0
- numba_cuda/numba/cuda/cudamath.py +140 -0
- numba_cuda/numba/cuda/decorators.py +189 -0
- numba_cuda/numba/cuda/descriptor.py +33 -0
- numba_cuda/numba/cuda/device_init.py +89 -0
- numba_cuda/numba/cuda/deviceufunc.py +908 -0
- numba_cuda/numba/cuda/dispatcher.py +1057 -0
- numba_cuda/numba/cuda/errors.py +59 -0
- numba_cuda/numba/cuda/extending.py +7 -0
- numba_cuda/numba/cuda/initialize.py +13 -0
- numba_cuda/numba/cuda/intrinsic_wrapper.py +77 -0
- numba_cuda/numba/cuda/intrinsics.py +198 -0
- numba_cuda/numba/cuda/kernels/__init__.py +0 -0
- numba_cuda/numba/cuda/kernels/reduction.py +262 -0
- numba_cuda/numba/cuda/kernels/transpose.py +65 -0
- numba_cuda/numba/cuda/libdevice.py +3382 -0
- numba_cuda/numba/cuda/libdevicedecl.py +17 -0
- numba_cuda/numba/cuda/libdevicefuncs.py +1057 -0
- numba_cuda/numba/cuda/libdeviceimpl.py +83 -0
- numba_cuda/numba/cuda/mathimpl.py +448 -0
- numba_cuda/numba/cuda/models.py +48 -0
- numba_cuda/numba/cuda/nvvmutils.py +235 -0
- numba_cuda/numba/cuda/printimpl.py +86 -0
- numba_cuda/numba/cuda/random.py +292 -0
- numba_cuda/numba/cuda/simulator/__init__.py +38 -0
- numba_cuda/numba/cuda/simulator/api.py +110 -0
- numba_cuda/numba/cuda/simulator/compiler.py +9 -0
- numba_cuda/numba/cuda/simulator/cudadrv/__init__.py +2 -0
- numba_cuda/numba/cuda/simulator/cudadrv/devicearray.py +432 -0
- numba_cuda/numba/cuda/simulator/cudadrv/devices.py +117 -0
- numba_cuda/numba/cuda/simulator/cudadrv/driver.py +62 -0
- numba_cuda/numba/cuda/simulator/cudadrv/drvapi.py +4 -0
- numba_cuda/numba/cuda/simulator/cudadrv/dummyarray.py +4 -0
- numba_cuda/numba/cuda/simulator/cudadrv/error.py +6 -0
- numba_cuda/numba/cuda/simulator/cudadrv/libs.py +2 -0
- numba_cuda/numba/cuda/simulator/cudadrv/nvvm.py +29 -0
- numba_cuda/numba/cuda/simulator/cudadrv/runtime.py +19 -0
- numba_cuda/numba/cuda/simulator/kernel.py +308 -0
- numba_cuda/numba/cuda/simulator/kernelapi.py +495 -0
- numba_cuda/numba/cuda/simulator/reduction.py +15 -0
- numba_cuda/numba/cuda/simulator/vector_types.py +58 -0
- numba_cuda/numba/cuda/simulator_init.py +17 -0
- numba_cuda/numba/cuda/stubs.py +902 -0
- numba_cuda/numba/cuda/target.py +440 -0
- numba_cuda/numba/cuda/testing.py +202 -0
- numba_cuda/numba/cuda/tests/__init__.py +58 -0
- numba_cuda/numba/cuda/tests/cudadrv/__init__.py +8 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_array_attr.py +145 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_context_stack.py +145 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py +375 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_auto_context.py +21 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py +179 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_driver.py +235 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_libraries.py +22 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_memory.py +193 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +547 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py +249 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_detect.py +81 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py +192 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_events.py +38 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_host_alloc.py +65 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_init.py +139 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_inline_ptx.py +37 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_is_fp16.py +12 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_linker.py +317 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_managed_alloc.py +127 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_mvc.py +54 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_nvvm_driver.py +199 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_pinned.py +37 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_profiler.py +20 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_ptds.py +149 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_reset_device.py +36 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_runtime.py +85 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_select_device.py +41 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_streams.py +122 -0
- numba_cuda/numba/cuda/tests/cudapy/__init__.py +8 -0
- numba_cuda/numba/cuda/tests/cudapy/cache_usecases.py +234 -0
- numba_cuda/numba/cuda/tests/cudapy/cache_with_cpu_usecases.py +41 -0
- numba_cuda/numba/cuda/tests/cudapy/extensions_usecases.py +58 -0
- numba_cuda/numba/cuda/tests/cudapy/jitlink.ptx +30 -0
- numba_cuda/numba/cuda/tests/cudapy/recursion_usecases.py +100 -0
- numba_cuda/numba/cuda/tests/cudapy/test_alignment.py +42 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array.py +260 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_args.py +201 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_methods.py +35 -0
- numba_cuda/numba/cuda/tests/cudapy/test_atomics.py +1620 -0
- numba_cuda/numba/cuda/tests/cudapy/test_blackscholes.py +120 -0
- numba_cuda/numba/cuda/tests/cudapy/test_boolean.py +24 -0
- numba_cuda/numba/cuda/tests/cudapy/test_caching.py +545 -0
- numba_cuda/numba/cuda/tests/cudapy/test_casting.py +257 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cffi.py +33 -0
- numba_cuda/numba/cuda/tests/cudapy/test_compiler.py +276 -0
- numba_cuda/numba/cuda/tests/cudapy/test_complex.py +296 -0
- numba_cuda/numba/cuda/tests/cudapy/test_complex_kernel.py +20 -0
- numba_cuda/numba/cuda/tests/cudapy/test_const_string.py +129 -0
- numba_cuda/numba/cuda/tests/cudapy/test_constmem.py +176 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cooperative_groups.py +147 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cuda_array_interface.py +435 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cuda_jit_no_types.py +90 -0
- numba_cuda/numba/cuda/tests/cudapy/test_datetime.py +94 -0
- numba_cuda/numba/cuda/tests/cudapy/test_debug.py +101 -0
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py +221 -0
- numba_cuda/numba/cuda/tests/cudapy/test_device_func.py +222 -0
- numba_cuda/numba/cuda/tests/cudapy/test_dispatcher.py +700 -0
- numba_cuda/numba/cuda/tests/cudapy/test_enums.py +121 -0
- numba_cuda/numba/cuda/tests/cudapy/test_errors.py +79 -0
- numba_cuda/numba/cuda/tests/cudapy/test_exception.py +174 -0
- numba_cuda/numba/cuda/tests/cudapy/test_extending.py +155 -0
- numba_cuda/numba/cuda/tests/cudapy/test_fastmath.py +244 -0
- numba_cuda/numba/cuda/tests/cudapy/test_forall.py +52 -0
- numba_cuda/numba/cuda/tests/cudapy/test_freevar.py +29 -0
- numba_cuda/numba/cuda/tests/cudapy/test_frexp_ldexp.py +66 -0
- numba_cuda/numba/cuda/tests/cudapy/test_globals.py +60 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc.py +456 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scalar.py +159 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +95 -0
- numba_cuda/numba/cuda/tests/cudapy/test_idiv.py +37 -0
- numba_cuda/numba/cuda/tests/cudapy/test_inspect.py +165 -0
- numba_cuda/numba/cuda/tests/cudapy/test_intrinsics.py +1106 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ipc.py +318 -0
- numba_cuda/numba/cuda/tests/cudapy/test_iterators.py +99 -0
- numba_cuda/numba/cuda/tests/cudapy/test_lang.py +64 -0
- numba_cuda/numba/cuda/tests/cudapy/test_laplace.py +119 -0
- numba_cuda/numba/cuda/tests/cudapy/test_libdevice.py +187 -0
- numba_cuda/numba/cuda/tests/cudapy/test_lineinfo.py +199 -0
- numba_cuda/numba/cuda/tests/cudapy/test_localmem.py +164 -0
- numba_cuda/numba/cuda/tests/cudapy/test_mandel.py +37 -0
- numba_cuda/numba/cuda/tests/cudapy/test_math.py +786 -0
- numba_cuda/numba/cuda/tests/cudapy/test_matmul.py +74 -0
- numba_cuda/numba/cuda/tests/cudapy/test_minmax.py +113 -0
- numba_cuda/numba/cuda/tests/cudapy/test_montecarlo.py +22 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multigpu.py +140 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multiprocessing.py +46 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multithreads.py +101 -0
- numba_cuda/numba/cuda/tests/cudapy/test_nondet.py +49 -0
- numba_cuda/numba/cuda/tests/cudapy/test_operator.py +401 -0
- numba_cuda/numba/cuda/tests/cudapy/test_optimization.py +86 -0
- numba_cuda/numba/cuda/tests/cudapy/test_overload.py +335 -0
- numba_cuda/numba/cuda/tests/cudapy/test_powi.py +124 -0
- numba_cuda/numba/cuda/tests/cudapy/test_print.py +128 -0
- numba_cuda/numba/cuda/tests/cudapy/test_py2_div_issue.py +33 -0
- numba_cuda/numba/cuda/tests/cudapy/test_random.py +104 -0
- numba_cuda/numba/cuda/tests/cudapy/test_record_dtype.py +610 -0
- numba_cuda/numba/cuda/tests/cudapy/test_recursion.py +125 -0
- numba_cuda/numba/cuda/tests/cudapy/test_reduction.py +76 -0
- numba_cuda/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +83 -0
- numba_cuda/numba/cuda/tests/cudapy/test_serialize.py +85 -0
- numba_cuda/numba/cuda/tests/cudapy/test_slicing.py +37 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sm.py +444 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sm_creation.py +205 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sync.py +271 -0
- numba_cuda/numba/cuda/tests/cudapy/test_transpose.py +80 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ufuncs.py +277 -0
- numba_cuda/numba/cuda/tests/cudapy/test_userexc.py +47 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vector_type.py +307 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize.py +283 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_complex.py +20 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_decor.py +69 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_device.py +36 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +37 -0
- numba_cuda/numba/cuda/tests/cudapy/test_warning.py +139 -0
- numba_cuda/numba/cuda/tests/cudapy/test_warp_ops.py +276 -0
- numba_cuda/numba/cuda/tests/cudasim/__init__.py +6 -0
- numba_cuda/numba/cuda/tests/cudasim/support.py +6 -0
- numba_cuda/numba/cuda/tests/cudasim/test_cudasim_issues.py +102 -0
- numba_cuda/numba/cuda/tests/data/__init__.py +0 -0
- numba_cuda/numba/cuda/tests/data/cuda_include.cu +5 -0
- numba_cuda/numba/cuda/tests/data/error.cu +7 -0
- numba_cuda/numba/cuda/tests/data/jitlink.cu +23 -0
- numba_cuda/numba/cuda/tests/data/jitlink.ptx +51 -0
- numba_cuda/numba/cuda/tests/data/warn.cu +7 -0
- numba_cuda/numba/cuda/tests/doc_examples/__init__.py +6 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/__init__.py +0 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/functions.cu +49 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cg.py +77 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cpu_gpu_compat.py +76 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_ffi.py +82 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_laplace.py +155 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_matmul.py +173 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_montecarlo.py +109 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_random.py +59 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_reduction.py +76 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_sessionize.py +130 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_ufunc.py +50 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_vecadd.py +73 -0
- numba_cuda/numba/cuda/tests/nocuda/__init__.py +8 -0
- numba_cuda/numba/cuda/tests/nocuda/test_dummyarray.py +359 -0
- numba_cuda/numba/cuda/tests/nocuda/test_function_resolution.py +36 -0
- numba_cuda/numba/cuda/tests/nocuda/test_import.py +49 -0
- numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +238 -0
- numba_cuda/numba/cuda/tests/nocuda/test_nvvm.py +54 -0
- numba_cuda/numba/cuda/types.py +37 -0
- numba_cuda/numba/cuda/ufuncs.py +662 -0
- numba_cuda/numba/cuda/vector_types.py +209 -0
- numba_cuda/numba/cuda/vectorizers.py +252 -0
- numba_cuda-0.0.13.dist-info/LICENSE +25 -0
- numba_cuda-0.0.13.dist-info/METADATA +69 -0
- numba_cuda-0.0.13.dist-info/RECORD +231 -0
- {numba_cuda-0.0.1.dist-info → numba_cuda-0.0.13.dist-info}/WHEEL +1 -1
- numba_cuda-0.0.1.dist-info/METADATA +0 -10
- numba_cuda-0.0.1.dist-info/RECORD +0 -5
- {numba_cuda-0.0.1.dist-info → numba_cuda-0.0.13.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
"""
|
2
|
+
Test cases adapted from numba/tests/test_enums.py
|
3
|
+
"""
|
4
|
+
|
5
|
+
import numpy as np
|
6
|
+
|
7
|
+
from numba import int16, int32
|
8
|
+
from numba import cuda, vectorize, njit
|
9
|
+
from numba.cuda.testing import unittest, CUDATestCase, skip_on_cudasim
|
10
|
+
from numba.tests.enum_usecases import (
|
11
|
+
Color,
|
12
|
+
Shape,
|
13
|
+
Planet,
|
14
|
+
RequestError,
|
15
|
+
IntEnumWithNegatives
|
16
|
+
)
|
17
|
+
|
18
|
+
|
19
|
+
class EnumTest(CUDATestCase):
|
20
|
+
|
21
|
+
pairs = [
|
22
|
+
(Color.red, Color.red),
|
23
|
+
(Color.red, Color.green),
|
24
|
+
(Planet.EARTH, Planet.EARTH),
|
25
|
+
(Planet.VENUS, Planet.MARS),
|
26
|
+
(Shape.circle, IntEnumWithNegatives.two) # IntEnum, same value
|
27
|
+
]
|
28
|
+
|
29
|
+
def test_compare(self):
|
30
|
+
def f(a, b, out):
|
31
|
+
out[0] = a == b
|
32
|
+
out[1] = a != b
|
33
|
+
out[2] = a is b
|
34
|
+
out[3] = a is not b
|
35
|
+
|
36
|
+
cuda_f = cuda.jit(f)
|
37
|
+
for a, b in self.pairs:
|
38
|
+
got = np.zeros((4,), dtype=np.bool_)
|
39
|
+
expected = got.copy()
|
40
|
+
cuda_f[1, 1](a, b, got)
|
41
|
+
f(a, b, expected)
|
42
|
+
self.assertPreciseEqual(expected, got)
|
43
|
+
|
44
|
+
def test_getattr_getitem(self):
|
45
|
+
def f(out):
|
46
|
+
# Lookup of an enum member on its class
|
47
|
+
out[0] = Color.red == Color.green
|
48
|
+
out[1] = Color['red'] == Color['green']
|
49
|
+
|
50
|
+
cuda_f = cuda.jit(f)
|
51
|
+
got = np.zeros((2,), dtype=np.bool_)
|
52
|
+
expected = got.copy()
|
53
|
+
cuda_f[1, 1](got)
|
54
|
+
f(expected)
|
55
|
+
self.assertPreciseEqual(expected, got)
|
56
|
+
|
57
|
+
def test_return_from_device_func(self):
|
58
|
+
@njit
|
59
|
+
def inner(pred):
|
60
|
+
return Color.red if pred else Color.green
|
61
|
+
|
62
|
+
def f(pred, out):
|
63
|
+
out[0] = inner(pred) == Color.red
|
64
|
+
out[1] = inner(not pred) == Color.green
|
65
|
+
|
66
|
+
cuda_f = cuda.jit(f)
|
67
|
+
got = np.zeros((2,), dtype=np.bool_)
|
68
|
+
expected = got.copy()
|
69
|
+
f(True, expected)
|
70
|
+
cuda_f[1, 1](True, got)
|
71
|
+
self.assertPreciseEqual(expected, got)
|
72
|
+
|
73
|
+
def test_int_coerce(self):
|
74
|
+
def f(x, out):
|
75
|
+
# Implicit coercion of intenums to ints
|
76
|
+
if x > RequestError.internal_error:
|
77
|
+
out[0] = x - RequestError.not_found
|
78
|
+
else:
|
79
|
+
out[0] = x + Shape.circle
|
80
|
+
|
81
|
+
cuda_f = cuda.jit(f)
|
82
|
+
for x in [300, 450, 550]:
|
83
|
+
got = np.zeros((1,), dtype=np.int32)
|
84
|
+
expected = got.copy()
|
85
|
+
cuda_f[1, 1](x, got)
|
86
|
+
f(x, expected)
|
87
|
+
self.assertPreciseEqual(expected, got)
|
88
|
+
|
89
|
+
def test_int_cast(self):
|
90
|
+
def f(x, out):
|
91
|
+
# Explicit coercion of intenums to ints
|
92
|
+
if x > int16(RequestError.internal_error):
|
93
|
+
out[0] = x - int32(RequestError.not_found)
|
94
|
+
else:
|
95
|
+
out[0] = x + int16(Shape.circle)
|
96
|
+
|
97
|
+
cuda_f = cuda.jit(f)
|
98
|
+
for x in [300, 450, 550]:
|
99
|
+
got = np.zeros((1,), dtype=np.int32)
|
100
|
+
expected = got.copy()
|
101
|
+
cuda_f[1, 1](x, got)
|
102
|
+
f(x, expected)
|
103
|
+
self.assertEqual(expected, got)
|
104
|
+
|
105
|
+
@skip_on_cudasim("ufuncs are unsupported on simulator.")
|
106
|
+
def test_vectorize(self):
|
107
|
+
def f(x):
|
108
|
+
if x != RequestError.not_found:
|
109
|
+
return RequestError['internal_error']
|
110
|
+
else:
|
111
|
+
return RequestError.dummy
|
112
|
+
|
113
|
+
cuda_func = vectorize("int64(int64)", target='cuda')(f)
|
114
|
+
arr = np.array([2, 404, 500, 404], dtype=np.int64)
|
115
|
+
expected = np.array([f(x) for x in arr], dtype=np.int64)
|
116
|
+
got = cuda_func(arr)
|
117
|
+
self.assertPreciseEqual(expected, got)
|
118
|
+
|
119
|
+
|
120
|
+
if __name__ == '__main__':
|
121
|
+
unittest.main()
|
@@ -0,0 +1,79 @@
|
|
1
|
+
from numba import cuda
|
2
|
+
from numba.core.errors import TypingError
|
3
|
+
from numba.cuda.testing import unittest, CUDATestCase, skip_on_cudasim
|
4
|
+
|
5
|
+
|
6
|
+
def noop(x):
|
7
|
+
pass
|
8
|
+
|
9
|
+
|
10
|
+
class TestJitErrors(CUDATestCase):
|
11
|
+
"""
|
12
|
+
Test compile-time errors with @jit.
|
13
|
+
"""
|
14
|
+
|
15
|
+
def test_too_many_dims(self):
|
16
|
+
kernfunc = cuda.jit(noop)
|
17
|
+
|
18
|
+
with self.assertRaises(ValueError) as raises:
|
19
|
+
kernfunc[(1, 2, 3, 4), (5, 6)]
|
20
|
+
self.assertIn("griddim must be a sequence of 1, 2 or 3 integers, "
|
21
|
+
"got [1, 2, 3, 4]",
|
22
|
+
str(raises.exception))
|
23
|
+
|
24
|
+
with self.assertRaises(ValueError) as raises:
|
25
|
+
kernfunc[(1, 2,), (3, 4, 5, 6)]
|
26
|
+
self.assertIn("blockdim must be a sequence of 1, 2 or 3 integers, "
|
27
|
+
"got [3, 4, 5, 6]",
|
28
|
+
str(raises.exception))
|
29
|
+
|
30
|
+
def test_non_integral_dims(self):
|
31
|
+
kernfunc = cuda.jit(noop)
|
32
|
+
|
33
|
+
with self.assertRaises(TypeError) as raises:
|
34
|
+
kernfunc[2.0, 3]
|
35
|
+
self.assertIn("griddim must be a sequence of integers, got [2.0]",
|
36
|
+
str(raises.exception))
|
37
|
+
|
38
|
+
with self.assertRaises(TypeError) as raises:
|
39
|
+
kernfunc[2, 3.0]
|
40
|
+
self.assertIn("blockdim must be a sequence of integers, got [3.0]",
|
41
|
+
str(raises.exception))
|
42
|
+
|
43
|
+
def _test_unconfigured(self, kernfunc):
|
44
|
+
with self.assertRaises(ValueError) as raises:
|
45
|
+
kernfunc(0)
|
46
|
+
self.assertIn("launch configuration was not specified",
|
47
|
+
str(raises.exception))
|
48
|
+
|
49
|
+
def test_unconfigured_typed_cudakernel(self):
|
50
|
+
kernfunc = cuda.jit("void(int32)")(noop)
|
51
|
+
self._test_unconfigured(kernfunc)
|
52
|
+
|
53
|
+
def test_unconfigured_untyped_cudakernel(self):
|
54
|
+
kernfunc = cuda.jit(noop)
|
55
|
+
self._test_unconfigured(kernfunc)
|
56
|
+
|
57
|
+
@skip_on_cudasim('TypingError does not occur on simulator')
|
58
|
+
def test_typing_error(self):
|
59
|
+
# see #5860, this is present to catch changes to error reporting
|
60
|
+
# accidentally breaking the CUDA target
|
61
|
+
|
62
|
+
@cuda.jit(device=True)
|
63
|
+
def dev_func(x):
|
64
|
+
# floor is deliberately not imported for the purpose of this test.
|
65
|
+
return floor(x) # noqa: F821
|
66
|
+
|
67
|
+
@cuda.jit
|
68
|
+
def kernel_func():
|
69
|
+
dev_func(1.5)
|
70
|
+
|
71
|
+
with self.assertRaises(TypingError) as raises:
|
72
|
+
kernel_func[1, 1]()
|
73
|
+
excstr = str(raises.exception)
|
74
|
+
self.assertIn("resolving callee type: type(CUDADispatcher", excstr)
|
75
|
+
self.assertIn("NameError: name 'floor' is not defined", excstr)
|
76
|
+
|
77
|
+
|
78
|
+
if __name__ == '__main__':
|
79
|
+
unittest.main()
|
@@ -0,0 +1,174 @@
|
|
1
|
+
import numpy as np
|
2
|
+
|
3
|
+
from numba import cuda
|
4
|
+
from numba.cuda.testing import unittest, xfail_unless_cudasim, CUDATestCase
|
5
|
+
from numba.core import config
|
6
|
+
|
7
|
+
|
8
|
+
class TestException(CUDATestCase):
|
9
|
+
def setUp(self):
|
10
|
+
super().setUp()
|
11
|
+
# LTO optimizes away the exception status due to an oversight
|
12
|
+
# in the way we generate it (it is not added to the used list).
|
13
|
+
self.skip_if_lto("Exceptions not supported with LTO")
|
14
|
+
|
15
|
+
def test_exception(self):
|
16
|
+
def foo(ary):
|
17
|
+
x = cuda.threadIdx.x
|
18
|
+
if x == 2:
|
19
|
+
# NOTE: indexing with a out-of-bounds constant can fail at
|
20
|
+
# compile-time instead (because the getitem is rewritten as a
|
21
|
+
# static_getitem)
|
22
|
+
ary.shape[-x]
|
23
|
+
|
24
|
+
unsafe_foo = cuda.jit(foo)
|
25
|
+
safe_foo = cuda.jit(debug=True, opt=False)(foo)
|
26
|
+
|
27
|
+
if not config.ENABLE_CUDASIM:
|
28
|
+
# Simulator throws exceptions regardless of debug
|
29
|
+
# setting
|
30
|
+
unsafe_foo[1, 3](np.array([0, 1]))
|
31
|
+
|
32
|
+
with self.assertRaises(IndexError) as cm:
|
33
|
+
safe_foo[1, 3](np.array([0, 1]))
|
34
|
+
self.assertIn("tuple index out of range", str(cm.exception))
|
35
|
+
|
36
|
+
def test_user_raise(self):
|
37
|
+
@cuda.jit(debug=True, opt=False)
|
38
|
+
def foo(do_raise):
|
39
|
+
if do_raise:
|
40
|
+
raise ValueError
|
41
|
+
|
42
|
+
foo[1, 1](False)
|
43
|
+
with self.assertRaises(ValueError):
|
44
|
+
foo[1, 1](True)
|
45
|
+
|
46
|
+
def case_raise_causing_warp_diverge(self, with_debug_mode):
|
47
|
+
"""Testing issue #2655.
|
48
|
+
|
49
|
+
Exception raising code can cause the compiler to miss location
|
50
|
+
of unifying branch target and resulting in unexpected warp
|
51
|
+
divergence.
|
52
|
+
"""
|
53
|
+
with_opt_mode = not with_debug_mode
|
54
|
+
|
55
|
+
@cuda.jit(debug=with_debug_mode, opt=with_opt_mode)
|
56
|
+
def problematic(x, y):
|
57
|
+
tid = cuda.threadIdx.x
|
58
|
+
ntid = cuda.blockDim.x
|
59
|
+
|
60
|
+
if tid > 12:
|
61
|
+
for i in range(ntid):
|
62
|
+
y[i] += x[i] // y[i]
|
63
|
+
|
64
|
+
cuda.syncthreads()
|
65
|
+
if tid < 17:
|
66
|
+
for i in range(ntid):
|
67
|
+
x[i] += x[i] // y[i]
|
68
|
+
|
69
|
+
@cuda.jit
|
70
|
+
def oracle(x, y):
|
71
|
+
tid = cuda.threadIdx.x
|
72
|
+
ntid = cuda.blockDim.x
|
73
|
+
|
74
|
+
if tid > 12:
|
75
|
+
for i in range(ntid):
|
76
|
+
if y[i] != 0:
|
77
|
+
y[i] += x[i] // y[i]
|
78
|
+
|
79
|
+
cuda.syncthreads()
|
80
|
+
if tid < 17:
|
81
|
+
for i in range(ntid):
|
82
|
+
if y[i] != 0:
|
83
|
+
x[i] += x[i] // y[i]
|
84
|
+
|
85
|
+
n = 32
|
86
|
+
got_x = 1. / (np.arange(n) + 0.01)
|
87
|
+
got_y = 1. / (np.arange(n) + 0.01)
|
88
|
+
problematic[1, n](got_x, got_y)
|
89
|
+
|
90
|
+
expect_x = 1. / (np.arange(n) + 0.01)
|
91
|
+
expect_y = 1. / (np.arange(n) + 0.01)
|
92
|
+
oracle[1, n](expect_x, expect_y)
|
93
|
+
|
94
|
+
np.testing.assert_almost_equal(expect_x, got_x)
|
95
|
+
np.testing.assert_almost_equal(expect_y, got_y)
|
96
|
+
|
97
|
+
def test_raise_causing_warp_diverge(self):
|
98
|
+
"""Test case for issue #2655.
|
99
|
+
"""
|
100
|
+
self.case_raise_causing_warp_diverge(with_debug_mode=False)
|
101
|
+
|
102
|
+
# The following two cases relate to Issue #7806: Division by zero stops the
|
103
|
+
# kernel. https://github.com/numba/numba/issues/7806.
|
104
|
+
|
105
|
+
def test_no_zero_division_error(self):
|
106
|
+
# When debug is False:
|
107
|
+
# - Division by zero raises no exception
|
108
|
+
# - Execution proceeds after a divide by zero
|
109
|
+
@cuda.jit
|
110
|
+
def f(r, x, y):
|
111
|
+
r[0] = y[0] / x[0]
|
112
|
+
r[1] = y[0]
|
113
|
+
|
114
|
+
r = np.zeros(2)
|
115
|
+
x = np.zeros(1)
|
116
|
+
y = np.ones(1)
|
117
|
+
|
118
|
+
f[1, 1](r, x, y)
|
119
|
+
|
120
|
+
self.assertTrue(np.isinf(r[0]), 'Expected inf from div by zero')
|
121
|
+
self.assertEqual(r[1], y[0], 'Expected execution to continue')
|
122
|
+
|
123
|
+
def test_zero_division_error_in_debug(self):
|
124
|
+
# When debug is True:
|
125
|
+
# - Zero by division raises an exception
|
126
|
+
# - Execution halts at the point of division by zero
|
127
|
+
@cuda.jit(debug=True, opt=False)
|
128
|
+
def f(r, x, y):
|
129
|
+
r[0] = y[0] / x[0]
|
130
|
+
r[1] = y[0]
|
131
|
+
|
132
|
+
r = np.zeros(2)
|
133
|
+
x = np.zeros(1)
|
134
|
+
y = np.ones(1)
|
135
|
+
|
136
|
+
# Simulator and device behaviour differs slightly in the exception
|
137
|
+
# raised - in debug mode, the CUDA target uses the Python error model,
|
138
|
+
# which gives a ZeroDivision error. The simulator uses NumPy with the
|
139
|
+
# error mode for division by zero set to raise, which results in a
|
140
|
+
# FloatingPointError instead.
|
141
|
+
if config.ENABLE_CUDASIM:
|
142
|
+
exc = FloatingPointError
|
143
|
+
else:
|
144
|
+
exc = ZeroDivisionError
|
145
|
+
|
146
|
+
with self.assertRaises(exc):
|
147
|
+
f[1, 1](r, x, y)
|
148
|
+
|
149
|
+
self.assertEqual(r[0], 0, 'Expected result to be left unset')
|
150
|
+
self.assertEqual(r[1], 0, 'Expected execution to stop')
|
151
|
+
|
152
|
+
@xfail_unless_cudasim
|
153
|
+
def test_raise_in_device_function(self):
|
154
|
+
# This is an expected failure because reporting of exceptions raised in
|
155
|
+
# device functions does not work correctly - see Issue #8036:
|
156
|
+
# https://github.com/numba/numba/issues/8036
|
157
|
+
msg = 'Device Function Error'
|
158
|
+
|
159
|
+
@cuda.jit(device=True)
|
160
|
+
def f():
|
161
|
+
raise ValueError(msg)
|
162
|
+
|
163
|
+
@cuda.jit(debug=True)
|
164
|
+
def kernel():
|
165
|
+
f()
|
166
|
+
|
167
|
+
with self.assertRaises(ValueError) as raises:
|
168
|
+
kernel[1, 1]()
|
169
|
+
|
170
|
+
self.assertIn(msg, str(raises.exception))
|
171
|
+
|
172
|
+
|
173
|
+
if __name__ == '__main__':
|
174
|
+
unittest.main()
|
@@ -0,0 +1,155 @@
|
|
1
|
+
from numba.cuda.testing import skip_on_cudasim, unittest, CUDATestCase
|
2
|
+
|
3
|
+
import numpy as np
|
4
|
+
from numba import config, cuda, njit, types
|
5
|
+
|
6
|
+
|
7
|
+
class Interval:
|
8
|
+
"""
|
9
|
+
A half-open interval on the real number line.
|
10
|
+
"""
|
11
|
+
def __init__(self, lo, hi):
|
12
|
+
self.lo = lo
|
13
|
+
self.hi = hi
|
14
|
+
|
15
|
+
def __repr__(self):
|
16
|
+
return 'Interval(%f, %f)' % (self.lo, self.hi)
|
17
|
+
|
18
|
+
@property
|
19
|
+
def width(self):
|
20
|
+
return self.hi - self.lo
|
21
|
+
|
22
|
+
|
23
|
+
@njit
|
24
|
+
def interval_width(interval):
|
25
|
+
return interval.width
|
26
|
+
|
27
|
+
|
28
|
+
@njit
|
29
|
+
def sum_intervals(i, j):
|
30
|
+
return Interval(i.lo + j.lo, i.hi + j.hi)
|
31
|
+
|
32
|
+
|
33
|
+
if not config.ENABLE_CUDASIM:
|
34
|
+
from numba.core import cgutils
|
35
|
+
from numba.core.extending import (lower_builtin, make_attribute_wrapper,
|
36
|
+
models, register_model, type_callable,
|
37
|
+
typeof_impl)
|
38
|
+
from numba.core.typing.templates import AttributeTemplate
|
39
|
+
from numba.cuda.cudadecl import registry as cuda_registry
|
40
|
+
from numba.cuda.cudaimpl import lower_attr as cuda_lower_attr
|
41
|
+
|
42
|
+
class IntervalType(types.Type):
|
43
|
+
def __init__(self):
|
44
|
+
super().__init__(name='Interval')
|
45
|
+
|
46
|
+
interval_type = IntervalType()
|
47
|
+
|
48
|
+
@typeof_impl.register(Interval)
|
49
|
+
def typeof_interval(val, c):
|
50
|
+
return interval_type
|
51
|
+
|
52
|
+
@type_callable(Interval)
|
53
|
+
def type_interval(context):
|
54
|
+
def typer(lo, hi):
|
55
|
+
if isinstance(lo, types.Float) and isinstance(hi, types.Float):
|
56
|
+
return interval_type
|
57
|
+
return typer
|
58
|
+
|
59
|
+
@register_model(IntervalType)
|
60
|
+
class IntervalModel(models.StructModel):
|
61
|
+
def __init__(self, dmm, fe_type):
|
62
|
+
members = [
|
63
|
+
('lo', types.float64),
|
64
|
+
('hi', types.float64),
|
65
|
+
]
|
66
|
+
models.StructModel.__init__(self, dmm, fe_type, members)
|
67
|
+
|
68
|
+
make_attribute_wrapper(IntervalType, 'lo', 'lo')
|
69
|
+
make_attribute_wrapper(IntervalType, 'hi', 'hi')
|
70
|
+
|
71
|
+
@lower_builtin(Interval, types.Float, types.Float)
|
72
|
+
def impl_interval(context, builder, sig, args):
|
73
|
+
typ = sig.return_type
|
74
|
+
lo, hi = args
|
75
|
+
interval = cgutils.create_struct_proxy(typ)(context, builder)
|
76
|
+
interval.lo = lo
|
77
|
+
interval.hi = hi
|
78
|
+
return interval._getvalue()
|
79
|
+
|
80
|
+
@cuda_registry.register_attr
|
81
|
+
class Interval_attrs(AttributeTemplate):
|
82
|
+
key = IntervalType
|
83
|
+
|
84
|
+
def resolve_width(self, mod):
|
85
|
+
return types.float64
|
86
|
+
|
87
|
+
@cuda_lower_attr(IntervalType, 'width')
|
88
|
+
def cuda_Interval_width(context, builder, sig, arg):
|
89
|
+
lo = builder.extract_value(arg, 0)
|
90
|
+
hi = builder.extract_value(arg, 1)
|
91
|
+
return builder.fsub(hi, lo)
|
92
|
+
|
93
|
+
|
94
|
+
@skip_on_cudasim('Extensions not supported in the simulator')
|
95
|
+
class TestExtending(CUDATestCase):
|
96
|
+
def test_attributes(self):
|
97
|
+
@cuda.jit
|
98
|
+
def f(r, x):
|
99
|
+
iv = Interval(x[0], x[1])
|
100
|
+
r[0] = iv.lo
|
101
|
+
r[1] = iv.hi
|
102
|
+
|
103
|
+
x = np.asarray((1.5, 2.5))
|
104
|
+
r = np.zeros_like(x)
|
105
|
+
|
106
|
+
f[1, 1](r, x)
|
107
|
+
|
108
|
+
np.testing.assert_equal(r, x)
|
109
|
+
|
110
|
+
def test_property(self):
|
111
|
+
@cuda.jit
|
112
|
+
def f(r, x):
|
113
|
+
iv = Interval(x[0], x[1])
|
114
|
+
r[0] = iv.width
|
115
|
+
|
116
|
+
x = np.asarray((1.5, 2.5))
|
117
|
+
r = np.zeros(1)
|
118
|
+
|
119
|
+
f[1, 1](r, x)
|
120
|
+
|
121
|
+
np.testing.assert_allclose(r[0], x[1] - x[0])
|
122
|
+
|
123
|
+
def test_extension_type_as_arg(self):
|
124
|
+
@cuda.jit
|
125
|
+
def f(r, x):
|
126
|
+
iv = Interval(x[0], x[1])
|
127
|
+
r[0] = interval_width(iv)
|
128
|
+
|
129
|
+
x = np.asarray((1.5, 2.5))
|
130
|
+
r = np.zeros(1)
|
131
|
+
|
132
|
+
f[1, 1](r, x)
|
133
|
+
|
134
|
+
np.testing.assert_allclose(r[0], x[1] - x[0])
|
135
|
+
|
136
|
+
def test_extension_type_as_retvalue(self):
|
137
|
+
@cuda.jit
|
138
|
+
def f(r, x):
|
139
|
+
iv1 = Interval(x[0], x[1])
|
140
|
+
iv2 = Interval(x[2], x[3])
|
141
|
+
iv_sum = sum_intervals(iv1, iv2)
|
142
|
+
r[0] = iv_sum.lo
|
143
|
+
r[1] = iv_sum.hi
|
144
|
+
|
145
|
+
x = np.asarray((1.5, 2.5, 3.0, 4.0))
|
146
|
+
r = np.zeros(2)
|
147
|
+
|
148
|
+
f[1, 1](r, x)
|
149
|
+
|
150
|
+
expected = np.asarray((x[0] + x[2], x[1] + x[3]))
|
151
|
+
np.testing.assert_allclose(r, expected)
|
152
|
+
|
153
|
+
|
154
|
+
if __name__ == '__main__':
|
155
|
+
unittest.main()
|