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
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# This code was automatically generated with version 0.3.0. Do not modify it directly.
|
|
6
|
+
|
|
7
|
+
from ..cyfft cimport *
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
###############################################################################
|
|
11
|
+
# Wrapper functions
|
|
12
|
+
###############################################################################
|
|
13
|
+
|
|
14
|
+
cdef int _nvpl_fft_get_version() except?-42 nogil
|
|
15
|
+
cdef fftw_plan _fftw_plan_many_dft(int rank, const int* n, int batch, fftw_complex* in_, const int* inembed, int istride, int idist, fftw_complex* out, const int* onembed, int ostride, int odist, int sign, unsigned flags) except?NULL nogil
|
|
16
|
+
cdef fftw_plan _fftw_plan_many_dft_r2c(int rank, const int* n, int batch, double* in_, const int* inembed, int istride, int idist, fftw_complex* out, const int* onembed, int ostride, int odist, unsigned flags) except?NULL nogil
|
|
17
|
+
cdef fftw_plan _fftw_plan_many_dft_c2r(int rank, const int* n, int batch, fftw_complex* in_, const int* inembed, int istride, int idist, double* out, const int* onembed, int ostride, int odist, unsigned flags) except?NULL nogil
|
|
18
|
+
cdef void _fftw_execute_dft(const fftw_plan plan, fftw_complex* idata, fftw_complex* odata) except* nogil
|
|
19
|
+
cdef void _fftw_execute_dft_r2c(const fftw_plan plan, double* idata, fftw_complex* odata) except* nogil
|
|
20
|
+
cdef void _fftw_execute_dft_c2r(const fftw_plan plan, fftw_complex* idata, double* odata) except* nogil
|
|
21
|
+
cdef fftwf_plan _fftwf_plan_many_dft(int rank, const int* n, int batch, fftwf_complex* in_, const int* inembed, int istride, int idist, fftwf_complex* out, const int* onembed, int ostride, int odist, int sign, unsigned flags) except?NULL nogil
|
|
22
|
+
cdef fftwf_plan _fftwf_plan_many_dft_r2c(int rank, const int* n, int batch, float* in_, const int* inembed, int istride, int idist, fftwf_complex* out, const int* onembed, int ostride, int odist, unsigned flags) except?NULL nogil
|
|
23
|
+
cdef fftwf_plan _fftwf_plan_many_dft_c2r(int rank, const int* n, int batch, fftwf_complex* in_, const int* inembed, int istride, int idist, float* out, const int* onembed, int ostride, int odist, unsigned flags) except?NULL nogil
|
|
24
|
+
cdef void _fftwf_execute_dft(const fftwf_plan plan, fftwf_complex* idata, fftwf_complex* odata) except* nogil
|
|
25
|
+
cdef void _fftwf_execute_dft_r2c(const fftwf_plan plan, float* idata, fftwf_complex* odata) except* nogil
|
|
26
|
+
cdef void _fftwf_execute_dft_c2r(const fftwf_plan plan, fftwf_complex* idata, float* odata) except* nogil
|
|
27
|
+
cdef int _fftw_init_threads() except?-42 nogil
|
|
28
|
+
cdef int _fftwf_init_threads() except?-42 nogil
|
|
29
|
+
cdef void _fftw_plan_with_nthreads(int nthreads) except* nogil
|
|
30
|
+
cdef void _fftwf_plan_with_nthreads(int nthreads) except* nogil
|
|
31
|
+
cdef int _fftw_planner_nthreads() except?-42 nogil
|
|
32
|
+
cdef int _fftwf_planner_nthreads() except?-42 nogil
|
|
33
|
+
cdef void _fftw_cleanup_threads() except* nogil
|
|
34
|
+
cdef void _fftwf_cleanup_threads() except* nogil
|
|
35
|
+
cdef void _fftw_destroy_plan(fftw_plan plan) except* nogil
|
|
36
|
+
cdef void _fftwf_destroy_plan(fftwf_plan plan) except* nogil
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# This code was automatically generated with version 0.3.0. Do not modify it directly.
|
|
6
|
+
# This layer exposes the C header to Cython as-is.
|
|
7
|
+
|
|
8
|
+
###############################################################################
|
|
9
|
+
# Types (structs, enums, ...)
|
|
10
|
+
###############################################################################
|
|
11
|
+
|
|
12
|
+
# enums
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# types
|
|
17
|
+
cdef extern from *:
|
|
18
|
+
"""
|
|
19
|
+
// Transform direction
|
|
20
|
+
#define FFTW_FORWARD -1
|
|
21
|
+
#define FFTW_INVERSE 1
|
|
22
|
+
#define FFTW_BACKWARD 1
|
|
23
|
+
|
|
24
|
+
// Planner flags
|
|
25
|
+
#define FFTW_ESTIMATE 0x01
|
|
26
|
+
#define FFTW_MEASURE 0x02
|
|
27
|
+
#define FFTW_PATIENT 0x03
|
|
28
|
+
#define FFTW_EXHAUSTIVE 0x04
|
|
29
|
+
#define FFTW_WISDOM_ONLY 0x05
|
|
30
|
+
|
|
31
|
+
// Algorithm restriction flags
|
|
32
|
+
#define FFTW_DESTROY_INPUT 0x08
|
|
33
|
+
#define FFTW_PRESERVE_INPUT 0x0C
|
|
34
|
+
#define FFTW_UNALIGNED 0x10
|
|
35
|
+
|
|
36
|
+
typedef double fftw_complex[2] __attribute__ ((aligned (16)));
|
|
37
|
+
typedef float fftwf_complex[2] __attribute__ ((aligned (8)));
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
cdef const int FFTW_FORWARD
|
|
41
|
+
cdef const int FFTW_INVERSE
|
|
42
|
+
|
|
43
|
+
cdef const int FFTW_ESTIMATE
|
|
44
|
+
cdef const int FFTW_MEASURE
|
|
45
|
+
cdef const int FFTW_PATIENT
|
|
46
|
+
cdef const int FFTW_EXHAUSTIVE
|
|
47
|
+
cdef const int FFTW_WISDOM_ONLY
|
|
48
|
+
|
|
49
|
+
cdef const int FFTW_DESTROY_INPUT
|
|
50
|
+
cdef const int FFTW_PRESERVE_INPUT
|
|
51
|
+
cdef const int FFTW_UNALIGNED
|
|
52
|
+
|
|
53
|
+
ctypedef double fftw_complex[2]
|
|
54
|
+
ctypedef float fftwf_complex[2]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
ctypedef void* fftw_plan 'fftw_plan'
|
|
58
|
+
ctypedef void* fftwf_plan 'fftwf_plan'
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
###############################################################################
|
|
62
|
+
# Functions
|
|
63
|
+
###############################################################################
|
|
64
|
+
|
|
65
|
+
cdef int nvpl_fft_get_version() except?-42 nogil
|
|
66
|
+
cdef fftw_plan fftw_plan_many_dft(int rank, const int* n, int batch, fftw_complex* in_, const int* inembed, int istride, int idist, fftw_complex* out, const int* onembed, int ostride, int odist, int sign, unsigned flags) except?NULL nogil
|
|
67
|
+
cdef fftw_plan fftw_plan_many_dft_r2c(int rank, const int* n, int batch, double* in_, const int* inembed, int istride, int idist, fftw_complex* out, const int* onembed, int ostride, int odist, unsigned flags) except?NULL nogil
|
|
68
|
+
cdef fftw_plan fftw_plan_many_dft_c2r(int rank, const int* n, int batch, fftw_complex* in_, const int* inembed, int istride, int idist, double* out, const int* onembed, int ostride, int odist, unsigned flags) except?NULL nogil
|
|
69
|
+
cdef void fftw_execute_dft(const fftw_plan plan, fftw_complex* idata, fftw_complex* odata) except* nogil
|
|
70
|
+
cdef void fftw_execute_dft_r2c(const fftw_plan plan, double* idata, fftw_complex* odata) except* nogil
|
|
71
|
+
cdef void fftw_execute_dft_c2r(const fftw_plan plan, fftw_complex* idata, double* odata) except* nogil
|
|
72
|
+
cdef fftwf_plan fftwf_plan_many_dft(int rank, const int* n, int batch, fftwf_complex* in_, const int* inembed, int istride, int idist, fftwf_complex* out, const int* onembed, int ostride, int odist, int sign, unsigned flags) except?NULL nogil
|
|
73
|
+
cdef fftwf_plan fftwf_plan_many_dft_r2c(int rank, const int* n, int batch, float* in_, const int* inembed, int istride, int idist, fftwf_complex* out, const int* onembed, int ostride, int odist, unsigned flags) except?NULL nogil
|
|
74
|
+
cdef fftwf_plan fftwf_plan_many_dft_c2r(int rank, const int* n, int batch, fftwf_complex* in_, const int* inembed, int istride, int idist, float* out, const int* onembed, int ostride, int odist, unsigned flags) except?NULL nogil
|
|
75
|
+
cdef void fftwf_execute_dft(const fftwf_plan plan, fftwf_complex* idata, fftwf_complex* odata) except* nogil
|
|
76
|
+
cdef void fftwf_execute_dft_r2c(const fftwf_plan plan, float* idata, fftwf_complex* odata) except* nogil
|
|
77
|
+
cdef void fftwf_execute_dft_c2r(const fftwf_plan plan, fftwf_complex* idata, float* odata) except* nogil
|
|
78
|
+
cdef int fftw_init_threads() except?-42 nogil
|
|
79
|
+
cdef int fftwf_init_threads() except?-42 nogil
|
|
80
|
+
cdef void fftw_plan_with_nthreads(int nthreads) except* nogil
|
|
81
|
+
cdef void fftwf_plan_with_nthreads(int nthreads) except* nogil
|
|
82
|
+
cdef int fftw_planner_nthreads() except?-42 nogil
|
|
83
|
+
cdef int fftwf_planner_nthreads() except?-42 nogil
|
|
84
|
+
cdef void fftw_cleanup_threads() except* nogil
|
|
85
|
+
cdef void fftwf_cleanup_threads() except* nogil
|
|
86
|
+
cdef void fftw_destroy_plan(fftw_plan plan) except* nogil
|
|
87
|
+
cdef void fftwf_destroy_plan(fftwf_plan plan) except* nogil
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# This code was automatically generated with version 0.3.0. Do not modify it directly.
|
|
6
|
+
|
|
7
|
+
from libc.stdint cimport intptr_t
|
|
8
|
+
|
|
9
|
+
from .cyfft cimport *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
###############################################################################
|
|
13
|
+
# Types
|
|
14
|
+
###############################################################################
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
cdef class Plan:
|
|
20
|
+
cdef intptr_t forward_handle
|
|
21
|
+
cdef intptr_t inverse_handle
|
|
22
|
+
cdef int precision
|
|
23
|
+
cdef int kind
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
###############################################################################
|
|
27
|
+
# Enum
|
|
28
|
+
###############################################################################
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# The `UNSPECIFIED` value is not valid sign in NVPL's header,
|
|
32
|
+
# but is used here to allow for planning C2C that can handle
|
|
33
|
+
# both directions
|
|
34
|
+
cpdef enum Sign:
|
|
35
|
+
UNSPECIFIED = 0
|
|
36
|
+
FORWARD = FFTW_FORWARD
|
|
37
|
+
INVERSE = FFTW_INVERSE
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
cpdef enum PlannerFlags:
|
|
41
|
+
ESTIMATE = FFTW_ESTIMATE
|
|
42
|
+
MEASURE = FFTW_MEASURE
|
|
43
|
+
PATIENT = FFTW_PATIENT
|
|
44
|
+
EXHAUSTIVE = FFTW_EXHAUSTIVE
|
|
45
|
+
WISDOM_ONLY = FFTW_WISDOM_ONLY
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
cpdef enum Precision:
|
|
49
|
+
FLOAT = 32
|
|
50
|
+
DOUBLE = 64
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
cpdef enum Kind:
|
|
54
|
+
C2C = 1
|
|
55
|
+
C2R = 2
|
|
56
|
+
R2C = 3
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
###############################################################################
|
|
63
|
+
# Convenience wrappers/adapters
|
|
64
|
+
###############################################################################
|
|
65
|
+
|
|
66
|
+
cpdef int plan_with_nthreads(int precision, int num_threads) except -1
|
|
67
|
+
cpdef int planner_nthreads(int precision) except? -1
|
|
68
|
+
cpdef int init_threads(int precision) except -1
|
|
69
|
+
cpdef int cleanup_threads(int precision) except -1
|
|
70
|
+
cpdef Plan plan_many(int precision, int kind, int sign, int rank, n, int batch, intptr_t in_, inembed, int istride, int idist, intptr_t out, onembed, int ostride, int odist, unsigned flags)
|
|
71
|
+
cpdef int destroy(Plan plan) except -1
|
|
72
|
+
cpdef int execute(Plan plan, intptr_t idata, intptr_t odata, int sign) except -1
|
|
73
|
+
|
|
74
|
+
###############################################################################
|
|
75
|
+
# Functions
|
|
76
|
+
###############################################################################
|
|
77
|
+
|
|
78
|
+
cpdef int get_version() except? -1
|
|
79
|
+
cpdef intptr_t plan_many_c2c_double(int rank, n, int batch, intptr_t in_, inembed, int istride, int idist, intptr_t out, onembed, int ostride, int odist, int sign, unsigned flags) except? 0
|
|
80
|
+
cpdef intptr_t plan_many_r2c_double(int rank, n, int batch, intptr_t in_, inembed, int istride, int idist, intptr_t out, onembed, int ostride, int odist, unsigned flags) except? 0
|
|
81
|
+
cpdef intptr_t plan_many_c2r_double(int rank, n, int batch, intptr_t in_, inembed, int istride, int idist, intptr_t out, onembed, int ostride, int odist, unsigned flags) except? 0
|
|
82
|
+
cpdef void execute_c2c_double(intptr_t plan, intptr_t idata, intptr_t odata) except*
|
|
83
|
+
cpdef void execute_r2c_double(intptr_t plan, intptr_t idata, intptr_t odata) except*
|
|
84
|
+
cpdef void execute_c2r_double(intptr_t plan, intptr_t idata, intptr_t odata) except*
|
|
85
|
+
cpdef intptr_t plan_many_c2c_float(int rank, n, int batch, intptr_t in_, inembed, int istride, int idist, intptr_t out, onembed, int ostride, int odist, int sign, unsigned flags) except? 0
|
|
86
|
+
cpdef intptr_t plan_many_r2c_float(int rank, n, int batch, intptr_t in_, inembed, int istride, int idist, intptr_t out, onembed, int ostride, int odist, unsigned flags) except? 0
|
|
87
|
+
cpdef intptr_t plan_many_c2r_float(int rank, n, int batch, intptr_t in_, inembed, int istride, int idist, intptr_t out, onembed, int ostride, int odist, unsigned flags) except? 0
|
|
88
|
+
cpdef void execute_c2c_float(intptr_t plan, intptr_t idata, intptr_t odata) except*
|
|
89
|
+
cpdef void execute_r2c_float(intptr_t plan, intptr_t idata, intptr_t odata) except*
|
|
90
|
+
cpdef void execute_c2r_float(intptr_t plan, intptr_t idata, intptr_t odata) except*
|
|
91
|
+
cpdef int init_threads_double() except 0
|
|
92
|
+
cpdef int init_threads_float() except 0
|
|
93
|
+
cpdef void plan_with_nthreads_double(int nthreads) except*
|
|
94
|
+
cpdef void plan_with_nthreads_float(int nthreads) except*
|
|
95
|
+
cpdef int planner_nthreads_double() except? 0
|
|
96
|
+
cpdef int planner_nthreads_float() except? 0
|
|
97
|
+
cpdef void cleanup_threads_double() except*
|
|
98
|
+
cpdef void cleanup_threads_float() except*
|
|
99
|
+
cpdef void destroy_plan_double(intptr_t plan) except*
|
|
100
|
+
cpdef void destroy_plan_float(intptr_t plan) except*
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# This code was automatically generated with version 3.1.7. Do not modify it directly.
|
|
6
|
+
|
|
7
|
+
from libc.stdint cimport intptr_t
|
|
8
|
+
|
|
9
|
+
from .cynvshmem cimport *
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
###############################################################################
|
|
13
|
+
# Types
|
|
14
|
+
###############################################################################
|
|
15
|
+
|
|
16
|
+
ctypedef nvshmem_team_config_v1 team_config
|
|
17
|
+
ctypedef nvshmemx_uniqueid_args_v1 uniqueid_args
|
|
18
|
+
ctypedef nvshmemx_init_args_v1 init_args
|
|
19
|
+
ctypedef nvshmemx_init_attr_v1 init_attr
|
|
20
|
+
|
|
21
|
+
ctypedef cudaStream_t Stream
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
###############################################################################
|
|
25
|
+
# Enum
|
|
26
|
+
###############################################################################
|
|
27
|
+
|
|
28
|
+
ctypedef _anon_enum0 __anon_enum0
|
|
29
|
+
ctypedef _anon_enum1 __anon_enum1
|
|
30
|
+
ctypedef _anon_enum2 __anon_enum2
|
|
31
|
+
ctypedef nvshmemx_status _Status
|
|
32
|
+
ctypedef flags _Flags
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
###############################################################################
|
|
36
|
+
# Functions
|
|
37
|
+
###############################################################################
|
|
38
|
+
|
|
39
|
+
cpdef int init_status() except? -1
|
|
40
|
+
cpdef int my_pe() except? -1
|
|
41
|
+
cpdef int n_pes() except? -1
|
|
42
|
+
cpdef intptr_t malloc(size_t size) except? 0
|
|
43
|
+
cpdef intptr_t calloc(size_t count, size_t size) except? 0
|
|
44
|
+
cpdef intptr_t align(size_t alignment, size_t size) except? 0
|
|
45
|
+
cpdef void free(intptr_t ptr) except*
|
|
46
|
+
cpdef intptr_t ptr(intptr_t dest, int pe) except? 0
|
|
47
|
+
cpdef void int_p(intptr_t dest, int value, int pe) except*
|
|
48
|
+
cpdef int team_my_pe(int32_t team) except? -1
|
|
49
|
+
cpdef void barrier_all_on_stream(intptr_t stream) except*
|
|
50
|
+
cpdef void sync_all_on_stream(intptr_t stream) except*
|
|
51
|
+
cpdef hostlib_init_attr(unsigned int flags, intptr_t attr)
|
|
52
|
+
cpdef void hostlib_finalize() except*
|
|
53
|
+
cpdef set_attr_uniqueid_args(int myrank, int nranks, intptr_t uniqueid, intptr_t attr)
|
|
54
|
+
cpdef get_uniqueid(intptr_t uniqueid)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from .patch import patch_codegen
|
|
6
|
+
from nvmath._utils import force_loading_libmathdx
|
|
7
|
+
|
|
8
|
+
patch_codegen()
|
|
9
|
+
force_loading_libmathdx("12")
|
|
10
|
+
|
|
11
|
+
from .common_cuda import * # noqa: E402, F403
|
|
12
|
+
from .cufftdx import * # noqa: E402, F403
|
|
13
|
+
from .cublasdx import * # noqa: E402, F403
|
|
14
|
+
from .cublasdx_backend import * # noqa: E402, F403
|
|
15
|
+
from .vector_types_numba import * # noqa: E402, F403
|
|
16
|
+
from . import nvrtc # noqa: E402, F403, F401
|
|
17
|
+
from .common import make_tensor # noqa: E402, F401
|
|
18
|
+
|
|
19
|
+
# register models in numba
|
|
20
|
+
from . import cublasdx_numba # noqa: E402, F401
|
|
21
|
+
|
|
22
|
+
del patch_codegen
|
|
23
|
+
del force_loading_libmathdx
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import functools
|
|
6
|
+
import sys
|
|
7
|
+
from warnings import warn
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _deprecated(
|
|
11
|
+
msg,
|
|
12
|
+
category: type[Warning] | None = DeprecationWarning,
|
|
13
|
+
stacklevel: int = 1,
|
|
14
|
+
):
|
|
15
|
+
"""Dropin replacement for @warnings.deprecated(...)"""
|
|
16
|
+
|
|
17
|
+
def decorator(func):
|
|
18
|
+
@functools.wraps(func)
|
|
19
|
+
def wrapper(*args, **kwargs):
|
|
20
|
+
warn(msg, category=category, stacklevel=stacklevel + 1)
|
|
21
|
+
return func(*args, **kwargs)
|
|
22
|
+
|
|
23
|
+
return wrapper
|
|
24
|
+
|
|
25
|
+
return decorator
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
deprecated = _deprecated
|
|
29
|
+
|
|
30
|
+
if (sys.version_info.major, sys.version_info.minor) >= (3, 13):
|
|
31
|
+
from warnings import deprecated as _warnings_deprecated # type: ignore
|
|
32
|
+
|
|
33
|
+
deprecated = _warnings_deprecated
|
nvmath/device/caching.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import hashlib
|
|
7
|
+
import json
|
|
8
|
+
import logging
|
|
9
|
+
import pickle
|
|
10
|
+
|
|
11
|
+
_ENABLE_CACHE = "NVMATH_ENABLE_CACHE" in os.environ
|
|
12
|
+
if _ENABLE_CACHE:
|
|
13
|
+
logging.warning("nvmath: NVMATH_ENABLE_CACHE is set in the environment, cache is enabled")
|
|
14
|
+
_CACHE_LOCATION = os.path.join(os.path.expanduser("~"), ".cache", "nvmath-device")
|
|
15
|
+
if not os.path.exists(_CACHE_LOCATION):
|
|
16
|
+
logging.debug(f"pymathdx: creating directory {_CACHE_LOCATION}")
|
|
17
|
+
os.makedirs(_CACHE_LOCATION)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# We use
|
|
21
|
+
# json.dumps to serialize args/kwargs to a string
|
|
22
|
+
# hashlib to compute the hash
|
|
23
|
+
def json_hash(*args, **kwargs):
|
|
24
|
+
hasher = hashlib.sha1()
|
|
25
|
+
hasher.update(json.dumps([args, kwargs]).encode("utf-8"))
|
|
26
|
+
return hasher.hexdigest()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def disk_cache(func):
|
|
30
|
+
def cacher(*args, **kwargs):
|
|
31
|
+
if _ENABLE_CACHE:
|
|
32
|
+
# compute hash(args, kwargs)
|
|
33
|
+
h = json_hash(*args, **kwargs)
|
|
34
|
+
# if file exist...
|
|
35
|
+
if os.path.isfile(os.path.join(_CACHE_LOCATION, h)):
|
|
36
|
+
# open it
|
|
37
|
+
with open(os.path.join(_CACHE_LOCATION, h), "rb") as f:
|
|
38
|
+
out = pickle.load(f)
|
|
39
|
+
# return cache
|
|
40
|
+
return out
|
|
41
|
+
else:
|
|
42
|
+
# compute output
|
|
43
|
+
out = func(*args, **kwargs)
|
|
44
|
+
# store to file
|
|
45
|
+
with open(os.path.join(_CACHE_LOCATION, h), "wb") as f:
|
|
46
|
+
pickle.dump(out, f)
|
|
47
|
+
return out
|
|
48
|
+
else:
|
|
49
|
+
return func(*args, **kwargs)
|
|
50
|
+
|
|
51
|
+
return cacher
|
nvmath/device/common.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from abc import abstractmethod
|
|
6
|
+
import tempfile
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
from .common_cuda import CodeType
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"make_tensor",
|
|
15
|
+
"OpaqueTensor",
|
|
16
|
+
"Layout",
|
|
17
|
+
"axpby",
|
|
18
|
+
"copy",
|
|
19
|
+
"copy_fragment",
|
|
20
|
+
"clear",
|
|
21
|
+
"copy_wait",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
SHARED_DEVICE_DOCSTRINGS = {
|
|
25
|
+
"compiler": "A string to specify the compiler for the device code, currently supports ``None`` (default) and ``'numba'``",
|
|
26
|
+
#
|
|
27
|
+
"precision": """\
|
|
28
|
+
The computation precision specified as a numpy float dtype, currently supports ``numpy.float16``, ``numpy.float32`` and
|
|
29
|
+
``numpy.float64``.""".replace("\n", " "),
|
|
30
|
+
#
|
|
31
|
+
"code_type": "The target GPU code and compute-capability.",
|
|
32
|
+
#
|
|
33
|
+
"execution": "A string specifying the execution method, can be ``'Block'`` or ``'Thread'``.",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# TODO: maybe pre-compile regular expression
|
|
38
|
+
def make_binary_tempfile(content, suffix):
|
|
39
|
+
# TODO: may need to set it False for Windows? (refer to Python API doc)
|
|
40
|
+
tmp = tempfile.NamedTemporaryFile(mode="w+b", suffix=suffix, delete=True) # noqa: SIM115
|
|
41
|
+
tmp.write(content)
|
|
42
|
+
tmp.flush()
|
|
43
|
+
return tmp
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def check_in(name, arg, set):
|
|
47
|
+
if arg not in set:
|
|
48
|
+
raise ValueError(f"{name} must be in {set} ; got {name} = {arg}")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def check_not_in(name, arg, set):
|
|
52
|
+
if arg in set:
|
|
53
|
+
raise ValueError(f"{name} must not be any of those value {set} ; got {name} = {arg}")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def check_contains(set, key):
|
|
57
|
+
if key not in set:
|
|
58
|
+
raise ValueError(f"{key} must be in {set}")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def check_code_type(code_type):
|
|
62
|
+
if isinstance(code_type, CodeType):
|
|
63
|
+
if code_type.cc.major < 7:
|
|
64
|
+
raise ValueError(f"code_type.cc.major must be >= 7 ; got code_type.cc.major = {code_type.cc.major}")
|
|
65
|
+
if code_type.cc.minor < 0:
|
|
66
|
+
raise ValueError(f"code_type.cc.minor must be >= 0 ; got code_type.cc.minor = {code_type.cc.minor}")
|
|
67
|
+
check_in("code_type.kind", code_type.kind, ["lto"])
|
|
68
|
+
else:
|
|
69
|
+
raise ValueError(f"code_type should be an instance of CodeType ; got code_type = {code_type}")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def pad_or_truncate(list, target_len):
|
|
73
|
+
return list[:target_len] + [0] * (target_len - len(list))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class Layout:
|
|
77
|
+
"""Layout for the OpaqueTensor"""
|
|
78
|
+
|
|
79
|
+
def __init__(self):
|
|
80
|
+
raise RuntimeError("Layout should not be called directly.")
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
@abstractmethod
|
|
84
|
+
def size(self) -> int:
|
|
85
|
+
"""
|
|
86
|
+
Number of valid elements in a tensor. This is simply a product of all
|
|
87
|
+
shape dimensions.
|
|
88
|
+
"""
|
|
89
|
+
pass
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
@abstractmethod
|
|
93
|
+
def cosize(self) -> int:
|
|
94
|
+
"""
|
|
95
|
+
Returns a distance from last element of a tensor to its first element.
|
|
96
|
+
It describes how many elements does the argument layout span.
|
|
97
|
+
"""
|
|
98
|
+
pass
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class OpaqueTensor:
|
|
102
|
+
buffer: np.ndarray
|
|
103
|
+
layout: Layout
|
|
104
|
+
leading_dimension: int | None
|
|
105
|
+
|
|
106
|
+
def __init__(self, *args):
|
|
107
|
+
raise RuntimeError("OpaqueTensor should not be called directly outside of a numba.cuda.jit(...) kernel.")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def make_tensor(array: np.ndarray, layout: Layout) -> OpaqueTensor:
|
|
111
|
+
raise RuntimeError("make_tensor should not be called directly outside of a numba.cuda.jit(...) kernel.")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def axpby(alpha: float, x_tensor: OpaqueTensor, beta: float, y_tensor: OpaqueTensor) -> None:
|
|
115
|
+
raise RuntimeError("axpby should not be called directly outside of a numba.cuda.jit(...) kernel.")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def copy(src: OpaqueTensor, dst: OpaqueTensor):
|
|
119
|
+
raise RuntimeError("copy should not be called directly outside of a numba.cuda.jit(...) kernel.")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def copy_fragment(src: OpaqueTensor, dst: OpaqueTensor):
|
|
123
|
+
raise RuntimeError("copy_fragment should not be called directly outside of a numba.cuda.jit(...) kernel.")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def clear(arr: OpaqueTensor):
|
|
127
|
+
raise RuntimeError("copy_c should not be called directly outside of a numba.cuda.jit(...) kernel.")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def copy_wait():
|
|
131
|
+
raise RuntimeError("copy_wait should not be called directly outside of a numba.cuda.jit(...) kernel.")
|
|
@@ -0,0 +1,125 @@
|
|
|
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 Callable
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from nvmath.device.common_cuda import ISAVersion
|
|
9
|
+
from .types import np_float16x2, np_float16x4
|
|
10
|
+
|
|
11
|
+
from nvmath.bindings import mathdx
|
|
12
|
+
|
|
13
|
+
MATHDX_TYPES_TO_NP = {
|
|
14
|
+
mathdx.CommondxValueType.R_16F: np.float16,
|
|
15
|
+
mathdx.CommondxValueType.R_16F2: np_float16x2,
|
|
16
|
+
mathdx.CommondxValueType.R_32F: np.float32,
|
|
17
|
+
mathdx.CommondxValueType.R_64F: np.float64,
|
|
18
|
+
mathdx.CommondxValueType.C_16F: np_float16x2,
|
|
19
|
+
mathdx.CommondxValueType.C_16F2: np_float16x4,
|
|
20
|
+
mathdx.CommondxValueType.C_32F: np.complex64,
|
|
21
|
+
mathdx.CommondxValueType.C_64F: np.complex128,
|
|
22
|
+
mathdx.CommondxValueType.R_8I: np.int8,
|
|
23
|
+
mathdx.CommondxValueType.R_16I: np.int16,
|
|
24
|
+
mathdx.CommondxValueType.R_32I: np.int32,
|
|
25
|
+
mathdx.CommondxValueType.R_64I: np.int64,
|
|
26
|
+
mathdx.CommondxValueType.R_8UI: np.uint8,
|
|
27
|
+
mathdx.CommondxValueType.R_16UI: np.uint16,
|
|
28
|
+
mathdx.CommondxValueType.R_32UI: np.uint32,
|
|
29
|
+
mathdx.CommondxValueType.R_64UI: np.uint64,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
NP_TYPES_TO_MATHDX_TYPES = {np_type: mathdx_type for mathdx_type, np_type in MATHDX_TYPES_TO_NP.items()}
|
|
34
|
+
|
|
35
|
+
NP_TYPES_TO_MATHDX_PRECISION = {
|
|
36
|
+
np.float16: mathdx.CommondxPrecision.F16,
|
|
37
|
+
np.float32: mathdx.CommondxPrecision.F32,
|
|
38
|
+
np.float64: mathdx.CommondxPrecision.F64,
|
|
39
|
+
np.int8: mathdx.CommondxPrecision.I8,
|
|
40
|
+
np.int16: mathdx.CommondxPrecision.I16,
|
|
41
|
+
np.int32: mathdx.CommondxPrecision.I32,
|
|
42
|
+
np.int64: mathdx.CommondxPrecision.I64,
|
|
43
|
+
np.uint8: mathdx.CommondxPrecision.UI8,
|
|
44
|
+
np.uint16: mathdx.CommondxPrecision.UI16,
|
|
45
|
+
np.uint32: mathdx.CommondxPrecision.UI32,
|
|
46
|
+
np.uint64: mathdx.CommondxPrecision.UI64,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
EXECUTION_STR_TO_MATHDX = {
|
|
50
|
+
"Block": mathdx.CommondxExecution.BLOCK,
|
|
51
|
+
"Thread": mathdx.CommondxExecution.THREAD,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
NVARG_GEN_OPT_LTO = "-gen-opt-lto"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class DescriptorWrapper:
|
|
58
|
+
"""
|
|
59
|
+
A smart pointer to a descriptor.
|
|
60
|
+
|
|
61
|
+
Lives as long as we need the descriptor (due to lru cache usage). Once the
|
|
62
|
+
descriptor is no longer needed/cached, it will trigger proper resource
|
|
63
|
+
deallocation.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
def __init__(self, descriptor, destructor):
|
|
67
|
+
self.descriptor = descriptor
|
|
68
|
+
self._destructor = destructor
|
|
69
|
+
|
|
70
|
+
def __del__(self):
|
|
71
|
+
if not self.descriptor:
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
self._destructor(self.descriptor)
|
|
75
|
+
|
|
76
|
+
# Safety clean up
|
|
77
|
+
self.descriptor = None
|
|
78
|
+
self._destructor = None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def get_lto(code_descriptor: int) -> bytes:
|
|
82
|
+
"""Get lto binary from the mathdx common code descriptor."""
|
|
83
|
+
lto_size = mathdx.commondx_get_code_ltoir_size(code_descriptor)
|
|
84
|
+
|
|
85
|
+
lto_fn = bytearray(lto_size)
|
|
86
|
+
mathdx.commondx_get_code_ltoir(code_descriptor, lto_size, lto_fn)
|
|
87
|
+
return bytes(lto_fn)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def get_isa_version(code_descriptor: int) -> ISAVersion:
|
|
91
|
+
"""Parse isa version from the mathdx common code descriptor."""
|
|
92
|
+
isa = mathdx.commondx_get_code_option_int64(code_descriptor, mathdx.CommondxOption.CODE_ISA)
|
|
93
|
+
return ISAVersion.from_integer(isa)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def build_get_int_traits(get_trait_int64s: Callable[[int, int, int, int], int]):
|
|
97
|
+
"""Generate function that returns mathdx tuple of int traits."""
|
|
98
|
+
|
|
99
|
+
def get_int_traits(handle: int, trait_type: int, size: int) -> tuple:
|
|
100
|
+
int_buffer = np.zeros(size, np.int64)
|
|
101
|
+
get_trait_int64s(handle, trait_type, size, int_buffer.ctypes.data)
|
|
102
|
+
return tuple(map(int, int_buffer))
|
|
103
|
+
|
|
104
|
+
return get_int_traits
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def build_get_str_trait(
|
|
108
|
+
get_trait_str_size: Callable[[int, int], int],
|
|
109
|
+
get_trait_str: Callable[[int, int, int, bytearray], bytearray],
|
|
110
|
+
):
|
|
111
|
+
"""Generate function that returns mathdx string trait."""
|
|
112
|
+
|
|
113
|
+
def get_str_trait(handle: int, trait_type: int) -> str:
|
|
114
|
+
symbol_size = get_trait_str_size(handle, trait_type)
|
|
115
|
+
|
|
116
|
+
symbol = bytearray(symbol_size)
|
|
117
|
+
|
|
118
|
+
get_trait_str(handle, trait_type, symbol_size, symbol)
|
|
119
|
+
|
|
120
|
+
# terminate trailing 0 (indicator of c-string end)
|
|
121
|
+
symbol_str = symbol[:-1].decode()
|
|
122
|
+
|
|
123
|
+
return symbol_str
|
|
124
|
+
|
|
125
|
+
return get_str_trait
|