Skip to content

Commit c9c3461

Browse files
committed
Show error if cuda functions are used without cuda tool kit
1 parent e915949 commit c9c3461

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

lib/src/extensions.cc

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,26 @@
33
#include "kernel_helpers.h"
44
#include <nanobind/nanobind.h>
55
#include <cstddef>
6+
7+
#ifndef NO_CUDA_COMPILER
68
#include "cuda_runtime.h"
79
#include "plan_cache.h"
810
#include "s2fft_kernels.h"
911
#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
1018

1119
namespace nb = nanobind;
1220

1321
namespace s2fft {
1422

23+
#ifdef NO_CUDA_COMPILER
24+
void healpix_fft_cuda() { print_error(); }
25+
#else
1526
void healpix_forward(cudaStream_t stream, void** buffers, s2fftDescriptor descriptor) {
1627
void* data = buffers[0];
1728
void* output = buffers[1];
@@ -88,27 +99,7 @@ void healpix_fft_cuda(cudaStream_t stream, void** buffers, const char* opaque, s
8899
}
89100
}
90101

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
112103

113104
nb::dict Registration() {
114105
nb::dict dict;
@@ -123,6 +114,7 @@ NB_MODULE(_s2fft, m) {
123114

124115
m.def("build_healpix_fft_descriptor",
125116
[](int nside, int harmonic_band_limit, bool reality, bool forward, bool double_precision) {
117+
#ifndef NO_CUDA_COMPILER
126118
size_t work_size;
127119
// Only backward for now
128120
s2fftKernels::fft_norm norm = s2fftKernels::fft_norm::BACKWARD;
@@ -142,5 +134,8 @@ NB_MODULE(_s2fft, m) {
142134
executor->Initialize(descriptor, work_size);
143135
return PackDescriptor(descriptor);
144136
}
137+
#else
138+
print_error();
139+
#endif
145140
});
146141
}

0 commit comments

Comments
 (0)