numba-cuda 0.21.1__cp313-cp313-win_amd64.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 +4 -0
- _numba_cuda_redirector.py +89 -0
- numba_cuda/VERSION +1 -0
- numba_cuda/__init__.py +6 -0
- numba_cuda/_version.py +11 -0
- numba_cuda/numba/cuda/__init__.py +70 -0
- numba_cuda/numba/cuda/_internal/cuda_bf16.py +16394 -0
- numba_cuda/numba/cuda/_internal/cuda_fp16.py +8112 -0
- numba_cuda/numba/cuda/api.py +577 -0
- numba_cuda/numba/cuda/api_util.py +76 -0
- numba_cuda/numba/cuda/args.py +72 -0
- numba_cuda/numba/cuda/bf16.py +397 -0
- numba_cuda/numba/cuda/cache_hints.py +287 -0
- numba_cuda/numba/cuda/cext/__init__.py +2 -0
- numba_cuda/numba/cuda/cext/_devicearray.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_devicearray.cpp +159 -0
- numba_cuda/numba/cuda/cext/_devicearray.h +29 -0
- numba_cuda/numba/cuda/cext/_dispatcher.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_dispatcher.cpp +1098 -0
- numba_cuda/numba/cuda/cext/_hashtable.cpp +532 -0
- numba_cuda/numba/cuda/cext/_hashtable.h +135 -0
- numba_cuda/numba/cuda/cext/_helperlib.c +71 -0
- numba_cuda/numba/cuda/cext/_helperlib.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_helpermod.c +82 -0
- numba_cuda/numba/cuda/cext/_pymodule.h +38 -0
- numba_cuda/numba/cuda/cext/_typeconv.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_typeconv.cpp +206 -0
- numba_cuda/numba/cuda/cext/_typeof.cpp +1159 -0
- numba_cuda/numba/cuda/cext/_typeof.h +19 -0
- numba_cuda/numba/cuda/cext/capsulethunk.h +111 -0
- numba_cuda/numba/cuda/cext/mviewbuf.c +385 -0
- numba_cuda/numba/cuda/cext/mviewbuf.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/typeconv.cpp +212 -0
- numba_cuda/numba/cuda/cext/typeconv.hpp +101 -0
- numba_cuda/numba/cuda/cg.py +67 -0
- numba_cuda/numba/cuda/cgutils.py +1294 -0
- 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 +541 -0
- numba_cuda/numba/cuda/compiler.py +1396 -0
- numba_cuda/numba/cuda/core/analysis.py +758 -0
- numba_cuda/numba/cuda/core/annotations/__init__.py +0 -0
- numba_cuda/numba/cuda/core/annotations/pretty_annotate.py +288 -0
- numba_cuda/numba/cuda/core/annotations/type_annotations.py +305 -0
- numba_cuda/numba/cuda/core/base.py +1332 -0
- numba_cuda/numba/cuda/core/boxing.py +1411 -0
- numba_cuda/numba/cuda/core/bytecode.py +728 -0
- numba_cuda/numba/cuda/core/byteflow.py +2346 -0
- numba_cuda/numba/cuda/core/caching.py +744 -0
- numba_cuda/numba/cuda/core/callconv.py +392 -0
- numba_cuda/numba/cuda/core/codegen.py +171 -0
- numba_cuda/numba/cuda/core/compiler.py +199 -0
- numba_cuda/numba/cuda/core/compiler_lock.py +85 -0
- numba_cuda/numba/cuda/core/compiler_machinery.py +497 -0
- numba_cuda/numba/cuda/core/config.py +650 -0
- numba_cuda/numba/cuda/core/consts.py +124 -0
- numba_cuda/numba/cuda/core/controlflow.py +989 -0
- numba_cuda/numba/cuda/core/entrypoints.py +57 -0
- numba_cuda/numba/cuda/core/environment.py +66 -0
- numba_cuda/numba/cuda/core/errors.py +917 -0
- numba_cuda/numba/cuda/core/event.py +511 -0
- numba_cuda/numba/cuda/core/funcdesc.py +330 -0
- numba_cuda/numba/cuda/core/generators.py +387 -0
- numba_cuda/numba/cuda/core/imputils.py +509 -0
- numba_cuda/numba/cuda/core/inline_closurecall.py +1787 -0
- numba_cuda/numba/cuda/core/interpreter.py +3617 -0
- numba_cuda/numba/cuda/core/ir.py +1812 -0
- numba_cuda/numba/cuda/core/ir_utils.py +2638 -0
- numba_cuda/numba/cuda/core/optional.py +129 -0
- 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 +1859 -0
- numba_cuda/numba/cuda/core/registry.py +46 -0
- numba_cuda/numba/cuda/core/removerefctpass.py +123 -0
- numba_cuda/numba/cuda/core/rewrites/__init__.py +26 -0
- numba_cuda/numba/cuda/core/rewrites/ir_print.py +91 -0
- numba_cuda/numba/cuda/core/rewrites/registry.py +104 -0
- numba_cuda/numba/cuda/core/rewrites/static_binop.py +41 -0
- numba_cuda/numba/cuda/core/rewrites/static_getitem.py +189 -0
- numba_cuda/numba/cuda/core/rewrites/static_raise.py +100 -0
- numba_cuda/numba/cuda/core/sigutils.py +68 -0
- numba_cuda/numba/cuda/core/ssa.py +498 -0
- numba_cuda/numba/cuda/core/targetconfig.py +330 -0
- numba_cuda/numba/cuda/core/tracing.py +231 -0
- numba_cuda/numba/cuda/core/transforms.py +956 -0
- numba_cuda/numba/cuda/core/typed_passes.py +867 -0
- numba_cuda/numba/cuda/core/typeinfer.py +1950 -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 +67 -0
- numba_cuda/numba/cuda/core/unsafe/refcount.py +98 -0
- numba_cuda/numba/cuda/core/untyped_passes.py +1979 -0
- numba_cuda/numba/cuda/cpython/builtins.py +1153 -0
- numba_cuda/numba/cuda/cpython/charseq.py +1218 -0
- numba_cuda/numba/cuda/cpython/cmathimpl.py +560 -0
- numba_cuda/numba/cuda/cpython/enumimpl.py +103 -0
- numba_cuda/numba/cuda/cpython/iterators.py +167 -0
- numba_cuda/numba/cuda/cpython/listobj.py +1326 -0
- numba_cuda/numba/cuda/cpython/mathimpl.py +499 -0
- numba_cuda/numba/cuda/cpython/numbers.py +1475 -0
- numba_cuda/numba/cuda/cpython/rangeobj.py +289 -0
- numba_cuda/numba/cuda/cpython/slicing.py +322 -0
- numba_cuda/numba/cuda/cpython/tupleobj.py +456 -0
- numba_cuda/numba/cuda/cpython/unicode.py +2865 -0
- numba_cuda/numba/cuda/cpython/unicode_support.py +1597 -0
- numba_cuda/numba/cuda/cpython/unsafe/__init__.py +0 -0
- numba_cuda/numba/cuda/cpython/unsafe/numbers.py +64 -0
- numba_cuda/numba/cuda/cpython/unsafe/tuple.py +92 -0
- numba_cuda/numba/cuda/cuda_paths.py +691 -0
- numba_cuda/numba/cuda/cudadecl.py +556 -0
- numba_cuda/numba/cuda/cudadrv/__init__.py +14 -0
- numba_cuda/numba/cuda/cudadrv/devicearray.py +951 -0
- numba_cuda/numba/cuda/cudadrv/devices.py +249 -0
- numba_cuda/numba/cuda/cudadrv/driver.py +3222 -0
- numba_cuda/numba/cuda/cudadrv/drvapi.py +435 -0
- numba_cuda/numba/cuda/cudadrv/dummyarray.py +558 -0
- numba_cuda/numba/cuda/cudadrv/enums.py +613 -0
- numba_cuda/numba/cuda/cudadrv/error.py +48 -0
- numba_cuda/numba/cuda/cudadrv/libs.py +220 -0
- numba_cuda/numba/cuda/cudadrv/linkable_code.py +184 -0
- numba_cuda/numba/cuda/cudadrv/mappings.py +14 -0
- numba_cuda/numba/cuda/cudadrv/ndarray.py +26 -0
- numba_cuda/numba/cuda/cudadrv/nvrtc.py +193 -0
- numba_cuda/numba/cuda/cudadrv/nvvm.py +756 -0
- numba_cuda/numba/cuda/cudadrv/rtapi.py +13 -0
- numba_cuda/numba/cuda/cudadrv/runtime.py +34 -0
- numba_cuda/numba/cuda/cudaimpl.py +995 -0
- numba_cuda/numba/cuda/cudamath.py +149 -0
- numba_cuda/numba/cuda/datamodel/__init__.py +7 -0
- numba_cuda/numba/cuda/datamodel/cuda_manager.py +66 -0
- numba_cuda/numba/cuda/datamodel/cuda_models.py +1446 -0
- numba_cuda/numba/cuda/datamodel/cuda_packer.py +224 -0
- numba_cuda/numba/cuda/datamodel/cuda_registry.py +22 -0
- numba_cuda/numba/cuda/datamodel/cuda_testing.py +153 -0
- numba_cuda/numba/cuda/datamodel/manager.py +11 -0
- numba_cuda/numba/cuda/datamodel/models.py +9 -0
- numba_cuda/numba/cuda/datamodel/packer.py +9 -0
- numba_cuda/numba/cuda/datamodel/registry.py +11 -0
- numba_cuda/numba/cuda/datamodel/testing.py +11 -0
- numba_cuda/numba/cuda/debuginfo.py +903 -0
- numba_cuda/numba/cuda/decorators.py +294 -0
- numba_cuda/numba/cuda/descriptor.py +35 -0
- numba_cuda/numba/cuda/device_init.py +158 -0
- numba_cuda/numba/cuda/deviceufunc.py +1021 -0
- numba_cuda/numba/cuda/dispatcher.py +2463 -0
- numba_cuda/numba/cuda/errors.py +72 -0
- numba_cuda/numba/cuda/extending.py +697 -0
- numba_cuda/numba/cuda/flags.py +178 -0
- numba_cuda/numba/cuda/fp16.py +357 -0
- numba_cuda/numba/cuda/include/12/cuda_bf16.h +5118 -0
- numba_cuda/numba/cuda/include/12/cuda_bf16.hpp +3865 -0
- numba_cuda/numba/cuda/include/12/cuda_fp16.h +5363 -0
- numba_cuda/numba/cuda/include/12/cuda_fp16.hpp +3483 -0
- 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/initialize.py +24 -0
- numba_cuda/numba/cuda/intrinsic_wrapper.py +41 -0
- numba_cuda/numba/cuda/intrinsics.py +382 -0
- numba_cuda/numba/cuda/itanium_mangler.py +214 -0
- numba_cuda/numba/cuda/kernels/__init__.py +2 -0
- numba_cuda/numba/cuda/kernels/reduction.py +265 -0
- numba_cuda/numba/cuda/kernels/transpose.py +65 -0
- numba_cuda/numba/cuda/libdevice.py +3386 -0
- numba_cuda/numba/cuda/libdevicedecl.py +20 -0
- numba_cuda/numba/cuda/libdevicefuncs.py +1060 -0
- numba_cuda/numba/cuda/libdeviceimpl.py +88 -0
- numba_cuda/numba/cuda/locks.py +19 -0
- numba_cuda/numba/cuda/lowering.py +1951 -0
- numba_cuda/numba/cuda/mathimpl.py +374 -0
- numba_cuda/numba/cuda/memory_management/__init__.py +4 -0
- numba_cuda/numba/cuda/memory_management/memsys.cu +99 -0
- numba_cuda/numba/cuda/memory_management/memsys.cuh +22 -0
- numba_cuda/numba/cuda/memory_management/nrt.cu +212 -0
- numba_cuda/numba/cuda/memory_management/nrt.cuh +48 -0
- numba_cuda/numba/cuda/memory_management/nrt.py +390 -0
- numba_cuda/numba/cuda/memory_management/nrt_context.py +438 -0
- numba_cuda/numba/cuda/misc/appdirs.py +594 -0
- numba_cuda/numba/cuda/misc/cffiimpl.py +24 -0
- numba_cuda/numba/cuda/misc/coverage_support.py +43 -0
- numba_cuda/numba/cuda/misc/dump_style.py +41 -0
- numba_cuda/numba/cuda/misc/findlib.py +75 -0
- numba_cuda/numba/cuda/misc/firstlinefinder.py +96 -0
- numba_cuda/numba/cuda/misc/gdb_hook.py +240 -0
- numba_cuda/numba/cuda/misc/literal.py +28 -0
- numba_cuda/numba/cuda/misc/llvm_pass_timings.py +412 -0
- numba_cuda/numba/cuda/misc/special.py +94 -0
- numba_cuda/numba/cuda/models.py +56 -0
- numba_cuda/numba/cuda/np/arraymath.py +5130 -0
- numba_cuda/numba/cuda/np/arrayobj.py +7635 -0
- numba_cuda/numba/cuda/np/extensions.py +11 -0
- numba_cuda/numba/cuda/np/linalg.py +3087 -0
- numba_cuda/numba/cuda/np/math/__init__.py +0 -0
- numba_cuda/numba/cuda/np/math/cmathimpl.py +558 -0
- numba_cuda/numba/cuda/np/math/mathimpl.py +487 -0
- numba_cuda/numba/cuda/np/math/numbers.py +1461 -0
- numba_cuda/numba/cuda/np/npdatetime.py +969 -0
- numba_cuda/numba/cuda/np/npdatetime_helpers.py +217 -0
- numba_cuda/numba/cuda/np/npyfuncs.py +1808 -0
- numba_cuda/numba/cuda/np/npyimpl.py +1027 -0
- numba_cuda/numba/cuda/np/numpy_support.py +798 -0
- numba_cuda/numba/cuda/np/polynomial/__init__.py +4 -0
- numba_cuda/numba/cuda/np/polynomial/polynomial_core.py +242 -0
- numba_cuda/numba/cuda/np/polynomial/polynomial_functions.py +380 -0
- numba_cuda/numba/cuda/np/ufunc/__init__.py +4 -0
- numba_cuda/numba/cuda/np/ufunc/decorators.py +203 -0
- numba_cuda/numba/cuda/np/ufunc/sigparse.py +68 -0
- numba_cuda/numba/cuda/np/ufunc/ufuncbuilder.py +65 -0
- numba_cuda/numba/cuda/np/ufunc_db.py +1282 -0
- numba_cuda/numba/cuda/np/unsafe/__init__.py +0 -0
- numba_cuda/numba/cuda/np/unsafe/ndarray.py +84 -0
- numba_cuda/numba/cuda/nvvmutils.py +254 -0
- numba_cuda/numba/cuda/printimpl.py +126 -0
- numba_cuda/numba/cuda/random.py +308 -0
- numba_cuda/numba/cuda/reshape_funcs.cu +156 -0
- numba_cuda/numba/cuda/serialize.py +267 -0
- numba_cuda/numba/cuda/simulator/__init__.py +63 -0
- numba_cuda/numba/cuda/simulator/_internal/__init__.py +4 -0
- numba_cuda/numba/cuda/simulator/_internal/cuda_bf16.py +2 -0
- numba_cuda/numba/cuda/simulator/api.py +179 -0
- numba_cuda/numba/cuda/simulator/bf16.py +4 -0
- numba_cuda/numba/cuda/simulator/compiler.py +38 -0
- numba_cuda/numba/cuda/simulator/cudadrv/__init__.py +11 -0
- numba_cuda/numba/cuda/simulator/cudadrv/devicearray.py +462 -0
- numba_cuda/numba/cuda/simulator/cudadrv/devices.py +122 -0
- numba_cuda/numba/cuda/simulator/cudadrv/driver.py +66 -0
- numba_cuda/numba/cuda/simulator/cudadrv/drvapi.py +7 -0
- numba_cuda/numba/cuda/simulator/cudadrv/dummyarray.py +7 -0
- numba_cuda/numba/cuda/simulator/cudadrv/error.py +10 -0
- numba_cuda/numba/cuda/simulator/cudadrv/libs.py +10 -0
- numba_cuda/numba/cuda/simulator/cudadrv/linkable_code.py +61 -0
- numba_cuda/numba/cuda/simulator/cudadrv/nvrtc.py +11 -0
- numba_cuda/numba/cuda/simulator/cudadrv/nvvm.py +32 -0
- numba_cuda/numba/cuda/simulator/cudadrv/runtime.py +22 -0
- numba_cuda/numba/cuda/simulator/dispatcher.py +11 -0
- numba_cuda/numba/cuda/simulator/kernel.py +320 -0
- numba_cuda/numba/cuda/simulator/kernelapi.py +509 -0
- numba_cuda/numba/cuda/simulator/memory_management/__init__.py +4 -0
- numba_cuda/numba/cuda/simulator/memory_management/nrt.py +21 -0
- numba_cuda/numba/cuda/simulator/reduction.py +19 -0
- numba_cuda/numba/cuda/simulator/tests/support.py +4 -0
- numba_cuda/numba/cuda/simulator/vector_types.py +65 -0
- numba_cuda/numba/cuda/simulator_init.py +18 -0
- numba_cuda/numba/cuda/stubs.py +635 -0
- numba_cuda/numba/cuda/target.py +505 -0
- numba_cuda/numba/cuda/testing.py +347 -0
- numba_cuda/numba/cuda/tests/__init__.py +62 -0
- numba_cuda/numba/cuda/tests/benchmarks/__init__.py +0 -0
- numba_cuda/numba/cuda/tests/benchmarks/test_kernel_launch.py +119 -0
- numba_cuda/numba/cuda/tests/cloudpickle_main_class.py +9 -0
- numba_cuda/numba/cuda/tests/core/serialize_usecases.py +113 -0
- numba_cuda/numba/cuda/tests/core/test_itanium_mangler.py +83 -0
- numba_cuda/numba/cuda/tests/core/test_serialize.py +371 -0
- numba_cuda/numba/cuda/tests/cudadrv/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_array_attr.py +147 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_context_stack.py +161 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py +397 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_auto_context.py +24 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py +180 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_driver.py +313 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_memory.py +187 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +621 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py +247 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_detect.py +100 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py +198 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_events.py +53 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_host_alloc.py +72 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_init.py +138 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_inline_ptx.py +43 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_is_fp16.py +15 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_linkable_code.py +58 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_linker.py +348 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_managed_alloc.py +128 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_module_callbacks.py +301 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_nvjitlink.py +174 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_nvrtc.py +28 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_nvvm_driver.py +185 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_pinned.py +39 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_profiler.py +23 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_reset_device.py +38 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_runtime.py +48 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_select_device.py +44 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_streams.py +127 -0
- numba_cuda/numba/cuda/tests/cudapy/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/cudapy/cache_usecases.py +231 -0
- numba_cuda/numba/cuda/tests/cudapy/cache_with_cpu_usecases.py +50 -0
- numba_cuda/numba/cuda/tests/cudapy/cg_cache_usecases.py +36 -0
- numba_cuda/numba/cuda/tests/cudapy/complex_usecases.py +116 -0
- numba_cuda/numba/cuda/tests/cudapy/enum_usecases.py +59 -0
- numba_cuda/numba/cuda/tests/cudapy/extensions_usecases.py +62 -0
- numba_cuda/numba/cuda/tests/cudapy/jitlink.ptx +28 -0
- numba_cuda/numba/cuda/tests/cudapy/overload_usecases.py +33 -0
- numba_cuda/numba/cuda/tests/cudapy/recursion_usecases.py +104 -0
- numba_cuda/numba/cuda/tests/cudapy/test_alignment.py +47 -0
- numba_cuda/numba/cuda/tests/cudapy/test_analysis.py +1122 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array.py +344 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_alignment.py +268 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_args.py +203 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_methods.py +63 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_reductions.py +360 -0
- numba_cuda/numba/cuda/tests/cudapy/test_atomics.py +1815 -0
- numba_cuda/numba/cuda/tests/cudapy/test_bfloat16.py +599 -0
- numba_cuda/numba/cuda/tests/cudapy/test_bfloat16_bindings.py +377 -0
- numba_cuda/numba/cuda/tests/cudapy/test_blackscholes.py +160 -0
- numba_cuda/numba/cuda/tests/cudapy/test_boolean.py +27 -0
- numba_cuda/numba/cuda/tests/cudapy/test_byteflow.py +98 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cache_hints.py +210 -0
- numba_cuda/numba/cuda/tests/cudapy/test_caching.py +683 -0
- numba_cuda/numba/cuda/tests/cudapy/test_casting.py +265 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cffi.py +42 -0
- numba_cuda/numba/cuda/tests/cudapy/test_compiler.py +718 -0
- numba_cuda/numba/cuda/tests/cudapy/test_complex.py +370 -0
- numba_cuda/numba/cuda/tests/cudapy/test_complex_kernel.py +23 -0
- numba_cuda/numba/cuda/tests/cudapy/test_const_string.py +142 -0
- numba_cuda/numba/cuda/tests/cudapy/test_constmem.py +178 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cooperative_groups.py +193 -0
- numba_cuda/numba/cuda/tests/cudapy/test_copy_propagate.py +131 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cuda_array_interface.py +438 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cuda_jit_no_types.py +94 -0
- numba_cuda/numba/cuda/tests/cudapy/test_datetime.py +101 -0
- numba_cuda/numba/cuda/tests/cudapy/test_debug.py +105 -0
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py +889 -0
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo_types.py +476 -0
- numba_cuda/numba/cuda/tests/cudapy/test_device_func.py +500 -0
- numba_cuda/numba/cuda/tests/cudapy/test_dispatcher.py +820 -0
- numba_cuda/numba/cuda/tests/cudapy/test_enums.py +152 -0
- numba_cuda/numba/cuda/tests/cudapy/test_errors.py +111 -0
- numba_cuda/numba/cuda/tests/cudapy/test_exception.py +170 -0
- numba_cuda/numba/cuda/tests/cudapy/test_extending.py +1088 -0
- numba_cuda/numba/cuda/tests/cudapy/test_extending_types.py +71 -0
- numba_cuda/numba/cuda/tests/cudapy/test_fastmath.py +265 -0
- numba_cuda/numba/cuda/tests/cudapy/test_flow_control.py +1433 -0
- numba_cuda/numba/cuda/tests/cudapy/test_forall.py +57 -0
- numba_cuda/numba/cuda/tests/cudapy/test_freevar.py +34 -0
- numba_cuda/numba/cuda/tests/cudapy/test_frexp_ldexp.py +69 -0
- numba_cuda/numba/cuda/tests/cudapy/test_globals.py +62 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc.py +474 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scalar.py +167 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +92 -0
- numba_cuda/numba/cuda/tests/cudapy/test_idiv.py +39 -0
- numba_cuda/numba/cuda/tests/cudapy/test_inline.py +170 -0
- numba_cuda/numba/cuda/tests/cudapy/test_inspect.py +255 -0
- numba_cuda/numba/cuda/tests/cudapy/test_intrinsics.py +1219 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ipc.py +263 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ir.py +598 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ir_utils.py +276 -0
- numba_cuda/numba/cuda/tests/cudapy/test_iterators.py +101 -0
- numba_cuda/numba/cuda/tests/cudapy/test_lang.py +68 -0
- numba_cuda/numba/cuda/tests/cudapy/test_laplace.py +123 -0
- numba_cuda/numba/cuda/tests/cudapy/test_libdevice.py +194 -0
- numba_cuda/numba/cuda/tests/cudapy/test_lineinfo.py +220 -0
- numba_cuda/numba/cuda/tests/cudapy/test_localmem.py +173 -0
- numba_cuda/numba/cuda/tests/cudapy/test_make_function_to_jit_function.py +364 -0
- numba_cuda/numba/cuda/tests/cudapy/test_mandel.py +47 -0
- numba_cuda/numba/cuda/tests/cudapy/test_math.py +842 -0
- numba_cuda/numba/cuda/tests/cudapy/test_matmul.py +76 -0
- numba_cuda/numba/cuda/tests/cudapy/test_minmax.py +78 -0
- numba_cuda/numba/cuda/tests/cudapy/test_montecarlo.py +25 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multigpu.py +145 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multiprocessing.py +39 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multithreads.py +82 -0
- numba_cuda/numba/cuda/tests/cudapy/test_nondet.py +53 -0
- numba_cuda/numba/cuda/tests/cudapy/test_operator.py +504 -0
- numba_cuda/numba/cuda/tests/cudapy/test_optimization.py +93 -0
- numba_cuda/numba/cuda/tests/cudapy/test_overload.py +402 -0
- numba_cuda/numba/cuda/tests/cudapy/test_powi.py +128 -0
- numba_cuda/numba/cuda/tests/cudapy/test_print.py +193 -0
- numba_cuda/numba/cuda/tests/cudapy/test_py2_div_issue.py +37 -0
- numba_cuda/numba/cuda/tests/cudapy/test_random.py +117 -0
- numba_cuda/numba/cuda/tests/cudapy/test_record_dtype.py +614 -0
- numba_cuda/numba/cuda/tests/cudapy/test_recursion.py +130 -0
- numba_cuda/numba/cuda/tests/cudapy/test_reduction.py +94 -0
- numba_cuda/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +83 -0
- numba_cuda/numba/cuda/tests/cudapy/test_serialize.py +86 -0
- numba_cuda/numba/cuda/tests/cudapy/test_slicing.py +40 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sm.py +457 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sm_creation.py +233 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ssa.py +454 -0
- numba_cuda/numba/cuda/tests/cudapy/test_stream_api.py +56 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sync.py +277 -0
- numba_cuda/numba/cuda/tests/cudapy/test_tracing.py +200 -0
- numba_cuda/numba/cuda/tests/cudapy/test_transpose.py +90 -0
- numba_cuda/numba/cuda/tests/cudapy/test_typeconv.py +333 -0
- numba_cuda/numba/cuda/tests/cudapy/test_typeinfer.py +538 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ufuncs.py +585 -0
- numba_cuda/numba/cuda/tests/cudapy/test_userexc.py +42 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vector_type.py +485 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize.py +312 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_complex.py +23 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_decor.py +183 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_device.py +40 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +40 -0
- numba_cuda/numba/cuda/tests/cudapy/test_warning.py +206 -0
- numba_cuda/numba/cuda/tests/cudapy/test_warp_ops.py +331 -0
- numba_cuda/numba/cuda/tests/cudasim/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/cudasim/support.py +9 -0
- numba_cuda/numba/cuda/tests/cudasim/test_cudasim_issues.py +111 -0
- numba_cuda/numba/cuda/tests/data/__init__.py +2 -0
- numba_cuda/numba/cuda/tests/data/cta_barrier.cu +28 -0
- numba_cuda/numba/cuda/tests/data/cuda_include.cu +10 -0
- numba_cuda/numba/cuda/tests/data/error.cu +12 -0
- numba_cuda/numba/cuda/tests/data/include/add.cuh +8 -0
- numba_cuda/numba/cuda/tests/data/jitlink.cu +28 -0
- numba_cuda/numba/cuda/tests/data/jitlink.ptx +49 -0
- numba_cuda/numba/cuda/tests/data/warn.cu +12 -0
- numba_cuda/numba/cuda/tests/doc_examples/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/__init__.py +2 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/functions.cu +54 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/include/mul.cuh +8 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/saxpy.cu +14 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cg.py +86 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cpointer.py +68 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cpu_gpu_compat.py +81 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_ffi.py +141 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_laplace.py +160 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_matmul.py +180 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_montecarlo.py +119 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_random.py +66 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_reduction.py +80 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_sessionize.py +206 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_ufunc.py +53 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_vecadd.py +76 -0
- numba_cuda/numba/cuda/tests/nocuda/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/nocuda/test_dummyarray.py +391 -0
- numba_cuda/numba/cuda/tests/nocuda/test_function_resolution.py +48 -0
- numba_cuda/numba/cuda/tests/nocuda/test_import.py +63 -0
- numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +252 -0
- numba_cuda/numba/cuda/tests/nocuda/test_nvvm.py +59 -0
- numba_cuda/numba/cuda/tests/nrt/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/nrt/test_nrt.py +387 -0
- numba_cuda/numba/cuda/tests/nrt/test_nrt_refct.py +124 -0
- numba_cuda/numba/cuda/tests/support.py +900 -0
- numba_cuda/numba/cuda/typeconv/__init__.py +4 -0
- numba_cuda/numba/cuda/typeconv/castgraph.py +137 -0
- numba_cuda/numba/cuda/typeconv/rules.py +63 -0
- numba_cuda/numba/cuda/typeconv/typeconv.py +121 -0
- numba_cuda/numba/cuda/types/__init__.py +233 -0
- numba_cuda/numba/cuda/types/__init__.pyi +167 -0
- numba_cuda/numba/cuda/types/abstract.py +9 -0
- numba_cuda/numba/cuda/types/common.py +9 -0
- numba_cuda/numba/cuda/types/containers.py +9 -0
- numba_cuda/numba/cuda/types/cuda_abstract.py +533 -0
- numba_cuda/numba/cuda/types/cuda_common.py +110 -0
- numba_cuda/numba/cuda/types/cuda_containers.py +971 -0
- numba_cuda/numba/cuda/types/cuda_function_type.py +230 -0
- numba_cuda/numba/cuda/types/cuda_functions.py +798 -0
- numba_cuda/numba/cuda/types/cuda_iterators.py +120 -0
- numba_cuda/numba/cuda/types/cuda_misc.py +569 -0
- numba_cuda/numba/cuda/types/cuda_npytypes.py +690 -0
- numba_cuda/numba/cuda/types/cuda_scalars.py +280 -0
- numba_cuda/numba/cuda/types/ext_types.py +101 -0
- numba_cuda/numba/cuda/types/function_type.py +11 -0
- numba_cuda/numba/cuda/types/functions.py +9 -0
- numba_cuda/numba/cuda/types/iterators.py +9 -0
- numba_cuda/numba/cuda/types/misc.py +9 -0
- numba_cuda/numba/cuda/types/npytypes.py +9 -0
- numba_cuda/numba/cuda/types/scalars.py +9 -0
- numba_cuda/numba/cuda/typing/__init__.py +19 -0
- numba_cuda/numba/cuda/typing/arraydecl.py +939 -0
- numba_cuda/numba/cuda/typing/asnumbatype.py +130 -0
- numba_cuda/numba/cuda/typing/bufproto.py +70 -0
- numba_cuda/numba/cuda/typing/builtins.py +1209 -0
- numba_cuda/numba/cuda/typing/cffi_utils.py +219 -0
- numba_cuda/numba/cuda/typing/cmathdecl.py +47 -0
- numba_cuda/numba/cuda/typing/collections.py +138 -0
- numba_cuda/numba/cuda/typing/context.py +782 -0
- numba_cuda/numba/cuda/typing/ctypes_utils.py +125 -0
- numba_cuda/numba/cuda/typing/dictdecl.py +63 -0
- numba_cuda/numba/cuda/typing/enumdecl.py +74 -0
- numba_cuda/numba/cuda/typing/listdecl.py +147 -0
- numba_cuda/numba/cuda/typing/mathdecl.py +158 -0
- numba_cuda/numba/cuda/typing/npdatetime.py +322 -0
- numba_cuda/numba/cuda/typing/npydecl.py +749 -0
- numba_cuda/numba/cuda/typing/setdecl.py +115 -0
- numba_cuda/numba/cuda/typing/templates.py +1446 -0
- numba_cuda/numba/cuda/typing/typeof.py +301 -0
- numba_cuda/numba/cuda/ufuncs.py +746 -0
- numba_cuda/numba/cuda/utils.py +724 -0
- numba_cuda/numba/cuda/vector_types.py +214 -0
- numba_cuda/numba/cuda/vectorizers.py +260 -0
- numba_cuda-0.21.1.dist-info/METADATA +109 -0
- numba_cuda-0.21.1.dist-info/RECORD +488 -0
- numba_cuda-0.21.1.dist-info/WHEEL +5 -0
- numba_cuda-0.21.1.dist-info/licenses/LICENSE +26 -0
- numba_cuda-0.21.1.dist-info/licenses/LICENSE.numba +24 -0
- numba_cuda-0.21.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,995 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
3
|
+
|
|
4
|
+
from functools import reduce
|
|
5
|
+
import operator
|
|
6
|
+
import math
|
|
7
|
+
import struct
|
|
8
|
+
|
|
9
|
+
from llvmlite import ir
|
|
10
|
+
import llvmlite.binding as ll
|
|
11
|
+
|
|
12
|
+
from numba.cuda.core.imputils import Registry
|
|
13
|
+
from numba.cuda.typing.npydecl import parse_dtype
|
|
14
|
+
from numba.cuda.datamodel.models import StructModel
|
|
15
|
+
from numba.cuda import types
|
|
16
|
+
from numba.cuda import cgutils
|
|
17
|
+
from numba.cuda.np import ufunc_db
|
|
18
|
+
from numba.cuda.np.npyimpl import register_ufuncs
|
|
19
|
+
from .cudadrv import nvvm
|
|
20
|
+
from numba import cuda
|
|
21
|
+
from numba.cuda.api_util import normalize_indices
|
|
22
|
+
from numba.cuda import nvvmutils, stubs
|
|
23
|
+
from numba.cuda.types.ext_types import dim3, CUDADispatcher
|
|
24
|
+
|
|
25
|
+
if cuda.HAS_NUMBA:
|
|
26
|
+
from numba.core.datamodel.models import StructModel as CoreStructModel
|
|
27
|
+
from numba.core import types as core_types
|
|
28
|
+
|
|
29
|
+
registry = Registry("cudaimpl")
|
|
30
|
+
lower = registry.lower
|
|
31
|
+
lower_attr = registry.lower_getattr
|
|
32
|
+
lower_constant = registry.lower_constant
|
|
33
|
+
lower_getattr_generic = registry.lower_getattr_generic
|
|
34
|
+
lower_setattr = registry.lower_setattr
|
|
35
|
+
lower_setattr_generic = registry.lower_setattr_generic
|
|
36
|
+
lower_cast = registry.lower_cast
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def initialize_dim3(builder, prefix):
|
|
40
|
+
x = nvvmutils.call_sreg(builder, "%s.x" % prefix)
|
|
41
|
+
y = nvvmutils.call_sreg(builder, "%s.y" % prefix)
|
|
42
|
+
z = nvvmutils.call_sreg(builder, "%s.z" % prefix)
|
|
43
|
+
return cgutils.pack_struct(builder, (x, y, z))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@lower_attr(types.Module(cuda), "threadIdx")
|
|
47
|
+
def cuda_threadIdx(context, builder, sig, args):
|
|
48
|
+
return initialize_dim3(builder, "tid")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@lower_attr(types.Module(cuda), "blockDim")
|
|
52
|
+
def cuda_blockDim(context, builder, sig, args):
|
|
53
|
+
return initialize_dim3(builder, "ntid")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@lower_attr(types.Module(cuda), "blockIdx")
|
|
57
|
+
def cuda_blockIdx(context, builder, sig, args):
|
|
58
|
+
return initialize_dim3(builder, "ctaid")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@lower_attr(types.Module(cuda), "gridDim")
|
|
62
|
+
def cuda_gridDim(context, builder, sig, args):
|
|
63
|
+
return initialize_dim3(builder, "nctaid")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@lower_attr(types.Module(cuda), "laneid")
|
|
67
|
+
def cuda_laneid(context, builder, sig, args):
|
|
68
|
+
return nvvmutils.call_sreg(builder, "laneid")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@lower_attr(dim3, "x")
|
|
72
|
+
def dim3_x(context, builder, sig, args):
|
|
73
|
+
return builder.extract_value(args, 0)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@lower_attr(dim3, "y")
|
|
77
|
+
def dim3_y(context, builder, sig, args):
|
|
78
|
+
return builder.extract_value(args, 1)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@lower_attr(dim3, "z")
|
|
82
|
+
def dim3_z(context, builder, sig, args):
|
|
83
|
+
return builder.extract_value(args, 2)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# -----------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@lower(cuda.const.array_like, types.Array)
|
|
90
|
+
def cuda_const_array_like(context, builder, sig, args):
|
|
91
|
+
# This is a no-op because CUDATargetContext.make_constant_array already
|
|
92
|
+
# created the constant array.
|
|
93
|
+
return args[0]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
_unique_smem_id = 0
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _get_unique_smem_id(name):
|
|
100
|
+
"""Due to bug with NVVM invalid internalizing of shared memory in the
|
|
101
|
+
PTX output. We can't mark shared memory to be internal. We have to
|
|
102
|
+
ensure unique name is generated for shared memory symbol.
|
|
103
|
+
"""
|
|
104
|
+
global _unique_smem_id
|
|
105
|
+
_unique_smem_id += 1
|
|
106
|
+
return "{0}_{1}".format(name, _unique_smem_id)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _validate_alignment(alignment: int):
|
|
110
|
+
"""
|
|
111
|
+
Ensures that *alignment*, if not None, is a) greater than zero, b) a power
|
|
112
|
+
of two, and c) a multiple of the size of a pointer. If any of these
|
|
113
|
+
conditions are not met, a ValueError is raised. Otherwise, this
|
|
114
|
+
function returns None, indicating that the alignment is valid.
|
|
115
|
+
"""
|
|
116
|
+
if alignment is None:
|
|
117
|
+
return
|
|
118
|
+
if not isinstance(alignment, int):
|
|
119
|
+
raise ValueError("Alignment must be an integer")
|
|
120
|
+
if alignment <= 0:
|
|
121
|
+
raise ValueError("Alignment must be positive")
|
|
122
|
+
if (alignment & (alignment - 1)) != 0:
|
|
123
|
+
raise ValueError("Alignment must be a power of 2")
|
|
124
|
+
pointer_size = struct.calcsize("P")
|
|
125
|
+
if (alignment % pointer_size) != 0:
|
|
126
|
+
msg = f"Alignment must be a multiple of {pointer_size}"
|
|
127
|
+
raise ValueError(msg)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _try_extract_and_validate_alignment(sig: types.Tuple):
|
|
131
|
+
"""
|
|
132
|
+
Extracts and validates the alignment from the supplied signature.
|
|
133
|
+
|
|
134
|
+
Returns the alignment if it is present and is an integer literal;
|
|
135
|
+
otherwise, returns None.
|
|
136
|
+
|
|
137
|
+
N.B. Currently, this routine assumes the signature has exactly
|
|
138
|
+
three arguments, with the alignment (if present) as the third
|
|
139
|
+
argument, as is the case with the shared and local array
|
|
140
|
+
helper routines below.
|
|
141
|
+
|
|
142
|
+
If this routine is called from new places, you may need to
|
|
143
|
+
review this implicit assumption.
|
|
144
|
+
"""
|
|
145
|
+
if len(sig.args) != 3:
|
|
146
|
+
return None
|
|
147
|
+
|
|
148
|
+
alignment_arg = sig.args[2]
|
|
149
|
+
if not isinstance(alignment_arg, types.IntegerLiteral):
|
|
150
|
+
return None
|
|
151
|
+
|
|
152
|
+
alignment_arg = alignment_arg.literal_value
|
|
153
|
+
_validate_alignment(alignment_arg)
|
|
154
|
+
return alignment_arg
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@lower(cuda.shared.array, types.IntegerLiteral, types.Any)
|
|
158
|
+
@lower(cuda.shared.array, types.IntegerLiteral, types.Any, types.IntegerLiteral)
|
|
159
|
+
@lower(cuda.shared.array, types.IntegerLiteral, types.Any, types.NoneType)
|
|
160
|
+
def cuda_shared_array_integer(context, builder, sig, args):
|
|
161
|
+
length = sig.args[0].literal_value
|
|
162
|
+
dtype = parse_dtype(sig.args[1])
|
|
163
|
+
alignment = _try_extract_and_validate_alignment(sig)
|
|
164
|
+
return _generic_array(
|
|
165
|
+
context,
|
|
166
|
+
builder,
|
|
167
|
+
shape=(length,),
|
|
168
|
+
dtype=dtype,
|
|
169
|
+
symbol_name=_get_unique_smem_id("_cudapy_smem"),
|
|
170
|
+
addrspace=nvvm.ADDRSPACE_SHARED,
|
|
171
|
+
can_dynsized=True,
|
|
172
|
+
alignment=alignment,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@lower(cuda.shared.array, types.BaseTuple, types.Any)
|
|
177
|
+
@lower(cuda.shared.array, types.BaseTuple, types.Any, types.IntegerLiteral)
|
|
178
|
+
@lower(cuda.shared.array, types.BaseTuple, types.Any, types.NoneType)
|
|
179
|
+
def cuda_shared_array_tuple(context, builder, sig, args):
|
|
180
|
+
shape = [s.literal_value for s in sig.args[0]]
|
|
181
|
+
dtype = parse_dtype(sig.args[1])
|
|
182
|
+
alignment = _try_extract_and_validate_alignment(sig)
|
|
183
|
+
return _generic_array(
|
|
184
|
+
context,
|
|
185
|
+
builder,
|
|
186
|
+
shape=shape,
|
|
187
|
+
dtype=dtype,
|
|
188
|
+
symbol_name=_get_unique_smem_id("_cudapy_smem"),
|
|
189
|
+
addrspace=nvvm.ADDRSPACE_SHARED,
|
|
190
|
+
can_dynsized=True,
|
|
191
|
+
alignment=alignment,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@lower(cuda.local.array, types.IntegerLiteral, types.Any)
|
|
196
|
+
@lower(cuda.local.array, types.IntegerLiteral, types.Any, types.IntegerLiteral)
|
|
197
|
+
@lower(cuda.local.array, types.IntegerLiteral, types.Any, types.NoneType)
|
|
198
|
+
def cuda_local_array_integer(context, builder, sig, args):
|
|
199
|
+
length = sig.args[0].literal_value
|
|
200
|
+
dtype = parse_dtype(sig.args[1])
|
|
201
|
+
alignment = _try_extract_and_validate_alignment(sig)
|
|
202
|
+
return _generic_array(
|
|
203
|
+
context,
|
|
204
|
+
builder,
|
|
205
|
+
shape=(length,),
|
|
206
|
+
dtype=dtype,
|
|
207
|
+
symbol_name="_cudapy_lmem",
|
|
208
|
+
addrspace=nvvm.ADDRSPACE_LOCAL,
|
|
209
|
+
can_dynsized=False,
|
|
210
|
+
alignment=alignment,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
@lower(cuda.local.array, types.BaseTuple, types.Any)
|
|
215
|
+
@lower(cuda.local.array, types.BaseTuple, types.Any, types.IntegerLiteral)
|
|
216
|
+
@lower(cuda.local.array, types.BaseTuple, types.Any, types.NoneType)
|
|
217
|
+
def cuda_local_array_tuple(context, builder, sig, args):
|
|
218
|
+
shape = [s.literal_value for s in sig.args[0]]
|
|
219
|
+
dtype = parse_dtype(sig.args[1])
|
|
220
|
+
alignment = _try_extract_and_validate_alignment(sig)
|
|
221
|
+
return _generic_array(
|
|
222
|
+
context,
|
|
223
|
+
builder,
|
|
224
|
+
shape=shape,
|
|
225
|
+
dtype=dtype,
|
|
226
|
+
symbol_name="_cudapy_lmem",
|
|
227
|
+
addrspace=nvvm.ADDRSPACE_LOCAL,
|
|
228
|
+
can_dynsized=False,
|
|
229
|
+
alignment=alignment,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@lower(stubs.threadfence_block)
|
|
234
|
+
def ptx_threadfence_block(context, builder, sig, args):
|
|
235
|
+
assert not args
|
|
236
|
+
fname = "llvm.nvvm.membar.cta"
|
|
237
|
+
lmod = builder.module
|
|
238
|
+
fnty = ir.FunctionType(ir.VoidType(), ())
|
|
239
|
+
sync = cgutils.get_or_insert_function(lmod, fnty, fname)
|
|
240
|
+
builder.call(sync, ())
|
|
241
|
+
return context.get_dummy_value()
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@lower(stubs.threadfence_system)
|
|
245
|
+
def ptx_threadfence_system(context, builder, sig, args):
|
|
246
|
+
assert not args
|
|
247
|
+
fname = "llvm.nvvm.membar.sys"
|
|
248
|
+
lmod = builder.module
|
|
249
|
+
fnty = ir.FunctionType(ir.VoidType(), ())
|
|
250
|
+
sync = cgutils.get_or_insert_function(lmod, fnty, fname)
|
|
251
|
+
builder.call(sync, ())
|
|
252
|
+
return context.get_dummy_value()
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
@lower(stubs.threadfence)
|
|
256
|
+
def ptx_threadfence_device(context, builder, sig, args):
|
|
257
|
+
assert not args
|
|
258
|
+
fname = "llvm.nvvm.membar.gl"
|
|
259
|
+
lmod = builder.module
|
|
260
|
+
fnty = ir.FunctionType(ir.VoidType(), ())
|
|
261
|
+
sync = cgutils.get_or_insert_function(lmod, fnty, fname)
|
|
262
|
+
builder.call(sync, ())
|
|
263
|
+
return context.get_dummy_value()
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
@lower(stubs.syncwarp)
|
|
267
|
+
def ptx_syncwarp(context, builder, sig, args):
|
|
268
|
+
mask = context.get_constant(types.int32, 0xFFFFFFFF)
|
|
269
|
+
mask_sig = types.none(types.int32)
|
|
270
|
+
return ptx_syncwarp_mask(context, builder, mask_sig, [mask])
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
@lower(stubs.syncwarp, types.i4)
|
|
274
|
+
def ptx_syncwarp_mask(context, builder, sig, args):
|
|
275
|
+
fname = "llvm.nvvm.bar.warp.sync"
|
|
276
|
+
lmod = builder.module
|
|
277
|
+
fnty = ir.FunctionType(ir.VoidType(), (ir.IntType(32),))
|
|
278
|
+
sync = cgutils.get_or_insert_function(lmod, fnty, fname)
|
|
279
|
+
builder.call(sync, args)
|
|
280
|
+
return context.get_dummy_value()
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
@lower(stubs.vote_sync_intrinsic, types.i4, types.i4, types.boolean)
|
|
284
|
+
def ptx_vote_sync(context, builder, sig, args):
|
|
285
|
+
fname = "llvm.nvvm.vote.sync"
|
|
286
|
+
lmod = builder.module
|
|
287
|
+
fnty = ir.FunctionType(
|
|
288
|
+
ir.LiteralStructType((ir.IntType(32), ir.IntType(1))),
|
|
289
|
+
(ir.IntType(32), ir.IntType(32), ir.IntType(1)),
|
|
290
|
+
)
|
|
291
|
+
func = cgutils.get_or_insert_function(lmod, fnty, fname)
|
|
292
|
+
return builder.call(func, args)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
@lower(stubs.match_any_sync, types.i4, types.i4)
|
|
296
|
+
@lower(stubs.match_any_sync, types.i4, types.i8)
|
|
297
|
+
@lower(stubs.match_any_sync, types.i4, types.f4)
|
|
298
|
+
@lower(stubs.match_any_sync, types.i4, types.f8)
|
|
299
|
+
def ptx_match_any_sync(context, builder, sig, args):
|
|
300
|
+
mask, value = args
|
|
301
|
+
width = sig.args[1].bitwidth
|
|
302
|
+
if sig.args[1] in types.real_domain:
|
|
303
|
+
value = builder.bitcast(value, ir.IntType(width))
|
|
304
|
+
fname = "llvm.nvvm.match.any.sync.i{}".format(width)
|
|
305
|
+
lmod = builder.module
|
|
306
|
+
fnty = ir.FunctionType(ir.IntType(32), (ir.IntType(32), ir.IntType(width)))
|
|
307
|
+
func = cgutils.get_or_insert_function(lmod, fnty, fname)
|
|
308
|
+
return builder.call(func, (mask, value))
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
@lower(stubs.match_all_sync, types.i4, types.i4)
|
|
312
|
+
@lower(stubs.match_all_sync, types.i4, types.i8)
|
|
313
|
+
@lower(stubs.match_all_sync, types.i4, types.f4)
|
|
314
|
+
@lower(stubs.match_all_sync, types.i4, types.f8)
|
|
315
|
+
def ptx_match_all_sync(context, builder, sig, args):
|
|
316
|
+
mask, value = args
|
|
317
|
+
width = sig.args[1].bitwidth
|
|
318
|
+
if sig.args[1] in types.real_domain:
|
|
319
|
+
value = builder.bitcast(value, ir.IntType(width))
|
|
320
|
+
fname = "llvm.nvvm.match.all.sync.i{}".format(width)
|
|
321
|
+
lmod = builder.module
|
|
322
|
+
fnty = ir.FunctionType(
|
|
323
|
+
ir.LiteralStructType((ir.IntType(32), ir.IntType(1))),
|
|
324
|
+
(ir.IntType(32), ir.IntType(width)),
|
|
325
|
+
)
|
|
326
|
+
func = cgutils.get_or_insert_function(lmod, fnty, fname)
|
|
327
|
+
return builder.call(func, (mask, value))
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
@lower(stubs.activemask)
|
|
331
|
+
def ptx_activemask(context, builder, sig, args):
|
|
332
|
+
activemask = ir.InlineAsm(
|
|
333
|
+
ir.FunctionType(ir.IntType(32), []),
|
|
334
|
+
"activemask.b32 $0;",
|
|
335
|
+
"=r",
|
|
336
|
+
side_effect=True,
|
|
337
|
+
)
|
|
338
|
+
return builder.call(activemask, [])
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
@lower(stubs.lanemask_lt)
|
|
342
|
+
def ptx_lanemask_lt(context, builder, sig, args):
|
|
343
|
+
activemask = ir.InlineAsm(
|
|
344
|
+
ir.FunctionType(ir.IntType(32), []),
|
|
345
|
+
"mov.u32 $0, %lanemask_lt;",
|
|
346
|
+
"=r",
|
|
347
|
+
side_effect=True,
|
|
348
|
+
)
|
|
349
|
+
return builder.call(activemask, [])
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
@lower(stubs.popc, types.Any)
|
|
353
|
+
def ptx_popc(context, builder, sig, args):
|
|
354
|
+
return builder.ctpop(args[0])
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
@lower(stubs.fma, types.Any, types.Any, types.Any)
|
|
358
|
+
def ptx_fma(context, builder, sig, args):
|
|
359
|
+
return builder.fma(*args)
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
# See:
|
|
363
|
+
# https://docs.nvidia.com/cuda/libdevice-users-guide/__nv_cbrt.html#__nv_cbrt
|
|
364
|
+
# https://docs.nvidia.com/cuda/libdevice-users-guide/__nv_cbrtf.html#__nv_cbrtf
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
cbrt_funcs = {
|
|
368
|
+
types.float32: "__nv_cbrtf",
|
|
369
|
+
types.float64: "__nv_cbrt",
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
@lower(stubs.cbrt, types.float32)
|
|
374
|
+
@lower(stubs.cbrt, types.float64)
|
|
375
|
+
def ptx_cbrt(context, builder, sig, args):
|
|
376
|
+
ty = sig.return_type
|
|
377
|
+
fname = cbrt_funcs[ty]
|
|
378
|
+
fty = context.get_value_type(ty)
|
|
379
|
+
lmod = builder.module
|
|
380
|
+
fnty = ir.FunctionType(fty, [fty])
|
|
381
|
+
fn = cgutils.get_or_insert_function(lmod, fnty, fname)
|
|
382
|
+
return builder.call(fn, args)
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
@lower(stubs.brev, types.u4)
|
|
386
|
+
def ptx_brev_u4(context, builder, sig, args):
|
|
387
|
+
# FIXME the llvm.bitreverse.i32 intrinsic isn't supported by nvcc
|
|
388
|
+
# return builder.bitreverse(args[0])
|
|
389
|
+
|
|
390
|
+
fn = cgutils.get_or_insert_function(
|
|
391
|
+
builder.module,
|
|
392
|
+
ir.FunctionType(ir.IntType(32), (ir.IntType(32),)),
|
|
393
|
+
"__nv_brev",
|
|
394
|
+
)
|
|
395
|
+
return builder.call(fn, args)
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
@lower(stubs.brev, types.u8)
|
|
399
|
+
def ptx_brev_u8(context, builder, sig, args):
|
|
400
|
+
# FIXME the llvm.bitreverse.i64 intrinsic isn't supported by nvcc
|
|
401
|
+
# return builder.bitreverse(args[0])
|
|
402
|
+
|
|
403
|
+
fn = cgutils.get_or_insert_function(
|
|
404
|
+
builder.module,
|
|
405
|
+
ir.FunctionType(ir.IntType(64), (ir.IntType(64),)),
|
|
406
|
+
"__nv_brevll",
|
|
407
|
+
)
|
|
408
|
+
return builder.call(fn, args)
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
@lower(stubs.clz, types.Any)
|
|
412
|
+
def ptx_clz(context, builder, sig, args):
|
|
413
|
+
return builder.ctlz(args[0], context.get_constant(types.boolean, 0))
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
@lower(stubs.ffs, types.i4)
|
|
417
|
+
@lower(stubs.ffs, types.u4)
|
|
418
|
+
def ptx_ffs_32(context, builder, sig, args):
|
|
419
|
+
fn = cgutils.get_or_insert_function(
|
|
420
|
+
builder.module,
|
|
421
|
+
ir.FunctionType(ir.IntType(32), (ir.IntType(32),)),
|
|
422
|
+
"__nv_ffs",
|
|
423
|
+
)
|
|
424
|
+
return builder.call(fn, args)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
@lower(stubs.ffs, types.i8)
|
|
428
|
+
@lower(stubs.ffs, types.u8)
|
|
429
|
+
def ptx_ffs_64(context, builder, sig, args):
|
|
430
|
+
fn = cgutils.get_or_insert_function(
|
|
431
|
+
builder.module,
|
|
432
|
+
ir.FunctionType(ir.IntType(32), (ir.IntType(64),)),
|
|
433
|
+
"__nv_ffsll",
|
|
434
|
+
)
|
|
435
|
+
return builder.call(fn, args)
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
@lower(stubs.selp, types.Any, types.Any, types.Any)
|
|
439
|
+
def ptx_selp(context, builder, sig, args):
|
|
440
|
+
test, a, b = args
|
|
441
|
+
return builder.select(test, a, b)
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
@lower(max, types.f4, types.f4)
|
|
445
|
+
def ptx_max_f4(context, builder, sig, args):
|
|
446
|
+
fn = cgutils.get_or_insert_function(
|
|
447
|
+
builder.module,
|
|
448
|
+
ir.FunctionType(ir.FloatType(), (ir.FloatType(), ir.FloatType())),
|
|
449
|
+
"__nv_fmaxf",
|
|
450
|
+
)
|
|
451
|
+
return builder.call(fn, args)
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
@lower(max, types.f8, types.f4)
|
|
455
|
+
@lower(max, types.f4, types.f8)
|
|
456
|
+
@lower(max, types.f8, types.f8)
|
|
457
|
+
def ptx_max_f8(context, builder, sig, args):
|
|
458
|
+
fn = cgutils.get_or_insert_function(
|
|
459
|
+
builder.module,
|
|
460
|
+
ir.FunctionType(ir.DoubleType(), (ir.DoubleType(), ir.DoubleType())),
|
|
461
|
+
"__nv_fmax",
|
|
462
|
+
)
|
|
463
|
+
|
|
464
|
+
return builder.call(
|
|
465
|
+
fn,
|
|
466
|
+
[
|
|
467
|
+
context.cast(builder, args[0], sig.args[0], types.double),
|
|
468
|
+
context.cast(builder, args[1], sig.args[1], types.double),
|
|
469
|
+
],
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
@lower(min, types.f4, types.f4)
|
|
474
|
+
def ptx_min_f4(context, builder, sig, args):
|
|
475
|
+
fn = cgutils.get_or_insert_function(
|
|
476
|
+
builder.module,
|
|
477
|
+
ir.FunctionType(ir.FloatType(), (ir.FloatType(), ir.FloatType())),
|
|
478
|
+
"__nv_fminf",
|
|
479
|
+
)
|
|
480
|
+
return builder.call(fn, args)
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
@lower(min, types.f8, types.f4)
|
|
484
|
+
@lower(min, types.f4, types.f8)
|
|
485
|
+
@lower(min, types.f8, types.f8)
|
|
486
|
+
def ptx_min_f8(context, builder, sig, args):
|
|
487
|
+
fn = cgutils.get_or_insert_function(
|
|
488
|
+
builder.module,
|
|
489
|
+
ir.FunctionType(ir.DoubleType(), (ir.DoubleType(), ir.DoubleType())),
|
|
490
|
+
"__nv_fmin",
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
return builder.call(
|
|
494
|
+
fn,
|
|
495
|
+
[
|
|
496
|
+
context.cast(builder, args[0], sig.args[0], types.double),
|
|
497
|
+
context.cast(builder, args[1], sig.args[1], types.double),
|
|
498
|
+
],
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
@lower(round, types.f4)
|
|
503
|
+
@lower(round, types.f8)
|
|
504
|
+
def ptx_round(context, builder, sig, args):
|
|
505
|
+
fn = cgutils.get_or_insert_function(
|
|
506
|
+
builder.module,
|
|
507
|
+
ir.FunctionType(ir.IntType(64), (ir.DoubleType(),)),
|
|
508
|
+
"__nv_llrint",
|
|
509
|
+
)
|
|
510
|
+
return builder.call(
|
|
511
|
+
fn,
|
|
512
|
+
[
|
|
513
|
+
context.cast(builder, args[0], sig.args[0], types.double),
|
|
514
|
+
],
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
# This rounding implementation follows the algorithm used in the "fallback
|
|
519
|
+
# version" of double_round in CPython.
|
|
520
|
+
# https://github.com/python/cpython/blob/a755410e054e1e2390de5830befc08fe80706c66/Objects/floatobject.c#L964-L1007
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
@lower(round, types.f4, types.Integer)
|
|
524
|
+
@lower(round, types.f8, types.Integer)
|
|
525
|
+
def round_to_impl(context, builder, sig, args):
|
|
526
|
+
def round_ndigits(x, ndigits):
|
|
527
|
+
if math.isinf(x) or math.isnan(x):
|
|
528
|
+
return x
|
|
529
|
+
|
|
530
|
+
if ndigits >= 0:
|
|
531
|
+
if ndigits > 22:
|
|
532
|
+
# pow1 and pow2 are each safe from overflow, but
|
|
533
|
+
# pow1*pow2 ~= pow(10.0, ndigits) might overflow.
|
|
534
|
+
pow1 = 10.0 ** (ndigits - 22)
|
|
535
|
+
pow2 = 1e22
|
|
536
|
+
else:
|
|
537
|
+
pow1 = 10.0**ndigits
|
|
538
|
+
pow2 = 1.0
|
|
539
|
+
y = (x * pow1) * pow2
|
|
540
|
+
if math.isinf(y):
|
|
541
|
+
return x
|
|
542
|
+
|
|
543
|
+
else:
|
|
544
|
+
pow1 = 10.0 ** (-ndigits)
|
|
545
|
+
y = x / pow1
|
|
546
|
+
|
|
547
|
+
z = round(y)
|
|
548
|
+
if math.fabs(y - z) == 0.5:
|
|
549
|
+
# halfway between two integers; use round-half-even
|
|
550
|
+
z = 2.0 * round(y / 2.0)
|
|
551
|
+
|
|
552
|
+
if ndigits >= 0:
|
|
553
|
+
z = (z / pow2) / pow1
|
|
554
|
+
else:
|
|
555
|
+
z *= pow1
|
|
556
|
+
|
|
557
|
+
return z
|
|
558
|
+
|
|
559
|
+
return context.compile_internal(
|
|
560
|
+
builder,
|
|
561
|
+
round_ndigits,
|
|
562
|
+
sig,
|
|
563
|
+
args,
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def gen_deg_rad(const):
|
|
568
|
+
def impl(context, builder, sig, args):
|
|
569
|
+
(argty,) = sig.args
|
|
570
|
+
factor = context.get_constant(argty, const)
|
|
571
|
+
return builder.fmul(factor, args[0])
|
|
572
|
+
|
|
573
|
+
return impl
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
_deg2rad = math.pi / 180.0
|
|
577
|
+
_rad2deg = 180.0 / math.pi
|
|
578
|
+
lower(math.radians, types.f4)(gen_deg_rad(_deg2rad))
|
|
579
|
+
lower(math.radians, types.f8)(gen_deg_rad(_deg2rad))
|
|
580
|
+
lower(math.degrees, types.f4)(gen_deg_rad(_rad2deg))
|
|
581
|
+
lower(math.degrees, types.f8)(gen_deg_rad(_rad2deg))
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
def _atomic_dispatcher(dispatch_fn):
|
|
585
|
+
def imp(context, builder, sig, args):
|
|
586
|
+
# The common argument handling code
|
|
587
|
+
aryty, indty, valty = sig.args
|
|
588
|
+
ary, inds, val = args
|
|
589
|
+
dtype = aryty.dtype
|
|
590
|
+
|
|
591
|
+
indty, indices = normalize_indices(
|
|
592
|
+
context, builder, indty, inds, aryty, valty
|
|
593
|
+
)
|
|
594
|
+
|
|
595
|
+
lary = context.make_array(aryty)(context, builder, ary)
|
|
596
|
+
ptr = cgutils.get_item_pointer(
|
|
597
|
+
context, builder, aryty, lary, indices, wraparound=True
|
|
598
|
+
)
|
|
599
|
+
# dispatcher to implementation base on dtype
|
|
600
|
+
return dispatch_fn(context, builder, dtype, ptr, val)
|
|
601
|
+
|
|
602
|
+
return imp
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
@lower(stubs.atomic.add, types.Array, types.intp, types.Any)
|
|
606
|
+
@lower(stubs.atomic.add, types.Array, types.UniTuple, types.Any)
|
|
607
|
+
@lower(stubs.atomic.add, types.Array, types.Tuple, types.Any)
|
|
608
|
+
@_atomic_dispatcher
|
|
609
|
+
def ptx_atomic_add_tuple(context, builder, dtype, ptr, val):
|
|
610
|
+
if dtype == types.float32:
|
|
611
|
+
lmod = builder.module
|
|
612
|
+
return builder.call(
|
|
613
|
+
nvvmutils.declare_atomic_add_float32(lmod), (ptr, val)
|
|
614
|
+
)
|
|
615
|
+
elif dtype == types.float64:
|
|
616
|
+
lmod = builder.module
|
|
617
|
+
return builder.call(
|
|
618
|
+
nvvmutils.declare_atomic_add_float64(lmod), (ptr, val)
|
|
619
|
+
)
|
|
620
|
+
else:
|
|
621
|
+
return builder.atomic_rmw("add", ptr, val, "monotonic")
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
@lower(stubs.atomic.sub, types.Array, types.intp, types.Any)
|
|
625
|
+
@lower(stubs.atomic.sub, types.Array, types.UniTuple, types.Any)
|
|
626
|
+
@lower(stubs.atomic.sub, types.Array, types.Tuple, types.Any)
|
|
627
|
+
@_atomic_dispatcher
|
|
628
|
+
def ptx_atomic_sub(context, builder, dtype, ptr, val):
|
|
629
|
+
if dtype == types.float32:
|
|
630
|
+
lmod = builder.module
|
|
631
|
+
return builder.call(
|
|
632
|
+
nvvmutils.declare_atomic_sub_float32(lmod), (ptr, val)
|
|
633
|
+
)
|
|
634
|
+
elif dtype == types.float64:
|
|
635
|
+
lmod = builder.module
|
|
636
|
+
return builder.call(
|
|
637
|
+
nvvmutils.declare_atomic_sub_float64(lmod), (ptr, val)
|
|
638
|
+
)
|
|
639
|
+
else:
|
|
640
|
+
return builder.atomic_rmw("sub", ptr, val, "monotonic")
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
@lower(stubs.atomic.inc, types.Array, types.intp, types.Any)
|
|
644
|
+
@lower(stubs.atomic.inc, types.Array, types.UniTuple, types.Any)
|
|
645
|
+
@lower(stubs.atomic.inc, types.Array, types.Tuple, types.Any)
|
|
646
|
+
@_atomic_dispatcher
|
|
647
|
+
def ptx_atomic_inc(context, builder, dtype, ptr, val):
|
|
648
|
+
if dtype in cuda.cudadecl.unsigned_int_numba_types:
|
|
649
|
+
bw = dtype.bitwidth
|
|
650
|
+
lmod = builder.module
|
|
651
|
+
fn = getattr(nvvmutils, f"declare_atomic_inc_int{bw}")
|
|
652
|
+
return builder.call(fn(lmod), (ptr, val))
|
|
653
|
+
else:
|
|
654
|
+
raise TypeError(f"Unimplemented atomic inc with {dtype} array")
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
@lower(stubs.atomic.dec, types.Array, types.intp, types.Any)
|
|
658
|
+
@lower(stubs.atomic.dec, types.Array, types.UniTuple, types.Any)
|
|
659
|
+
@lower(stubs.atomic.dec, types.Array, types.Tuple, types.Any)
|
|
660
|
+
@_atomic_dispatcher
|
|
661
|
+
def ptx_atomic_dec(context, builder, dtype, ptr, val):
|
|
662
|
+
if dtype in cuda.cudadecl.unsigned_int_numba_types:
|
|
663
|
+
bw = dtype.bitwidth
|
|
664
|
+
lmod = builder.module
|
|
665
|
+
fn = getattr(nvvmutils, f"declare_atomic_dec_int{bw}")
|
|
666
|
+
return builder.call(fn(lmod), (ptr, val))
|
|
667
|
+
else:
|
|
668
|
+
raise TypeError(f"Unimplemented atomic dec with {dtype} array")
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
def ptx_atomic_bitwise(stub, op):
|
|
672
|
+
@_atomic_dispatcher
|
|
673
|
+
def impl_ptx_atomic(context, builder, dtype, ptr, val):
|
|
674
|
+
if dtype in (cuda.cudadecl.integer_numba_types):
|
|
675
|
+
return builder.atomic_rmw(op, ptr, val, "monotonic")
|
|
676
|
+
else:
|
|
677
|
+
raise TypeError(f"Unimplemented atomic {op} with {dtype} array")
|
|
678
|
+
|
|
679
|
+
for ty in (types.intp, types.UniTuple, types.Tuple):
|
|
680
|
+
lower(stub, types.Array, ty, types.Any)(impl_ptx_atomic)
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
ptx_atomic_bitwise(stubs.atomic.and_, "and")
|
|
684
|
+
ptx_atomic_bitwise(stubs.atomic.or_, "or")
|
|
685
|
+
ptx_atomic_bitwise(stubs.atomic.xor, "xor")
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
@lower(stubs.atomic.exch, types.Array, types.intp, types.Any)
|
|
689
|
+
@lower(stubs.atomic.exch, types.Array, types.UniTuple, types.Any)
|
|
690
|
+
@lower(stubs.atomic.exch, types.Array, types.Tuple, types.Any)
|
|
691
|
+
@_atomic_dispatcher
|
|
692
|
+
def ptx_atomic_exch(context, builder, dtype, ptr, val):
|
|
693
|
+
if dtype in (cuda.cudadecl.integer_numba_types):
|
|
694
|
+
return builder.atomic_rmw("xchg", ptr, val, "monotonic")
|
|
695
|
+
else:
|
|
696
|
+
raise TypeError(f"Unimplemented atomic exch with {dtype} array")
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
@lower(stubs.atomic.max, types.Array, types.intp, types.Any)
|
|
700
|
+
@lower(stubs.atomic.max, types.Array, types.Tuple, types.Any)
|
|
701
|
+
@lower(stubs.atomic.max, types.Array, types.UniTuple, types.Any)
|
|
702
|
+
@_atomic_dispatcher
|
|
703
|
+
def ptx_atomic_max(context, builder, dtype, ptr, val):
|
|
704
|
+
lmod = builder.module
|
|
705
|
+
if dtype == types.float64:
|
|
706
|
+
return builder.call(
|
|
707
|
+
nvvmutils.declare_atomic_max_float64(lmod), (ptr, val)
|
|
708
|
+
)
|
|
709
|
+
elif dtype == types.float32:
|
|
710
|
+
return builder.call(
|
|
711
|
+
nvvmutils.declare_atomic_max_float32(lmod), (ptr, val)
|
|
712
|
+
)
|
|
713
|
+
elif dtype in (types.int32, types.int64):
|
|
714
|
+
return builder.atomic_rmw("max", ptr, val, ordering="monotonic")
|
|
715
|
+
elif dtype in (types.uint32, types.uint64):
|
|
716
|
+
return builder.atomic_rmw("umax", ptr, val, ordering="monotonic")
|
|
717
|
+
else:
|
|
718
|
+
raise TypeError("Unimplemented atomic max with %s array" % dtype)
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
@lower(stubs.atomic.min, types.Array, types.intp, types.Any)
|
|
722
|
+
@lower(stubs.atomic.min, types.Array, types.Tuple, types.Any)
|
|
723
|
+
@lower(stubs.atomic.min, types.Array, types.UniTuple, types.Any)
|
|
724
|
+
@_atomic_dispatcher
|
|
725
|
+
def ptx_atomic_min(context, builder, dtype, ptr, val):
|
|
726
|
+
lmod = builder.module
|
|
727
|
+
if dtype == types.float64:
|
|
728
|
+
return builder.call(
|
|
729
|
+
nvvmutils.declare_atomic_min_float64(lmod), (ptr, val)
|
|
730
|
+
)
|
|
731
|
+
elif dtype == types.float32:
|
|
732
|
+
return builder.call(
|
|
733
|
+
nvvmutils.declare_atomic_min_float32(lmod), (ptr, val)
|
|
734
|
+
)
|
|
735
|
+
elif dtype in (types.int32, types.int64):
|
|
736
|
+
return builder.atomic_rmw("min", ptr, val, ordering="monotonic")
|
|
737
|
+
elif dtype in (types.uint32, types.uint64):
|
|
738
|
+
return builder.atomic_rmw("umin", ptr, val, ordering="monotonic")
|
|
739
|
+
else:
|
|
740
|
+
raise TypeError("Unimplemented atomic min with %s array" % dtype)
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
@lower(stubs.atomic.nanmax, types.Array, types.intp, types.Any)
|
|
744
|
+
@lower(stubs.atomic.nanmax, types.Array, types.Tuple, types.Any)
|
|
745
|
+
@lower(stubs.atomic.nanmax, types.Array, types.UniTuple, types.Any)
|
|
746
|
+
@_atomic_dispatcher
|
|
747
|
+
def ptx_atomic_nanmax(context, builder, dtype, ptr, val):
|
|
748
|
+
lmod = builder.module
|
|
749
|
+
if dtype == types.float64:
|
|
750
|
+
return builder.call(
|
|
751
|
+
nvvmutils.declare_atomic_nanmax_float64(lmod), (ptr, val)
|
|
752
|
+
)
|
|
753
|
+
elif dtype == types.float32:
|
|
754
|
+
return builder.call(
|
|
755
|
+
nvvmutils.declare_atomic_nanmax_float32(lmod), (ptr, val)
|
|
756
|
+
)
|
|
757
|
+
elif dtype in (types.int32, types.int64):
|
|
758
|
+
return builder.atomic_rmw("max", ptr, val, ordering="monotonic")
|
|
759
|
+
elif dtype in (types.uint32, types.uint64):
|
|
760
|
+
return builder.atomic_rmw("umax", ptr, val, ordering="monotonic")
|
|
761
|
+
else:
|
|
762
|
+
raise TypeError("Unimplemented atomic max with %s array" % dtype)
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
@lower(stubs.atomic.nanmin, types.Array, types.intp, types.Any)
|
|
766
|
+
@lower(stubs.atomic.nanmin, types.Array, types.Tuple, types.Any)
|
|
767
|
+
@lower(stubs.atomic.nanmin, types.Array, types.UniTuple, types.Any)
|
|
768
|
+
@_atomic_dispatcher
|
|
769
|
+
def ptx_atomic_nanmin(context, builder, dtype, ptr, val):
|
|
770
|
+
lmod = builder.module
|
|
771
|
+
if dtype == types.float64:
|
|
772
|
+
return builder.call(
|
|
773
|
+
nvvmutils.declare_atomic_nanmin_float64(lmod), (ptr, val)
|
|
774
|
+
)
|
|
775
|
+
elif dtype == types.float32:
|
|
776
|
+
return builder.call(
|
|
777
|
+
nvvmutils.declare_atomic_nanmin_float32(lmod), (ptr, val)
|
|
778
|
+
)
|
|
779
|
+
elif dtype in (types.int32, types.int64):
|
|
780
|
+
return builder.atomic_rmw("min", ptr, val, ordering="monotonic")
|
|
781
|
+
elif dtype in (types.uint32, types.uint64):
|
|
782
|
+
return builder.atomic_rmw("umin", ptr, val, ordering="monotonic")
|
|
783
|
+
else:
|
|
784
|
+
raise TypeError("Unimplemented atomic min with %s array" % dtype)
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
@lower(stubs.atomic.compare_and_swap, types.Array, types.Any, types.Any)
|
|
788
|
+
def ptx_atomic_compare_and_swap(context, builder, sig, args):
|
|
789
|
+
sig = sig.return_type(sig.args[0], types.intp, sig.args[1], sig.args[2])
|
|
790
|
+
args = (args[0], context.get_constant(types.intp, 0), args[1], args[2])
|
|
791
|
+
return ptx_atomic_cas(context, builder, sig, args)
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
@lower(stubs.atomic.cas, types.Array, types.intp, types.Any, types.Any)
|
|
795
|
+
@lower(stubs.atomic.cas, types.Array, types.Tuple, types.Any, types.Any)
|
|
796
|
+
@lower(stubs.atomic.cas, types.Array, types.UniTuple, types.Any, types.Any)
|
|
797
|
+
def ptx_atomic_cas(context, builder, sig, args):
|
|
798
|
+
aryty, indty, oldty, valty = sig.args
|
|
799
|
+
ary, inds, old, val = args
|
|
800
|
+
|
|
801
|
+
indty, indices = normalize_indices(
|
|
802
|
+
context, builder, indty, inds, aryty, valty
|
|
803
|
+
)
|
|
804
|
+
|
|
805
|
+
lary = context.make_array(aryty)(context, builder, ary)
|
|
806
|
+
ptr = cgutils.get_item_pointer(
|
|
807
|
+
context, builder, aryty, lary, indices, wraparound=True
|
|
808
|
+
)
|
|
809
|
+
|
|
810
|
+
if aryty.dtype in (cuda.cudadecl.integer_numba_types):
|
|
811
|
+
lmod = builder.module
|
|
812
|
+
bitwidth = aryty.dtype.bitwidth
|
|
813
|
+
return nvvmutils.atomic_cmpxchg(builder, lmod, bitwidth, ptr, old, val)
|
|
814
|
+
else:
|
|
815
|
+
raise TypeError("Unimplemented atomic cas with %s array" % aryty.dtype)
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
# -----------------------------------------------------------------------------
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
@lower(breakpoint)
|
|
822
|
+
def ptx_brkpt(context, builder, sig, args):
|
|
823
|
+
brkpt = ir.InlineAsm(
|
|
824
|
+
ir.FunctionType(ir.VoidType(), []), "brkpt;", "", side_effect=True
|
|
825
|
+
)
|
|
826
|
+
builder.call(brkpt, ())
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
@lower(stubs.nanosleep, types.uint32)
|
|
830
|
+
def ptx_nanosleep(context, builder, sig, args):
|
|
831
|
+
nanosleep = ir.InlineAsm(
|
|
832
|
+
ir.FunctionType(ir.VoidType(), [ir.IntType(32)]),
|
|
833
|
+
"nanosleep.u32 $0;",
|
|
834
|
+
"r",
|
|
835
|
+
side_effect=True,
|
|
836
|
+
)
|
|
837
|
+
ns = args[0]
|
|
838
|
+
builder.call(nanosleep, [ns])
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
# -----------------------------------------------------------------------------
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
def _generic_array(
|
|
845
|
+
context,
|
|
846
|
+
builder,
|
|
847
|
+
shape,
|
|
848
|
+
dtype,
|
|
849
|
+
symbol_name,
|
|
850
|
+
addrspace,
|
|
851
|
+
can_dynsized=False,
|
|
852
|
+
alignment=None,
|
|
853
|
+
):
|
|
854
|
+
elemcount = reduce(operator.mul, shape, 1)
|
|
855
|
+
|
|
856
|
+
# Check for valid shape for this type of allocation.
|
|
857
|
+
# Only 1d arrays can be dynamic.
|
|
858
|
+
dynamic_smem = elemcount <= 0 and can_dynsized and len(shape) == 1
|
|
859
|
+
if elemcount <= 0 and not dynamic_smem:
|
|
860
|
+
raise ValueError("array length <= 0")
|
|
861
|
+
|
|
862
|
+
# Check that we support the requested dtype
|
|
863
|
+
number_domain = types.number_domain
|
|
864
|
+
struct_model_types = (StructModel,)
|
|
865
|
+
if cuda.HAS_NUMBA:
|
|
866
|
+
number_domain |= core_types.number_domain
|
|
867
|
+
struct_model_types = (StructModel, CoreStructModel)
|
|
868
|
+
|
|
869
|
+
data_model = context.data_model_manager[dtype]
|
|
870
|
+
other_supported_type = (
|
|
871
|
+
isinstance(dtype, (types.Record, types.Boolean))
|
|
872
|
+
or isinstance(data_model, struct_model_types)
|
|
873
|
+
or dtype == types.float16
|
|
874
|
+
)
|
|
875
|
+
if dtype not in number_domain and not other_supported_type:
|
|
876
|
+
raise TypeError("unsupported type: %s" % dtype)
|
|
877
|
+
|
|
878
|
+
lldtype = context.get_data_type(dtype)
|
|
879
|
+
laryty = ir.ArrayType(lldtype, elemcount)
|
|
880
|
+
|
|
881
|
+
if addrspace == nvvm.ADDRSPACE_LOCAL:
|
|
882
|
+
# Special case local address space allocation to use alloca
|
|
883
|
+
# NVVM is smart enough to only use local memory if no register is
|
|
884
|
+
# available
|
|
885
|
+
dataptr = cgutils.alloca_once(builder, laryty, name=symbol_name)
|
|
886
|
+
|
|
887
|
+
# If the caller has specified a custom alignment, just set the align
|
|
888
|
+
# attribute on the alloca IR directly. We don't do any additional
|
|
889
|
+
# hand-holding here like checking the underlying data type's alignment
|
|
890
|
+
# or rounding up to the next power of 2--those checks will have already
|
|
891
|
+
# been done by the time we see the alignment value.
|
|
892
|
+
if alignment is not None:
|
|
893
|
+
dataptr.align = alignment
|
|
894
|
+
else:
|
|
895
|
+
lmod = builder.module
|
|
896
|
+
|
|
897
|
+
# Create global variable in the requested address space
|
|
898
|
+
gvmem = cgutils.add_global_variable(
|
|
899
|
+
lmod, laryty, symbol_name, addrspace
|
|
900
|
+
)
|
|
901
|
+
|
|
902
|
+
# If the caller hasn't specified a custom alignment, obtain the
|
|
903
|
+
# underlying dtype alignment from the ABI and then round it up to
|
|
904
|
+
# a power of two. Otherwise, just use the caller's alignment.
|
|
905
|
+
#
|
|
906
|
+
# N.B. The caller *could* provide a valid-but-smaller-than-natural
|
|
907
|
+
# alignment here; we'll assume the caller knows what they're
|
|
908
|
+
# doing and let that through without error.
|
|
909
|
+
|
|
910
|
+
if alignment is None:
|
|
911
|
+
abi_alignment = context.get_abi_alignment(lldtype)
|
|
912
|
+
# Alignment is required to be a power of 2 for shared memory.
|
|
913
|
+
# If it is not a power of 2 (e.g. for a Record array) then round
|
|
914
|
+
# up accordingly.
|
|
915
|
+
actual_alignment = 1 << (abi_alignment - 1).bit_length()
|
|
916
|
+
else:
|
|
917
|
+
actual_alignment = alignment
|
|
918
|
+
|
|
919
|
+
gvmem.align = actual_alignment
|
|
920
|
+
|
|
921
|
+
if dynamic_smem:
|
|
922
|
+
gvmem.linkage = "external"
|
|
923
|
+
else:
|
|
924
|
+
## Comment out the following line to workaround a NVVM bug
|
|
925
|
+
## which generates a invalid symbol name when the linkage
|
|
926
|
+
## is internal and in some situation.
|
|
927
|
+
## See _get_unique_smem_id()
|
|
928
|
+
# gvmem.linkage = lc.LINKAGE_INTERNAL
|
|
929
|
+
|
|
930
|
+
gvmem.initializer = ir.Constant(laryty, ir.Undefined)
|
|
931
|
+
|
|
932
|
+
# Convert to generic address-space
|
|
933
|
+
dataptr = builder.addrspacecast(
|
|
934
|
+
gvmem, ir.PointerType(ir.IntType(8)), "generic"
|
|
935
|
+
)
|
|
936
|
+
|
|
937
|
+
targetdata = ll.create_target_data(nvvm.NVVM().data_layout)
|
|
938
|
+
lldtype = context.get_data_type(dtype)
|
|
939
|
+
itemsize = lldtype.get_abi_size(targetdata)
|
|
940
|
+
|
|
941
|
+
# Compute strides
|
|
942
|
+
laststride = itemsize
|
|
943
|
+
rstrides = []
|
|
944
|
+
for i, lastsize in enumerate(reversed(shape)):
|
|
945
|
+
rstrides.append(laststride)
|
|
946
|
+
laststride *= lastsize
|
|
947
|
+
strides = [s for s in reversed(rstrides)]
|
|
948
|
+
kstrides = [context.get_constant(types.intp, s) for s in strides]
|
|
949
|
+
|
|
950
|
+
# Compute shape
|
|
951
|
+
if dynamic_smem:
|
|
952
|
+
# Compute the shape based on the dynamic shared memory configuration.
|
|
953
|
+
# Unfortunately NVVM does not provide an intrinsic for the
|
|
954
|
+
# %dynamic_smem_size register, so we must read it using inline
|
|
955
|
+
# assembly.
|
|
956
|
+
get_dynshared_size = ir.InlineAsm(
|
|
957
|
+
ir.FunctionType(ir.IntType(32), []),
|
|
958
|
+
"mov.u32 $0, %dynamic_smem_size;",
|
|
959
|
+
"=r",
|
|
960
|
+
side_effect=True,
|
|
961
|
+
)
|
|
962
|
+
dynsmem_size = builder.zext(
|
|
963
|
+
builder.call(get_dynshared_size, []), ir.IntType(64)
|
|
964
|
+
)
|
|
965
|
+
# Only 1-D dynamic shared memory is supported so the following is a
|
|
966
|
+
# sufficient construction of the shape
|
|
967
|
+
kitemsize = context.get_constant(types.intp, itemsize)
|
|
968
|
+
kshape = [builder.udiv(dynsmem_size, kitemsize)]
|
|
969
|
+
else:
|
|
970
|
+
kshape = [context.get_constant(types.intp, s) for s in shape]
|
|
971
|
+
|
|
972
|
+
# Create array object
|
|
973
|
+
ndim = len(shape)
|
|
974
|
+
aryty = types.Array(dtype=dtype, ndim=ndim, layout="C")
|
|
975
|
+
ary = context.make_array(aryty)(context, builder)
|
|
976
|
+
|
|
977
|
+
context.populate_array(
|
|
978
|
+
ary,
|
|
979
|
+
data=builder.bitcast(dataptr, ary.data.type),
|
|
980
|
+
shape=kshape,
|
|
981
|
+
strides=kstrides,
|
|
982
|
+
itemsize=context.get_constant(types.intp, itemsize),
|
|
983
|
+
meminfo=None,
|
|
984
|
+
)
|
|
985
|
+
return ary._getvalue()
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
@lower_constant(CUDADispatcher)
|
|
989
|
+
def cuda_dispatcher_const(context, builder, ty, pyval):
|
|
990
|
+
return context.get_dummy_value()
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
# NumPy
|
|
994
|
+
|
|
995
|
+
register_ufuncs(ufunc_db.get_ufuncs(), lower)
|