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>
69 #if defined(UNI_CUTENSOR)
73 #ifdef __DRIVER_TYPES_H__
74static const char *_cudaGetErrorEnum(cudaError_t error) {
79 case cudaErrorMissingConfiguration:
80 return "cudaErrorMissingConfiguration";
82 case cudaErrorMemoryAllocation:
83 return "cudaErrorMemoryAllocation";
85 case cudaErrorInitializationError:
86 return "cudaErrorInitializationError";
88 case cudaErrorLaunchFailure:
89 return "cudaErrorLaunchFailure";
91 case cudaErrorPriorLaunchFailure:
92 return "cudaErrorPriorLaunchFailure";
94 case cudaErrorLaunchTimeout:
95 return "cudaErrorLaunchTimeout";
97 case cudaErrorLaunchOutOfResources:
98 return "cudaErrorLaunchOutOfResources";
100 case cudaErrorInvalidDeviceFunction:
101 return "cudaErrorInvalidDeviceFunction";
103 case cudaErrorInvalidConfiguration:
104 return "cudaErrorInvalidConfiguration";
106 case cudaErrorInvalidDevice:
107 return "cudaErrorInvalidDevice";
109 case cudaErrorInvalidValue:
110 return "cudaErrorInvalidValue";
112 case cudaErrorInvalidPitchValue:
113 return "cudaErrorInvalidPitchValue";
115 case cudaErrorInvalidSymbol:
116 return "cudaErrorInvalidSymbol";
118 case cudaErrorMapBufferObjectFailed:
119 return "cudaErrorMapBufferObjectFailed";
121 case cudaErrorUnmapBufferObjectFailed:
122 return "cudaErrorUnmapBufferObjectFailed";
124 case cudaErrorInvalidHostPointer:
125 return "cudaErrorInvalidHostPointer";
127 case cudaErrorInvalidDevicePointer:
128 return "cudaErrorInvalidDevicePointer";
130 case cudaErrorInvalidTexture:
131 return "cudaErrorInvalidTexture";
133 case cudaErrorInvalidTextureBinding:
134 return "cudaErrorInvalidTextureBinding";
136 case cudaErrorInvalidChannelDescriptor:
137 return "cudaErrorInvalidChannelDescriptor";
139 case cudaErrorInvalidMemcpyDirection:
140 return "cudaErrorInvalidMemcpyDirection";
142 case cudaErrorAddressOfConstant:
143 return "cudaErrorAddressOfConstant";
145 case cudaErrorTextureFetchFailed:
146 return "cudaErrorTextureFetchFailed";
148 case cudaErrorTextureNotBound:
149 return "cudaErrorTextureNotBound";
151 case cudaErrorSynchronizationError:
152 return "cudaErrorSynchronizationError";
154 case cudaErrorInvalidFilterSetting:
155 return "cudaErrorInvalidFilterSetting";
157 case cudaErrorInvalidNormSetting:
158 return "cudaErrorInvalidNormSetting";
160 case cudaErrorMixedDeviceExecution:
161 return "cudaErrorMixedDeviceExecution";
163 case cudaErrorCudartUnloading:
164 return "cudaErrorCudartUnloading";
166 case cudaErrorUnknown:
167 return "cudaErrorUnknown";
169 case cudaErrorNotYetImplemented:
170 return "cudaErrorNotYetImplemented";
172 case cudaErrorMemoryValueTooLarge:
173 return "cudaErrorMemoryValueTooLarge";
175 case cudaErrorInvalidResourceHandle:
176 return "cudaErrorInvalidResourceHandle";
178 case cudaErrorNotReady:
179 return "cudaErrorNotReady";
181 case cudaErrorInsufficientDriver:
182 return "cudaErrorInsufficientDriver";
184 case cudaErrorSetOnActiveProcess:
185 return "cudaErrorSetOnActiveProcess";
187 case cudaErrorInvalidSurface:
188 return "cudaErrorInvalidSurface";
190 case cudaErrorNoDevice:
191 return "cudaErrorNoDevice";
193 case cudaErrorECCUncorrectable:
194 return "cudaErrorECCUncorrectable";
196 case cudaErrorSharedObjectSymbolNotFound:
197 return "cudaErrorSharedObjectSymbolNotFound";
199 case cudaErrorSharedObjectInitFailed:
200 return "cudaErrorSharedObjectInitFailed";
202 case cudaErrorUnsupportedLimit:
203 return "cudaErrorUnsupportedLimit";
205 case cudaErrorDuplicateVariableName:
206 return "cudaErrorDuplicateVariableName";
208 case cudaErrorDuplicateTextureName:
209 return "cudaErrorDuplicateTextureName";
211 case cudaErrorDuplicateSurfaceName:
212 return "cudaErrorDuplicateSurfaceName";
214 case cudaErrorDevicesUnavailable:
215 return "cudaErrorDevicesUnavailable";
217 case cudaErrorInvalidKernelImage:
218 return "cudaErrorInvalidKernelImage";
220 case cudaErrorNoKernelImageForDevice:
221 return "cudaErrorNoKernelImageForDevice";
223 case cudaErrorIncompatibleDriverContext:
224 return "cudaErrorIncompatibleDriverContext";
226 case cudaErrorPeerAccessAlreadyEnabled:
227 return "cudaErrorPeerAccessAlreadyEnabled";
229 case cudaErrorPeerAccessNotEnabled:
230 return "cudaErrorPeerAccessNotEnabled";
232 case cudaErrorDeviceAlreadyInUse:
233 return "cudaErrorDeviceAlreadyInUse";
235 case cudaErrorProfilerDisabled:
236 return "cudaErrorProfilerDisabled";
238 case cudaErrorProfilerNotInitialized:
239 return "cudaErrorProfilerNotInitialized";
241 case cudaErrorProfilerAlreadyStarted:
242 return "cudaErrorProfilerAlreadyStarted";
244 case cudaErrorProfilerAlreadyStopped:
245 return "cudaErrorProfilerAlreadyStopped";
248 case cudaErrorAssert:
249 return "cudaErrorAssert";
251 case cudaErrorTooManyPeers:
252 return "cudaErrorTooManyPeers";
254 case cudaErrorHostMemoryAlreadyRegistered:
255 return "cudaErrorHostMemoryAlreadyRegistered";
257 case cudaErrorHostMemoryNotRegistered:
258 return "cudaErrorHostMemoryNotRegistered";
261 case cudaErrorOperatingSystem:
262 return "cudaErrorOperatingSystem";
264 case cudaErrorPeerAccessUnsupported:
265 return "cudaErrorPeerAccessUnsupported";
267 case cudaErrorLaunchMaxDepthExceeded:
268 return "cudaErrorLaunchMaxDepthExceeded";
270 case cudaErrorLaunchFileScopedTex:
271 return "cudaErrorLaunchFileScopedTex";
273 case cudaErrorLaunchFileScopedSurf:
274 return "cudaErrorLaunchFileScopedSurf";
276 case cudaErrorSyncDepthExceeded:
277 return "cudaErrorSyncDepthExceeded";
279 case cudaErrorLaunchPendingCountExceeded:
280 return "cudaErrorLaunchPendingCountExceeded";
282 case cudaErrorNotPermitted:
283 return "cudaErrorNotPermitted";
285 case cudaErrorNotSupported:
286 return "cudaErrorNotSupported";
289 case cudaErrorHardwareStackError:
290 return "cudaErrorHardwareStackError";
292 case cudaErrorIllegalInstruction:
293 return "cudaErrorIllegalInstruction";
295 case cudaErrorMisalignedAddress:
296 return "cudaErrorMisalignedAddress";
298 case cudaErrorInvalidAddressSpace:
299 return "cudaErrorInvalidAddressSpace";
301 case cudaErrorInvalidPc:
302 return "cudaErrorInvalidPc";
304 case cudaErrorIllegalAddress:
305 return "cudaErrorIllegalAddress";
308 case cudaErrorInvalidPtx:
309 return "cudaErrorInvalidPtx";
311 case cudaErrorInvalidGraphicsContext:
312 return "cudaErrorInvalidGraphicsContext";
314 case cudaErrorStartupFailure:
315 return "cudaErrorStartupFailure";
317 case cudaErrorApiFailureBase:
318 return "cudaErrorApiFailureBase";
321 case cudaErrorNvlinkUncorrectable:
322 return "cudaErrorNvlinkUncorrectable";
333static const char *_cudaGetErrorEnum(cublasStatus_t error) {
335 case CUBLAS_STATUS_SUCCESS:
336 return "CUBLAS_STATUS_SUCCESS";
338 case CUBLAS_STATUS_NOT_INITIALIZED:
339 return "CUBLAS_STATUS_NOT_INITIALIZED";
341 case CUBLAS_STATUS_ALLOC_FAILED:
342 return "CUBLAS_STATUS_ALLOC_FAILED";
344 case CUBLAS_STATUS_INVALID_VALUE:
345 return "CUBLAS_STATUS_INVALID_VALUE";
347 case CUBLAS_STATUS_ARCH_MISMATCH:
348 return "CUBLAS_STATUS_ARCH_MISMATCH";
350 case CUBLAS_STATUS_MAPPING_ERROR:
351 return "CUBLAS_STATUS_MAPPING_ERROR";
353 case CUBLAS_STATUS_EXECUTION_FAILED:
354 return "CUBLAS_STATUS_EXECUTION_FAILED";
356 case CUBLAS_STATUS_INTERNAL_ERROR:
357 return "CUBLAS_STATUS_INTERNAL_ERROR";
359 case CUBLAS_STATUS_NOT_SUPPORTED:
360 return "CUBLAS_STATUS_NOT_SUPPORTED";
362 case CUBLAS_STATUS_LICENSE_ERROR:
363 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);
446 #ifdef __DRIVER_TYPES_H__
448 #define DEVICE_RESET cudaDeviceReset();
457void check(T result,
char const *
const func,
const char *
const file,
int const line) {
459 fprintf(stderr,
"CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line,
460 static_cast<unsigned int>(result), _cudaGetErrorEnum(result), func);
467 #ifdef __DRIVER_TYPES_H__
470 #define checkCudaErrors(val) check((val), #val, __FILE__, __LINE__)