mxnet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cuda_utils.h
Go to the documentation of this file.
1 
6 #ifndef MXNET_COMMON_CUDA_UTILS_H_
7 #define MXNET_COMMON_CUDA_UTILS_H_
8 
9 #include <dmlc/logging.h>
10 
11 #if MXNET_USE_CUDA
12 
13 #include <cuda_runtime.h>
14 #include <cublas_v2.h>
15 #include <curand.h>
16 
17 namespace mxnet {
18 namespace common {
20 namespace cuda {
26 inline const char* CublasGetErrorString(cublasStatus_t error) {
27  switch (error) {
28  case CUBLAS_STATUS_SUCCESS:
29  return "CUBLAS_STATUS_SUCCESS";
30  case CUBLAS_STATUS_NOT_INITIALIZED:
31  return "CUBLAS_STATUS_NOT_INITIALIZED";
32  case CUBLAS_STATUS_ALLOC_FAILED:
33  return "CUBLAS_STATUS_ALLOC_FAILED";
34  case CUBLAS_STATUS_INVALID_VALUE:
35  return "CUBLAS_STATUS_INVALID_VALUE";
36  case CUBLAS_STATUS_ARCH_MISMATCH:
37  return "CUBLAS_STATUS_ARCH_MISMATCH";
38  case CUBLAS_STATUS_MAPPING_ERROR:
39  return "CUBLAS_STATUS_MAPPING_ERROR";
40  case CUBLAS_STATUS_EXECUTION_FAILED:
41  return "CUBLAS_STATUS_EXECUTION_FAILED";
42  case CUBLAS_STATUS_INTERNAL_ERROR:
43  return "CUBLAS_STATUS_INTERNAL_ERROR";
44  case CUBLAS_STATUS_NOT_SUPPORTED:
45  return "CUBLAS_STATUS_NOT_SUPPORTED";
46  default:
47  break;
48  }
49  return "Unknown cuBLAS status";
50 }
51 
57 inline const char* CurandGetErrorString(curandStatus_t status) {
58  switch (status) {
59  case CURAND_STATUS_SUCCESS:
60  return "CURAND_STATUS_SUCCESS";
61  case CURAND_STATUS_VERSION_MISMATCH:
62  return "CURAND_STATUS_VERSION_MISMATCH";
63  case CURAND_STATUS_NOT_INITIALIZED:
64  return "CURAND_STATUS_NOT_INITIALIZED";
65  case CURAND_STATUS_ALLOCATION_FAILED:
66  return "CURAND_STATUS_ALLOCATION_FAILED";
67  case CURAND_STATUS_TYPE_ERROR:
68  return "CURAND_STATUS_TYPE_ERROR";
69  case CURAND_STATUS_OUT_OF_RANGE:
70  return "CURAND_STATUS_OUT_OF_RANGE";
71  case CURAND_STATUS_LENGTH_NOT_MULTIPLE:
72  return "CURAND_STATUS_LENGTH_NOT_MULTIPLE";
73  case CURAND_STATUS_DOUBLE_PRECISION_REQUIRED:
74  return "CURAND_STATUS_DOUBLE_PRECISION_REQUIRED";
75  case CURAND_STATUS_LAUNCH_FAILURE:
76  return "CURAND_STATUS_LAUNCH_FAILURE";
77  case CURAND_STATUS_PREEXISTING_FAILURE:
78  return "CURAND_STATUS_PREEXISTING_FAILURE";
79  case CURAND_STATUS_INITIALIZATION_FAILED:
80  return "CURAND_STATUS_INITIALIZATION_FAILED";
81  case CURAND_STATUS_ARCH_MISMATCH:
82  return "CURAND_STATUS_ARCH_MISMATCH";
83  case CURAND_STATUS_INTERNAL_ERROR:
84  return "CURAND_STATUS_INTERNAL_ERROR";
85  }
86  return "Unknown cuRAND status";
87 }
88 
89 } // namespace cuda
90 } // namespace common
91 } // namespace mxnet
92 
97 #define CHECK_CUDA_ERROR(msg) \
98  { \
99  cudaError_t e = cudaGetLastError(); \
100  CHECK_EQ(e, cudaSuccess) << (msg) << " CUDA: " << cudaGetErrorString(e); \
101  }
102 
109 #define CUDA_CALL(func) \
110  { \
111  cudaError_t e = (func); \
112  CHECK(e == cudaSuccess || e == cudaErrorCudartUnloading) \
113  << "CUDA: " << cudaGetErrorString(e); \
114  }
115 
122 #define CUBLAS_CALL(func) \
123  { \
124  cublasStatus_t e = (func); \
125  CHECK_EQ(e, CUBLAS_STATUS_SUCCESS) \
126  << "cuBLAS: " << common::cuda::CublasGetErrorString(e); \
127  }
128 
135 #define CURAND_CALL(func) \
136  { \
137  curandStatus_t e = (func); \
138  CHECK_EQ(e, CURAND_STATUS_SUCCESS) \
139  << "cuRAND: " << common::cuda::CurandGetErrorString(e); \
140  }
141 
142 #endif // MXNET_USE_CUDA
143 
144 #if MXNET_USE_CUDNN
145 
146 #include <cudnn.h>
147 
148 #define CUDNN_CALL(func) \
149  { \
150  cudnnStatus_t e = (func); \
151  CHECK_EQ(e, CUDNN_STATUS_SUCCESS) << "cuDNN: " << cudnnGetErrorString(e); \
152  }
153 
154 #endif // MXNET_USE_CUDNN
155 #endif // MXNET_COMMON_CUDA_UTILS_H_
const char * CurandGetErrorString(curandStatus_t status)
Get string representation of cuRAND errors.
Definition: cuda_utils.h:57
const char * CublasGetErrorString(cublasStatus_t error)
Get string representation of cuBLAS errors.
Definition: cuda_utils.h:26