3 #include <driver_types.h>
4 #include "iucore/coredefs.h"
28 const char* file=NULL,
const char*
function=NULL,
int line=0)
throw() :
29 IuException(std::string(
"CUDA Error: ") + cudaGetErrorString(cudaErr), file,
function, line),
47 static inline void checkCudaErrorState(
const char* file,
const char*
function,
const int line )
49 cudaDeviceSynchronize();
50 cudaError_t err = cudaGetLastError();
51 if( err != cudaSuccess )
58 static inline void checkCudaErrorState(cudaError_t err,
const char *file,
const char*
function,
61 if (cudaSuccess != err)
77 const char*
function = NULL,
int line = 0)
throw () :
78 IuException(std::string(
"CUFFT Error: ") + cufftGetErrorString(cudaErr),
79 file,
function, line),
85 cufftResult cufftResult_;
88 static const char *cufftGetErrorString(cufftResult err)
93 return "The cuFFT operation was successful.";
94 case CUFFT_INVALID_PLAN:
95 return "cuFFT was passed an invalid plan handle.";
96 case CUFFT_ALLOC_FAILED:
97 return "cuFFT failed to allocate GPU or CPU memory.";
98 case CUFFT_INVALID_VALUE:
99 return "User specified an invalid pointer or parameter.";
100 case CUFFT_INTERNAL_ERROR:
101 return "Driver or internal cuFFT library error";
102 case CUFFT_EXEC_FAILED:
103 return "Failed to execute an FFT on the GPU";
104 case CUFFT_SETUP_FAILED:
105 return "The cuFFT library failed to initialize";
106 case CUFFT_INVALID_SIZE:
107 return "User specified an invalid transform size";
108 case CUFFT_INCOMPLETE_PARAMETER_LIST:
109 return "Missing parameters in call";
110 case CUFFT_INVALID_DEVICE:
111 return "Execution of a plan was on different GPU than plan creation";
112 case CUFFT_PARSE_ERROR:
113 return "Internal plan database error";
114 case CUFFT_NO_WORKSPACE:
115 return "No workspace has been provided prior to plan execution";
117 return "Unknown CUFFT error.";
125 static inline void checkCufftErrorState(
const cufftResult status,
126 const char* file,
const char*
function,
129 if (status != CUFFT_SUCCESS)
136 static inline float getTotalGPUMemory()
140 cudaMemGetInfo(&free, &total);
141 return total/(1024.0f*1024.0f);
147 static inline float getFreeGPUMemory()
151 cudaMemGetInfo(&free, &total);
152 return free/(1024.0f*1024.0f);
158 static inline void printGPUMemoryUsage()
160 float total = iu::getTotalGPUMemory();
161 float free = iu::getFreeGPUMemory();
163 printf(
"GPU memory usage\n");
164 printf(
"----------------\n");
165 printf(
" Total memory: %.2f MiB\n", total);
166 printf(
" Used memory: %.2f MiB\n", total-free);
167 printf(
" Free memory: %.2f MiB\n", free);
175 static inline double getTime()
177 cudaDeviceSynchronize();
179 LARGE_INTEGER current_time,frequency;
180 QueryPerformanceCounter (¤t_time);
181 QueryPerformanceFrequency(&frequency);
182 return current_time.QuadPart*1000.0/frequency.QuadPart;
185 gettimeofday(&time, NULL);
186 return time.tv_sec * 1000.0 + time.tv_usec / 1000.0;
194 #define IU_CUDA_CHECK iu::checkCudaErrorState(__FILE__, __FUNCTION__, __LINE__)
195 #define IU_CUDA_SAFE_CALL(fun) iu::checkCudaErrorState(fun, __FILE__, __FUNCTION__, __LINE__)
196 #define IU_CUFFT_SAFE_CALL(state) iu::checkCufftErrorState(state, __FILE__, __FUNCTION__, __LINE__ )
Exceptions with additional error information.
Definition: coredefs.h:32
Exceptions related to cuda issues.
Definition: iucutil.h:24
Exceptions related to cufft issues.
Definition: iucutil.h:73