MAGMA  magma-1.4.0
Matrix Algebra on GPU and Multicore Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
error.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #include "error.h"
4 
5 
6 // ----------------------------------------
7 // C++ function is overloaded for different error types,
8 // which depends on error types being enums to be differentiable.
9 void magma_xerror( cudaError_t err, const char* func, const char* file, int line )
10 {
11  if ( err != cudaSuccess ) {
12  fprintf( stderr, "CUDA runtime error: %s (%d) in %s at %s:%d\n",
13  cudaGetErrorString( err ), err, func, file, line );
14  }
15 }
16 
17 
18 // --------------------
19 void magma_xerror( CUresult err, const char* func, const char* file, int line )
20 {
21  if ( err != CUDA_SUCCESS ) {
22  fprintf( stderr, "CUDA driver error: %s (%d) in %s at %s:%d\n",
23  cuGetErrorString( err ), err, func, file, line );
24  }
25 }
26 
27 
28 // --------------------
29 void magma_xerror( cublasStatus_t err, const char* func, const char* file, int line )
30 {
31  if ( err != CUBLAS_STATUS_SUCCESS ) {
32  fprintf( stderr, "CUBLAS error: %s (%d) in %s at %s:%d\n",
33  cublasGetErrorString( err ), err, func, file, line );
34  }
35 }
36 
37 
38 // --------------------
39 void magma_xerror( magma_err_t err, const char* func, const char* file, int line )
40 {
41  if ( err != MAGMA_SUCCESS ) {
42  fprintf( stderr, "MAGMA error: %s (%d) in %s at %s:%d\n",
43  magma_strerror( err ), (int) err, func, file, line );
44  }
45 }
46 
47 
48 // ----------------------------------------
49 // cuda provides cudaGetErrorString, but not cuGetErrorString.
50 extern "C"
51 const char* cuGetErrorString( CUresult error )
52 {
53  switch( error ) {
54  case CUDA_SUCCESS:
55  return "success";
56 
57  case CUDA_ERROR_INVALID_VALUE:
58  return "invalid value";
59 
60  case CUDA_ERROR_OUT_OF_MEMORY:
61  return "out of memory";
62 
63  case CUDA_ERROR_NOT_INITIALIZED:
64  return "not initialized";
65 
66  case CUDA_ERROR_DEINITIALIZED:
67  return "deinitialized";
68 
69  case CUDA_ERROR_PROFILER_DISABLED:
70  return "profiler disabled";
71 
72  case CUDA_ERROR_PROFILER_NOT_INITIALIZED:
73  return "profiler not initialized";
74 
75  case CUDA_ERROR_PROFILER_ALREADY_STARTED:
76  return "profiler already started";
77 
78  case CUDA_ERROR_PROFILER_ALREADY_STOPPED:
79  return "profiler already stopped";
80 
81  case CUDA_ERROR_NO_DEVICE:
82  return "no device";
83 
84  case CUDA_ERROR_INVALID_DEVICE:
85  return "invalid device";
86 
87  case CUDA_ERROR_INVALID_IMAGE:
88  return "invalid image";
89 
90  case CUDA_ERROR_INVALID_CONTEXT:
91  return "invalid context";
92 
93  case CUDA_ERROR_CONTEXT_ALREADY_CURRENT:
94  return "context already current";
95 
96  case CUDA_ERROR_MAP_FAILED:
97  return "map failed";
98 
99  case CUDA_ERROR_UNMAP_FAILED:
100  return "unmap failed";
101 
102  case CUDA_ERROR_ARRAY_IS_MAPPED:
103  return "array is mapped";
104 
105  case CUDA_ERROR_ALREADY_MAPPED:
106  return "already mapped";
107 
108  case CUDA_ERROR_NO_BINARY_FOR_GPU:
109  return "no binary for GPU";
110 
111  case CUDA_ERROR_ALREADY_ACQUIRED:
112  return "already acquired";
113 
114  case CUDA_ERROR_NOT_MAPPED:
115  return "not mapped";
116 
117  case CUDA_ERROR_NOT_MAPPED_AS_ARRAY:
118  return "not mapped as array";
119 
120  case CUDA_ERROR_NOT_MAPPED_AS_POINTER:
121  return "not mapped as pointer";
122 
123  case CUDA_ERROR_ECC_UNCORRECTABLE:
124  return "ECC uncorrectable";
125 
126  case CUDA_ERROR_UNSUPPORTED_LIMIT:
127  return "unsupported limit";
128 
129  case CUDA_ERROR_CONTEXT_ALREADY_IN_USE:
130  return "context already in use";
131 
132  case CUDA_ERROR_INVALID_SOURCE:
133  return "invalid source";
134 
135  case CUDA_ERROR_FILE_NOT_FOUND:
136  return "file not found";
137 
138  case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND:
139  return "shared object symbol not found";
140 
141  case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED:
142  return "shared object init failed";
143 
144  case CUDA_ERROR_OPERATING_SYSTEM:
145  return "operating system";
146 
147  case CUDA_ERROR_INVALID_HANDLE:
148  return "invalid handle";
149 
150  case CUDA_ERROR_NOT_FOUND:
151  return "not found";
152 
153  case CUDA_ERROR_NOT_READY:
154  return "not ready";
155 
156  case CUDA_ERROR_LAUNCH_FAILED:
157  return "launch failed";
158 
159  case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES:
160  return "launch out of resources";
161 
162  case CUDA_ERROR_LAUNCH_TIMEOUT:
163  return "launch timeout";
164 
165  case CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING:
166  return "launch incompatible texturing";
167 
168  case CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED:
169  return "peer access already enabled";
170 
171  case CUDA_ERROR_PEER_ACCESS_NOT_ENABLED:
172  return "peer access not enabled";
173 
174  case CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE:
175  return "primary context active";
176 
177  case CUDA_ERROR_CONTEXT_IS_DESTROYED:
178  return "context is destroyed";
179 
180  case CUDA_ERROR_UNKNOWN:
181  return "unknown";
182 
183  default:
184  return "unknown error code";
185  }
186 }
187 
188 
189 // ----------------------------------------
190 // cuda provides cudaGetErrorString, but not cublasGetErrorString.
191 extern "C"
192 const char* cublasGetErrorString( cublasStatus_t error )
193 {
194  switch( error ) {
195  case CUBLAS_STATUS_SUCCESS:
196  return "success";
197 
198  case CUBLAS_STATUS_NOT_INITIALIZED:
199  return "not initialized";
200 
201  case CUBLAS_STATUS_ALLOC_FAILED:
202  return "out of memory";
203 
204  case CUBLAS_STATUS_INVALID_VALUE:
205  return "invalid value";
206 
207  case CUBLAS_STATUS_ARCH_MISMATCH:
208  return "architecture mismatch";
209 
210  case CUBLAS_STATUS_MAPPING_ERROR:
211  return "memory mapping error";
212 
213  case CUBLAS_STATUS_EXECUTION_FAILED:
214  return "execution failed";
215 
216  case CUBLAS_STATUS_INTERNAL_ERROR:
217  return "internal error";
218 
219  default:
220  return "unknown error code";
221  }
222 }
223 
224 
225 // ----------------------------------------
226 extern "C"
227 const char* magma_strerror( magma_err_t error )
228 {
229  // LAPACK-compliant errors
230  if ( error > 0 ) {
231  return "function-specific error, see documentation";
232  }
233  else if ( error < 0 && error > MAGMA_ERR ) {
234  return "invalid argument";
235  }
236  // MAGMA-specific errors
237  switch( error ) {
238  case MAGMA_SUCCESS:
239  return "success";
240 
241  case MAGMA_ERR:
242  return "unknown error";
243 
245  return "not initialized";
246 
248  return "reinitialized";
249 
251  return "not supported";
252 
254  return "illegal value";
255 
256  case MAGMA_ERR_NOT_FOUND:
257  return "not found";
258 
260  return "allocation";
261 
263  return "internal limit";
264 
266  return "unallocated error";
267 
269  return "filesystem error";
270 
272  return "unexpected error";
273 
275  return "sequence flushed";
276 
278  return "cannot allocate memory on CPU host";
279 
281  return "cannot allocate memory on GPU device";
282 
284  return "CUDA stream error";
285 
287  return "invalid pointer";
288 
289  default:
290  return "unknown error code";
291  }
292 }
#define MAGMA_ERR_ILLEGAL_VALUE
Definition: magma.h:107
#define MAGMA_ERR_UNALLOCATED
Definition: magma_types.h:271
#define MAGMA_ERR_FILESYSTEM
Definition: magma_types.h:272
#define MAGMA_ERR_SEQUENCE_FLUSHED
Definition: magma_types.h:274
#define MAGMA_ERR_UNEXPECTED
Definition: magma_types.h:273
#define MAGMA_ERR_NOT_SUPPORTED
Definition: magma_types.h:266
#define MAGMA_ERR_DEVICE_ALLOC
Definition: magma_types.h:276
#define MAGMA_ERR_INTERNAL_LIMIT
Definition: magma_types.h:270
#define MAGMA_ERR_NOT_INITIALIZED
Definition: magma_types.h:264
const char * cuGetErrorString(CUresult error)
Definition: error.cpp:51
#define MAGMA_ERR_NOT_FOUND
Definition: magma_types.h:268
#define MAGMA_ERR_ALLOCATION
Definition: magma.h:108
const char * cublasGetErrorString(cublasStatus_t error)
Definition: error.cpp:192
#define MAGMA_ERR_REINITIALIZED
Definition: magma_types.h:265
#define MAGMA_SUCCESS
Definition: magma.h:106
int magma_err_t
Definition: magma_types.h:23
const char * magma_strerror(magma_err_t error)
Definition: error.cpp:227
void magma_xerror(cudaError_t err, const char *func, const char *file, int line)
Definition: error.cpp:9
#define MAGMA_ERR_CUDASTREAM
Definition: magma_types.h:277
#define MAGMA_ERR_INVALID_PTR
Definition: magma_types.h:278
#define MAGMA_ERR_HOST_ALLOC
Definition: magma_types.h:275
#define MAGMA_ERR
Definition: magma_types.h:263