47
47
#include < functional>
48
48
#include < optional>
49
49
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
+
50
81
namespace matx {
51
82
52
83
namespace detail {
@@ -267,7 +298,7 @@ template <typename OutTensorType, typename InTensorType> class matxCUDAFFTPlan_t
267
298
[[maybe_unused]] cufftResult res;
268
299
269
300
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 );
271
302
}
272
303
273
304
static inline constexpr cudaDataType GetInputType ()
@@ -402,7 +433,7 @@ matxCUDAFFTPlan1D_t(OutTensorType &o, const InTensorType &i, cudaStream_t stream
402
433
this ->params_ .output_type , this ->params_ .batch ,
403
434
&workspaceSize, this ->params_ .exec_type );
404
435
405
- MATX_ASSERT (error == CUFFT_SUCCESS, matxCufftError );
436
+ MATX_CUFFT_ASSERT_STR_EXP (error, CUFFT_SUCCESS );
406
437
407
438
matxAlloc ((void **)&this ->workspace_ , workspaceSize, MATX_ASYNC_DEVICE_MEMORY, stream);
408
439
@@ -415,7 +446,7 @@ matxCUDAFFTPlan1D_t(OutTensorType &o, const InTensorType &i, cudaStream_t stream
415
446
this ->params_ .output_type , this ->params_ .batch , &workspaceSize,
416
447
this ->params_ .exec_type );
417
448
418
- MATX_ASSERT (error == CUFFT_SUCCESS, matxCufftError );
449
+ MATX_CUFFT_ASSERT_STR_EXP (error, CUFFT_SUCCESS );
419
450
}
420
451
421
452
private:
@@ -526,15 +557,17 @@ class matxCUDAFFTPlan2D_t : public matxCUDAFFTPlan_t<OutTensorType, InTensorType
526
557
size_t workspaceSize;
527
558
cufftCreate (&this ->plan_ );
528
559
[[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 ,
530
561
this ->params_ .istride , this ->params_ .idist ,
531
562
this ->params_ .input_type , this ->params_ .onembed ,
532
563
this ->params_ .ostride , this ->params_ .odist ,
533
564
this ->params_ .output_type , this ->params_ .batch ,
534
565
&workspaceSize, this ->params_ .exec_type );
566
+ MATX_CUFFT_ASSERT_STR_EXP (error, CUFFT_SUCCESS);
535
567
536
568
matxAlloc ((void **)&this ->workspace_ , workspaceSize, MATX_ASYNC_DEVICE_MEMORY, stream);
537
569
cufftSetWorkArea (this ->plan_ , this ->workspace_ );
570
+ MATX_CUFFT_ASSERT_STR_EXP (error, CUFFT_SUCCESS);
538
571
539
572
error = cufftXtMakePlanMany (
540
573
this ->plan_ , 2 , this ->params_ .n , this ->params_ .inembed ,
@@ -543,7 +576,7 @@ class matxCUDAFFTPlan2D_t : public matxCUDAFFTPlan_t<OutTensorType, InTensorType
543
576
this ->params_ .output_type , this ->params_ .batch , &workspaceSize,
544
577
this ->params_ .exec_type );
545
578
546
- MATX_ASSERT (error == CUFFT_SUCCESS, matxCufftError );
579
+ MATX_CUFFT_ASSERT_STR_EXP (error, CUFFT_SUCCESS );
547
580
}
548
581
549
582
private:
0 commit comments