Skip to content

Commit effec8f

Browse files
authored
Improve cuFFT errors (#860)
1 parent 8bf818a commit effec8f

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

include/matx/transforms/fft/fft_cuda.h

+38-5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,37 @@
4747
#include <functional>
4848
#include <optional>
4949

50+
#define MATX_CUFFT_ASSERT_STR_EXP(a, expected) \
51+
{ \
52+
auto tmp = a; \
53+
if ((tmp != expected)) \
54+
{ \
55+
std::string fft_str = ""; \
56+
switch (tmp) {\
57+
case CUFFT_SUCCESS: fft_str = "cuFFT: The operation was successful"; break; \
58+
case CUFFT_INVALID_PLAN: fft_str = "cuFFT was passed an invalid plan handle"; break; \
59+
case CUFFT_ALLOC_FAILED: fft_str = "cuFFT failed to allocate GPU or CPU memory"; break; \
60+
case CUFFT_INVALID_TYPE: fft_str = "cuFFT: invalid type passed"; break; \
61+
case CUFFT_INVALID_VALUE: fft_str = "cuFFT: User specified an invalid pointer or parameter"; break; \
62+
case CUFFT_INTERNAL_ERROR: fft_str = "cuFFT: Driver or internal library error"; break; \
63+
case CUFFT_EXEC_FAILED: fft_str = "cuFFT: Failed to execute an FFT on the GPU"; break; \
64+
case CUFFT_SETUP_FAILED: fft_str = "The cuFFT library failed to initialize"; break; \
65+
case CUFFT_INVALID_SIZE: fft_str = "cuFFT: User specified an invalid transform size"; break; \
66+
case CUFFT_UNALIGNED_DATA: fft_str = "cuFFT: Input or output data is not aligned"; break; \
67+
case CUFFT_INCOMPLETE_PARAMETER_LIST: fft_str = "cuFFT: Missing parameters in call"; break; \
68+
case CUFFT_INVALID_DEVICE: fft_str = "cuFFT: Execution of a plan was on different GPU than plan creation"; break; \
69+
case CUFFT_PARSE_ERROR: fft_str = "cuFFT: Internal plan database error"; break; \
70+
case CUFFT_NO_WORKSPACE: fft_str = "cuFFT: No workspace has been provided prior to plan execution"; break; \
71+
case CUFFT_NOT_IMPLEMENTED: fft_str = "cuFFT: Function does not implement functionality for parameters"; break; \
72+
case CUFFT_LICENSE_ERROR: fft_str = "cuFFT: Used in previous versions"; break; \
73+
case CUFFT_NOT_SUPPORTED: fft_str = "cuFFT: Operation is not supported for parameters"; break; \
74+
default: fft_str = "cuFFT: Unknown error"; break; \
75+
} \
76+
std::cout << #a ": " << "(" << tmp << " != " << expected << "): " << fft_str << "\n";\
77+
MATX_THROW(matxCufftError, ""); \
78+
} \
79+
}
80+
5081
namespace matx {
5182

5283
namespace detail {
@@ -267,7 +298,7 @@ template <typename OutTensorType, typename InTensorType> class matxCUDAFFTPlan_t
267298
[[maybe_unused]] cufftResult res;
268299

269300
res = cufftXtExec(this->plan_, (void *)idata, (void *)odata, dir);
270-
MATX_ASSERT(res == CUFFT_SUCCESS, matxCufftError);
301+
MATX_CUFFT_ASSERT_STR_EXP(res, CUFFT_SUCCESS);
271302
}
272303

273304
static inline constexpr cudaDataType GetInputType()
@@ -402,7 +433,7 @@ matxCUDAFFTPlan1D_t(OutTensorType &o, const InTensorType &i, cudaStream_t stream
402433
this->params_.output_type, this->params_.batch,
403434
&workspaceSize, this->params_.exec_type);
404435

405-
MATX_ASSERT(error == CUFFT_SUCCESS, matxCufftError);
436+
MATX_CUFFT_ASSERT_STR_EXP(error, CUFFT_SUCCESS);
406437

407438
matxAlloc((void **)&this->workspace_, workspaceSize, MATX_ASYNC_DEVICE_MEMORY, stream);
408439

@@ -415,7 +446,7 @@ matxCUDAFFTPlan1D_t(OutTensorType &o, const InTensorType &i, cudaStream_t stream
415446
this->params_.output_type, this->params_.batch, &workspaceSize,
416447
this->params_.exec_type);
417448

418-
MATX_ASSERT(error == CUFFT_SUCCESS, matxCufftError);
449+
MATX_CUFFT_ASSERT_STR_EXP(error, CUFFT_SUCCESS);
419450
}
420451

421452
private:
@@ -526,15 +557,17 @@ class matxCUDAFFTPlan2D_t : public matxCUDAFFTPlan_t<OutTensorType, InTensorType
526557
size_t workspaceSize;
527558
cufftCreate(&this->plan_);
528559
[[maybe_unused]] cufftResult error;
529-
cufftXtGetSizeMany(this->plan_, 2, this->params_.n, this->params_.inembed,
560+
error = cufftXtGetSizeMany(this->plan_, 2, this->params_.n, this->params_.inembed,
530561
this->params_.istride, this->params_.idist,
531562
this->params_.input_type, this->params_.onembed,
532563
this->params_.ostride, this->params_.odist,
533564
this->params_.output_type, this->params_.batch,
534565
&workspaceSize, this->params_.exec_type);
566+
MATX_CUFFT_ASSERT_STR_EXP(error, CUFFT_SUCCESS);
535567

536568
matxAlloc((void **)&this->workspace_, workspaceSize, MATX_ASYNC_DEVICE_MEMORY, stream);
537569
cufftSetWorkArea(this->plan_, this->workspace_);
570+
MATX_CUFFT_ASSERT_STR_EXP(error, CUFFT_SUCCESS);
538571

539572
error = cufftXtMakePlanMany(
540573
this->plan_, 2, this->params_.n, this->params_.inembed,
@@ -543,7 +576,7 @@ class matxCUDAFFTPlan2D_t : public matxCUDAFFTPlan_t<OutTensorType, InTensorType
543576
this->params_.output_type, this->params_.batch, &workspaceSize,
544577
this->params_.exec_type);
545578

546-
MATX_ASSERT(error == CUFFT_SUCCESS, matxCufftError);
579+
MATX_CUFFT_ASSERT_STR_EXP(error, CUFFT_SUCCESS);
547580
}
548581

549582
private:

0 commit comments

Comments
 (0)