-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathrocm.c
More file actions
727 lines (613 loc) · 19.6 KB
/
rocm.c
File metadata and controls
727 lines (613 loc) · 19.6 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
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
/**
* @file rocm.c
* @author Giuseppe Congiu
* gcongiu@icl.utk.edu
*
* @ingroup papi_components
*
* @brief This implements a PAPI component that enables PAPI-C to
* access hardware monitoring counters for AMD ROCM GPU devices
* through the ROC-profiler library.
*
* The open source software license for PAPI conforms to the BSD
* License template.
*/
#include <string.h>
#include "papi.h"
#include "papi_internal.h"
#include "papi_memory.h"
#include "papi_vector.h"
#include "extras.h"
#include "roc_dispatch.h"
/* Init and finalize */
static int rocm_init_component(int cid);
static int rocm_init_thread(hwd_context_t *ctx);
static int rocm_init_control_state(hwd_control_state_t *ctl);
static int rocm_init_private(void);
static int rocm_shutdown_component(void);
static int rocm_shutdown_thread(hwd_context_t *ctx);
static int rocm_cleanup_eventset(hwd_control_state_t *ctl);
static void rocm_dispatch_timer(int n, hwd_siginfo_t *info, void *uc);
/* set and update component state */
static int rocm_update_control_state(hwd_control_state_t *ctl,
NativeInfo_t *ntv_info,
int ntv_count, hwd_context_t *ctx);
static int rocm_set_domain(hwd_control_state_t *ctl, int domain);
static int rocm_ctrl(hwd_context_t *ctx, int code, _papi_int_option_t *option);
/* start and stop monitoring of hardware counters */
static int rocm_start(hwd_context_t *ctx, hwd_control_state_t *ctl);
static int rocm_read(hwd_context_t *ctx, hwd_control_state_t *ctl,
long long **val, int flags);
static int rocm_stop(hwd_context_t *ctx, hwd_control_state_t *ctl);
static int rocm_reset(hwd_context_t *ctx, hwd_control_state_t *ctl);
/* event conversion utilities */
static int rocm_ntv_enum_events(unsigned int *event_code, int modifier);
static int rocm_ntv_code_to_name(unsigned int event_code, char *name, int len);
static int rocm_ntv_name_to_code(const char *name, unsigned int *event_code);
static int rocm_ntv_code_to_descr(unsigned int event_code, char *descr,
int len);
static int rocm_ntv_code_to_info(unsigned int event_code, PAPI_event_info_t *info);
typedef struct {
int initialized;
int state;
int component_id;
} rocm_context_t;
typedef struct {
int num_events;
unsigned int domain;
unsigned int granularity;
unsigned int overflow;
unsigned int overflow_signal;
unsigned int attached;
int component_id;
uint64_t *events_id;
rocd_ctx_t rocd_ctx;
} rocm_control_t;
papi_vector_t _rocm_vector = {
.cmp_info = {
.name = "rocm",
.short_name = "rocm",
.version = "2.0",
.description = "GPU events and metrics via AMD ROCm-PL API",
.num_mpx_cntrs = PAPI_ROCM_MAX_COUNTERS,
.num_cntrs = PAPI_ROCM_MAX_COUNTERS,
.default_domain = PAPI_DOM_USER,
.default_granularity = PAPI_GRN_THR,
.available_granularities = PAPI_GRN_THR,
.hardware_intr_sig = PAPI_INT_SIGNAL,
.fast_real_timer = 0,
.fast_virtual_timer = 0,
.attach = 0,
.attach_must_ptrace = 0,
.available_domains = PAPI_DOM_USER | PAPI_DOM_KERNEL,
.initialized = 0,
},
.size = {
.context = sizeof(rocm_context_t),
.control_state = sizeof(rocm_control_t),
.reg_value = 1,
.reg_alloc = 1,
},
.init_component = rocm_init_component,
.init_thread = rocm_init_thread,
.init_control_state = rocm_init_control_state,
.shutdown_component = rocm_shutdown_component,
.shutdown_thread = rocm_shutdown_thread,
.cleanup_eventset = rocm_cleanup_eventset,
.dispatch_timer = rocm_dispatch_timer,
.update_control_state = rocm_update_control_state,
.set_domain = rocm_set_domain,
.ctl = rocm_ctrl,
.start = rocm_start,
.stop = rocm_stop,
.read = rocm_read,
.reset = rocm_reset,
.ntv_enum_events = rocm_ntv_enum_events,
.ntv_code_to_name = rocm_ntv_code_to_name,
.ntv_name_to_code = rocm_ntv_name_to_code,
.ntv_code_to_descr = rocm_ntv_code_to_descr,
.ntv_code_to_info = rocm_ntv_code_to_info,
};
static int check_n_initialize(void);
int
rocm_init_component(int cid)
{
_rocm_vector.cmp_info.CmpIdx = cid;
_rocm_vector.cmp_info.num_native_events = -1;
_rocm_vector.cmp_info.num_cntrs = -1;
_rocm_lock = PAPI_NUM_LOCK + NUM_INNER_LOCK + cid;
SUBDBG("ENTER: cid: %d\n", cid);
/* Manage contension between rocm and rocp_sdk components. */
int use_rocm = 0;
#if defined(DEFAULT_TO_ROCM)
use_rocm = 1;
#endif
#if defined(DEFAULT_TO_ROCP_SDK)
char *disabledComps = getenv("PAPI_DISABLE_COMPONENTS");
if (disabledComps != NULL) {
char *penv = strdup(disabledComps);
char *p;
for (p = strtok (penv, ",:"); p != NULL; p = strtok (NULL, ",:")) {
if(!strcmp(p, "rocp_sdk")) use_rocm = 1;
}
free(penv);
} else {
SUBDBG("rocm: getenv(PAPI_DISABLE_COMPONENTS) was not set.\n");
}
#endif
int papi_errno, expect;
if (use_rocm) {
papi_errno = rocd_init_environment();
if (papi_errno != PAPI_OK) {
_rocm_vector.cmp_info.initialized = 1;
_rocm_vector.cmp_info.disabled = papi_errno;
const char *err_string;
rocd_err_get_last(&err_string);
expect = snprintf(_rocm_vector.cmp_info.disabled_reason,
PAPI_HUGE_STR_LEN, "%s", err_string);
if (expect < 0 || expect >= PAPI_HUGE_STR_LEN) {
SUBDBG("disabled_reason truncated");
}
goto fn_fail;
}
expect = snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_HUGE_STR_LEN, "%s",
"Not initialized. Access component events to initialize it.");
if (expect < 0 || expect >= PAPI_HUGE_STR_LEN) {
SUBDBG("disabled_reason truncated");
}
papi_errno = PAPI_EDELAY_INIT;
_rocm_vector.cmp_info.disabled = papi_errno;
} else {
expect = snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_HUGE_STR_LEN, "%s",
"Not active while rocp_sdk component is active. Set 'export PAPI_DISABLE_COMPONENTS=rocp_sdk' to override.");
if (expect < 0 || expect >= PAPI_HUGE_STR_LEN) {
SUBDBG("disabled_reason truncated");
}
papi_errno = PAPI_ECOMBO;
_rocm_vector.cmp_info.disabled = papi_errno;
}
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
goto fn_exit;
}
int
rocm_init_thread(hwd_context_t *ctx)
{
rocm_context_t *rocm_ctx = (rocm_context_t *) ctx;
memset(rocm_ctx, 0, sizeof(*rocm_ctx));
rocm_ctx->initialized = 1;
rocm_ctx->component_id = _rocm_vector.cmp_info.CmpIdx;
return PAPI_OK;
}
int
rocm_init_control_state(hwd_control_state_t *ctl __attribute__((unused)))
{
return check_n_initialize();
}
static int
evt_get_count(int *count)
{
uint64_t event_code = 0;
if (rocd_evt_enum(&event_code, PAPI_ENUM_FIRST) == PAPI_OK) {
++(*count);
}
while (rocd_evt_enum(&event_code, PAPI_ENUM_EVENTS) == PAPI_OK) {
++(*count);
}
return PAPI_OK;
}
int
rocm_init_private(void)
{
int papi_errno = PAPI_OK;
_papi_hwi_lock(COMPONENT_LOCK);
SUBDBG("ENTER\n");
if (_rocm_vector.cmp_info.initialized) {
papi_errno = _rocm_vector.cmp_info.disabled;
goto fn_exit;
}
papi_errno = rocd_init();
if (papi_errno != PAPI_OK) {
_rocm_vector.cmp_info.disabled = papi_errno;
const char *err_string;
rocd_err_get_last(&err_string);
int expect = snprintf(_rocm_vector.cmp_info.disabled_reason,
PAPI_HUGE_STR_LEN, "%s", err_string);
if (expect > PAPI_HUGE_STR_LEN) {
SUBDBG("disabled_reason truncated");
}
goto fn_fail;
}
int count = 0;
papi_errno = evt_get_count(&count);
_rocm_vector.cmp_info.num_native_events = count;
_rocm_vector.cmp_info.num_cntrs = count;
_rocm_vector.cmp_info.initialized = 1;
int strLen = snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_HUGE_STR_LEN, "%s", "");
if (strLen < 0 || strLen >= PAPI_HUGE_STR_LEN) {
SUBDBG("Failed to fully write disabled_reason.\n");
}
goto fn_exit;
fn_fail:
_rocm_vector.cmp_info.initialized = 0;
fn_exit:
_rocm_vector.cmp_info.disabled = papi_errno;
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
_papi_hwi_unlock(COMPONENT_LOCK);
return papi_errno;
}
int
rocm_shutdown_component(void)
{
int papi_errno = PAPI_OK;
int orig_state = _rocm_vector.cmp_info.initialized;
_rocm_vector.cmp_info.initialized = 0;
SUBDBG("ENTER\n");
if (!_rocm_vector.cmp_info.initialized) {
goto fn_exit;
}
if (_rocm_vector.cmp_info.disabled != PAPI_OK) {
goto fn_exit;
}
papi_errno = rocd_shutdown();
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
fn_exit:
SUBDBG("EXIT\n");
return papi_errno;
fn_fail:
_rocm_vector.cmp_info.initialized = orig_state;
goto fn_exit;
}
int
rocm_shutdown_thread(hwd_context_t *ctx)
{
rocm_context_t *rocm_ctx = (rocm_context_t *) ctx;
rocm_ctx->initialized = 0;
rocm_ctx->state = 0;
return PAPI_OK;
}
int
rocm_cleanup_eventset(hwd_control_state_t *ctl)
{
rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
if (rocm_ctl->rocd_ctx != NULL) {
SUBDBG("Cannot cleanup an eventset that is running.");
return PAPI_ECMP;
}
papi_free(rocm_ctl->events_id);
rocm_ctl->events_id = NULL;
rocm_ctl->num_events = 0;
return PAPI_OK;
}
static int
counter_sampling_compatible_with_prof_mode(void)
{
return (rocm_prof_mode == ROCM_PROFILE_SAMPLING_MODE);
}
void
rocm_dispatch_timer(int n __attribute__((unused)), hwd_siginfo_t *info, void *uc)
{
_papi_hwi_context_t hw_context;
vptr_t address;
EventSetInfo_t *ESI;
ThreadInfo_t *thread;
int cidx;
if (!counter_sampling_compatible_with_prof_mode()) {
SUBDBG("Counter sampling is not compatible with intercept mode");
return;
}
_papi_hwi_lock(_rocm_lock);
cidx = _rocm_vector.cmp_info.CmpIdx;
thread = _papi_hwi_lookup_thread(0);
if (thread == NULL) {
SUBDBG("thread == NULL in user_signal_handler!");
goto fn_exit;
}
ESI = thread->running_eventset[cidx];
rocm_control_t *rocm_ctl = (rocm_control_t *) ESI->ctl_state;
if (rocm_ctl->rocd_ctx == NULL) {
SUBDBG("ESI == NULL in user_signal_handler!");
goto fn_exit;
}
hw_context.si = info;
hw_context.ucontext = (hwd_ucontext_t *) uc;
address = GET_OVERFLOW_ADDRESS(hw_context);
_papi_hwi_dispatch_overflow_signal((void *)&hw_context, address, NULL, 0, 0,
&thread, cidx);
fn_exit:
_papi_hwi_unlock(_rocm_lock);
return;
}
static int update_native_events(rocm_control_t *, NativeInfo_t *, int);
static int try_open_events(rocm_control_t *);
int
rocm_update_control_state(hwd_control_state_t *ctl, NativeInfo_t *ntv_info,
int ntv_count,
hwd_context_t *ctx __attribute__((unused)))
{
SUBDBG("ENTER: ctl: %p, ntv_info: %p, ntv_count: %d, ctx: %p\n", ctl, ntv_info, ntv_count, ctx);
int papi_errno = check_n_initialize();
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
if (rocm_ctl->rocd_ctx != NULL) {
SUBDBG("Cannot update events in an eventset that has been already "
"started.");
papi_errno = PAPI_ECMP;
goto fn_fail;
}
papi_errno = update_native_events(rocm_ctl, ntv_info, ntv_count);
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
papi_errno = try_open_events(rocm_ctl);
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
goto fn_exit;
}
struct event_map_item {
int event_id;
int frontend_idx;
};
static int
compare(const void *a, const void *b)
{
struct event_map_item *A = (struct event_map_item *) a;
struct event_map_item *B = (struct event_map_item *) b;
return A->event_id - B->event_id;
}
int
update_native_events(rocm_control_t *ctl, NativeInfo_t *ntv_info,
int ntv_count)
{
int papi_errno = PAPI_OK;
struct event_map_item sorted_events[PAPI_ROCM_MAX_COUNTERS];
if (ntv_count != ctl->num_events) {
ctl->num_events = ntv_count;
if (ntv_count == 0) {
papi_free(ctl->events_id);
ctl->events_id = NULL;
goto fn_exit;
}
else {
ctl->events_id = papi_realloc(ctl->events_id, ntv_count * sizeof(*ctl->events_id));
if (ctl->events_id == NULL) {
papi_errno = PAPI_ENOMEM;
goto fn_fail;
}
}
}
int i;
for (i = 0; i < ntv_count; ++i) {
sorted_events[i].event_id = ntv_info[i].ni_event;
sorted_events[i].frontend_idx = i;
}
qsort(sorted_events, ntv_count, sizeof(struct event_map_item), compare);
for (i = 0; i < ntv_count; ++i) {
ctl->events_id[i] = sorted_events[i].event_id;
ntv_info[sorted_events[i].frontend_idx].ni_position = i;
}
fn_exit:
return papi_errno;
fn_fail:
ctl->num_events = 0;
goto fn_exit;
}
int
try_open_events(rocm_control_t *rocm_ctl)
{
int papi_errno = PAPI_OK;
rocd_ctx_t rocd_ctx;
if (rocm_prof_mode != ROCM_PROFILE_SAMPLING_MODE) {
/* Do not try open for intercept mode */
return papi_errno;
}
if (rocm_ctl->num_events <= 0) {
return PAPI_OK;
}
papi_errno = rocd_ctx_open(rocm_ctl->events_id, rocm_ctl->num_events,
&rocd_ctx);
if (papi_errno != PAPI_OK) {
rocm_cleanup_eventset(rocm_ctl);
return papi_errno;
}
return rocd_ctx_close(rocd_ctx);
}
int
rocm_set_domain(hwd_control_state_t *ctl __attribute__((unused)),
int domain __attribute__((unused)))
{
return PAPI_OK;
}
int
rocm_ctrl(hwd_context_t *ctx __attribute__((unused)),
int code __attribute__((unused)),
_papi_int_option_t *option __attribute__((unused)))
{
return PAPI_OK;
}
int
rocm_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
{
int papi_errno = PAPI_OK;
rocm_context_t *rocm_ctx = (rocm_context_t *) ctx;
rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
SUBDBG("ENTER: ctx: %p, ctl: %p\n", ctx, ctl);
if (rocm_ctx->state & ROCM_EVENTS_OPENED) {
SUBDBG("Error! Cannot PAPI_start more than one eventset at a time for every component.");
papi_errno = PAPI_ECNFLCT;
goto fn_fail;
}
papi_errno = rocd_ctx_open(rocm_ctl->events_id, rocm_ctl->num_events,
&rocm_ctl->rocd_ctx);
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
rocm_ctx->state = ROCM_EVENTS_OPENED;
papi_errno = rocd_ctx_start(rocm_ctl->rocd_ctx);
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
rocm_ctx->state |= ROCM_EVENTS_RUNNING;
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
if (rocm_ctx->state == ROCM_EVENTS_OPENED) {
rocd_ctx_close(rocm_ctl->rocd_ctx);
}
rocm_ctx->state = 0;
goto fn_exit;
}
int
rocm_read(hwd_context_t *ctx __attribute__((unused)), hwd_control_state_t *ctl,
long long **val, int flags __attribute__((unused)))
{
int papi_errno = PAPI_OK;
rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
SUBDBG("ENTER: ctx: %p, ctl: %p, val: %p, flags: %d\n", ctx, ctl, val, flags);
if (rocm_ctl->rocd_ctx == NULL) {
SUBDBG("Error! Cannot PAPI_read counters for an eventset that has not been PAPI_start'ed.");
papi_errno = PAPI_EMISC;
goto fn_fail;
}
papi_errno = rocd_ctx_read(rocm_ctl->rocd_ctx, val);
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
goto fn_exit;
}
int
rocm_stop(hwd_context_t *ctx, hwd_control_state_t *ctl)
{
int papi_errno = PAPI_OK;
rocm_context_t *rocm_ctx = (rocm_context_t *) ctx;
rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
SUBDBG("ENTER: ctx: %p, ctl: %p\n", ctx, ctl);
if (!(rocm_ctx->state & ROCM_EVENTS_OPENED)) {
SUBDBG("Error! Cannot PAPI_stop counters for an eventset that has not been PAPI_start'ed.");
papi_errno = PAPI_EMISC;
goto fn_fail;
}
papi_errno = rocd_ctx_stop(rocm_ctl->rocd_ctx);
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
rocm_ctx->state &= ~ROCM_EVENTS_RUNNING;
papi_errno = rocd_ctx_close(rocm_ctl->rocd_ctx);
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
rocm_ctx->state = 0;
rocm_ctl->rocd_ctx = NULL;
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
goto fn_exit;
}
int
rocm_reset(hwd_context_t *ctx __attribute__((unused)), hwd_control_state_t *ctl)
{
rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
if (rocm_ctl->rocd_ctx == NULL) {
SUBDBG("Cannot reset counters for an eventset that has not been started.");
return PAPI_EMISC;
}
return rocd_ctx_reset(rocm_ctl->rocd_ctx);
}
int
rocm_ntv_enum_events(unsigned int *event_code, int modifier)
{
SUBDBG("ENTER: event_code: %u, modifier: %d\n", *event_code, modifier);
int papi_errno = check_n_initialize();
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
uint64_t code = *(uint64_t *) event_code;
papi_errno = rocd_evt_enum(&code, modifier);
*event_code = (unsigned int) code;
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
goto fn_exit;
}
int
rocm_ntv_code_to_name(unsigned int event_code, char *name, int len)
{
SUBDBG("ENTER: event_code: %u, name: %p, len: %d\n", event_code, name, len);
int papi_errno = check_n_initialize();
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
papi_errno = rocd_evt_code_to_name((uint64_t) event_code, name, len);
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
goto fn_exit;
}
int
rocm_ntv_name_to_code(const char *name, unsigned int *code)
{
SUBDBG("ENTER: name: %s, code: %p\n", name, code);
int papi_errno = check_n_initialize();
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
uint64_t event_code;
papi_errno = rocd_evt_name_to_code(name, &event_code);
*code = (unsigned int) event_code;
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
goto fn_exit;
}
int
rocm_ntv_code_to_descr(unsigned int event_code, char *descr, int len)
{
SUBDBG("ENTER: event_code: %u, descr: %p, len: %d\n", event_code, descr, len);
int papi_errno = check_n_initialize();
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
papi_errno = rocd_evt_code_to_descr((uint64_t) event_code, descr, len);
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
goto fn_exit;
}
int
rocm_ntv_code_to_info(unsigned int event_code, PAPI_event_info_t *info)
{
SUBDBG("ENTER: event_code: %u, info: %p\n", event_code, info);
int papi_errno = check_n_initialize();
if (papi_errno != PAPI_OK) {
goto fn_fail;
}
papi_errno = rocd_evt_code_to_info((uint64_t) event_code, info);
fn_exit:
SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
return papi_errno;
fn_fail:
goto fn_exit;
}
int
check_n_initialize(void)
{
if (!_rocm_vector.cmp_info.initialized) {
return rocm_init_private();
}
return _rocm_vector.cmp_info.disabled;
}