13 #define __PRETTY_FUNCTION__ __FUNCTION__
16#define cytnx_error_msg(is_true, format, ...) \
19 error_msg(__PRETTY_FUNCTION__, __FILE__, __LINE__, (is_true), (format), __VA_ARGS__); \
21static inline void error_msg(
char const *
const func,
const char *
const file,
int const line,
22 bool is_true,
char const *format, ...) {
26 char output_str[1024];
28 va_start(args, format);
29 vsprintf(msg, format, args);
30 sprintf(output_str,
"\n# Cytnx error occur at %s\n# error: %s\n# file : %s (%d)", func, msg,
34 throw std::logic_error(output_str);
40#define cytnx_warning_msg(is_true, format, ...) \
43 warning_msg(__PRETTY_FUNCTION__, __FILE__, __LINE__, (is_true), (format), __VA_ARGS__); \
45static inline void warning_msg(
char const *
const func,
const char *
const file,
int const line,
46 bool is_true,
char const *format, ...) {
49 char output_str[1024];
51 va_start(args, format);
52 vsprintf(msg, format, args);
53 sprintf(output_str,
"\n# Cytnx warning occur at %s\n# warning: %s\n# file : %s (%d)", func, msg,
56 std::cerr << output_str << std::endl;
63 #include <cuda_runtime.h>
64 #include <cublas_v2.h>
65 #include <cusolverDn.h>
66 #include <cuComplex.h>
70 #ifdef __DRIVER_TYPES_H__
71static const char *_cudaGetErrorEnum(cudaError_t error) {
76 case cudaErrorMissingConfiguration:
77 return "cudaErrorMissingConfiguration";
79 case cudaErrorMemoryAllocation:
80 return "cudaErrorMemoryAllocation";
82 case cudaErrorInitializationError:
83 return "cudaErrorInitializationError";
85 case cudaErrorLaunchFailure:
86 return "cudaErrorLaunchFailure";
88 case cudaErrorPriorLaunchFailure:
89 return "cudaErrorPriorLaunchFailure";
91 case cudaErrorLaunchTimeout:
92 return "cudaErrorLaunchTimeout";
94 case cudaErrorLaunchOutOfResources:
95 return "cudaErrorLaunchOutOfResources";
97 case cudaErrorInvalidDeviceFunction:
98 return "cudaErrorInvalidDeviceFunction";
100 case cudaErrorInvalidConfiguration:
101 return "cudaErrorInvalidConfiguration";
103 case cudaErrorInvalidDevice:
104 return "cudaErrorInvalidDevice";
106 case cudaErrorInvalidValue:
107 return "cudaErrorInvalidValue";
109 case cudaErrorInvalidPitchValue:
110 return "cudaErrorInvalidPitchValue";
112 case cudaErrorInvalidSymbol:
113 return "cudaErrorInvalidSymbol";
115 case cudaErrorMapBufferObjectFailed:
116 return "cudaErrorMapBufferObjectFailed";
118 case cudaErrorUnmapBufferObjectFailed:
119 return "cudaErrorUnmapBufferObjectFailed";
121 case cudaErrorInvalidHostPointer:
122 return "cudaErrorInvalidHostPointer";
124 case cudaErrorInvalidDevicePointer:
125 return "cudaErrorInvalidDevicePointer";
127 case cudaErrorInvalidTexture:
128 return "cudaErrorInvalidTexture";
130 case cudaErrorInvalidTextureBinding:
131 return "cudaErrorInvalidTextureBinding";
133 case cudaErrorInvalidChannelDescriptor:
134 return "cudaErrorInvalidChannelDescriptor";
136 case cudaErrorInvalidMemcpyDirection:
137 return "cudaErrorInvalidMemcpyDirection";
139 case cudaErrorAddressOfConstant:
140 return "cudaErrorAddressOfConstant";
142 case cudaErrorTextureFetchFailed:
143 return "cudaErrorTextureFetchFailed";
145 case cudaErrorTextureNotBound:
146 return "cudaErrorTextureNotBound";
148 case cudaErrorSynchronizationError:
149 return "cudaErrorSynchronizationError";
151 case cudaErrorInvalidFilterSetting:
152 return "cudaErrorInvalidFilterSetting";
154 case cudaErrorInvalidNormSetting:
155 return "cudaErrorInvalidNormSetting";
157 case cudaErrorMixedDeviceExecution:
158 return "cudaErrorMixedDeviceExecution";
160 case cudaErrorCudartUnloading:
161 return "cudaErrorCudartUnloading";
163 case cudaErrorUnknown:
164 return "cudaErrorUnknown";
166 case cudaErrorNotYetImplemented:
167 return "cudaErrorNotYetImplemented";
169 case cudaErrorMemoryValueTooLarge:
170 return "cudaErrorMemoryValueTooLarge";
172 case cudaErrorInvalidResourceHandle:
173 return "cudaErrorInvalidResourceHandle";
175 case cudaErrorNotReady:
176 return "cudaErrorNotReady";
178 case cudaErrorInsufficientDriver:
179 return "cudaErrorInsufficientDriver";
181 case cudaErrorSetOnActiveProcess:
182 return "cudaErrorSetOnActiveProcess";
184 case cudaErrorInvalidSurface:
185 return "cudaErrorInvalidSurface";
187 case cudaErrorNoDevice:
188 return "cudaErrorNoDevice";
190 case cudaErrorECCUncorrectable:
191 return "cudaErrorECCUncorrectable";
193 case cudaErrorSharedObjectSymbolNotFound:
194 return "cudaErrorSharedObjectSymbolNotFound";
196 case cudaErrorSharedObjectInitFailed:
197 return "cudaErrorSharedObjectInitFailed";
199 case cudaErrorUnsupportedLimit:
200 return "cudaErrorUnsupportedLimit";
202 case cudaErrorDuplicateVariableName:
203 return "cudaErrorDuplicateVariableName";
205 case cudaErrorDuplicateTextureName:
206 return "cudaErrorDuplicateTextureName";
208 case cudaErrorDuplicateSurfaceName:
209 return "cudaErrorDuplicateSurfaceName";
211 case cudaErrorDevicesUnavailable:
212 return "cudaErrorDevicesUnavailable";
214 case cudaErrorInvalidKernelImage:
215 return "cudaErrorInvalidKernelImage";
217 case cudaErrorNoKernelImageForDevice:
218 return "cudaErrorNoKernelImageForDevice";
220 case cudaErrorIncompatibleDriverContext:
221 return "cudaErrorIncompatibleDriverContext";
223 case cudaErrorPeerAccessAlreadyEnabled:
224 return "cudaErrorPeerAccessAlreadyEnabled";
226 case cudaErrorPeerAccessNotEnabled:
227 return "cudaErrorPeerAccessNotEnabled";
229 case cudaErrorDeviceAlreadyInUse:
230 return "cudaErrorDeviceAlreadyInUse";
232 case cudaErrorProfilerDisabled:
233 return "cudaErrorProfilerDisabled";
235 case cudaErrorProfilerNotInitialized:
236 return "cudaErrorProfilerNotInitialized";
238 case cudaErrorProfilerAlreadyStarted:
239 return "cudaErrorProfilerAlreadyStarted";
241 case cudaErrorProfilerAlreadyStopped:
242 return "cudaErrorProfilerAlreadyStopped";
245 case cudaErrorAssert:
246 return "cudaErrorAssert";
248 case cudaErrorTooManyPeers:
249 return "cudaErrorTooManyPeers";
251 case cudaErrorHostMemoryAlreadyRegistered:
252 return "cudaErrorHostMemoryAlreadyRegistered";
254 case cudaErrorHostMemoryNotRegistered:
255 return "cudaErrorHostMemoryNotRegistered";
258 case cudaErrorOperatingSystem:
259 return "cudaErrorOperatingSystem";
261 case cudaErrorPeerAccessUnsupported:
262 return "cudaErrorPeerAccessUnsupported";
264 case cudaErrorLaunchMaxDepthExceeded:
265 return "cudaErrorLaunchMaxDepthExceeded";
267 case cudaErrorLaunchFileScopedTex:
268 return "cudaErrorLaunchFileScopedTex";
270 case cudaErrorLaunchFileScopedSurf:
271 return "cudaErrorLaunchFileScopedSurf";
273 case cudaErrorSyncDepthExceeded:
274 return "cudaErrorSyncDepthExceeded";
276 case cudaErrorLaunchPendingCountExceeded:
277 return "cudaErrorLaunchPendingCountExceeded";
279 case cudaErrorNotPermitted:
280 return "cudaErrorNotPermitted";
282 case cudaErrorNotSupported:
283 return "cudaErrorNotSupported";
286 case cudaErrorHardwareStackError:
287 return "cudaErrorHardwareStackError";
289 case cudaErrorIllegalInstruction:
290 return "cudaErrorIllegalInstruction";
292 case cudaErrorMisalignedAddress:
293 return "cudaErrorMisalignedAddress";
295 case cudaErrorInvalidAddressSpace:
296 return "cudaErrorInvalidAddressSpace";
298 case cudaErrorInvalidPc:
299 return "cudaErrorInvalidPc";
301 case cudaErrorIllegalAddress:
302 return "cudaErrorIllegalAddress";
305 case cudaErrorInvalidPtx:
306 return "cudaErrorInvalidPtx";
308 case cudaErrorInvalidGraphicsContext:
309 return "cudaErrorInvalidGraphicsContext";
311 case cudaErrorStartupFailure:
312 return "cudaErrorStartupFailure";
314 case cudaErrorApiFailureBase:
315 return "cudaErrorApiFailureBase";
318 case cudaErrorNvlinkUncorrectable:
319 return "cudaErrorNvlinkUncorrectable";
330static const char *_cudaGetErrorEnum(cublasStatus_t error) {
332 case CUBLAS_STATUS_SUCCESS:
333 return "CUBLAS_STATUS_SUCCESS";
335 case CUBLAS_STATUS_NOT_INITIALIZED:
336 return "CUBLAS_STATUS_NOT_INITIALIZED";
338 case CUBLAS_STATUS_ALLOC_FAILED:
339 return "CUBLAS_STATUS_ALLOC_FAILED";
341 case CUBLAS_STATUS_INVALID_VALUE:
342 return "CUBLAS_STATUS_INVALID_VALUE";
344 case CUBLAS_STATUS_ARCH_MISMATCH:
345 return "CUBLAS_STATUS_ARCH_MISMATCH";
347 case CUBLAS_STATUS_MAPPING_ERROR:
348 return "CUBLAS_STATUS_MAPPING_ERROR";
350 case CUBLAS_STATUS_EXECUTION_FAILED:
351 return "CUBLAS_STATUS_EXECUTION_FAILED";
353 case CUBLAS_STATUS_INTERNAL_ERROR:
354 return "CUBLAS_STATUS_INTERNAL_ERROR";
356 case CUBLAS_STATUS_NOT_SUPPORTED:
357 return "CUBLAS_STATUS_NOT_SUPPORTED";
359 case CUBLAS_STATUS_LICENSE_ERROR:
360 return "CUBLAS_STATUS_LICENSE_ERROR";
370 #ifdef CUSOLVER_COMMON_H_
372static const char *_cudaGetErrorEnum(cusolverStatus_t error) {
374 case CUSOLVER_STATUS_SUCCESS:
375 return "CUSOLVER_STATUS_SUCCESS";
376 case CUSOLVER_STATUS_NOT_INITIALIZED:
377 return "CUSOLVER_STATUS_NOT_INITIALIZED";
378 case CUSOLVER_STATUS_ALLOC_FAILED:
379 return "CUSOLVER_STATUS_ALLOC_FAILED";
380 case CUSOLVER_STATUS_INVALID_VALUE:
381 return "CUSOLVER_STATUS_INVALID_VALUE";
382 case CUSOLVER_STATUS_ARCH_MISMATCH:
383 return "CUSOLVER_STATUS_ARCH_MISMATCH";
384 case CUSOLVER_STATUS_MAPPING_ERROR:
385 return "CUSOLVER_STATUS_MAPPING_ERROR";
386 case CUSOLVER_STATUS_EXECUTION_FAILED:
387 return "CUSOLVER_STATUS_EXECUTION_FAILED";
388 case CUSOLVER_STATUS_INTERNAL_ERROR:
389 return "CUSOLVER_STATUS_INTERNAL_ERROR";
390 case CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
391 return "CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED";
392 case CUSOLVER_STATUS_NOT_SUPPORTED:
393 return "CUSOLVER_STATUS_NOT_SUPPORTED ";
394 case CUSOLVER_STATUS_ZERO_PIVOT:
395 return "CUSOLVER_STATUS_ZERO_PIVOT";
396 case CUSOLVER_STATUS_INVALID_LICENSE:
397 return "CUSOLVER_STATUS_INVALID_LICENSE";
406static const char *_cudaGetErrorEnum(curandStatus_t error) {
408 case CURAND_STATUS_SUCCESS:
409 return "CURAND_STATUS_SUCCESS";
410 case CURAND_STATUS_VERSION_MISMATCH:
411 return "CURAND_STATUS_VERSION_MISMATCH";
412 case CURAND_STATUS_NOT_INITIALIZED:
413 return "CURAND_STATUS_NOT_INITIALIZED";
414 case CURAND_STATUS_ALLOCATION_FAILED:
415 return "CURAND_STATUS_ALLOCATION_FAILED";
416 case CURAND_STATUS_TYPE_ERROR:
417 return "CURAND_STATUS_TYPE_ERROR";
418 case CURAND_STATUS_OUT_OF_RANGE:
419 return "CURAND_STATUS_OUT_OF_RANGE";
420 case CURAND_STATUS_LENGTH_NOT_MULTIPLE:
421 return "CURAND_STATUS_LENGTH_NOT_MULTIPLE";
422 case CURAND_STATUS_DOUBLE_PRECISION_REQUIRED:
423 return "CURAND_STATUS_DOUBLE_PRECISION_REQUIRED";
424 case CURAND_STATUS_LAUNCH_FAILURE:
425 return "CURAND_STATUS_LAUNCH_FAILURE";
426 case CURAND_STATUS_PREEXISTING_FAILURE:
427 return "CURAND_STATUS_PREEXISTING_FAILURE";
428 case CURAND_STATUS_INITIALIZATION_FAILED:
429 return "CURAND_STATUS_INITIALIZATION_FAILED";
430 case CURAND_STATUS_ARCH_MISMATCH:
431 return "CURAND_STATUS_ARCH_MISMATCH";
432 case CURAND_STATUS_INTERNAL_ERROR:
433 return "CURAND_STATUS_INTERNAL_ERROR";
441static const char* _cudaGetErrorEnum(cutensorStatus_t error){
442 return cutensorGetErrorString(error);
448 #ifdef __DRIVER_TYPES_H__
450 #define DEVICE_RESET cudaDeviceReset();
459void check(T result,
char const *
const func,
const char *
const file,
int const line) {
461 fprintf(stderr,
"CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line,
462 static_cast<unsigned int>(result), _cudaGetErrorEnum(result), func);
469 #ifdef __DRIVER_TYPES_H__
472 #define checkCudaErrors(val) check((val), #val, __FILE__, __LINE__)