|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "ATen/ATen.h" |
| 4 | +#include "ATen/Config.h" |
| 5 | + |
| 6 | +#include <string> |
| 7 | +#include <stdexcept> |
| 8 | +#include <sstream> |
| 9 | +#include <cufft.h> |
| 10 | +#include <cufftXt.h> |
| 11 | + |
| 12 | + |
| 13 | +namespace at { namespace native { |
| 14 | + |
| 15 | +static inline std::string _cudaGetErrorEnum(cufftResult error) |
| 16 | +{ |
| 17 | + switch (error) |
| 18 | + { |
| 19 | + case CUFFT_SUCCESS: |
| 20 | + return "CUFFT_SUCCESS"; |
| 21 | + case CUFFT_INVALID_PLAN: |
| 22 | + return "CUFFT_INVALID_PLAN"; |
| 23 | + case CUFFT_ALLOC_FAILED: |
| 24 | + return "CUFFT_ALLOC_FAILED"; |
| 25 | + case CUFFT_INVALID_TYPE: |
| 26 | + return "CUFFT_INVALID_TYPE"; |
| 27 | + case CUFFT_INVALID_VALUE: |
| 28 | + return "CUFFT_INVALID_VALUE"; |
| 29 | + case CUFFT_INTERNAL_ERROR: |
| 30 | + return "CUFFT_INTERNAL_ERROR"; |
| 31 | + case CUFFT_EXEC_FAILED: |
| 32 | + return "CUFFT_EXEC_FAILED"; |
| 33 | + case CUFFT_SETUP_FAILED: |
| 34 | + return "CUFFT_SETUP_FAILED"; |
| 35 | + case CUFFT_INVALID_SIZE: |
| 36 | + return "CUFFT_INVALID_SIZE"; |
| 37 | + case CUFFT_UNALIGNED_DATA: |
| 38 | + return "CUFFT_UNALIGNED_DATA"; |
| 39 | + case CUFFT_INCOMPLETE_PARAMETER_LIST: |
| 40 | + return "CUFFT_INCOMPLETE_PARAMETER_LIST"; |
| 41 | + case CUFFT_INVALID_DEVICE: |
| 42 | + return "CUFFT_INVALID_DEVICE"; |
| 43 | + case CUFFT_PARSE_ERROR: |
| 44 | + return "CUFFT_PARSE_ERROR"; |
| 45 | + case CUFFT_NO_WORKSPACE: |
| 46 | + return "CUFFT_NO_WORKSPACE"; |
| 47 | + case CUFFT_NOT_IMPLEMENTED: |
| 48 | + return "CUFFT_NOT_IMPLEMENTED"; |
| 49 | + case CUFFT_LICENSE_ERROR: |
| 50 | + return "CUFFT_LICENSE_ERROR"; |
| 51 | + case CUFFT_NOT_SUPPORTED: |
| 52 | + return "CUFFT_NOT_SUPPORTED"; |
| 53 | + default: |
| 54 | + std::ostringstream ss; |
| 55 | + ss << "unknown error " << error; |
| 56 | + return ss.str(); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +static inline void CUFFT_CHECK(cufftResult error) |
| 61 | +{ |
| 62 | + if (error != CUFFT_SUCCESS) { |
| 63 | + std::ostringstream ss; |
| 64 | + ss << "cuFFT error: " << _cudaGetErrorEnum(error); |
| 65 | + throw std::runtime_error(ss.str()); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +class CufftHandle { |
| 70 | +public: |
| 71 | + explicit CufftHandle() { |
| 72 | + CUFFT_CHECK(cufftCreate(&raw_plan)); |
| 73 | + } |
| 74 | + |
| 75 | + const cufftHandle &get() const { return raw_plan; } |
| 76 | + |
| 77 | + ~CufftHandle() { |
| 78 | + CUFFT_CHECK(cufftDestroy(raw_plan)); |
| 79 | + } |
| 80 | +private: |
| 81 | + cufftHandle raw_plan; |
| 82 | +}; |
| 83 | + |
| 84 | +}} // at::native |
0 commit comments