-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcudart_wrapper.h
More file actions
334 lines (294 loc) · 7.49 KB
/
Copy pathcudart_wrapper.h
File metadata and controls
334 lines (294 loc) · 7.49 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#ifndef CUDA_HOOK_H_
#define CUDA_HOOK_H_
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <cxxabi.h>
#include <pthread.h>
#include <math.h>
#include <execinfo.h>
#include <cupti.h>
#include <cuda.h>
#include <cuda_runtime.h>
#define METRIC_MAX_NUM 32
#define EVENT_MAX_NUM 128
#define METRIC_NAME_MAX_LEN 64
#define EVENT_NAME_MAX_LEN 64
#define KERNEL_NAME_MAX_LEN 256
#define SHORT_DESC_MAX_LEN 64
#define KERNEL_MAX_RECORD 50
#define DRIVER_API_CALL(apiFuncCall) \
do { \
CUresult _status = apiFuncCall; \
if (_status != CUDA_SUCCESS) { \
fprintf(stderr, "%s:%d: error: function %s \
failed with error %d.\n",__FILE__, \
__LINE__, #apiFuncCall, _status); \
exit(EXIT_FAILURE); \
} \
} while (0)
#define RUNTIME_API_CALL(apiFuncCall) \
do { \
cudaError_t _status = apiFuncCall; \
if (_status != cudaSuccess) { \
fprintf(stderr, "%s:%d: error: function %s \
failed with error %s.\n", __FILE__,\
__LINE__, #apiFuncCall, \
cudaGetErrorString(_status)); \
void *arr[10]; \
size_t size = backtrace(arr, 10); \
char **btStr = backtrace_symbols(arr, size);\
int i; \
for(i = 0; i < 10; i++) \
{ \
fprintf(stderr, "%s\n", btStr[i]); \
} \
free(btStr); \
exit(EXIT_FAILURE); \
} \
} while (0)
#define CUPTI_CALL(call) \
do { \
CUptiResult _status = call; \
if (_status != CUPTI_SUCCESS) { \
fprintf(stderr, "err code: %d\n", _status);\
const char *errstr; \
cuptiGetResultString(_status, &errstr); \
fprintf(stderr, "%s:%d: error: function %s \
failed with error %s.\n", __FILE__,\
__LINE__, #call, errstr); \
void *arr[10]; \
size_t size = backtrace(arr, 10); \
char **btStr = backtrace_symbols(arr, size);\
int i; \
for(i = 0; i < 10; i++) \
{ \
fprintf(stderr, "trace: %s\n", btStr[i]);\
} \
free(btStr); \
exit(EXIT_FAILURE); \
} \
} while (0)
#define PROF_CALL(call) \
do { \
int _status = call; \
if (_status != 0) { \
fprintf(stderr, "%s:%d: error: function %s \
failed.\n", __FILE__, \
__LINE__, #call); \
void *arr[10]; \
size_t size = backtrace(arr, 10); \
char **btStr = backtrace_symbols(arr, size);\
int i; \
for(i = 0; i < 10; i++) \
{ \
fprintf(stderr, "%s\n", btStr[i]); \
} \
free(btStr); \
exit(EXIT_FAILURE); \
} \
} while (0)
#define ALIGN_SIZE (8)
#define ALIGN_BUFFER(buffer, align) \
(((uintptr_t) (buffer) & ((align)-1)) ? \
((buffer) + (align) - ((uintptr_t) (buffer) & \
((align)-1))) : (buffer))
typedef enum memType_t
{
GLOBAL_MEM,
PAGELOCKED_MEM,
MAPPED_MEM_HOST,
MAPPED_MEM_DEVICE,
PITCHED_MEM,
GLOBAL_3D_MEM
}memType;
// User data for event collection callback
typedef struct EGSData_st
{
// the set of event groups to collect for a pass
CUpti_EventGroupSet *groupSet;
// the number of entries in eventIdArray and eventValueArray
uint32_t numEvents;
// array of event ids
CUpti_EventID *eventIDs;
// array of event values
uint64_t *eventValues;
} EGSData_t;
typedef struct eventIDArray_t
{
CUpti_EventID eventIDs[EVENT_MAX_NUM];
int numEvents;
}eventIDArray;
typedef struct metricIDEventNeedArray_t
{
CUpti_MetricID metricIDs[METRIC_MAX_NUM];
eventIDArray eventsNeed[METRIC_MAX_NUM];
int numMetrics;
}metricIDEventNeedArray;
typedef struct eventsCollection_t
{
CUpti_EventID eventIDs[EVENT_MAX_NUM];
CUpti_EventGroupSets *groupSets;
int numEventsEachSets[EVENT_MAX_NUM];
int numEvents;
}eventsCollection;
typedef struct eventData_t
{
CUpti_EventID eventID;
uint64_t eventValue;
}eventData;
typedef struct metricData_t
{
CUpti_MetricID metricID;
CUpti_MetricValue metricValue;
}metricData;
/*
typedef union customMetricValue_t
{
long long valueLongLong;
long double valueLongDouble;
}customMetricValue;
typedef enum customMetricValueKind_t
{
CUSTOM_MTR_VALUE_LONGLONG,
CUSTOM_MTR_VALUE_LONGDOUBLE
}customMetricValueKind;
typedef struct customMetricData_t
{
char name[METRIC_NAME_MAX_LEN];
customMetricValue value;
customMetricValueKind valueKind;
}customMetricData;
*/
typedef struct kernelInfo_t
{
char kernelName[KERNEL_NAME_MAX_LEN];
uint32_t deviceID;
uint32_t streamID;
int64_t gridID;
int32_t gridX;
int32_t gridY;
int32_t gridZ;
int32_t blockX;
int32_t blockY;
int32_t blockZ;
struct timespec start;
struct timespec end;
int32_t dynamicSharedMem;
int32_t staticSharedMem;
uint32_t localMemPerThread;
uint32_t localMemTotal;
uint16_t regPerThread;
uint8_t cacheConfigReq;
uint8_t cacheConfigUsed;
uint8_t sharedMemConfigUsed;
}kernelInfo;
typedef enum occupancyLimiter_t
{
NONE,
BLOCK_SIZE,
REG_PER_THREAD,
SMEM_PER_BLOCK,
GRID_SIZE
}occupancyLimiter;
typedef struct occupancyData_t
{
double achieved;
occupancyLimiter achiLimiter;
double theory;
occupancyLimiter theoLimiter;
}occupancyData;
typedef struct kernelProfileData_t
{
kernelInfo kerInfo;
eventData eventDatas[EVENT_MAX_NUM];
int numEvents;
metricData metricDatas[METRIC_MAX_NUM];
int numMetrics;
occupancyData occu;
}kernelProfileData;
typedef struct cudaMem_t
{
memType type;
void *addr;
void *content;
size_t sizeBytes;
}cudaMem;
typedef struct cudaMemItem_t
{
cudaMem mem;
struct cudaMemItem_t *next;
}cudaMemItem;
typedef struct cudaConfigCallArg_t
{
dim3 gridDim;
dim3 blockDim;
size_t sharedMem;
cudaStream_t stream;
}cudaConfCallArg;
typedef struct cudaSetupArg_t
{
void *arg;
size_t size;
size_t offset;
}cudaSetupArg;
typedef struct cudaSetupArgItem_t
{
cudaSetupArg arg;
struct cudaSetupArgItem_t *next;
}cudaSetupArgItem;
typedef struct kernelArgData_t
{
cudaConfCallArg confArg;
cudaSetupArgItem *cudaSetupArgHead;
}kernelArgData;
typedef struct cuMemcpyInfo_t
{
enum cudaMemcpyKind kind;
size_t count;
}cuMemcpyInfo;
typedef enum traceType_t
{
RUNTIME_MEMCPY,
PROF_OVERHEAD
}traceType;
typedef union traceInfo_t
{
cuMemcpyInfo cpyInfo;
}traceInfo;
typedef struct cuTimeTrace_t
{
char shortDesc[SHORT_DESC_MAX_LEN];
struct timespec start;
struct timespec end;
traceType type;
traceInfo info;
}cuTimeTrace;
typedef enum allocGranularity_t
{
GRANULARITY_BLOCK,
GRANULARITY_WARP
}allocGranularity;
typedef struct gpuLimit_t
{
int limitThreadsPerWarp;
int limitWarpsPerMultpro;
int limitThreadsPerMultpro;
int limitBlocksPerMultpro;
int limitTotalRegs;
int regAllocaUnitSize;
allocGranularity allocaGranularity;
int limitRegsPerThread;
int limitTotalSMemPerMultpro;
int SMemAllocaSize;
int warpAllocaGranularity;
int maxThreadsPerBlock;
}gpuLimit;
typedef struct kerProfClassRecord_t
{
kernelInfo kerInfo;
unsigned long times;
struct kerProfClassRecord_t *next;
}kerProfClassRecord;
#endif