Loading [MathJax]/extensions/MathZoom.js
cuML C++ API  23.12
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cufft_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2022, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cufft.h>
20 #include <raft/core/error.hpp>
21 
22 // TODO move to raft https://github.com/rapidsai/raft/issues/91
23 namespace raft {
24 
28 struct cufft_error : public raft::exception {
29  explicit cufft_error(char const* const message) : raft::exception(message) {}
30  explicit cufft_error(std::string const& message) : raft::exception(message) {}
31 };
32 
33 const char* getCufftErrStr(cufftResult status)
34 {
35  // https://docs.nvidia.com/cuda/cufft/index.html#cufftresult
36  switch (status) {
37  case CUFFT_SUCCESS: return "The cuFFT operation was successful.";
38  case CUFFT_INVALID_PLAN: return "cuFFT was passed an invalid plan handle.";
39  case CUFFT_ALLOC_FAILED: return "cuFFT failed to allocate GPU or CPU memory.";
40  case CUFFT_INVALID_VALUE: return "User specified an invalid pointer or parameter.";
41  case CUFFT_INTERNAL_ERROR: return "Driver or internal cuFFT library error.";
42  case CUFFT_EXEC_FAILED: return "Failed to execute an FFT on the GPU.";
43  case CUFFT_SETUP_FAILED: return "The cuFFT library failed to initialize.";
44  case CUFFT_INVALID_SIZE: return "User specified an invalid transform size.";
45  case CUFFT_INCOMPLETE_PARAMETER_LIST: return "Missing parameters in call.";
46  case CUFFT_INVALID_DEVICE:
47  return "Execution of a plan was on different GPU than plan creation.";
48  case CUFFT_PARSE_ERROR: return "Internal plan database error.";
49  case CUFFT_NO_WORKSPACE: return "No workspace has been provided prior to plan execution.";
50  case CUFFT_NOT_IMPLEMENTED:
51  return "Function does not implement functionality for parameters given.";
52  case CUFFT_NOT_SUPPORTED: return "Operation is not supported for parameters given.";
53  default: return "Unknown error.";
54  }
55 }
56 
63 #define CUFFT_TRY(call) \
64  do { \
65  const cufftResult status = call; \
66  if (status != CUFFT_SUCCESS) { \
67  std::string msg{}; \
68  SET_ERROR_MSG(msg, \
69  "cuFFT error encountered at: ", \
70  "call='%s', Reason=%s", \
71  #call, \
72  raft::getCufftErrStr(status)); \
73  throw raft::cufft_error(msg); \
74  } \
75  } while (0)
76 
77 class CuFFTHandle {
78  public:
79  CuFFTHandle(cudaStream_t stream)
80  {
81  CUFFT_TRY(cufftCreate(&handle));
82  CUFFT_TRY(cufftSetStream(handle, stream));
83  }
84  ~CuFFTHandle() { cufftDestroy(handle); }
85  operator cufftHandle() const { return handle; }
86 
87  private:
88  cufftHandle handle;
89 };
90 
91 } // namespace raft
Definition: cufft_utils.h:77
~CuFFTHandle()
Definition: cufft_utils.h:84
CuFFTHandle(cudaStream_t stream)
Definition: cufft_utils.h:79
#define CUFFT_TRY(call)
Error checking macro for cuFFT functions.
Definition: cufft_utils.h:63
Definition: dbscan.hpp:23
const char * getCufftErrStr(cufftResult status)
Definition: cufft_utils.h:33
Exception thrown when a cuFFT error is encountered.
Definition: cufft_utils.h:28
cufft_error(std::string const &message)
Definition: cufft_utils.h:30
cufft_error(char const *const message)
Definition: cufft_utils.h:29