-
Notifications
You must be signed in to change notification settings - Fork 3
/
hip.nw.cpp
711 lines (646 loc) · 14.3 KB
/
hip.nw.cpp
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
ava_name("HIP");
ava_version("1.9.0");
ava_identifier(HIP);
ava_number(3);
ava_cflags();
ava_libs(-lcuda);
ava_export_qualifier();
struct hipFuncAttributes;
typedef struct hipFuncAttributes hipFuncAttributes;
#include "hip_cpp_bridge.h"
#include <hip/hip_runtime.h>
#include <hip/hcc_detail/hip_runtime_api.h>
#include <hsa_limited.h>
hipError_t
hipDeviceSynchronize(void)
{
}
hipError_t
hipMalloc(void **dptr,
size_t size)
{
ava_argument(dptr) {
ava_out; ava_buffer(1); ava_element {ava_opaque;}
}
}
hipError_t
hipFree(void* ptr)
{
ava_argument(ptr) {ava_opaque;}
}
hipError_t
hipMemcpyHtoD(hipDeviceptr_t dst, void* src, size_t sizeBytes)
{
ava_argument(src) {
ava_in;
ava_buffer(sizeBytes);
}
ava_argument(dst) ava_opaque;
}
hipError_t
hipMemcpyDtoH(void* dst, hipDeviceptr_t src, size_t sizeBytes)
{
ava_argument(src) ava_opaque;
ava_argument(dst) {
ava_out;
ava_buffer(sizeBytes);
}
}
hipError_t
hipMemcpyDtoD(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes)
{
ava_argument(src) ava_opaque;
ava_argument(dst) ava_opaque;
}
hipError_t
nw_hipMemcpy(void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind)
{
ava_argument(dst) {
ava_depends_on(kind);
if (kind == hipMemcpyDeviceToHost) {
ava_out;
ava_buffer(sizeBytes);
} else {
ava_opaque;
}
}
ava_argument(src) {
ava_depends_on(kind);
if (kind == hipMemcpyHostToDevice) {
ava_in;
ava_buffer(sizeBytes);
} else {
ava_opaque;
}
}
}
hipError_t nw_hipMemcpyPeerAsync(void* dst, int dstDeviceId, const void* src, int srcDevice,
size_t sizeBytes, hipStream_t stream)
{
ava_argument(dst) ava_opaque;
ava_argument(src) ava_opaque;
ava_argument(stream) ava_opaque;
}
hipError_t
hipMemcpyHtoDAsync(hipDeviceptr_t dst, void* src, size_t sizeBytes, hipStream_t stream)
{
ava_argument(src) {
ava_in;
ava_buffer(sizeBytes);
}
ava_argument(dst) ava_opaque;
ava_argument(stream) ava_opaque;
}
hipError_t
hipMemcpyDtoHAsync(void* dst, hipDeviceptr_t src, size_t sizeBytes, hipStream_t stream)
{
ava_argument(src) ava_opaque;
ava_argument(dst) {
ava_out;
ava_buffer(sizeBytes);
}
ava_argument(stream) ava_opaque;
}
hipError_t
hipMemcpyDtoDAsync(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes, hipStream_t stream)
{
ava_argument(src) ava_opaque;
ava_argument(dst) ava_opaque;
ava_argument(stream) ava_opaque;
}
hipError_t
nw_hipMemcpySync(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind,
hipStream_t stream)
{
ava_argument(dst) {
ava_depends_on(kind);
if (kind == hipMemcpyDeviceToHost) {
ava_out;
ava_buffer(sizeBytes);
} else {
ava_opaque;
}
}
ava_argument(src) {
ava_depends_on(kind);
if (kind == hipMemcpyHostToDevice) {
ava_in;
ava_buffer(sizeBytes);
} else {
ava_opaque;
}
}
ava_argument(stream) ava_opaque;
}
hipError_t
hipGetDeviceCount(int* count)
{
ava_argument(count) {
ava_out; ava_buffer(1);
}
}
hipError_t
nw_hipSetDevice(int deviceId)
{
}
hipError_t
hipMemGetInfo(size_t* __free, size_t* total)
{
ava_argument(__free) {
ava_out; ava_buffer(1);
}
ava_argument(total) {
ava_out; ava_buffer(1);
}
}
hipError_t
nw_hipStreamCreate(hipStream_t* stream, hsa_agent_t *agent)
{
ava_argument(stream) {
ava_out; ava_buffer(1);
ava_element {
ava_opaque;
}
}
ava_argument(agent) {
ava_out; ava_buffer(1);
}
}
hipError_t
nw_hipGetDevice(int* deviceId)
{
ava_argument(deviceId) {
ava_out; ava_buffer(1);
}
}
hipError_t
hipInit(unsigned int flags)
{
ava_argument(flags) {
}
}
hipError_t
hipCtxGetCurrent(hipCtx_t* ctx)
{
ava_argument(ctx) {
ava_out; ava_buffer(1);
ava_element {
ava_opaque;
}
}
}
hipError_t
nw_hipStreamSynchronize(hipStream_t stream)
{
ava_argument(stream) {
ava_opaque;
}
}
hipError_t
__do_c_hipGetDeviceProperties(char* prop, int deviceId)
{
ava_argument(prop) {
ava_out; ava_buffer(sizeof(hipDeviceProp_t));
}
ava_argument(deviceId) {
}
}
ava_utility size_t hipLaunchKernel_extra_size(void **extra) {
size_t size = 1;
while (extra[size - 1] != HIP_LAUNCH_PARAM_END)
size++;
return size;
}
hipError_t
__do_c_hipHccModuleLaunchKernel(hsa_kernel_dispatch_packet_t *aql,
hipStream_t stream, void** kernelParams, char* extra,
size_t extra_size, hipEvent_t start, hipEvent_t stop)
{
ava_argument(aql) {
ava_in; ava_buffer(1);
}
ava_argument(kernelParams) {
ava_in; ava_buffer(1);
ava_element {
ava_opaque;
}
}
ava_argument(extra) {
ava_in; ava_buffer(extra_size);
}
ava_argument (stream) {
ava_opaque;
}
ava_argument (start) {
ava_opaque;
}
ava_argument (stop) {
ava_opaque;
}
}
hipError_t
__do_c_hipHccModuleLaunchMultiKernel(int numKernels,
hsa_kernel_dispatch_packet_t *aql, hipStream_t stream,
char* all_extra, size_t total_extra_size,
size_t* extra_size, hipEvent_t *start, hipEvent_t *stop) {
ava_argument(aql) {
ava_in; ava_buffer(numKernels);
}
ava_argument(stream) {
ava_opaque;
}
ava_argument(all_extra) {
ava_in; ava_buffer(total_extra_size);
}
ava_argument(extra_size) {
ava_in; ava_buffer(numKernels);
}
ava_argument(start) {
ava_in; ava_buffer(numKernels);
ava_element {
ava_opaque;
}
}
ava_argument(stop) {
ava_in; ava_buffer(numKernels);
ava_element {
ava_opaque;
}
}
}
hipError_t
__do_c_hipHccModuleLaunchMultiKernel_and_memcpy(
int numKernels, hsa_kernel_dispatch_packet_t *aql,
hipStream_t stream,
char* all_extra, size_t total_extra_size, size_t* extra_size,
hipEvent_t *start, hipEvent_t *stop,
void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind)
{
ava_argument(aql) {
ava_in; ava_buffer(numKernels);
}
ava_argument(stream) {
ava_opaque;
}
ava_argument(all_extra) {
ava_in; ava_buffer(total_extra_size);
}
ava_argument(extra_size) {
ava_in; ava_buffer(numKernels);
}
ava_argument(start) {
ava_in; ava_buffer(numKernels);
ava_element {
ava_opaque;
}
}
ava_argument(stop) {
ava_in; ava_buffer(numKernels);
ava_element {
ava_opaque;
}
}
ava_argument(dst) {
ava_depends_on(kind);
if (kind == hipMemcpyDeviceToHost) {
ava_out;
ava_buffer(sizeBytes);
} else {
ava_opaque;
}
}
ava_argument(src) {
ava_depends_on(kind);
if (kind == hipMemcpyHostToDevice) {
ava_in;
ava_buffer(sizeBytes);
} else {
ava_opaque;
}
}
}
hsa_status_t
HSA_API nw_hsa_system_major_extension_supported(
uint16_t extension,
uint16_t version_major,
uint16_t *version_minor,
bool *result)
{
ava_argument(result) {
ava_out; ava_buffer(1);
}
ava_argument(version_minor) {
ava_in; ava_out; ava_buffer(1);
}
}
hsa_status_t
HSA_API nw_hsa_executable_create_alt(
hsa_profile_t profile,
hsa_default_float_rounding_mode_t default_float_rounding_mode,
const char *options,
hsa_executable_t *executable)
{
ava_argument(options) {
ava_in; ava_buffer(strlen(options) + 1);
}
ava_argument(executable) {
ava_out; ava_buffer(1);
}
}
hsa_status_t
HSA_API nw_hsa_isa_from_name(
const char *name,
hsa_isa_t *isa)
{
ava_argument(name) {
ava_in; ava_buffer(strlen(name) + 1);
}
ava_argument(isa) {
ava_out; ava_buffer(1);
}
}
hipError_t hipPeekAtLastError(void)
{
}
hipError_t
nw_hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int deviceId)
{
ava_argument(pi) {
ava_out; ava_buffer(1);
}
}
typedef uint16_t Elf_Half;
typedef uint32_t Elf_Word;
typedef int32_t Elf_Sword;
typedef uint64_t Elf_Xword;
typedef int64_t Elf_Sxword;
typedef uint32_t Elf32_Addr;
typedef uint32_t Elf32_Off;
typedef uint64_t Elf64_Addr;
typedef uint64_t Elf64_Off;
#define Elf32_Half Elf_Half
#define Elf64_Half Elf_Half
#define Elf32_Word Elf_Word
#define Elf64_Word Elf_Word
#define Elf32_Sword Elf_Sword
#define Elf64_Sword Elf_Sword
#define EI_NIDENT 16
typedef struct Elf64_Ehdr {
unsigned char e_ident[EI_NIDENT];
Elf_Half e_type;
Elf_Half e_machine;
Elf_Word e_version;
Elf64_Addr e_entry;
Elf64_Off e_phoff;
Elf64_Off e_shoff;
Elf_Word e_flags;
Elf_Half e_ehsize;
Elf_Half e_phentsize;
Elf_Half e_phnum;
Elf_Half e_shentsize;
Elf_Half e_shnum;
Elf_Half e_shstrndx;
} Elf64_Ehdr;
ava_utility size_t calc_image_size(const void *image)
{
const Elf64_Ehdr *h = (Elf64_Ehdr *)image;
return sizeof(Elf64_Ehdr) + h->e_shoff + h->e_shentsize * h->e_shnum;
}
hipError_t
hipModuleLoadData(hipModule_t* module, const void* image)
{
ava_argument(module) {
ava_out; ava_buffer(1);
ava_element {
ava_opaque;
}
}
ava_argument(image) {
ava_in; ava_buffer(calc_image_size(image));
}
}
#include <stdint.h>
hsa_status_t HSA_API __do_c_hsa_executable_symbol_get_info(
hsa_executable_symbol_t executable_symbol,
hsa_executable_symbol_info_t attribute, char *value, size_t max_value)
{
ava_argument(value) {
ava_depends_on(max_value);
ava_out; ava_buffer(max_value);
}
}
hipError_t nw_hipCtxSetCurrent(hipCtx_t ctx)
{
ava_argument(ctx) ava_opaque;
}
hipError_t hipEventCreate(hipEvent_t* event)
{
ava_argument(event) {
ava_out; ava_buffer(1);
ava_element {
ava_opaque;
}
}
}
hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream)
{
ava_argument(event) ava_opaque;
ava_argument(stream) ava_opaque;
}
hipError_t hipEventSynchronize(hipEvent_t event)
{
ava_argument(event) ava_opaque;
}
hipError_t hipEventDestroy(hipEvent_t event)
{
ava_argument(event) {
ava_opaque;
}
}
hipError_t hipEventElapsedTime(float* ms, hipEvent_t start, hipEvent_t stop)
{
ava_argument(ms) {
ava_out; ava_buffer(1);
}
ava_argument(start) ava_opaque;
ava_argument(stop) ava_opaque;
}
hipError_t hipModuleLoad(hipModule_t* module, const char* fname)
{
ava_argument(module) {
ava_out; ava_buffer(1);
ava_element {
ava_opaque;
}
}
ava_argument(fname) {
ava_in; ava_buffer(strlen(fname) + 1);
}
}
hipError_t hipModuleUnload(hipModule_t module)
{
ava_argument(module) {
ava_opaque;
}
}
hipError_t nw_hipStreamDestroy(hipStream_t stream)
{
ava_argument(stream) {
ava_opaque;
}
}
hipError_t hipModuleGetFunction(hipFunction_t* function, hipModule_t module,
const char* kname)
{
ava_argument(function) {
ava_out; ava_buffer(1);
ava_element {
ava_opaque;
}
}
ava_argument(module) {
ava_opaque;
}
ava_argument(kname) {
ava_in; ava_buffer(strlen(kname) + 1);
}
}
hipError_t hipGetLastError(void)
{
}
hipError_t hipMemset(void *dst, int value, size_t sizeBytes)
{
ava_argument(dst) ava_opaque;
}
hipError_t
hipStreamWaitEvent(hipStream_t stream, hipEvent_t event, unsigned int flags)
{
ava_argument(stream) ava_opaque;
ava_argument(event) ava_opaque;
}
hsa_status_t HSA_API __do_c_hsa_agent_get_info(
hsa_agent_t agent,
hsa_agent_info_t attribute,
void* value,
size_t max_value)
{
ava_argument(value) {
ava_depends_on(max_value);
ava_out; ava_buffer(max_value);
}
}
int
__do_c_load_executable(const char *file_buf, size_t file_len,
hsa_executable_t *executable, hsa_agent_t *agent)
{
ava_argument(file_buf) {
ava_in; ava_buffer(file_len);
}
ava_argument(executable) {
ava_in; ava_out; ava_buffer(1);
}
ava_argument(agent) {
ava_in; ava_buffer(1);
}
}
size_t
__do_c_get_agents(hsa_agent_t *agents, size_t max_agents)
{
ava_argument(agents) {
ava_out; ava_buffer(max_agents);
}
}
size_t
__do_c_get_isas(hsa_agent_t agents, hsa_isa_t *isas, size_t max_isas)
{
ava_argument(isas) {
ava_out; ava_buffer(max_isas);
}
}
size_t
__do_c_get_kerenel_symbols(
const hsa_executable_t *exec,
const hsa_agent_t *agent,
hsa_executable_symbol_t *symbols,
size_t max_symbols)
{
ava_argument(exec) {
ava_in; ava_buffer(1);
}
ava_argument(agent) {
ava_in; ava_buffer(1);
}
ava_argument(symbols) {
ava_out; ava_buffer(max_symbols);
}
}
hsa_status_t
HSA_API __do_c_query_host_address(
uint64_t kernel_object_,
char *kernel_header_)
{
ava_argument(kernel_object_) ava_opaque;
ava_argument(kernel_header_) {
ava_out; ava_buffer(sizeof(amd_kernel_code_t));
}
}
hipError_t
__do_c_get_kernel_descriptor(const hsa_executable_symbol_t *symbol,
const char *name, hipFunction_t *f)
{
ava_argument(symbol) {
ava_in; ava_buffer(1);
}
ava_argument(name) {
ava_in; ava_buffer(strlen(name) + 1);
}
ava_argument(f) {
ava_out; ava_buffer(1);
ava_element {
ava_opaque;
}
}
}
hipError_t
nw_hipCtxGetDevice(hipDevice_t* device)
{
ava_argument(device) {
ava_out; ava_buffer(1);
}
}
hipError_t
nw_lookup_kern_info(hipFunction_t f, struct nw_kern_info *info)
{
ava_argument(f) {
ava_opaque;
}
ava_argument(info) {
ava_out; ava_buffer(1);
}
}
hipError_t
__do_c_mass_symbol_info(size_t n, const hsa_executable_symbol_t *syms,
hsa_symbol_kind_t *types, hipFunction_t *descriptors,
uint8_t * agents, unsigned *offsets, char *pool,
size_t pool_size)
{
ava_argument(syms) {
ava_in; ava_buffer(n);
}
ava_argument(types) {
ava_out; ava_buffer(n);
}
ava_argument(descriptors) {
ava_out; ava_buffer(n);
ava_element { ava_opaque; }
}
ava_argument(agents) {
ava_out; ava_buffer(n * sizeof(agents));
}
ava_argument(offsets) {
ava_out; ava_buffer(n);
}
ava_argument(pool) {
ava_out; ava_buffer(pool_size);
}
}