-
Notifications
You must be signed in to change notification settings - Fork 0
/
CUDA_helpers.cu
48 lines (40 loc) · 1.8 KB
/
CUDA_helpers.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//%%writefile CUDA_helpers.cu
// CUDA and cuBLAS error checkers
#ifndef __CUDA_HELPERS__
#define __CUDA_HELPERS__
#include <stdio.h>
#include <cuda_runtime.h>
#include <cublas_v2.h>
#define CUDA_CHECK(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
// Macro for cuBLAS error checking
#define CUBLAS_CHECK(ans) { \
if ((ans) != CUBLAS_STATUS_SUCCESS) { \
fprintf(stderr, "cuBLAS Error: %s %s %d\n", cublasGetErrorString(ans), __FILE__, __LINE__); \
exit(ans); \
} \
}
// Inline function to map cublasStatus_t to string within the macro
inline const char* cublasGetErrorString(cublasStatus_t status) {
switch (status) {
case CUBLAS_STATUS_SUCCESS: return "CUBLAS_STATUS_SUCCESS";
case CUBLAS_STATUS_NOT_INITIALIZED: return "CUBLAS_STATUS_NOT_INITIALIZED";
case CUBLAS_STATUS_ALLOC_FAILED: return "CUBLAS_STATUS_ALLOC_FAILED";
case CUBLAS_STATUS_INVALID_VALUE: return "CUBLAS_STATUS_INVALID_VALUE";
case CUBLAS_STATUS_ARCH_MISMATCH: return "CUBLAS_STATUS_ARCH_MISMATCH";
case CUBLAS_STATUS_MAPPING_ERROR: return "CUBLAS_STATUS_MAPPING_ERROR";
case CUBLAS_STATUS_EXECUTION_FAILED: return "CUBLAS_STATUS_EXECUTION_FAILED";
case CUBLAS_STATUS_INTERNAL_ERROR: return "CUBLAS_STATUS_INTERNAL_ERROR";
case CUBLAS_STATUS_NOT_SUPPORTED: return "CUBLAS_STATUS_NOT_SUPPORTED";
case CUBLAS_STATUS_LICENSE_ERROR: return "CUBLAS_STATUS_LICENSE_ERROR";
default: return "UNKNOWN_CUBLAS_STATUS";
}
}
#endif // __CUDA_HELPERS__