nvmath-python 0.5.0__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.
- nvmath/__init__.pxd +0 -0
- nvmath/__init__.py +37 -0
- nvmath/_internal/__init__.py +0 -0
- nvmath/_internal/layout.py +58 -0
- nvmath/_utils.py +363 -0
- nvmath/bindings/__init__.pxd +0 -0
- nvmath/bindings/__init__.py +44 -0
- nvmath/bindings/_internal/__init__.pxd +0 -0
- nvmath/bindings/_internal/__init__.py +0 -0
- nvmath/bindings/_internal/cublas.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cublas.pxd +518 -0
- nvmath/bindings/_internal/cublasLt.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cublasLt.pxd +54 -0
- nvmath/bindings/_internal/cudss.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cudss.pxd +44 -0
- nvmath/bindings/_internal/cufft.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cufft.pxd +69 -0
- nvmath/bindings/_internal/cufftMp.pxd +77 -0
- nvmath/bindings/_internal/curand.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/curand.pxd +42 -0
- nvmath/bindings/_internal/cusolver.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusolver.pxd +15 -0
- nvmath/bindings/_internal/cusolverDn.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusolverDn.pxd +386 -0
- nvmath/bindings/_internal/cusparse.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/cusparse.pxd +270 -0
- nvmath/bindings/_internal/mathdx.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/mathdx.pxd +79 -0
- nvmath/bindings/_internal/nvshmem.pxd +29 -0
- nvmath/bindings/_internal/utils.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/_internal/utils.pxd +186 -0
- nvmath/bindings/cublas.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cublas.pxd +545 -0
- nvmath/bindings/cublas.pyi +18 -0
- nvmath/bindings/cublasLt.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cublasLt.pxd +99 -0
- nvmath/bindings/cudss.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cudss.pxd +83 -0
- nvmath/bindings/cudss.pyi +249 -0
- nvmath/bindings/cufft.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cufft.pxd +114 -0
- nvmath/bindings/cufftMp.pxd +124 -0
- nvmath/bindings/curand.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/curand.pxd +71 -0
- nvmath/bindings/cusolver.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cusolver.pxd +60 -0
- nvmath/bindings/cusolverDn.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cusolverDn.pxd +410 -0
- nvmath/bindings/cusparse.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cusparse.pxd +329 -0
- nvmath/bindings/cycublas.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycublas.pxd +657 -0
- nvmath/bindings/cycublasLt.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycublasLt.pxd +1010 -0
- nvmath/bindings/cycudss.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycudss.pxd +191 -0
- nvmath/bindings/cycufft.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycufft.pxd +320 -0
- nvmath/bindings/cycufftMp.pxd +333 -0
- nvmath/bindings/cycurand.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycurand.pxd +146 -0
- nvmath/bindings/cycusolver.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycusolver.pxd +143 -0
- nvmath/bindings/cycusolverDn.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycusolverDn.pxd +414 -0
- nvmath/bindings/cycusparse.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cycusparse.pxd +476 -0
- nvmath/bindings/cymathdx.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/cymathdx.pxd +363 -0
- nvmath/bindings/cynvshmem.pxd +126 -0
- nvmath/bindings/mathdx.cp313-win_amd64.pyd +0 -0
- nvmath/bindings/mathdx.pxd +131 -0
- nvmath/bindings/mathdx.pyi +686 -0
- nvmath/bindings/nvpl/__init__.pxd +0 -0
- nvmath/bindings/nvpl/__init__.py +11 -0
- nvmath/bindings/nvpl/_internal/__init__.pxd +0 -0
- nvmath/bindings/nvpl/_internal/__init__.py +0 -0
- nvmath/bindings/nvpl/_internal/fft.pxd +36 -0
- nvmath/bindings/nvpl/cyfft.pxd +87 -0
- nvmath/bindings/nvpl/fft.pxd +100 -0
- nvmath/bindings/nvshmem.pxd +54 -0
- nvmath/device/__init__.py +23 -0
- nvmath/device/_deprecated.py +33 -0
- nvmath/device/caching.py +51 -0
- nvmath/device/common.py +131 -0
- nvmath/device/common_backend.py +125 -0
- nvmath/device/common_cuda.py +156 -0
- nvmath/device/common_mathdx.py +97 -0
- nvmath/device/common_numba.py +159 -0
- nvmath/device/common_opaque_tensor.py +128 -0
- nvmath/device/cublasdx.py +1085 -0
- nvmath/device/cublasdx_backend.py +552 -0
- nvmath/device/cublasdx_numba.py +528 -0
- nvmath/device/cufftdx.py +551 -0
- nvmath/device/cufftdx_backend.py +194 -0
- nvmath/device/cufftdx_numba.py +123 -0
- nvmath/device/curand_kernel.py +9147 -0
- nvmath/device/nvrtc.py +95 -0
- nvmath/device/patch.py +35 -0
- nvmath/device/random.py +417 -0
- nvmath/device/random_helpers.py +23 -0
- nvmath/device/random_states.py +189 -0
- nvmath/device/types.py +11 -0
- nvmath/device/vector_types_numba.py +203 -0
- nvmath/distributed/__init__.py +117 -0
- nvmath/distributed/_internal/__init__.py +0 -0
- nvmath/distributed/_internal/nvshmem.py +243 -0
- nvmath/distributed/_internal/tensor_ifc_cupy.py +111 -0
- nvmath/distributed/_internal/tensor_ifc_numpy.py +53 -0
- nvmath/distributed/_internal/tensor_ifc_torch.py +108 -0
- nvmath/distributed/_internal/tensor_wrapper.py +59 -0
- nvmath/distributed/_utils.py +152 -0
- nvmath/distributed/fft/__init__.py +6 -0
- nvmath/distributed/fft/_configuration.py +86 -0
- nvmath/distributed/fft/fft.py +1737 -0
- nvmath/distributed/reshape/__init__.py +6 -0
- nvmath/distributed/reshape/_configuration.py +39 -0
- nvmath/distributed/reshape/reshape.py +1249 -0
- nvmath/fft/__init__.py +7 -0
- nvmath/fft/_configuration.py +208 -0
- nvmath/fft/_exec_utils.py +116 -0
- nvmath/fft/_helpers.py +260 -0
- nvmath/fft/fft.py +2346 -0
- nvmath/internal/__init__.py +5 -0
- nvmath/internal/enum_utils.py +142 -0
- nvmath/internal/formatters.py +87 -0
- nvmath/internal/mem_limit.py +51 -0
- nvmath/internal/package_ifc.py +119 -0
- nvmath/internal/package_ifc_cuda.py +43 -0
- nvmath/internal/package_ifc_cupy.py +49 -0
- nvmath/internal/package_ifc_torch.py +31 -0
- nvmath/internal/package_wrapper.py +14 -0
- nvmath/internal/tensor_ifc.py +143 -0
- nvmath/internal/tensor_ifc_cupy.py +185 -0
- nvmath/internal/tensor_ifc_numpy.py +157 -0
- nvmath/internal/tensor_ifc_torch.py +115 -0
- nvmath/internal/tensor_wrapper.py +160 -0
- nvmath/internal/typemaps.py +154 -0
- nvmath/internal/utils.py +634 -0
- nvmath/linalg/__init__.py +11 -0
- nvmath/linalg/_internal/__init__.py +3 -0
- nvmath/linalg/_internal/algo_cap_ifc.py +86 -0
- nvmath/linalg/_internal/algo_config_ifc.py +87 -0
- nvmath/linalg/_internal/enum_to_tuples.py +64 -0
- nvmath/linalg/_internal/epilog_protocol.py +738 -0
- nvmath/linalg/_internal/matmul_desc_ifc.py +72 -0
- nvmath/linalg/_internal/matmul_pref_ifc.py +65 -0
- nvmath/linalg/_internal/matrix_layout_ifc.py +59 -0
- nvmath/linalg/_internal/typemaps.py +135 -0
- nvmath/linalg/_internal/utils.py +96 -0
- nvmath/linalg/advanced/__init__.py +8 -0
- nvmath/linalg/advanced/_algorithmmod.py +142 -0
- nvmath/linalg/advanced/_configuration.py +320 -0
- nvmath/linalg/advanced/helpers/__init__.py +5 -0
- nvmath/linalg/advanced/helpers/matmul.py +173 -0
- nvmath/linalg/advanced/matmulmod.py +2855 -0
- nvmath/memory.py +266 -0
- nvmath/sparse/__init__.py +18 -0
- nvmath/sparse/_internal/__init__.py +21 -0
- nvmath/sparse/_internal/common_utils.py +81 -0
- nvmath/sparse/_internal/cudss_config_ifc.py +584 -0
- nvmath/sparse/_internal/cudss_data_ifc.py +291 -0
- nvmath/sparse/_internal/cudss_utils.py +398 -0
- nvmath/sparse/_internal/sparse_csr_ifc.py +154 -0
- nvmath/sparse/_internal/sparse_format_helpers.py +88 -0
- nvmath/sparse/_internal/sparse_tensor_ifc.py +80 -0
- nvmath/sparse/advanced/__init__.py +7 -0
- nvmath/sparse/advanced/_configuration.py +150 -0
- nvmath/sparse/advanced/direct_solver.py +1705 -0
- nvmath_python-0.5.0.dist-info/METADATA +122 -0
- nvmath_python-0.5.0.dist-info/RECORD +174 -0
- nvmath_python-0.5.0.dist-info/WHEEL +5 -0
- nvmath_python-0.5.0.dist-info/licenses/LICENSE +177 -0
- nvmath_python-0.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
from functools import lru_cache
|
|
7
|
+
from typing import Protocol
|
|
8
|
+
|
|
9
|
+
import numpy
|
|
10
|
+
|
|
11
|
+
from nvmath.device.common_backend import DescriptorWrapper
|
|
12
|
+
from nvmath.device.common_cuda import ComputeCapability
|
|
13
|
+
from .common import check_contains, check_in, check_not_in, check_code_type
|
|
14
|
+
from .common_backend import (
|
|
15
|
+
NP_TYPES_TO_MATHDX_PRECISION,
|
|
16
|
+
EXECUTION_STR_TO_MATHDX,
|
|
17
|
+
NVARG_GEN_OPT_LTO,
|
|
18
|
+
build_get_int_traits,
|
|
19
|
+
build_get_str_trait,
|
|
20
|
+
)
|
|
21
|
+
from .types import REAL_NP_TYPES
|
|
22
|
+
|
|
23
|
+
from nvmath.bindings import mathdx
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
_FFT_TYPE_TO_MATHDX = {t.name.lower(): t for t in mathdx.CufftdxType}
|
|
27
|
+
|
|
28
|
+
_FFT_DIRECTION_TO_MATHDX = {d.name.lower(): d for d in mathdx.CufftdxDirection}
|
|
29
|
+
|
|
30
|
+
_FFT_COMPLEX_LAYOUT_TO_MATHDX = {cl.name.lower(): cl for cl in mathdx.CufftdxComplexLayout}
|
|
31
|
+
|
|
32
|
+
_FFT_REAL_MODE_TO_MATHDX = {m.name.lower(): m for m in mathdx.CufftdxRealMode}
|
|
33
|
+
|
|
34
|
+
_FFT_API_STR_TO_MATHDX = {
|
|
35
|
+
"register_memory": mathdx.CufftdxApi.LMEM,
|
|
36
|
+
"shared_memory": mathdx.CufftdxApi.SMEM,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_FFT_KNOB_TYPE_TO_MATHDX = {t.name.lower(): t for t in mathdx.CufftdxKnobType}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class CallableGetIntTraits(Protocol):
|
|
43
|
+
def __call__(self, handle: int, trait_type: mathdx.CufftdxTraitType, size: int) -> tuple: ...
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class CallableGetStrTrait(Protocol):
|
|
47
|
+
def __call__(self, handle: int, trait_type: mathdx.CufftdxTraitType) -> str: ...
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
get_int_traits: CallableGetIntTraits = build_get_int_traits(mathdx.cufftdx_get_trait_int64s)
|
|
51
|
+
|
|
52
|
+
get_str_trait: CallableGetStrTrait = build_get_str_trait(mathdx.cufftdx_get_trait_str_size, mathdx.cufftdx_get_trait_str)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_int_trait(handle: int, trait_type: mathdx.CufftdxTraitType) -> int:
|
|
56
|
+
return int(mathdx.cufftdx_get_trait_int64(handle, trait_type))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_data_type_trait(handle: int, trait_type: mathdx.CufftdxTraitType) -> mathdx.CommondxValueType:
|
|
60
|
+
return mathdx.CommondxValueType(mathdx.cufftdx_get_trait_commondx_data_type(handle, trait_type))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def validate(
|
|
64
|
+
size,
|
|
65
|
+
precision,
|
|
66
|
+
fft_type,
|
|
67
|
+
execution,
|
|
68
|
+
direction,
|
|
69
|
+
ffts_per_block,
|
|
70
|
+
elements_per_thread,
|
|
71
|
+
real_fft_options,
|
|
72
|
+
code_type,
|
|
73
|
+
):
|
|
74
|
+
if size <= 0:
|
|
75
|
+
raise ValueError(f"size must be > 0. Got {size}")
|
|
76
|
+
check_in("precision", precision, REAL_NP_TYPES)
|
|
77
|
+
check_in("fft_type", fft_type, ["c2c", "c2r", "r2c"])
|
|
78
|
+
check_in("execution", execution, ["Block", "Thread"])
|
|
79
|
+
if direction is not None:
|
|
80
|
+
check_in("direction", direction, ["forward", "inverse"])
|
|
81
|
+
if ffts_per_block in (None, "suggested"):
|
|
82
|
+
pass
|
|
83
|
+
else:
|
|
84
|
+
if ffts_per_block <= 0:
|
|
85
|
+
raise ValueError(
|
|
86
|
+
f"ffts_per_block must be None, 'suggested' or a positive integer ; got ffts_per_block = {ffts_per_block}"
|
|
87
|
+
)
|
|
88
|
+
if elements_per_thread in (None, "suggested"):
|
|
89
|
+
pass
|
|
90
|
+
else:
|
|
91
|
+
if elements_per_thread <= 0:
|
|
92
|
+
raise ValueError(
|
|
93
|
+
f"elements_per_thread must be None, 'suggested' or a positive integer ; "
|
|
94
|
+
f"got elements_per_thread = {elements_per_thread}"
|
|
95
|
+
)
|
|
96
|
+
if real_fft_options is None:
|
|
97
|
+
pass
|
|
98
|
+
else:
|
|
99
|
+
check_contains(real_fft_options, "complex_layout")
|
|
100
|
+
check_contains(real_fft_options, "real_mode")
|
|
101
|
+
check_in("real_fft_options['complex_layout']", real_fft_options["complex_layout"], ["natural", "packed", "full"])
|
|
102
|
+
check_in("real_fft_options['real_mode']", real_fft_options["real_mode"], ["normal", "folded"])
|
|
103
|
+
check_code_type(code_type)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def validate_execute_api(execution: str, execute_api: str | None):
|
|
107
|
+
"""
|
|
108
|
+
Validate the execute_api argument.
|
|
109
|
+
"""
|
|
110
|
+
if execution == "Block":
|
|
111
|
+
check_in("execute_api", execute_api, list(_FFT_API_STR_TO_MATHDX.keys()) + [None])
|
|
112
|
+
else:
|
|
113
|
+
if execute_api is not None:
|
|
114
|
+
raise ValueError(f"api may be set only for block execution ; got execution = {execution}")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@lru_cache
|
|
118
|
+
def generate_FFT(
|
|
119
|
+
size,
|
|
120
|
+
precision,
|
|
121
|
+
fft_type,
|
|
122
|
+
direction,
|
|
123
|
+
code_type,
|
|
124
|
+
execution,
|
|
125
|
+
ffts_per_block,
|
|
126
|
+
elements_per_thread,
|
|
127
|
+
real_fft_options,
|
|
128
|
+
execute_api=None,
|
|
129
|
+
):
|
|
130
|
+
check_not_in("ffts_per_block", ffts_per_block, ["suggested"])
|
|
131
|
+
check_not_in("elements_per_thread", elements_per_thread, ["suggested"])
|
|
132
|
+
|
|
133
|
+
h = mathdx.cufftdx_create_descriptor()
|
|
134
|
+
|
|
135
|
+
if execute_api is not None:
|
|
136
|
+
mathdx.cufftdx_set_operator_int64(h, mathdx.CufftdxOperatorType.API, _FFT_API_STR_TO_MATHDX[execute_api])
|
|
137
|
+
|
|
138
|
+
mathdx.cufftdx_set_operator_int64(h, mathdx.CufftdxOperatorType.SIZE, size)
|
|
139
|
+
mathdx.cufftdx_set_operator_int64(h, mathdx.CufftdxOperatorType.PRECISION, NP_TYPES_TO_MATHDX_PRECISION[precision])
|
|
140
|
+
mathdx.cufftdx_set_operator_int64(h, mathdx.CufftdxOperatorType.TYPE, _FFT_TYPE_TO_MATHDX[fft_type])
|
|
141
|
+
mathdx.cufftdx_set_operator_int64(h, mathdx.CufftdxOperatorType.DIRECTION, _FFT_DIRECTION_TO_MATHDX[direction])
|
|
142
|
+
|
|
143
|
+
if real_fft_options:
|
|
144
|
+
real_fft_options = dict(real_fft_options)
|
|
145
|
+
ll = real_fft_options["complex_layout"]
|
|
146
|
+
mm = real_fft_options["real_mode"]
|
|
147
|
+
mathdx.cufftdx_set_operator_int64s(
|
|
148
|
+
h, mathdx.CufftdxOperatorType.REAL_FFT_OPTIONS, 2, [_FFT_COMPLEX_LAYOUT_TO_MATHDX[ll], _FFT_REAL_MODE_TO_MATHDX[mm]]
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
mathdx.cufftdx_set_operator_int64(h, mathdx.CufftdxOperatorType.EXECUTION, EXECUTION_STR_TO_MATHDX[execution])
|
|
152
|
+
|
|
153
|
+
if code_type:
|
|
154
|
+
mathdx.cufftdx_set_operator_int64(h, mathdx.CufftdxOperatorType.SM, code_type.cc.major * 100 + code_type.cc.minor * 10)
|
|
155
|
+
|
|
156
|
+
if ffts_per_block:
|
|
157
|
+
mathdx.cufftdx_set_operator_int64(h, mathdx.CufftdxOperatorType.FFTS_PER_BLOCK, ffts_per_block)
|
|
158
|
+
|
|
159
|
+
if elements_per_thread:
|
|
160
|
+
mathdx.cufftdx_set_operator_int64(h, mathdx.CufftdxOperatorType.ELEMENTS_PER_THREAD, elements_per_thread)
|
|
161
|
+
|
|
162
|
+
return DescriptorWrapper(h, mathdx.cufftdx_destroy_descriptor)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@lru_cache
|
|
166
|
+
def generate_code(handle, version: ComputeCapability):
|
|
167
|
+
code = mathdx.commondx_create_code()
|
|
168
|
+
|
|
169
|
+
mathdx.commondx_set_code_option_int64(code, mathdx.CommondxOption.TARGET_SM, version.integer)
|
|
170
|
+
mathdx.commondx_set_code_option_str(code, mathdx.CommondxOption.EXTRA_NVTRC_ARGS, NVARG_GEN_OPT_LTO)
|
|
171
|
+
mathdx.cufftdx_finalize_code(code, handle)
|
|
172
|
+
|
|
173
|
+
return DescriptorWrapper(code, mathdx.commondx_destroy_code)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@lru_cache
|
|
177
|
+
def get_knobs(handle, knobs: Sequence[str]):
|
|
178
|
+
knobs_dx: list[mathdx.CufftdxKnobType] = [_FFT_KNOB_TYPE_TO_MATHDX[k] for k in knobs]
|
|
179
|
+
knobs_size = mathdx.cufftdx_get_knob_int64size(handle, len(knobs), knobs_dx)
|
|
180
|
+
|
|
181
|
+
knobs_result_dx = numpy.empty(knobs_size, dtype=numpy.int64)
|
|
182
|
+
mathdx.cufftdx_get_knob_int64s(
|
|
183
|
+
handle,
|
|
184
|
+
len(knobs),
|
|
185
|
+
knobs_dx,
|
|
186
|
+
knobs_size,
|
|
187
|
+
knobs_result_dx.ctypes.data,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
knobs_result = [
|
|
191
|
+
tuple(int(knobs_result_dx[j]) for j in range(i, i + len(knobs))) for i in range(0, len(knobs_result_dx), len(knobs))
|
|
192
|
+
]
|
|
193
|
+
|
|
194
|
+
return knobs_result
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from numba import types
|
|
6
|
+
from numba.core.typing import signature
|
|
7
|
+
from numba.extending import intrinsic, overload
|
|
8
|
+
from .common_numba import NUMBA_FE_TYPES_TO_NUMBA_IR, make_function_call
|
|
9
|
+
from .common import check_in
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#
|
|
13
|
+
# Lowering down to function call to cuFFTDx
|
|
14
|
+
# io = 'thread' or 'smem'
|
|
15
|
+
# execution = 'Thread' or 'Block'
|
|
16
|
+
# value_type = real or complex numpy type of the input/output thread-private and shared
|
|
17
|
+
# memory
|
|
18
|
+
# symbols = name of the function, as a string
|
|
19
|
+
#
|
|
20
|
+
def make_codegen(io, execution, value_type, symbol):
|
|
21
|
+
check_in("io", io, ["thread", "smem"]) # input in thread-private vs shared memory
|
|
22
|
+
check_in("execution", execution, ["Thread", "Block"]) # Thread() or Block() APIs
|
|
23
|
+
|
|
24
|
+
array_type = types.Array(value_type, 1, "C")
|
|
25
|
+
return_type = types.void
|
|
26
|
+
|
|
27
|
+
# Thread() APIs only work on a single thread-private array
|
|
28
|
+
# no shared memory, no workspace
|
|
29
|
+
# (void) ( (value_type*)thread array )
|
|
30
|
+
|
|
31
|
+
if execution == "Thread" and io == "thread":
|
|
32
|
+
return signature(return_type, array_type), make_function_call(symbol)
|
|
33
|
+
|
|
34
|
+
# Block() APIs have two variants
|
|
35
|
+
# (void) ( (value_type*)thread array, (value_type*)shared memory array ) # noqa: W505
|
|
36
|
+
# (void) ( (value_type*)shared memory array ) # noqa: W505
|
|
37
|
+
|
|
38
|
+
elif execution == "Block" and io == "thread":
|
|
39
|
+
codegen = make_function_call(symbol)
|
|
40
|
+
|
|
41
|
+
def wrap_codegen(context, builder, sig, args):
|
|
42
|
+
assert len(args) == 2
|
|
43
|
+
assert len(sig.args) == 2
|
|
44
|
+
codegen(context, builder, sig, [args[0], args[1]])
|
|
45
|
+
|
|
46
|
+
return signature(return_type, array_type, array_type), wrap_codegen
|
|
47
|
+
|
|
48
|
+
elif execution == "Block" and io == "smem":
|
|
49
|
+
codegen = make_function_call(symbol)
|
|
50
|
+
|
|
51
|
+
def wrap_codegen(context, builder, sig, args):
|
|
52
|
+
assert len(args) == 1
|
|
53
|
+
assert len(sig.args) == 1
|
|
54
|
+
codegen(context, builder, sig, args)
|
|
55
|
+
|
|
56
|
+
return signature(return_type, array_type), wrap_codegen
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def codegen(description, func_to_overload):
|
|
60
|
+
execution = description["execution"]
|
|
61
|
+
execute_api = description["execute_api"]
|
|
62
|
+
|
|
63
|
+
check_in("execution", execution, ["Block", "Thread"])
|
|
64
|
+
|
|
65
|
+
if execution == "Thread":
|
|
66
|
+
codegen_thread(description, func_to_overload)
|
|
67
|
+
else:
|
|
68
|
+
assert execution == "Block"
|
|
69
|
+
|
|
70
|
+
if execute_api == "register_memory":
|
|
71
|
+
codegen_block_lmem(description, func_to_overload)
|
|
72
|
+
else:
|
|
73
|
+
assert execute_api == "shared_memory"
|
|
74
|
+
|
|
75
|
+
codegen_block_smem(description, func_to_overload)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def codegen_thread(description, func_to_overload):
|
|
79
|
+
value_type = NUMBA_FE_TYPES_TO_NUMBA_IR[description["value_type"]]
|
|
80
|
+
symbol = description["symbol"]
|
|
81
|
+
|
|
82
|
+
@intrinsic
|
|
83
|
+
def intrinsic_1(typingctx, thread):
|
|
84
|
+
return make_codegen("thread", "Thread", value_type, symbol)
|
|
85
|
+
|
|
86
|
+
@overload(func_to_overload, target="cuda")
|
|
87
|
+
def fft(thread):
|
|
88
|
+
def impl(thread):
|
|
89
|
+
return intrinsic_1(thread)
|
|
90
|
+
|
|
91
|
+
return impl
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def codegen_block_lmem(description, func_to_overload):
|
|
95
|
+
value_type = NUMBA_FE_TYPES_TO_NUMBA_IR[description["value_type"]]
|
|
96
|
+
symbol = description["symbol"]
|
|
97
|
+
|
|
98
|
+
@intrinsic
|
|
99
|
+
def intrinsic_2(typingctx, thread, smem):
|
|
100
|
+
return make_codegen("thread", "Block", value_type, symbol)
|
|
101
|
+
|
|
102
|
+
@overload(func_to_overload, target="cuda")
|
|
103
|
+
def fft(thread, smem):
|
|
104
|
+
def impl(thread, smem):
|
|
105
|
+
return intrinsic_2(thread, smem)
|
|
106
|
+
|
|
107
|
+
return impl
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def codegen_block_smem(description, func_to_overload):
|
|
111
|
+
value_type = NUMBA_FE_TYPES_TO_NUMBA_IR[description["value_type"]]
|
|
112
|
+
symbol = description["symbol"]
|
|
113
|
+
|
|
114
|
+
@intrinsic
|
|
115
|
+
def intrinsic_1(typingctx, smem):
|
|
116
|
+
return make_codegen("smem", "Block", value_type, symbol)
|
|
117
|
+
|
|
118
|
+
@overload(func_to_overload, target="cuda")
|
|
119
|
+
def fft(smem):
|
|
120
|
+
def impl(smem):
|
|
121
|
+
return intrinsic_1(smem)
|
|
122
|
+
|
|
123
|
+
return impl
|