13 #define __PRETTY_FUNCTION__ __FUNCTION__
18 #define cytnx_error_msg(is_true, format, ...) {error_msg ( __PRETTY_FUNCTION__, __FILE__, __LINE__, (is_true), (format), __VA_ARGS__);}
19 static inline void error_msg(
char const *
const func,
const char *
const file,
int const line,
bool is_true,
char const* format, ...){
24 char output_str[1024];
26 va_start(args, format);
27 vsprintf(msg, format, args);
28 sprintf(output_str,
"\n# Cytnx error occur at %s\n# error: %s\n# file : %s (%d)", func, msg, file, line) ;
30 throw std::logic_error(output_str);
32 }
catch(
const char *output_msg){
33 std::cerr << output_msg << std::endl;
37 #define cytnx_warning_msg(is_true, format, ...) {warning_msg ( __PRETTY_FUNCTION__, __FILE__, __LINE__, (is_true), (format), __VA_ARGS__);}
38 static inline void warning_msg(
char const *
const func,
const char *
const file,
int const line,
bool is_true,
char const* format, ...){
42 char output_str[1024];
44 va_start(args, format);
45 vsprintf(msg, format, args);
46 sprintf(output_str,
"\n# Cytnx warning occur at %s\n# warning: %s\n# file : %s (%d)", func, msg, file, line) ;
48 std::cerr << output_str << std::endl;
56 #include <cuda_runtime.h>
57 #include <cublas_v2.h>
58 #include <cusolverDn.h>
59 #include <cuComplex.h>
62 #ifdef __DRIVER_TYPES_H__
63 static const char *_cudaGetErrorEnum(cudaError_t error)
70 case cudaErrorMissingConfiguration:
71 return "cudaErrorMissingConfiguration";
73 case cudaErrorMemoryAllocation:
74 return "cudaErrorMemoryAllocation";
76 case cudaErrorInitializationError:
77 return "cudaErrorInitializationError";
79 case cudaErrorLaunchFailure:
80 return "cudaErrorLaunchFailure";
82 case cudaErrorPriorLaunchFailure:
83 return "cudaErrorPriorLaunchFailure";
85 case cudaErrorLaunchTimeout:
86 return "cudaErrorLaunchTimeout";
88 case cudaErrorLaunchOutOfResources:
89 return "cudaErrorLaunchOutOfResources";
91 case cudaErrorInvalidDeviceFunction:
92 return "cudaErrorInvalidDeviceFunction";
94 case cudaErrorInvalidConfiguration:
95 return "cudaErrorInvalidConfiguration";
97 case cudaErrorInvalidDevice:
98 return "cudaErrorInvalidDevice";
100 case cudaErrorInvalidValue:
101 return "cudaErrorInvalidValue";
103 case cudaErrorInvalidPitchValue:
104 return "cudaErrorInvalidPitchValue";
106 case cudaErrorInvalidSymbol:
107 return "cudaErrorInvalidSymbol";
109 case cudaErrorMapBufferObjectFailed:
110 return "cudaErrorMapBufferObjectFailed";
112 case cudaErrorUnmapBufferObjectFailed:
113 return "cudaErrorUnmapBufferObjectFailed";
115 case cudaErrorInvalidHostPointer:
116 return "cudaErrorInvalidHostPointer";
118 case cudaErrorInvalidDevicePointer:
119 return "cudaErrorInvalidDevicePointer";
121 case cudaErrorInvalidTexture:
122 return "cudaErrorInvalidTexture";
124 case cudaErrorInvalidTextureBinding:
125 return "cudaErrorInvalidTextureBinding";
127 case cudaErrorInvalidChannelDescriptor:
128 return "cudaErrorInvalidChannelDescriptor";
130 case cudaErrorInvalidMemcpyDirection:
131 return "cudaErrorInvalidMemcpyDirection";
133 case cudaErrorAddressOfConstant:
134 return "cudaErrorAddressOfConstant";
136 case cudaErrorTextureFetchFailed:
137 return "cudaErrorTextureFetchFailed";
139 case cudaErrorTextureNotBound:
140 return "cudaErrorTextureNotBound";
142 case cudaErrorSynchronizationError:
143 return "cudaErrorSynchronizationError";
145 case cudaErrorInvalidFilterSetting:
146 return "cudaErrorInvalidFilterSetting";
148 case cudaErrorInvalidNormSetting:
149 return "cudaErrorInvalidNormSetting";
151 case cudaErrorMixedDeviceExecution:
152 return "cudaErrorMixedDeviceExecution";
154 case cudaErrorCudartUnloading:
155 return "cudaErrorCudartUnloading";
157 case cudaErrorUnknown:
158 return "cudaErrorUnknown";
160 case cudaErrorNotYetImplemented:
161 return "cudaErrorNotYetImplemented";
163 case cudaErrorMemoryValueTooLarge:
164 return "cudaErrorMemoryValueTooLarge";
166 case cudaErrorInvalidResourceHandle:
167 return "cudaErrorInvalidResourceHandle";
169 case cudaErrorNotReady:
170 return "cudaErrorNotReady";
172 case cudaErrorInsufficientDriver:
173 return "cudaErrorInsufficientDriver";
175 case cudaErrorSetOnActiveProcess:
176 return "cudaErrorSetOnActiveProcess";
178 case cudaErrorInvalidSurface:
179 return "cudaErrorInvalidSurface";
181 case cudaErrorNoDevice:
182 return "cudaErrorNoDevice";
184 case cudaErrorECCUncorrectable:
185 return "cudaErrorECCUncorrectable";
187 case cudaErrorSharedObjectSymbolNotFound:
188 return "cudaErrorSharedObjectSymbolNotFound";
190 case cudaErrorSharedObjectInitFailed:
191 return "cudaErrorSharedObjectInitFailed";
193 case cudaErrorUnsupportedLimit:
194 return "cudaErrorUnsupportedLimit";
196 case cudaErrorDuplicateVariableName:
197 return "cudaErrorDuplicateVariableName";
199 case cudaErrorDuplicateTextureName:
200 return "cudaErrorDuplicateTextureName";
202 case cudaErrorDuplicateSurfaceName:
203 return "cudaErrorDuplicateSurfaceName";
205 case cudaErrorDevicesUnavailable:
206 return "cudaErrorDevicesUnavailable";
208 case cudaErrorInvalidKernelImage:
209 return "cudaErrorInvalidKernelImage";
211 case cudaErrorNoKernelImageForDevice:
212 return "cudaErrorNoKernelImageForDevice";
214 case cudaErrorIncompatibleDriverContext:
215 return "cudaErrorIncompatibleDriverContext";
217 case cudaErrorPeerAccessAlreadyEnabled:
218 return "cudaErrorPeerAccessAlreadyEnabled";
220 case cudaErrorPeerAccessNotEnabled:
221 return "cudaErrorPeerAccessNotEnabled";
223 case cudaErrorDeviceAlreadyInUse:
224 return "cudaErrorDeviceAlreadyInUse";
226 case cudaErrorProfilerDisabled:
227 return "cudaErrorProfilerDisabled";
229 case cudaErrorProfilerNotInitialized:
230 return "cudaErrorProfilerNotInitialized";
232 case cudaErrorProfilerAlreadyStarted:
233 return "cudaErrorProfilerAlreadyStarted";
235 case cudaErrorProfilerAlreadyStopped:
236 return "cudaErrorProfilerAlreadyStopped";
239 case cudaErrorAssert:
240 return "cudaErrorAssert";
242 case cudaErrorTooManyPeers:
243 return "cudaErrorTooManyPeers";
245 case cudaErrorHostMemoryAlreadyRegistered:
246 return "cudaErrorHostMemoryAlreadyRegistered";
248 case cudaErrorHostMemoryNotRegistered:
249 return "cudaErrorHostMemoryNotRegistered";
252 case cudaErrorOperatingSystem:
253 return "cudaErrorOperatingSystem";
255 case cudaErrorPeerAccessUnsupported:
256 return "cudaErrorPeerAccessUnsupported";
258 case cudaErrorLaunchMaxDepthExceeded:
259 return "cudaErrorLaunchMaxDepthExceeded";
261 case cudaErrorLaunchFileScopedTex:
262 return "cudaErrorLaunchFileScopedTex";
264 case cudaErrorLaunchFileScopedSurf:
265 return "cudaErrorLaunchFileScopedSurf";
267 case cudaErrorSyncDepthExceeded:
268 return "cudaErrorSyncDepthExceeded";
270 case cudaErrorLaunchPendingCountExceeded:
271 return "cudaErrorLaunchPendingCountExceeded";
273 case cudaErrorNotPermitted:
274 return "cudaErrorNotPermitted";
276 case cudaErrorNotSupported:
277 return "cudaErrorNotSupported";
280 case cudaErrorHardwareStackError:
281 return "cudaErrorHardwareStackError";
283 case cudaErrorIllegalInstruction:
284 return "cudaErrorIllegalInstruction";
286 case cudaErrorMisalignedAddress:
287 return "cudaErrorMisalignedAddress";
289 case cudaErrorInvalidAddressSpace:
290 return "cudaErrorInvalidAddressSpace";
292 case cudaErrorInvalidPc:
293 return "cudaErrorInvalidPc";
295 case cudaErrorIllegalAddress:
296 return "cudaErrorIllegalAddress";
299 case cudaErrorInvalidPtx:
300 return "cudaErrorInvalidPtx";
302 case cudaErrorInvalidGraphicsContext:
303 return "cudaErrorInvalidGraphicsContext";
305 case cudaErrorStartupFailure:
306 return "cudaErrorStartupFailure";
308 case cudaErrorApiFailureBase:
309 return "cudaErrorApiFailureBase";
312 case cudaErrorNvlinkUncorrectable :
313 return "cudaErrorNvlinkUncorrectable";
324 static const char *_cudaGetErrorEnum(cublasStatus_t error)
328 case CUBLAS_STATUS_SUCCESS:
329 return "CUBLAS_STATUS_SUCCESS";
331 case CUBLAS_STATUS_NOT_INITIALIZED:
332 return "CUBLAS_STATUS_NOT_INITIALIZED";
334 case CUBLAS_STATUS_ALLOC_FAILED:
335 return "CUBLAS_STATUS_ALLOC_FAILED";
337 case CUBLAS_STATUS_INVALID_VALUE:
338 return "CUBLAS_STATUS_INVALID_VALUE";
340 case CUBLAS_STATUS_ARCH_MISMATCH:
341 return "CUBLAS_STATUS_ARCH_MISMATCH";
343 case CUBLAS_STATUS_MAPPING_ERROR:
344 return "CUBLAS_STATUS_MAPPING_ERROR";
346 case CUBLAS_STATUS_EXECUTION_FAILED:
347 return "CUBLAS_STATUS_EXECUTION_FAILED";
349 case CUBLAS_STATUS_INTERNAL_ERROR:
350 return "CUBLAS_STATUS_INTERNAL_ERROR";
352 case CUBLAS_STATUS_NOT_SUPPORTED:
353 return "CUBLAS_STATUS_NOT_SUPPORTED";
355 case CUBLAS_STATUS_LICENSE_ERROR:
356 return "CUBLAS_STATUS_LICENSE_ERROR";
363 #ifdef CUSOLVER_COMMON_H_
365 static const char *_cudaGetErrorEnum(cusolverStatus_t error)
369 case CUSOLVER_STATUS_SUCCESS:
370 return "CUSOLVER_STATUS_SUCCESS";
371 case CUSOLVER_STATUS_NOT_INITIALIZED:
372 return "CUSOLVER_STATUS_NOT_INITIALIZED";
373 case CUSOLVER_STATUS_ALLOC_FAILED:
374 return "CUSOLVER_STATUS_ALLOC_FAILED";
375 case CUSOLVER_STATUS_INVALID_VALUE:
376 return "CUSOLVER_STATUS_INVALID_VALUE";
377 case CUSOLVER_STATUS_ARCH_MISMATCH:
378 return "CUSOLVER_STATUS_ARCH_MISMATCH";
379 case CUSOLVER_STATUS_MAPPING_ERROR:
380 return "CUSOLVER_STATUS_MAPPING_ERROR";
381 case CUSOLVER_STATUS_EXECUTION_FAILED:
382 return "CUSOLVER_STATUS_EXECUTION_FAILED";
383 case CUSOLVER_STATUS_INTERNAL_ERROR:
384 return "CUSOLVER_STATUS_INTERNAL_ERROR";
385 case CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
386 return "CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED";
387 case CUSOLVER_STATUS_NOT_SUPPORTED :
388 return "CUSOLVER_STATUS_NOT_SUPPORTED ";
389 case CUSOLVER_STATUS_ZERO_PIVOT:
390 return "CUSOLVER_STATUS_ZERO_PIVOT";
391 case CUSOLVER_STATUS_INVALID_LICENSE:
392 return "CUSOLVER_STATUS_INVALID_LICENSE";
402 static const char *_cudaGetErrorEnum(curandStatus_t error)
406 case CURAND_STATUS_SUCCESS:
return "CURAND_STATUS_SUCCESS";
407 case CURAND_STATUS_VERSION_MISMATCH:
return "CURAND_STATUS_VERSION_MISMATCH";
408 case CURAND_STATUS_NOT_INITIALIZED:
return "CURAND_STATUS_NOT_INITIALIZED";
409 case CURAND_STATUS_ALLOCATION_FAILED:
return "CURAND_STATUS_ALLOCATION_FAILED";
410 case CURAND_STATUS_TYPE_ERROR:
return "CURAND_STATUS_TYPE_ERROR";
411 case CURAND_STATUS_OUT_OF_RANGE:
return "CURAND_STATUS_OUT_OF_RANGE";
412 case CURAND_STATUS_LENGTH_NOT_MULTIPLE:
return "CURAND_STATUS_LENGTH_NOT_MULTIPLE";
413 case CURAND_STATUS_DOUBLE_PRECISION_REQUIRED:
return "CURAND_STATUS_DOUBLE_PRECISION_REQUIRED";
414 case CURAND_STATUS_LAUNCH_FAILURE:
return "CURAND_STATUS_LAUNCH_FAILURE";
415 case CURAND_STATUS_PREEXISTING_FAILURE:
return "CURAND_STATUS_PREEXISTING_FAILURE";
416 case CURAND_STATUS_INITIALIZATION_FAILED:
return "CURAND_STATUS_INITIALIZATION_FAILED";
417 case CURAND_STATUS_ARCH_MISMATCH:
return "CURAND_STATUS_ARCH_MISMATCH";
418 case CURAND_STATUS_INTERNAL_ERROR:
return "CURAND_STATUS_INTERNAL_ERROR";
430 #ifdef __DRIVER_TYPES_H__
432 #define DEVICE_RESET cudaDeviceReset();
440 template<
typename T >
441 void check(T result,
char const *
const func,
const char *
const file,
int const line)
445 fprintf(stderr,
"CUDA error at %s:%d code=%d(%s) \"%s\" \n",
446 file, line,
static_cast<unsigned int>(result), _cudaGetErrorEnum(result), func);
453 #ifdef __DRIVER_TYPES_H__
455 #define checkCudaErrors(val) check ( (val), #val, __FILE__, __LINE__ )