-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcuda_errors.cu
183 lines (162 loc) · 8.12 KB
/
cuda_errors.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "mpi.h"
#include "cuda_common.hpp"
#include <cstdarg>
#include <cstdio>
static const char* errorCodes
(int err_code)
{
switch(err_code)
{
case cudaSuccess: return "cudaSuccess"; // 0
case cudaErrorMissingConfiguration: return "cudaErrorMissingConfiguration"; // 1
case cudaErrorMemoryAllocation: return "cudaErrorMemoryAllocation"; // 2
case cudaErrorInitializationError: return "cudaErrorInitializationError"; // 3
case cudaErrorLaunchFailure: return "cudaErrorLaunchFailure"; // 4
case cudaErrorPriorLaunchFailure: return "cudaErrorPriorLaunchFailure"; // 5
case cudaErrorLaunchTimeout: return "cudaErrorLaunchTimeout"; // 6
case cudaErrorLaunchOutOfResources: return "cudaErrorLaunchOutOfResources"; // 7
case cudaErrorInvalidDeviceFunction: return "cudaErrorInvalidDeviceFunction"; // 8
case cudaErrorInvalidConfiguration: return "cudaErrorInvalidConfiguration"; // 9
case cudaErrorInvalidDevice: return "cudaErrorInvalidDevice"; // 10
case cudaErrorInvalidValue: return "cudaErrorInvalidValue";// 11
case cudaErrorInvalidPitchValue: return "cudaErrorInvalidPitchValue";// 12
case cudaErrorInvalidSymbol: return "cudaErrorInvalidSymbol";// 13
case cudaErrorMapBufferObjectFailed: return "cudaErrorMapBufferObjectFailed";// 14
case cudaErrorUnmapBufferObjectFailed: return "cudaErrorUnmapBufferObjectFailed";// 15
case cudaErrorInvalidHostPointer: return "cudaErrorInvalidHostPointer";// 16
case cudaErrorInvalidDevicePointer: return "cudaErrorInvalidDevicePointer";// 17
case cudaErrorInvalidTexture: return "cudaErrorInvalidTexture";// 18
case cudaErrorInvalidTextureBinding: return "cudaErrorInvalidTextureBinding";// 19
case cudaErrorInvalidChannelDescriptor: return "cudaErrorInvalidChannelDescriptor";// 20
case cudaErrorInvalidMemcpyDirection: return "cudaErrorInvalidMemcpyDirection";// 21
case cudaErrorAddressOfConstant: return "cudaErrorAddressOfConstant";// 22
case cudaErrorTextureFetchFailed: return "cudaErrorTextureFetchFailed";// 23
case cudaErrorTextureNotBound: return "cudaErrorTextureNotBound";// 24
case cudaErrorSynchronizationError: return "cudaErrorSynchronizationError";// 25
case cudaErrorInvalidFilterSetting: return "cudaErrorInvalidFilterSetting";// 26
case cudaErrorInvalidNormSetting: return "cudaErrorInvalidNormSetting";// 27
case cudaErrorMixedDeviceExecution: return "cudaErrorMixedDeviceExecution";// 28
case cudaErrorCudartUnloading: return "cudaErrorCudartUnloading";// 29
case cudaErrorUnknown: return "cudaErrorUnknown";// 30
case cudaErrorNotYetImplemented: return "cudaErrorNotYetImplemented";// 31
case cudaErrorMemoryValueTooLarge: return "cudaErrorMemoryValueTooLarge";// 32
case cudaErrorInvalidResourceHandle: return "cudaErrorInvalidResourceHandle";// 33
case cudaErrorNotReady: return "cudaErrorNotReady";// 34
case cudaErrorInsufficientDriver: return "cudaErrorInsufficientDriver";// 35
case cudaErrorSetOnActiveProcess: return "cudaErrorSetOnActiveProcess";// 36
case cudaErrorInvalidSurface: return "cudaErrorInvalidSurface";// 37
case cudaErrorNoDevice: return "cudaErrorNoDevice";// 38
case cudaErrorECCUncorrectable: return "cudaErrorECCUncorrectable";// 39
case cudaErrorSharedObjectSymbolNotFound: return "cudaErrorSharedObjectSymbolNotFound";// 40
case cudaErrorSharedObjectInitFailed: return "cudaErrorSharedObjectInitFailed";// 41
case cudaErrorUnsupportedLimit: return "cudaErrorUnsupportedLimit";// 42
case cudaErrorDuplicateVariableName: return "cudaErrorDuplicateVariableName";// 43
case cudaErrorDuplicateTextureName: return "cudaErrorDuplicateTextureName";// 44
case cudaErrorDuplicateSurfaceName: return "cudaErrorDuplicateSurfaceName";// 45
case cudaErrorDevicesUnavailable: return "cudaErrorDevicesUnavailable";// 46
case cudaErrorInvalidKernelImage: return "cudaErrorInvalidKernelImage";// 47
case cudaErrorNoKernelImageForDevice: return "cudaErrorNoKernelImageForDevice";// 48
case cudaErrorIncompatibleDriverContext: return "cudaErrorIncompatibleDriverContext";// 49
case cudaErrorPeerAccessAlreadyEnabled: return "cudaErrorPeerAccessAlreadyEnabled";// 50
case cudaErrorPeerAccessNotEnabled: return "cudaErrorPeerAccessNotEnabled";// 51
case cudaErrorDeviceAlreadyInUse: return "cudaErrorDeviceAlreadyInUse";// 52
case cudaErrorProfilerDisabled: return "cudaErrorProfilerDisabled";// 53
case cudaErrorProfilerNotInitialized: return "cudaErrorProfilerNotInitialized";// 54
case cudaErrorProfilerAlreadyStarted: return "cudaErrorProfilerAlreadyStarted";// 55
case cudaErrorProfilerAlreadyStopped: return "cudaErrorProfilerAlreadyStopped";// 56
case cudaErrorAssert: return "cudaErrorAssert";// 57
case cudaErrorTooManyPeers: return "cudaErrorTooManyPeers";// 58
case cudaErrorHostMemoryAlreadyRegistered: return "cudaErrorHostMemoryAlreadyRegistered";// 59
case cudaErrorHostMemoryNotRegistered: return "cudaErrorHostMemoryNotRegistered";// 60
case cudaErrorOperatingSystem: return "cudaErrorOperatingSystem";// 61
case cudaErrorStartupFailure: return "cudaErrorStartupFailure";// 62
case cudaErrorApiFailureBase: return "cudaErrorApiFailureBase";// 63
default: return "Unknown error";
}
}
void TealeafCudaChunk::errorHandler
(int line_num, const char* file)
{
cudaDeviceSynchronize();
int l_e = cudaGetLastError();
if (cudaSuccess != l_e)
{
TeaDie(line_num, file, "Error in %s - return code %d (%s)\n", file, l_e, errorCodes(l_e));
}
}
// print out timing info when done
TealeafCudaChunk::~TealeafCudaChunk
(void)
{
if (profiler_on)
// TODO mpi_reduce
if (!rank)
{
fprintf(stdout, "@@@@@ PROFILING @@@@@\n");
for (std::map<std::string, double>::iterator ii = kernel_times.begin();
ii != kernel_times.end(); ii++)
{
fprintf(stdout, "%35s : %.3f\n", ii->first.c_str(), ii->second);
}
}
}
std::vector<double> TealeafCudaChunk::dumpArray
(const std::string& arr_name, int x_extra, int y_extra)
{
// number of bytes to allocate for 2d array
#define BUFSZ2D(x_extra, y_extra) \
( ((x_max) + 2*halo_exchange_depth + x_extra) \
* ((y_max) + 2*halo_exchange_depth + y_extra) \
* sizeof(double) )
std::vector<double> host_arr(BUFSZ2D(x_extra, y_extra)/sizeof(double));
cudaDeviceSynchronize();
try
{
cudaMemcpy(&host_arr.front(), arr_names.at(arr_name),
BUFSZ2D(x_extra, y_extra), cudaMemcpyDeviceToHost);
}
catch (std::out_of_range e)
{
DIE("Error - %s was not in the arr_names map\n", arr_name.c_str());
}
errorHandler(__LINE__, __FILE__);
#if 1
int x_sz = x_max + 2*halo_exchange_depth + x_extra;
int y_sz = y_max + 2*halo_exchange_depth + y_extra;
std::cout << std::endl;
for (int k = 0; k < y_sz; k++)
fprintf(stdout, "%3d ", k);
std::cout << std::endl;
for (int k = 0; k < y_sz; k++)
fprintf(stdout, "%3d ", k-halo_exchange_depth);
std::cout << std::endl;
std::cout << std::endl;
for (int k = y_sz-1; k >= 0; k--)
{
for (int j = 0; j < x_sz; j++)
{
fprintf(stdout, "% 4.1f ", host_arr.at(j + k*x_sz));
//fprintf(stdout, "%3d ", (int)host_arr.at(j + k*x_sz));
}
std::cout << std::endl;
}
#endif
return host_arr;
}
// called when something goes wrong
void TeaDie
(int line, const char* filename, const char* format, ...)
{
fprintf(stderr, "@@@@@\n");
fprintf(stderr, "\x1b[31m");
fprintf(stderr, "Fatal error at line %d in %s:", line, filename);
fprintf(stderr, "\x1b[0m");
fprintf(stderr, "\n");
va_list arglist;
va_start(arglist, format);
vfprintf(stderr, format, arglist);
va_end(arglist);
// TODO add logging or something
fprintf(stderr, "\nExiting\n");
MPI_Abort(MPI_COMM_WORLD, 1);
}