3
3
#include " kernel_helpers.h"
4
4
#include < nanobind/nanobind.h>
5
5
#include < cstddef>
6
+
7
+ #ifndef NO_CUDA_COMPILER
6
8
#include " cuda_runtime.h"
7
9
#include " plan_cache.h"
8
10
#include " s2fft_kernels.h"
9
11
#include " s2fft.h"
12
+ #else
13
+ void print_error () {
14
+
15
+ throw std::runtime_error (" This extension was compiled without CUDA support. Cuda functions are not supported." );
16
+ }
17
+ #endif
10
18
11
19
namespace nb = nanobind;
12
20
13
21
namespace s2fft {
14
22
23
+ #ifdef NO_CUDA_COMPILER
24
+ void healpix_fft_cuda () { print_error (); }
25
+ #else
15
26
void healpix_forward (cudaStream_t stream, void ** buffers, s2fftDescriptor descriptor) {
16
27
void * data = buffers[0 ];
17
28
void * output = buffers[1 ];
@@ -88,27 +99,7 @@ void healpix_fft_cuda(cudaStream_t stream, void** buffers, const char* opaque, s
88
99
}
89
100
}
90
101
91
- std::pair<int64_t , nb::bytes> build_healpix_fft_descriptor (int nside, int harmonic_band_limit, bool reality,
92
- bool forward, bool double_precision) {
93
- size_t work_size;
94
- // Only backward for now
95
- s2fftKernels::fft_norm norm = s2fftKernels::fft_norm::BACKWARD;
96
- // Always shift
97
- bool shift = true ;
98
- s2fftDescriptor descriptor (nside, harmonic_band_limit, reality, forward, norm, shift, double_precision);
99
-
100
- if (double_precision) {
101
- auto executor = std::make_shared<s2fftExec<cufftDoubleComplex>>();
102
- PlanCache::GetInstance ().GetS2FFTExec (descriptor, executor);
103
- executor->Initialize (descriptor, work_size);
104
- return std::pair<int64_t , nb::bytes>(work_size, PackDescriptor (descriptor));
105
- } else {
106
- auto executor = std::make_shared<s2fftExec<cufftComplex>>();
107
- PlanCache::GetInstance ().GetS2FFTExec (descriptor, executor);
108
- executor->Initialize (descriptor, work_size);
109
- return std::pair<int64_t , nb::bytes>(work_size, PackDescriptor (descriptor));
110
- }
111
- }
102
+ #endif // NO_CUDA_COMPILER
112
103
113
104
nb::dict Registration () {
114
105
nb::dict dict;
@@ -123,6 +114,7 @@ NB_MODULE(_s2fft, m) {
123
114
124
115
m.def (" build_healpix_fft_descriptor" ,
125
116
[](int nside, int harmonic_band_limit, bool reality, bool forward, bool double_precision) {
117
+ #ifndef NO_CUDA_COMPILER
126
118
size_t work_size;
127
119
// Only backward for now
128
120
s2fftKernels::fft_norm norm = s2fftKernels::fft_norm::BACKWARD;
@@ -142,5 +134,8 @@ NB_MODULE(_s2fft, m) {
142
134
executor->Initialize (descriptor, work_size);
143
135
return PackDescriptor (descriptor);
144
136
}
137
+ #else
138
+ print_error ();
139
+ #endif
145
140
});
146
141
}
0 commit comments