numba-cuda 0.0.1__py3-none-any.whl → 0.0.12__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.12.dist-info/LICENSE +25 -0
- numba_cuda-0.0.12.dist-info/METADATA +68 -0
- numba_cuda-0.0.12.dist-info/RECORD +231 -0
- {numba_cuda-0.0.1.dist-info → numba_cuda-0.0.12.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.12.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,271 @@
|
|
1
|
+
import numpy as np
|
2
|
+
from numba import cuda, int32, float32
|
3
|
+
from numba.cuda.testing import skip_on_cudasim, unittest, CUDATestCase
|
4
|
+
from numba.core.config import ENABLE_CUDASIM
|
5
|
+
|
6
|
+
|
7
|
+
def useless_syncthreads(ary):
|
8
|
+
i = cuda.grid(1)
|
9
|
+
cuda.syncthreads()
|
10
|
+
ary[i] = i
|
11
|
+
|
12
|
+
|
13
|
+
def useless_syncwarp(ary):
|
14
|
+
i = cuda.grid(1)
|
15
|
+
cuda.syncwarp()
|
16
|
+
ary[i] = i
|
17
|
+
|
18
|
+
|
19
|
+
def useless_syncwarp_with_mask(ary):
|
20
|
+
i = cuda.grid(1)
|
21
|
+
cuda.syncwarp(0xFFFF)
|
22
|
+
ary[i] = i
|
23
|
+
|
24
|
+
|
25
|
+
def coop_syncwarp(res):
|
26
|
+
sm = cuda.shared.array(32, int32)
|
27
|
+
i = cuda.grid(1)
|
28
|
+
|
29
|
+
sm[i] = i
|
30
|
+
cuda.syncwarp()
|
31
|
+
|
32
|
+
if i < 16:
|
33
|
+
sm[i] = sm[i] + sm[i + 16]
|
34
|
+
cuda.syncwarp(0xFFFF)
|
35
|
+
|
36
|
+
if i < 8:
|
37
|
+
sm[i] = sm[i] + sm[i + 8]
|
38
|
+
cuda.syncwarp(0xFF)
|
39
|
+
|
40
|
+
if i < 4:
|
41
|
+
sm[i] = sm[i] + sm[i + 4]
|
42
|
+
cuda.syncwarp(0xF)
|
43
|
+
|
44
|
+
if i < 2:
|
45
|
+
sm[i] = sm[i] + sm[i + 2]
|
46
|
+
cuda.syncwarp(0x3)
|
47
|
+
|
48
|
+
if i == 0:
|
49
|
+
res[0] = sm[0] + sm[1]
|
50
|
+
|
51
|
+
|
52
|
+
def simple_smem(ary):
|
53
|
+
N = 100
|
54
|
+
sm = cuda.shared.array(N, int32)
|
55
|
+
i = cuda.grid(1)
|
56
|
+
if i == 0:
|
57
|
+
for j in range(N):
|
58
|
+
sm[j] = j
|
59
|
+
cuda.syncthreads()
|
60
|
+
ary[i] = sm[i]
|
61
|
+
|
62
|
+
|
63
|
+
def coop_smem2d(ary):
|
64
|
+
i, j = cuda.grid(2)
|
65
|
+
sm = cuda.shared.array((10, 20), float32)
|
66
|
+
sm[i, j] = (i + 1) / (j + 1)
|
67
|
+
cuda.syncthreads()
|
68
|
+
ary[i, j] = sm[i, j]
|
69
|
+
|
70
|
+
|
71
|
+
def dyn_shared_memory(ary):
|
72
|
+
i = cuda.grid(1)
|
73
|
+
sm = cuda.shared.array(0, float32)
|
74
|
+
sm[i] = i * 2
|
75
|
+
cuda.syncthreads()
|
76
|
+
ary[i] = sm[i]
|
77
|
+
|
78
|
+
|
79
|
+
def use_threadfence(ary):
|
80
|
+
ary[0] += 123
|
81
|
+
cuda.threadfence()
|
82
|
+
ary[0] += 321
|
83
|
+
|
84
|
+
|
85
|
+
def use_threadfence_block(ary):
|
86
|
+
ary[0] += 123
|
87
|
+
cuda.threadfence_block()
|
88
|
+
ary[0] += 321
|
89
|
+
|
90
|
+
|
91
|
+
def use_threadfence_system(ary):
|
92
|
+
ary[0] += 123
|
93
|
+
cuda.threadfence_system()
|
94
|
+
ary[0] += 321
|
95
|
+
|
96
|
+
|
97
|
+
def use_syncthreads_count(ary_in, ary_out):
|
98
|
+
i = cuda.grid(1)
|
99
|
+
ary_out[i] = cuda.syncthreads_count(ary_in[i])
|
100
|
+
|
101
|
+
|
102
|
+
def use_syncthreads_and(ary_in, ary_out):
|
103
|
+
i = cuda.grid(1)
|
104
|
+
ary_out[i] = cuda.syncthreads_and(ary_in[i])
|
105
|
+
|
106
|
+
|
107
|
+
def use_syncthreads_or(ary_in, ary_out):
|
108
|
+
i = cuda.grid(1)
|
109
|
+
ary_out[i] = cuda.syncthreads_or(ary_in[i])
|
110
|
+
|
111
|
+
|
112
|
+
def _safe_cc_check(cc):
|
113
|
+
if ENABLE_CUDASIM:
|
114
|
+
return True
|
115
|
+
else:
|
116
|
+
return cuda.get_current_device().compute_capability >= cc
|
117
|
+
|
118
|
+
|
119
|
+
class TestCudaSync(CUDATestCase):
|
120
|
+
def _test_useless(self, kernel):
|
121
|
+
compiled = cuda.jit("void(int32[::1])")(kernel)
|
122
|
+
nelem = 10
|
123
|
+
ary = np.empty(nelem, dtype=np.int32)
|
124
|
+
exp = np.arange(nelem, dtype=np.int32)
|
125
|
+
compiled[1, nelem](ary)
|
126
|
+
np.testing.assert_equal(ary, exp)
|
127
|
+
|
128
|
+
def test_useless_syncthreads(self):
|
129
|
+
self._test_useless(useless_syncthreads)
|
130
|
+
|
131
|
+
@skip_on_cudasim("syncwarp not implemented on cudasim")
|
132
|
+
def test_useless_syncwarp(self):
|
133
|
+
self._test_useless(useless_syncwarp)
|
134
|
+
|
135
|
+
@skip_on_cudasim("syncwarp not implemented on cudasim")
|
136
|
+
@unittest.skipUnless(_safe_cc_check((7, 0)),
|
137
|
+
"Partial masks require CC 7.0 or greater")
|
138
|
+
def test_useless_syncwarp_with_mask(self):
|
139
|
+
self._test_useless(useless_syncwarp_with_mask)
|
140
|
+
|
141
|
+
@skip_on_cudasim("syncwarp not implemented on cudasim")
|
142
|
+
@unittest.skipUnless(_safe_cc_check((7, 0)),
|
143
|
+
"Partial masks require CC 7.0 or greater")
|
144
|
+
def test_coop_syncwarp(self):
|
145
|
+
# coop_syncwarp computes the sum of all integers from 0 to 31 (496)
|
146
|
+
# using a single warp
|
147
|
+
expected = 496
|
148
|
+
nthreads = 32
|
149
|
+
nblocks = 1
|
150
|
+
|
151
|
+
compiled = cuda.jit("void(int32[::1])")(coop_syncwarp)
|
152
|
+
res = np.zeros(1, dtype=np.int32)
|
153
|
+
compiled[nblocks, nthreads](res)
|
154
|
+
np.testing.assert_equal(expected, res[0])
|
155
|
+
|
156
|
+
def test_simple_smem(self):
|
157
|
+
compiled = cuda.jit("void(int32[::1])")(simple_smem)
|
158
|
+
nelem = 100
|
159
|
+
ary = np.empty(nelem, dtype=np.int32)
|
160
|
+
compiled[1, nelem](ary)
|
161
|
+
self.assertTrue(np.all(ary == np.arange(nelem, dtype=np.int32)))
|
162
|
+
|
163
|
+
def test_coop_smem2d(self):
|
164
|
+
compiled = cuda.jit("void(float32[:,::1])")(coop_smem2d)
|
165
|
+
shape = 10, 20
|
166
|
+
ary = np.empty(shape, dtype=np.float32)
|
167
|
+
compiled[1, shape](ary)
|
168
|
+
exp = np.empty_like(ary)
|
169
|
+
for i in range(ary.shape[0]):
|
170
|
+
for j in range(ary.shape[1]):
|
171
|
+
exp[i, j] = (i + 1) / (j + 1)
|
172
|
+
self.assertTrue(np.allclose(ary, exp))
|
173
|
+
|
174
|
+
def test_dyn_shared_memory(self):
|
175
|
+
compiled = cuda.jit("void(float32[::1])")(dyn_shared_memory)
|
176
|
+
shape = 50
|
177
|
+
ary = np.empty(shape, dtype=np.float32)
|
178
|
+
compiled[1, shape, 0, ary.size * 4](ary)
|
179
|
+
self.assertTrue(np.all(ary == 2 * np.arange(ary.size, dtype=np.int32)))
|
180
|
+
|
181
|
+
def test_threadfence_codegen(self):
|
182
|
+
# Does not test runtime behavior, just the code generation.
|
183
|
+
sig = (int32[:],)
|
184
|
+
compiled = cuda.jit(sig)(use_threadfence)
|
185
|
+
ary = np.zeros(10, dtype=np.int32)
|
186
|
+
compiled[1, 1](ary)
|
187
|
+
self.assertEqual(123 + 321, ary[0])
|
188
|
+
if not ENABLE_CUDASIM:
|
189
|
+
self.assertIn("membar.gl;", compiled.inspect_asm(sig))
|
190
|
+
|
191
|
+
def test_threadfence_block_codegen(self):
|
192
|
+
# Does not test runtime behavior, just the code generation.
|
193
|
+
sig = (int32[:],)
|
194
|
+
compiled = cuda.jit(sig)(use_threadfence_block)
|
195
|
+
ary = np.zeros(10, dtype=np.int32)
|
196
|
+
compiled[1, 1](ary)
|
197
|
+
self.assertEqual(123 + 321, ary[0])
|
198
|
+
if not ENABLE_CUDASIM:
|
199
|
+
self.assertIn("membar.cta;", compiled.inspect_asm(sig))
|
200
|
+
|
201
|
+
def test_threadfence_system_codegen(self):
|
202
|
+
# Does not test runtime behavior, just the code generation.
|
203
|
+
sig = (int32[:],)
|
204
|
+
compiled = cuda.jit(sig)(use_threadfence_system)
|
205
|
+
ary = np.zeros(10, dtype=np.int32)
|
206
|
+
compiled[1, 1](ary)
|
207
|
+
self.assertEqual(123 + 321, ary[0])
|
208
|
+
if not ENABLE_CUDASIM:
|
209
|
+
self.assertIn("membar.sys;", compiled.inspect_asm(sig))
|
210
|
+
|
211
|
+
def _test_syncthreads_count(self, in_dtype):
|
212
|
+
compiled = cuda.jit(use_syncthreads_count)
|
213
|
+
ary_in = np.ones(72, dtype=in_dtype)
|
214
|
+
ary_out = np.zeros(72, dtype=np.int32)
|
215
|
+
ary_in[31] = 0
|
216
|
+
ary_in[42] = 0
|
217
|
+
compiled[1, 72](ary_in, ary_out)
|
218
|
+
self.assertTrue(np.all(ary_out == 70))
|
219
|
+
|
220
|
+
def test_syncthreads_count(self):
|
221
|
+
self._test_syncthreads_count(np.int32)
|
222
|
+
|
223
|
+
def test_syncthreads_count_upcast(self):
|
224
|
+
self._test_syncthreads_count(np.int16)
|
225
|
+
|
226
|
+
def test_syncthreads_count_downcast(self):
|
227
|
+
self._test_syncthreads_count(np.int64)
|
228
|
+
|
229
|
+
def _test_syncthreads_and(self, in_dtype):
|
230
|
+
compiled = cuda.jit(use_syncthreads_and)
|
231
|
+
nelem = 100
|
232
|
+
ary_in = np.ones(nelem, dtype=in_dtype)
|
233
|
+
ary_out = np.zeros(nelem, dtype=np.int32)
|
234
|
+
compiled[1, nelem](ary_in, ary_out)
|
235
|
+
self.assertTrue(np.all(ary_out == 1))
|
236
|
+
ary_in[31] = 0
|
237
|
+
compiled[1, nelem](ary_in, ary_out)
|
238
|
+
self.assertTrue(np.all(ary_out == 0))
|
239
|
+
|
240
|
+
def test_syncthreads_and(self):
|
241
|
+
self._test_syncthreads_and(np.int32)
|
242
|
+
|
243
|
+
def test_syncthreads_and_upcast(self):
|
244
|
+
self._test_syncthreads_and(np.int16)
|
245
|
+
|
246
|
+
def test_syncthreads_and_downcast(self):
|
247
|
+
self._test_syncthreads_and(np.int64)
|
248
|
+
|
249
|
+
def _test_syncthreads_or(self, in_dtype):
|
250
|
+
compiled = cuda.jit(use_syncthreads_or)
|
251
|
+
nelem = 100
|
252
|
+
ary_in = np.zeros(nelem, dtype=in_dtype)
|
253
|
+
ary_out = np.zeros(nelem, dtype=np.int32)
|
254
|
+
compiled[1, nelem](ary_in, ary_out)
|
255
|
+
self.assertTrue(np.all(ary_out == 0))
|
256
|
+
ary_in[31] = 1
|
257
|
+
compiled[1, nelem](ary_in, ary_out)
|
258
|
+
self.assertTrue(np.all(ary_out == 1))
|
259
|
+
|
260
|
+
def test_syncthreads_or(self):
|
261
|
+
self._test_syncthreads_or(np.int32)
|
262
|
+
|
263
|
+
def test_syncthreads_or_upcast(self):
|
264
|
+
self._test_syncthreads_or(np.int16)
|
265
|
+
|
266
|
+
def test_syncthreads_or_downcast(self):
|
267
|
+
self._test_syncthreads_or(np.int64)
|
268
|
+
|
269
|
+
|
270
|
+
if __name__ == '__main__':
|
271
|
+
unittest.main()
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import numpy as np
|
2
|
+
from numba import cuda
|
3
|
+
from numba.cuda.kernels.transpose import transpose
|
4
|
+
from numba.cuda.testing import unittest
|
5
|
+
from numba.cuda.testing import skip_on_cudasim, CUDATestCase
|
6
|
+
|
7
|
+
|
8
|
+
recordwith2darray = np.dtype([('i', np.int32),
|
9
|
+
('j', np.float32, (3, 2))])
|
10
|
+
|
11
|
+
|
12
|
+
@skip_on_cudasim('Device Array API unsupported in the simulator')
|
13
|
+
class TestTranspose(CUDATestCase):
|
14
|
+
|
15
|
+
def test_transpose(self):
|
16
|
+
variants = ((5, 6, np.float64),
|
17
|
+
(128, 128, np.complex128),
|
18
|
+
(1025, 512, np.float64))
|
19
|
+
|
20
|
+
for rows, cols, dtype in variants:
|
21
|
+
with self.subTest(rows=rows, cols=cols, dtype=dtype):
|
22
|
+
x = np.arange(rows * cols, dtype=dtype).reshape(cols, rows)
|
23
|
+
y = np.zeros(rows * cols, dtype=dtype).reshape(rows, cols)
|
24
|
+
dx = cuda.to_device(x)
|
25
|
+
dy = cuda.cudadrv.devicearray.from_array_like(y)
|
26
|
+
transpose(dx, dy)
|
27
|
+
dy.copy_to_host(y)
|
28
|
+
np.testing.assert_array_equal(x.transpose(), y)
|
29
|
+
|
30
|
+
small_variants = ((2, 3), (16, 16), (16, 17), (17, 16), (14, 15), (15, 14),
|
31
|
+
(14, 14))
|
32
|
+
|
33
|
+
def test_transpose_record(self):
|
34
|
+
for rows, cols in self.small_variants:
|
35
|
+
with self.subTest(rows=rows, cols=cols):
|
36
|
+
arr = np.recarray((rows, cols), dtype=recordwith2darray)
|
37
|
+
for x in range(rows):
|
38
|
+
for y in range(cols):
|
39
|
+
arr[x, y].i = x ** 2 + y
|
40
|
+
j = np.arange(3 * 2, dtype=np.float32)
|
41
|
+
arr[x, y].j = j.reshape(3, 2) * x + y
|
42
|
+
|
43
|
+
transposed = arr.T
|
44
|
+
d_arr = cuda.to_device(arr)
|
45
|
+
d_transposed = cuda.device_array_like(transposed)
|
46
|
+
transpose(d_arr, d_transposed)
|
47
|
+
host_transposed = d_transposed.copy_to_host()
|
48
|
+
np.testing.assert_array_equal(transposed, host_transposed)
|
49
|
+
|
50
|
+
def test_transpose_bool(self):
|
51
|
+
for rows, cols in self.small_variants:
|
52
|
+
with self.subTest(rows=rows, cols=cols):
|
53
|
+
arr = np.random.randint(2, size=(rows, cols), dtype=np.bool_)
|
54
|
+
transposed = arr.T
|
55
|
+
|
56
|
+
d_arr = cuda.to_device(arr)
|
57
|
+
d_transposed = cuda.device_array_like(transposed)
|
58
|
+
transpose(d_arr, d_transposed)
|
59
|
+
|
60
|
+
host_transposed = d_transposed.copy_to_host()
|
61
|
+
np.testing.assert_array_equal(transposed, host_transposed)
|
62
|
+
|
63
|
+
def test_transpose_view(self):
|
64
|
+
# Because the strides of transposes of views differ to those in NumPy
|
65
|
+
# (see issue #4974), we test the shape and strides of a transpose.
|
66
|
+
a = np.arange(120, dtype=np.int64).reshape((10, 12))
|
67
|
+
a_view_t = a[::2, ::2].T
|
68
|
+
|
69
|
+
d_a = cuda.to_device(a)
|
70
|
+
d_a_view_t = d_a[::2, ::2].T
|
71
|
+
|
72
|
+
self.assertEqual(d_a_view_t.shape, (6, 5))
|
73
|
+
self.assertEqual(d_a_view_t.strides, (40, 8))
|
74
|
+
|
75
|
+
h_a_view_t = d_a_view_t.copy_to_host()
|
76
|
+
np.testing.assert_array_equal(a_view_t, h_a_view_t)
|
77
|
+
|
78
|
+
|
79
|
+
if __name__ == '__main__':
|
80
|
+
unittest.main()
|
@@ -0,0 +1,277 @@
|
|
1
|
+
import functools
|
2
|
+
import numpy as np
|
3
|
+
import unittest
|
4
|
+
|
5
|
+
from numba import config, cuda, types
|
6
|
+
from numba.tests.support import TestCase
|
7
|
+
from numba.tests.test_ufuncs import BasicUFuncTest
|
8
|
+
|
9
|
+
|
10
|
+
def _make_ufunc_usecase(ufunc):
|
11
|
+
ldict = {}
|
12
|
+
arg_str = ','.join(['a{0}'.format(i) for i in range(ufunc.nargs)])
|
13
|
+
func_str = f'def fn({arg_str}):\n np.{ufunc.__name__}({arg_str})'
|
14
|
+
exec(func_str, globals(), ldict)
|
15
|
+
fn = ldict['fn']
|
16
|
+
fn.__name__ = '{0}_usecase'.format(ufunc.__name__)
|
17
|
+
return fn
|
18
|
+
|
19
|
+
|
20
|
+
# This test would also be a CUDATestCase, but to avoid a confusing and
|
21
|
+
# potentially dangerous inheritance diamond with setUp methods that modify
|
22
|
+
# global state, we implement the necessary parts of CUDATestCase within this
|
23
|
+
# class instead. These are:
|
24
|
+
#
|
25
|
+
# - Disable parallel testing with _numba_parallel_test_.
|
26
|
+
# - Disabling CUDA performance warnings for the duration of tests.
|
27
|
+
class TestUFuncs(BasicUFuncTest, TestCase):
|
28
|
+
_numba_parallel_test_ = False
|
29
|
+
|
30
|
+
def setUp(self):
|
31
|
+
BasicUFuncTest.setUp(self)
|
32
|
+
|
33
|
+
# The basic ufunc test does not set up complex inputs, so we'll add
|
34
|
+
# some here for testing with CUDA.
|
35
|
+
self.inputs.extend([
|
36
|
+
(np.complex64(-0.5 - 0.5j), types.complex64),
|
37
|
+
(np.complex64(0.0), types.complex64),
|
38
|
+
(np.complex64(0.5 + 0.5j), types.complex64),
|
39
|
+
|
40
|
+
(np.complex128(-0.5 - 0.5j), types.complex128),
|
41
|
+
(np.complex128(0.0), types.complex128),
|
42
|
+
(np.complex128(0.5 + 0.5j), types.complex128),
|
43
|
+
|
44
|
+
(np.array([-0.5 - 0.5j, 0.0, 0.5 + 0.5j], dtype='c8'),
|
45
|
+
types.Array(types.complex64, 1, 'C')),
|
46
|
+
(np.array([-0.5 - 0.5j, 0.0, 0.5 + 0.5j], dtype='c16'),
|
47
|
+
types.Array(types.complex128, 1, 'C')),
|
48
|
+
])
|
49
|
+
|
50
|
+
# Test with multiple dimensions
|
51
|
+
self.inputs.extend([
|
52
|
+
# Basic 2D and 3D arrays
|
53
|
+
(np.linspace(0, 1).reshape((5, -1)),
|
54
|
+
types.Array(types.float64, 2, 'C')),
|
55
|
+
(np.linspace(0, 1).reshape((2, 5, -1)),
|
56
|
+
types.Array(types.float64, 3, 'C')),
|
57
|
+
# Complex data (i.e. interleaved)
|
58
|
+
(np.linspace(0, 1 + 1j).reshape(5, -1),
|
59
|
+
types.Array(types.complex128, 2, 'C')),
|
60
|
+
# F-ordered
|
61
|
+
(np.asfortranarray(np.linspace(0, 1).reshape((5, -1))),
|
62
|
+
types.Array(types.float64, 2, 'F')),
|
63
|
+
])
|
64
|
+
|
65
|
+
# Add tests for other integer types
|
66
|
+
self.inputs.extend([
|
67
|
+
(np.uint8(0), types.uint8),
|
68
|
+
(np.uint8(1), types.uint8),
|
69
|
+
(np.int8(-1), types.int8),
|
70
|
+
(np.int8(0), types.int8),
|
71
|
+
|
72
|
+
(np.uint16(0), types.uint16),
|
73
|
+
(np.uint16(1), types.uint16),
|
74
|
+
(np.int16(-1), types.int16),
|
75
|
+
(np.int16(0), types.int16),
|
76
|
+
|
77
|
+
(np.ulonglong(0), types.ulonglong),
|
78
|
+
(np.ulonglong(1), types.ulonglong),
|
79
|
+
(np.longlong(-1), types.longlong),
|
80
|
+
(np.longlong(0), types.longlong),
|
81
|
+
|
82
|
+
(np.array([0,1], dtype=np.ulonglong),
|
83
|
+
types.Array(types.ulonglong, 1, 'C')),
|
84
|
+
(np.array([0,1], dtype=np.longlong),
|
85
|
+
types.Array(types.longlong, 1, 'C')),
|
86
|
+
])
|
87
|
+
|
88
|
+
self._low_occupancy_warnings = config.CUDA_LOW_OCCUPANCY_WARNINGS
|
89
|
+
self._warn_on_implicit_copy = config.CUDA_WARN_ON_IMPLICIT_COPY
|
90
|
+
|
91
|
+
# Disable warnings about low gpu utilization in the test suite
|
92
|
+
config.CUDA_LOW_OCCUPANCY_WARNINGS = 0
|
93
|
+
# Disable warnings about host arrays in the test suite
|
94
|
+
config.CUDA_WARN_ON_IMPLICIT_COPY = 0
|
95
|
+
|
96
|
+
def tearDown(self):
|
97
|
+
# Restore original warning settings
|
98
|
+
config.CUDA_LOW_OCCUPANCY_WARNINGS = self._low_occupancy_warnings
|
99
|
+
config.CUDA_WARN_ON_IMPLICIT_COPY = self._warn_on_implicit_copy
|
100
|
+
|
101
|
+
def _make_ufunc_usecase(self, ufunc):
|
102
|
+
return _make_ufunc_usecase(ufunc)
|
103
|
+
|
104
|
+
@functools.lru_cache(maxsize=None)
|
105
|
+
def _compile(self, pyfunc, args):
|
106
|
+
# We return an already-configured kernel so that basic_ufunc_test can
|
107
|
+
# call it just like it does for a CPU function
|
108
|
+
return cuda.jit(args)(pyfunc)[1, 1]
|
109
|
+
|
110
|
+
def basic_int_ufunc_test(self, name=None):
|
111
|
+
skip_inputs = [
|
112
|
+
types.float32,
|
113
|
+
types.float64,
|
114
|
+
types.Array(types.float32, 1, 'C'),
|
115
|
+
types.Array(types.float32, 2, 'C'),
|
116
|
+
types.Array(types.float64, 1, 'C'),
|
117
|
+
types.Array(types.float64, 2, 'C'),
|
118
|
+
types.Array(types.float64, 3, 'C'),
|
119
|
+
types.Array(types.float64, 2, 'F'),
|
120
|
+
types.complex64,
|
121
|
+
types.complex128,
|
122
|
+
types.Array(types.complex64, 1, 'C'),
|
123
|
+
types.Array(types.complex64, 2, 'C'),
|
124
|
+
types.Array(types.complex128, 1, 'C'),
|
125
|
+
types.Array(types.complex128, 2, 'C'),
|
126
|
+
]
|
127
|
+
self.basic_ufunc_test(name, skip_inputs=skip_inputs)
|
128
|
+
|
129
|
+
############################################################################
|
130
|
+
# Trigonometric Functions
|
131
|
+
|
132
|
+
def test_sin_ufunc(self):
|
133
|
+
self.basic_ufunc_test(np.sin, kinds='cf')
|
134
|
+
|
135
|
+
def test_cos_ufunc(self):
|
136
|
+
self.basic_ufunc_test(np.cos, kinds='cf')
|
137
|
+
|
138
|
+
def test_tan_ufunc(self):
|
139
|
+
self.basic_ufunc_test(np.tan, kinds='cf')
|
140
|
+
|
141
|
+
def test_arcsin_ufunc(self):
|
142
|
+
self.basic_ufunc_test(np.arcsin, kinds='cf')
|
143
|
+
|
144
|
+
def test_arccos_ufunc(self):
|
145
|
+
self.basic_ufunc_test(np.arccos, kinds='cf')
|
146
|
+
|
147
|
+
def test_arctan_ufunc(self):
|
148
|
+
self.basic_ufunc_test(np.arctan, kinds='cf')
|
149
|
+
|
150
|
+
def test_arctan2_ufunc(self):
|
151
|
+
self.basic_ufunc_test(np.arctan2, kinds='f')
|
152
|
+
|
153
|
+
def test_hypot_ufunc(self):
|
154
|
+
self.basic_ufunc_test(np.hypot, kinds='f')
|
155
|
+
|
156
|
+
def test_sinh_ufunc(self):
|
157
|
+
self.basic_ufunc_test(np.sinh, kinds='cf')
|
158
|
+
|
159
|
+
def test_cosh_ufunc(self):
|
160
|
+
self.basic_ufunc_test(np.cosh, kinds='cf')
|
161
|
+
|
162
|
+
def test_tanh_ufunc(self):
|
163
|
+
self.basic_ufunc_test(np.tanh, kinds='cf')
|
164
|
+
|
165
|
+
def test_arcsinh_ufunc(self):
|
166
|
+
self.basic_ufunc_test(np.arcsinh, kinds='cf')
|
167
|
+
|
168
|
+
def test_arccosh_ufunc(self):
|
169
|
+
self.basic_ufunc_test(np.arccosh, kinds='cf')
|
170
|
+
|
171
|
+
def test_arctanh_ufunc(self):
|
172
|
+
# arctanh is only valid is only finite in the range ]-1, 1[
|
173
|
+
# This means that for any of the integer types it will produce
|
174
|
+
# conversion from infinity/-infinity to integer. That's undefined
|
175
|
+
# behavior in C, so the results may vary from implementation to
|
176
|
+
# implementation. This means that the result from the compiler
|
177
|
+
# used to compile NumPy may differ from the result generated by
|
178
|
+
# llvm. Skipping the integer types in this test avoids failed
|
179
|
+
# tests because of this.
|
180
|
+
to_skip = [types.Array(types.uint32, 1, 'C'), types.uint32,
|
181
|
+
types.Array(types.int32, 1, 'C'), types.int32,
|
182
|
+
types.Array(types.uint64, 1, 'C'), types.uint64,
|
183
|
+
types.Array(types.int64, 1, 'C'), types.int64]
|
184
|
+
|
185
|
+
self.basic_ufunc_test(np.arctanh, skip_inputs=to_skip, kinds='cf')
|
186
|
+
|
187
|
+
def test_deg2rad_ufunc(self):
|
188
|
+
self.basic_ufunc_test(np.deg2rad, kinds='f')
|
189
|
+
|
190
|
+
def test_rad2deg_ufunc(self):
|
191
|
+
self.basic_ufunc_test(np.rad2deg, kinds='f')
|
192
|
+
|
193
|
+
def test_degrees_ufunc(self):
|
194
|
+
self.basic_ufunc_test(np.degrees, kinds='f')
|
195
|
+
|
196
|
+
def test_radians_ufunc(self):
|
197
|
+
self.basic_ufunc_test(np.radians, kinds='f')
|
198
|
+
|
199
|
+
############################################################################
|
200
|
+
# Comparison functions
|
201
|
+
def test_greater_ufunc(self):
|
202
|
+
self.signed_unsigned_cmp_test(np.greater)
|
203
|
+
|
204
|
+
def test_greater_equal_ufunc(self):
|
205
|
+
self.signed_unsigned_cmp_test(np.greater_equal)
|
206
|
+
|
207
|
+
def test_less_ufunc(self):
|
208
|
+
self.signed_unsigned_cmp_test(np.less)
|
209
|
+
|
210
|
+
def test_less_equal_ufunc(self):
|
211
|
+
self.signed_unsigned_cmp_test(np.less_equal)
|
212
|
+
|
213
|
+
def test_not_equal_ufunc(self):
|
214
|
+
self.signed_unsigned_cmp_test(np.not_equal)
|
215
|
+
|
216
|
+
def test_equal_ufunc(self):
|
217
|
+
self.signed_unsigned_cmp_test(np.equal)
|
218
|
+
|
219
|
+
def test_logical_and_ufunc(self):
|
220
|
+
self.basic_ufunc_test(np.logical_and)
|
221
|
+
|
222
|
+
def test_logical_or_ufunc(self):
|
223
|
+
self.basic_ufunc_test(np.logical_or)
|
224
|
+
|
225
|
+
def test_logical_xor_ufunc(self):
|
226
|
+
self.basic_ufunc_test(np.logical_xor)
|
227
|
+
|
228
|
+
def test_logical_not_ufunc(self):
|
229
|
+
self.basic_ufunc_test(np.logical_not)
|
230
|
+
|
231
|
+
def test_maximum_ufunc(self):
|
232
|
+
self.basic_ufunc_test(np.maximum)
|
233
|
+
|
234
|
+
def test_minimum_ufunc(self):
|
235
|
+
self.basic_ufunc_test(np.minimum)
|
236
|
+
|
237
|
+
def test_fmax_ufunc(self):
|
238
|
+
self.basic_ufunc_test(np.fmax)
|
239
|
+
|
240
|
+
def test_fmin_ufunc(self):
|
241
|
+
self.basic_ufunc_test(np.fmin)
|
242
|
+
|
243
|
+
def test_bitwise_and_ufunc(self):
|
244
|
+
self.basic_int_ufunc_test(np.bitwise_and)
|
245
|
+
|
246
|
+
def test_bitwise_or_ufunc(self):
|
247
|
+
self.basic_int_ufunc_test(np.bitwise_or)
|
248
|
+
|
249
|
+
def test_bitwise_xor_ufunc(self):
|
250
|
+
self.basic_int_ufunc_test(np.bitwise_xor)
|
251
|
+
|
252
|
+
def test_invert_ufunc(self):
|
253
|
+
self.basic_int_ufunc_test(np.invert)
|
254
|
+
|
255
|
+
def test_bitwise_not_ufunc(self):
|
256
|
+
self.basic_int_ufunc_test(np.bitwise_not)
|
257
|
+
|
258
|
+
# Note: there is no entry for np.left_shift and np.right_shift
|
259
|
+
# because their implementations in NumPy have undefined behavior
|
260
|
+
# when the second argument is a negative. See the comment in
|
261
|
+
# numba/tests/test_ufuncs.py for more details.
|
262
|
+
|
263
|
+
############################################################################
|
264
|
+
# Mathematical Functions
|
265
|
+
|
266
|
+
def test_log_ufunc(self):
|
267
|
+
self.basic_ufunc_test(np.log, kinds='cf')
|
268
|
+
|
269
|
+
def test_log2_ufunc(self):
|
270
|
+
self.basic_ufunc_test(np.log2, kinds='cf')
|
271
|
+
|
272
|
+
def test_log10_ufunc(self):
|
273
|
+
self.basic_ufunc_test(np.log10, kinds='cf')
|
274
|
+
|
275
|
+
|
276
|
+
if __name__ == '__main__':
|
277
|
+
unittest.main()
|
@@ -0,0 +1,47 @@
|
|
1
|
+
from numba.cuda.testing import unittest, CUDATestCase
|
2
|
+
from numba import cuda
|
3
|
+
from numba.core import config
|
4
|
+
|
5
|
+
|
6
|
+
class MyError(Exception):
|
7
|
+
pass
|
8
|
+
|
9
|
+
|
10
|
+
regex_pattern = (
|
11
|
+
r'In function [\'"]test_exc[\'"], file [\:\.\/\\\-a-zA-Z_0-9]+, line \d+'
|
12
|
+
)
|
13
|
+
|
14
|
+
|
15
|
+
class TestUserExc(CUDATestCase):
|
16
|
+
|
17
|
+
def setUp(self):
|
18
|
+
super().setUp()
|
19
|
+
# LTO optimizes away the exception status due to an oversight
|
20
|
+
# in the way we generate it (it is not added to the used list).
|
21
|
+
# See https://github.com/numba/numba/issues/9526.
|
22
|
+
self.skip_if_lto("Exceptions not supported with LTO")
|
23
|
+
|
24
|
+
def test_user_exception(self):
|
25
|
+
@cuda.jit("void(int32)", debug=True)
|
26
|
+
def test_exc(x):
|
27
|
+
if x == 1:
|
28
|
+
raise MyError
|
29
|
+
elif x == 2:
|
30
|
+
raise MyError("foo")
|
31
|
+
|
32
|
+
test_exc[1, 1](0) # no raise
|
33
|
+
with self.assertRaises(MyError) as cm:
|
34
|
+
test_exc[1, 1](1)
|
35
|
+
if not config.ENABLE_CUDASIM:
|
36
|
+
self.assertRegex(str(cm.exception), regex_pattern)
|
37
|
+
self.assertIn("tid=[0, 0, 0] ctaid=[0, 0, 0]", str(cm.exception))
|
38
|
+
with self.assertRaises(MyError) as cm:
|
39
|
+
test_exc[1, 1](2)
|
40
|
+
if not config.ENABLE_CUDASIM:
|
41
|
+
self.assertRegex(str(cm.exception), regex_pattern)
|
42
|
+
self.assertRegex(str(cm.exception), regex_pattern)
|
43
|
+
self.assertIn("tid=[0, 0, 0] ctaid=[0, 0, 0]: foo", str(cm.exception))
|
44
|
+
|
45
|
+
|
46
|
+
if __name__ == '__main__':
|
47
|
+
unittest.main()
|