MAGMA  1.2.0
MatrixAlgebraonGPUandMulticoreArchitectures
 All Classes 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  magmaGetErrorString( err ), err, func, file, line );
44  }
45 }
46 
47 
48 // ----------------------------------------
49 // cuda provides cudaGetErrorString, but not cuGetErrorString.
50 const char* cuGetErrorString( CUresult error )
51 {
52  switch( error ) {
53  case CUDA_SUCCESS:
54  return "success";
55 
56  case CUDA_ERROR_INVALID_VALUE:
57  return "invalid value";
58 
59  case CUDA_ERROR_OUT_OF_MEMORY:
60  return "out of memory";
61 
62  case CUDA_ERROR_NOT_INITIALIZED:
63  return "not initialized";
64 
65  case CUDA_ERROR_DEINITIALIZED:
66  return "deinitialized";
67 
68  case CUDA_ERROR_PROFILER_DISABLED:
69  return "profiler disabled";
70 
71  case CUDA_ERROR_PROFILER_NOT_INITIALIZED:
72  return "profiler not initialized";
73 
74  case CUDA_ERROR_PROFILER_ALREADY_STARTED:
75  return "profiler already started";
76 
77  case CUDA_ERROR_PROFILER_ALREADY_STOPPED:
78  return "profiler already stopped";
79 
80  case CUDA_ERROR_NO_DEVICE:
81  return "no device";
82 
83  case CUDA_ERROR_INVALID_DEVICE:
84  return "invalid device";
85 
86  case CUDA_ERROR_INVALID_IMAGE:
87  return "invalid image";
88 
89  case CUDA_ERROR_INVALID_CONTEXT:
90  return "invalid context";
91 
92  case CUDA_ERROR_CONTEXT_ALREADY_CURRENT:
93  return "context already current";
94 
95  case CUDA_ERROR_MAP_FAILED:
96  return "map failed";
97 
98  case CUDA_ERROR_UNMAP_FAILED:
99  return "unmap failed";
100 
101  case CUDA_ERROR_ARRAY_IS_MAPPED:
102  return "array is mapped";
103 
104  case CUDA_ERROR_ALREADY_MAPPED:
105  return "already mapped";
106 
107  case CUDA_ERROR_NO_BINARY_FOR_GPU:
108  return "no binary for GPU";
109 
110  case CUDA_ERROR_ALREADY_ACQUIRED:
111  return "already acquired";
112 
113  case CUDA_ERROR_NOT_MAPPED:
114  return "not mapped";
115 
116  case CUDA_ERROR_NOT_MAPPED_AS_ARRAY:
117  return "not mapped as array";
118 
119  case CUDA_ERROR_NOT_MAPPED_AS_POINTER:
120  return "not mapped as pointer";
121 
122  case CUDA_ERROR_ECC_UNCORRECTABLE:
123  return "ECC uncorrectable";
124 
125  case CUDA_ERROR_UNSUPPORTED_LIMIT:
126  return "unsupported limit";
127 
128  case CUDA_ERROR_CONTEXT_ALREADY_IN_USE:
129  return "context already in use";
130 
131  case CUDA_ERROR_INVALID_SOURCE:
132  return "invalid source";
133 
134  case CUDA_ERROR_FILE_NOT_FOUND:
135  return "file not found";
136 
137  case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND:
138  return "shared object symbol not found";
139 
140  case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED:
141  return "shared object init failed";
142 
143  case CUDA_ERROR_OPERATING_SYSTEM:
144  return "operating system";
145 
146  case CUDA_ERROR_INVALID_HANDLE:
147  return "invalid handle";
148 
149  case CUDA_ERROR_NOT_FOUND:
150  return "not found";
151 
152  case CUDA_ERROR_NOT_READY:
153  return "not ready";
154 
155  case CUDA_ERROR_LAUNCH_FAILED:
156  return "launch failed";
157 
158  case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES:
159  return "launch out of resources";
160 
161  case CUDA_ERROR_LAUNCH_TIMEOUT:
162  return "launch timeout";
163 
164  case CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING:
165  return "launch incompatible texturing";
166 
167  case CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED:
168  return "peer access already enabled";
169 
170  case CUDA_ERROR_PEER_ACCESS_NOT_ENABLED:
171  return "peer access not enabled";
172 
173  case CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE:
174  return "primary context active";
175 
176  case CUDA_ERROR_CONTEXT_IS_DESTROYED:
177  return "context is destroyed";
178 
179  case CUDA_ERROR_UNKNOWN:
180  return "unknown";
181 
182  default:
183  return "unknown error code";
184  }
185 }
186 
187 
188 // ----------------------------------------
189 // cuda provides cudaGetErrorString, but not cublasGetErrorString.
190 const char* cublasGetErrorString( cublasStatus_t error )
191 {
192  switch( error ) {
193  case CUBLAS_STATUS_SUCCESS:
194  return "success";
195 
196  case CUBLAS_STATUS_NOT_INITIALIZED:
197  return "not initialized";
198 
199  case CUBLAS_STATUS_ALLOC_FAILED:
200  return "out of memory";
201 
202  case CUBLAS_STATUS_INVALID_VALUE:
203  return "invalid value";
204 
205  case CUBLAS_STATUS_ARCH_MISMATCH:
206  return "architecture mismatch";
207 
208  case CUBLAS_STATUS_MAPPING_ERROR:
209  return "memory mapping error";
210 
211  case CUBLAS_STATUS_EXECUTION_FAILED:
212  return "execution failed";
213 
214  case CUBLAS_STATUS_INTERNAL_ERROR:
215  return "internal error";
216 
217  default:
218  return "unknown error code";
219  }
220 }
221 
222 
223 // ----------------------------------------
224 const char* magmaGetErrorString( magma_err_t error )
225 {
226  switch( error ) {
227  case MAGMA_SUCCESS:
228  return "success";
229 
231  return "illegal value";
232 
234  return "host malloc";
235 
237  return "device malloc";
238 
240  return "CUDA stream";
241 
243  return "invalid pointer";
244 
245  default:
246  return "unknown error code";
247  }
248 }