PAPI 7.1.0.0
Loading...
Searching...
No Matches
rocm.c File Reference

This implements a PAPI component that enables PAPI-C to access hardware monitoring counters for AMD ROCM GPU devices through the ROC-profiler library. More...

Include dependency graph for rocm.c:

Go to the source code of this file.

Data Structures

struct  rocm_context_t
 
struct  rocm_control_t
 
struct  event_map_item
 

Functions

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)
 
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)
 
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)
 
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)
 
static int check_n_initialize (void)
 
int rocm_init_control_state (hwd_control_state_t *ctl __attribute__((unused)))
 
static int evt_get_count (int *count)
 
static int counter_sampling_compatible_with_prof_mode (void)
 
void rocm_dispatch_timer (int n __attribute__((unused)), hwd_siginfo_t *info, void *uc)
 
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)))
 
static int compare (const void *a, const void *b)
 
int rocm_set_domain (hwd_control_state_t *ctl __attribute__((unused)), int domain __attribute__((unused)))
 
int rocm_ctrl (hwd_context_t *ctx __attribute__((unused)), int code __attribute__((unused)), _papi_int_option_t *option __attribute__((unused)))
 
int rocm_read (hwd_context_t *ctx __attribute__((unused)), hwd_control_state_t *ctl, long long **val, int flags __attribute__((unused)))
 
int rocm_reset (hwd_context_t *ctx __attribute__((unused)), hwd_control_state_t *ctl)
 

Variables

papi_vector_t _rocm_vector
 

Detailed Description

Author
Giuseppe Congiu gcong.nosp@m.iu@i.nosp@m.cl.ut.nosp@m.k.ed.nosp@m.u

The open source software license for PAPI conforms to the BSD License template.

Definition in file rocm.c.

Function Documentation

◆ check_n_initialize()

int check_n_initialize ( void  )
static

Definition at line 676 of file rocm.c.

677{
679 return rocm_init_private();
680 }
682}
papi_vector_t _rocm_vector
Definition: rocm.c:74
static int rocm_init_private(void)
Definition: rocm.c:194
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare()

static int compare ( const void *  a,
const void *  b 
)
static

Definition at line 384 of file rocm.c.

385{
386 struct event_map_item *A = (struct event_map_item *) a;
387 struct event_map_item *B = (struct event_map_item *) b;
388 return A->event_id - B->event_id;
389}
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
int event_id
Definition: rocm.c:379
Here is the caller graph for this function:

◆ counter_sampling_compatible_with_prof_mode()

static int counter_sampling_compatible_with_prof_mode ( void  )
static

Definition at line 291 of file rocm.c.

292{
294}
unsigned int rocm_prof_mode
Definition: roc_profiler.c:84
#define ROCM_PROFILE_SAMPLING_MODE
Here is the caller graph for this function:

◆ evt_get_count()

static int evt_get_count ( int count)
static

Definition at line 179 of file rocm.c.

180{
181 uint64_t event_code = 0;
182
183 if (rocd_evt_enum(&event_code, PAPI_ENUM_FIRST) == PAPI_OK) {
184 ++(*count);
185 }
186 while (rocd_evt_enum(&event_code, PAPI_ENUM_EVENTS) == PAPI_OK) {
187 ++(*count);
188 }
189
190 return PAPI_OK;
191}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
int rocd_evt_enum(uint64_t *event_code, int modifier)
Definition: roc_dispatch.c:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rocm_cleanup_eventset()

int rocm_cleanup_eventset ( hwd_control_state_t ctl)
static

Definition at line 274 of file rocm.c.

275{
276 rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
277
278 if (rocm_ctl->rocd_ctx != NULL) {
279 SUBDBG("Cannot cleanup an eventset that is running.");
280 return PAPI_ECMP;
281 }
282
283 papi_free(rocm_ctl->events_id);
284 rocm_ctl->events_id = NULL;
285 rocm_ctl->num_events = 0;
286
287 return PAPI_OK;
288}
#define PAPI_ECMP
Definition: f90papi.h:214
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
#define papi_free(a)
Definition: papi_memory.h:35
rocd_ctx_t rocd_ctx
Definition: rocm.c:71
int num_events
Definition: rocm.c:63
uint64_t * events_id
Definition: rocm.c:70
Here is the caller graph for this function:

◆ rocm_ctrl() [1/2]

int rocm_ctrl ( hwd_context_t *ctx   __attribute__(unused),
int code   __attribute__(unused),
_papi_int_option_t *option   __attribute__(unused) 
)

Definition at line 462 of file rocm.c.

465{
466 return PAPI_OK;
467}

◆ rocm_ctrl() [2/2]

static int rocm_ctrl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)
static

◆ rocm_dispatch_timer() [1/2]

void rocm_dispatch_timer ( int n   __attribute__(unused),
hwd_siginfo_t info,
void *  uc 
)

Definition at line 297 of file rocm.c.

298{
299 _papi_hwi_context_t hw_context;
300 vptr_t address;
301 EventSetInfo_t *ESI;
303 int cidx;
304
306 SUBDBG("Counter sampling is not compatible with intercept mode");
307 return;
308 }
309
311
314
315 if (thread == NULL) {
316 SUBDBG("thread == NULL in user_signal_handler!");
317 goto fn_exit;
318 }
319
320 ESI = thread->running_eventset[cidx];
321 rocm_control_t *rocm_ctl = (rocm_control_t *) ESI->ctl_state;
322
323 if (rocm_ctl->rocd_ctx == NULL) {
324 SUBDBG("ESI == NULL in user_signal_handler!");
325 goto fn_exit;
326 }
327
328 hw_context.si = info;
329 hw_context.ucontext = (hwd_ucontext_t *) uc;
330
331 address = GET_OVERFLOW_ADDRESS(hw_context);
332
333 _papi_hwi_dispatch_overflow_signal((void *)&hw_context, address, NULL, 0, 0,
334 &thread, cidx);
335
336 fn_exit:
338 return;
339}
#define GET_OVERFLOW_ADDRESS(ctx)
Definition: aix-context.h:12
int _papi_hwi_dispatch_overflow_signal(void *papiContext, vptr_t address, int *isHardware, long long overflow_bit, int genOverflowBit, ThreadInfo_t **t, int cidx)
Definition: extras.c:216
void * thread(void *arg)
Definition: kufrin.c:38
void * vptr_t
Definition: papi.h:576
static int cidx
if(file==NULL) goto out
unsigned int _rocm_lock
Definition: roc_profiler.c:85
static int counter_sampling_compatible_with_prof_mode(void)
Definition: rocm.c:291
hwd_control_state_t * ctl_state
hwd_siginfo_t * si
hwd_ucontext_t * ucontext
inline_static ThreadInfo_t * _papi_hwi_lookup_thread(int custom_tid)
Definition: threads.h:97
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:69
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:83
Here is the call graph for this function:

◆ rocm_dispatch_timer() [2/2]

static void rocm_dispatch_timer ( int  n,
hwd_siginfo_t info,
void *  uc 
)
static

◆ rocm_init_component()

int rocm_init_component ( int  cid)
static

Definition at line 128 of file rocm.c.

129{
134 SUBDBG("ENTER: cid: %d\n", cid);
135
136 int papi_errno = rocd_init_environment();
137 if (papi_errno != PAPI_OK) {
139 _rocm_vector.cmp_info.disabled = papi_errno;
140 const char *err_string;
141 rocd_err_get_last(&err_string);
142 int expect = snprintf(_rocm_vector.cmp_info.disabled_reason,
143 PAPI_MAX_STR_LEN, "%s", err_string);
144 if (expect > PAPI_MAX_STR_LEN) {
145 SUBDBG("disabled_reason truncated");
146 }
147 goto fn_fail;
148 }
149
151 "Not initialized. Access component events to initialize it.");
152 papi_errno = PAPI_EDELAY_INIT;
153 _rocm_vector.cmp_info.disabled = papi_errno;
154
155 fn_exit:
156 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
157 return papi_errno;
158 fn_fail:
159 goto fn_exit;
160}
Returns a string describing the PAPI error code.
#define PAPI_NUM_LOCK
Definition: f90papi.h:80
#define PAPI_EDELAY_INIT
Definition: f90papi.h:271
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define NUM_INNER_LOCK
Definition: papi_lock.h:17
int rocd_err_get_last(const char **error_str)
Definition: roc_dispatch.c:73
int rocd_init_environment(void)
Definition: roc_dispatch.c:15
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
Here is the call graph for this function:

◆ rocm_init_control_state() [1/2]

int rocm_init_control_state ( hwd_control_state_t *ctl   __attribute__(unused))

Definition at line 173 of file rocm.c.

174{
175 return check_n_initialize();
176}
static int check_n_initialize(void)
Definition: rocm.c:676
Here is the call graph for this function:

◆ rocm_init_control_state() [2/2]

static int rocm_init_control_state ( hwd_control_state_t ctl)
static

◆ rocm_init_private()

int rocm_init_private ( void  )
static

Definition at line 194 of file rocm.c.

195{
196 int papi_errno = PAPI_OK;
197
199 SUBDBG("ENTER\n");
200
202 papi_errno = _rocm_vector.cmp_info.disabled;
203 goto fn_exit;
204 }
205
206 papi_errno = rocd_init();
207 if (papi_errno != PAPI_OK) {
208 _rocm_vector.cmp_info.disabled = papi_errno;
209 const char *err_string;
210 rocd_err_get_last(&err_string);
211 int expect = snprintf(_rocm_vector.cmp_info.disabled_reason,
212 PAPI_MAX_STR_LEN, "%s", err_string);
213 if (expect > PAPI_MAX_STR_LEN) {
214 SUBDBG("disabled_reason truncated");
215 }
216
217 goto fn_fail;
218 }
219
220 int count = 0;
221 papi_errno = evt_get_count(&count);
224
225 fn_exit:
227 _rocm_vector.cmp_info.disabled = papi_errno;
228 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
230 return papi_errno;
231 fn_fail:
232 goto fn_exit;
233}
static long count
#define COMPONENT_LOCK
Definition: papi_internal.h:90
int rocd_init(void)
Definition: roc_dispatch.c:21
static int evt_get_count(int *count)
Definition: rocm.c:179
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rocm_init_thread()

int rocm_init_thread ( hwd_context_t ctx)
static

Definition at line 163 of file rocm.c.

164{
165 rocm_context_t *rocm_ctx = (rocm_context_t *) ctx;
166 memset(rocm_ctx, 0, sizeof(*rocm_ctx));
167 rocm_ctx->initialized = 1;
169 return PAPI_OK;
170}
int component_id
Definition: rocm.c:59
int initialized
Definition: rocm.c:57

◆ rocm_ntv_code_to_descr()

int rocm_ntv_code_to_descr ( unsigned int  event_code,
char *  descr,
int  len 
)
static

Definition at line 640 of file rocm.c.

641{
642 SUBDBG("ENTER: event_code: %u, descr: %p, len: %d\n", event_code, descr, len);
643 int papi_errno = check_n_initialize();
644 if (papi_errno != PAPI_OK) {
645 goto fn_fail;
646 }
647
648 papi_errno = rocd_evt_code_to_descr((uint64_t) event_code, descr, len);
649
650 fn_exit:
651 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
652 return papi_errno;
653 fn_fail:
654 goto fn_exit;
655}
int rocd_evt_code_to_descr(uint64_t event_code, char *descr, int len)
Definition: roc_dispatch.c:49
char * descr
Here is the call graph for this function:

◆ rocm_ntv_code_to_info()

int rocm_ntv_code_to_info ( unsigned int  event_code,
PAPI_event_info_t info 
)
static

Definition at line 658 of file rocm.c.

659{
660 SUBDBG("ENTER: event_code: %u, info: %p\n", event_code, info);
661 int papi_errno = check_n_initialize();
662 if (papi_errno != PAPI_OK) {
663 goto fn_fail;
664 }
665
666 papi_errno = rocd_evt_code_to_info((uint64_t) event_code, info);
667
668 fn_exit:
669 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
670 return papi_errno;
671 fn_fail:
672 goto fn_exit;
673}
int rocd_evt_code_to_info(uint64_t event_code, PAPI_event_info_t *info)
Definition: roc_dispatch.c:67
Here is the call graph for this function:

◆ rocm_ntv_code_to_name()

int rocm_ntv_code_to_name ( unsigned int  event_code,
char *  name,
int  len 
)
static

Definition at line 602 of file rocm.c.

603{
604 SUBDBG("ENTER: event_code: %u, name: %p, len: %d\n", event_code, name, len);
605 int papi_errno = check_n_initialize();
606 if (papi_errno != PAPI_OK) {
607 goto fn_fail;
608 }
609
610 papi_errno = rocd_evt_code_to_name((uint64_t) event_code, name, len);
611
612 fn_exit:
613 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
614 return papi_errno;
615 fn_fail:
616 goto fn_exit;
617}
int rocd_evt_code_to_name(uint64_t event_code, char *name, int len)
Definition: roc_dispatch.c:61
const char * name
Definition: rocs.c:225
Here is the call graph for this function:

◆ rocm_ntv_enum_events()

int rocm_ntv_enum_events ( unsigned int event_code,
int  modifier 
)
static

Definition at line 582 of file rocm.c.

583{
584 SUBDBG("ENTER: event_code: %u, modifier: %d\n", *event_code, modifier);
585 int papi_errno = check_n_initialize();
586 if (papi_errno != PAPI_OK) {
587 goto fn_fail;
588 }
589
590 uint64_t code = *(uint64_t *) event_code;
591 papi_errno = rocd_evt_enum(&code, modifier);
592 *event_code = (unsigned int) code;
593
594 fn_exit:
595 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
596 return papi_errno;
597 fn_fail:
598 goto fn_exit;
599}
int
Definition: sde_internal.h:89
Here is the call graph for this function:

◆ rocm_ntv_name_to_code()

int rocm_ntv_name_to_code ( const char *  name,
unsigned int event_code 
)
static

Definition at line 620 of file rocm.c.

621{
622 SUBDBG("ENTER: name: %s, code: %p\n", name, code);
623 int papi_errno = check_n_initialize();
624 if (papi_errno != PAPI_OK) {
625 goto fn_fail;
626 }
627
628 uint64_t event_code;
629 papi_errno = rocd_evt_name_to_code(name, &event_code);
630 *code = (unsigned int) event_code;
631
632 fn_exit:
633 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
634 return papi_errno;
635 fn_fail:
636 goto fn_exit;
637}
int rocd_evt_name_to_code(const char *name, uint64_t *event_code)
Definition: roc_dispatch.c:55
Here is the call graph for this function:

◆ rocm_read() [1/2]

int rocm_read ( hwd_context_t *ctx   __attribute__(unused),
hwd_control_state_t ctl,
long long **  val,
int flags   __attribute__(unused) 
)

Definition at line 510 of file rocm.c.

512{
513 int papi_errno = PAPI_OK;
514 rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
515 SUBDBG("ENTER: ctx: %p, ctl: %p, val: %p, flags: %d\n", ctx, ctl, val, flags);
516
517 if (rocm_ctl->rocd_ctx == NULL) {
518 SUBDBG("Error! Cannot PAPI_read counters for an eventset that has not been PAPI_start'ed.");
519 papi_errno = PAPI_EMISC;
520 goto fn_fail;
521 }
522
523 papi_errno = rocd_ctx_read(rocm_ctl->rocd_ctx, val);
524
525 fn_exit:
526 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
527 return papi_errno;
528 fn_fail:
529 goto fn_exit;
530}
#define PAPI_EMISC
Definition: f90papi.h:122
int rocd_ctx_read(rocd_ctx_t ctx, long long **counters)
Definition: roc_dispatch.c:103
Here is the call graph for this function:

◆ rocm_read() [2/2]

static int rocm_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  val,
int  flags 
)
static

◆ rocm_reset() [1/2]

int rocm_reset ( hwd_context_t *ctx   __attribute__(unused),
hwd_control_state_t ctl 
)

Definition at line 569 of file rocm.c.

570{
571 rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
572
573 if (rocm_ctl->rocd_ctx == NULL) {
574 SUBDBG("Cannot reset counters for an eventset that has not been started.");
575 return PAPI_EMISC;
576 }
577
578 return rocd_ctx_reset(rocm_ctl->rocd_ctx);
579}
int rocd_ctx_reset(rocd_ctx_t ctx)
Definition: roc_dispatch.c:109
Here is the call graph for this function:

◆ rocm_reset() [2/2]

static int rocm_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

◆ rocm_set_domain() [1/2]

int rocm_set_domain ( hwd_control_state_t *ctl   __attribute__(unused),
int domain   __attribute__(unused) 
)

Definition at line 455 of file rocm.c.

457{
458 return PAPI_OK;
459}

◆ rocm_set_domain() [2/2]

static int rocm_set_domain ( hwd_control_state_t ctl,
int  domain 
)
static

◆ rocm_shutdown_component()

int rocm_shutdown_component ( void  )
static

Definition at line 236 of file rocm.c.

237{
238 int papi_errno = PAPI_OK;
239 int orig_state = _rocm_vector.cmp_info.initialized;
241 SUBDBG("ENTER\n");
242
244 goto fn_exit;
245 }
246
248 goto fn_exit;
249 }
250
251 papi_errno = rocd_shutdown();
252 if (papi_errno != PAPI_OK) {
253 goto fn_fail;
254 }
255
256 fn_exit:
257 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
258 return papi_errno;
259 fn_fail:
260 _rocm_vector.cmp_info.initialized = orig_state;
261 goto fn_exit;
262}
int rocd_shutdown(void)
Definition: roc_dispatch.c:32
Here is the call graph for this function:

◆ rocm_shutdown_thread()

int rocm_shutdown_thread ( hwd_context_t ctx)
static

Definition at line 265 of file rocm.c.

266{
267 rocm_context_t *rocm_ctx = (rocm_context_t *) ctx;
268 rocm_ctx->initialized = 0;
269 rocm_ctx->state = 0;
270 return PAPI_OK;
271}
int state
Definition: rocm.c:58

◆ rocm_start()

int rocm_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 470 of file rocm.c.

471{
472 int papi_errno = PAPI_OK;
473 rocm_context_t *rocm_ctx = (rocm_context_t *) ctx;
474 rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
475 SUBDBG("ENTER: ctx: %p, ctl: %p\n", ctx, ctl);
476
477 if (rocm_ctx->state & ROCM_EVENTS_OPENED) {
478 SUBDBG("Error! Cannot PAPI_start more than one eventset at a time for every component.");
479 papi_errno = PAPI_ECNFLCT;
480 goto fn_fail;
481 }
482
483 papi_errno = rocd_ctx_open(rocm_ctl->events_id, rocm_ctl->num_events,
484 &rocm_ctl->rocd_ctx);
485 if (papi_errno != PAPI_OK) {
486 goto fn_fail;
487 }
488
489 rocm_ctx->state = ROCM_EVENTS_OPENED;
490
491 papi_errno = rocd_ctx_start(rocm_ctl->rocd_ctx);
492 if (papi_errno != PAPI_OK) {
493 goto fn_fail;
494 }
495
496 rocm_ctx->state |= ROCM_EVENTS_RUNNING;
497
498 fn_exit:
499 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
500 return papi_errno;
501 fn_fail:
502 if (rocm_ctx->state == ROCM_EVENTS_OPENED) {
503 rocd_ctx_close(rocm_ctl->rocd_ctx);
504 }
505 rocm_ctx->state = 0;
506 goto fn_exit;
507}
#define PAPI_ECNFLCT
Definition: f90papi.h:234
int rocd_ctx_open(uint64_t *events_id, int num_events, rocd_ctx_t *ctx)
Definition: roc_dispatch.c:79
int rocd_ctx_start(rocd_ctx_t ctx)
Definition: roc_dispatch.c:91
int rocd_ctx_close(rocd_ctx_t ctx)
Definition: roc_dispatch.c:85
#define ROCM_EVENTS_RUNNING
#define ROCM_EVENTS_OPENED
Here is the call graph for this function:

◆ rocm_stop()

int rocm_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 533 of file rocm.c.

534{
535 int papi_errno = PAPI_OK;
536 rocm_context_t *rocm_ctx = (rocm_context_t *) ctx;
537 rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
538 SUBDBG("ENTER: ctx: %p, ctl: %p\n", ctx, ctl);
539
540 if (!(rocm_ctx->state & ROCM_EVENTS_OPENED)) {
541 SUBDBG("Error! Cannot PAPI_stop counters for an eventset that has not been PAPI_start'ed.");
542 papi_errno = PAPI_EMISC;
543 goto fn_fail;
544 }
545
546 papi_errno = rocd_ctx_stop(rocm_ctl->rocd_ctx);
547 if (papi_errno != PAPI_OK) {
548 goto fn_fail;
549 }
550
551 rocm_ctx->state &= ~ROCM_EVENTS_RUNNING;
552
553 papi_errno = rocd_ctx_close(rocm_ctl->rocd_ctx);
554 if (papi_errno != PAPI_OK) {
555 goto fn_fail;
556 }
557
558 rocm_ctx->state = 0;
559 rocm_ctl->rocd_ctx = NULL;
560
561 fn_exit:
562 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
563 return papi_errno;
564 fn_fail:
565 goto fn_exit;
566}
int rocd_ctx_stop(rocd_ctx_t ctx)
Definition: roc_dispatch.c:97
Here is the call graph for this function:

◆ rocm_update_control_state() [1/2]

int rocm_update_control_state ( hwd_control_state_t ctl,
NativeInfo_t ntv_info,
int  ntv_count,
hwd_context_t *ctx   __attribute__(unused) 
)

Definition at line 345 of file rocm.c.

348{
349 SUBDBG("ENTER: ctl: %p, ntv_info: %p, ntv_count: %d, ctx: %p\n", ctl, ntv_info, ntv_count, ctx);
350 int papi_errno = check_n_initialize();
351 if (papi_errno != PAPI_OK) {
352 goto fn_fail;
353 }
354
355 rocm_control_t *rocm_ctl = (rocm_control_t *) ctl;
356
357 if (rocm_ctl->rocd_ctx != NULL) {
358 SUBDBG("Cannot update events in an eventset that has been already "
359 "started.");
360 papi_errno = PAPI_ECMP;
361 goto fn_fail;
362 }
363
364 papi_errno = update_native_events(rocm_ctl, ntv_info, ntv_count);
365 if (papi_errno != PAPI_OK) {
366 goto fn_fail;
367 }
368
369 papi_errno = try_open_events(rocm_ctl);
370
371 fn_exit:
372 SUBDBG("EXIT: %s\n", PAPI_strerror(papi_errno));
373 return papi_errno;
374 fn_fail:
375 goto fn_exit;
376}
static int update_native_events(rocm_control_t *, NativeInfo_t *, int)
Definition: rocm.c:392
static int try_open_events(rocm_control_t *)
Definition: rocm.c:430
Here is the call graph for this function:

◆ rocm_update_control_state() [2/2]

static int rocm_update_control_state ( hwd_control_state_t ctl,
NativeInfo_t ntv_info,
int  ntv_count,
hwd_context_t ctx 
)
static

◆ try_open_events()

int try_open_events ( rocm_control_t rocm_ctl)
static

Definition at line 430 of file rocm.c.

431{
432 int papi_errno = PAPI_OK;
433 rocd_ctx_t rocd_ctx;
434
436 /* Do not try open for intercept mode */
437 return papi_errno;
438 }
439
440 if (rocm_ctl->num_events <= 0) {
441 return PAPI_OK;
442 }
443
444 papi_errno = rocd_ctx_open(rocm_ctl->events_id, rocm_ctl->num_events,
445 &rocd_ctx);
446 if (papi_errno != PAPI_OK) {
447 rocm_cleanup_eventset(rocm_ctl);
448 return papi_errno;
449 }
450
451 return rocd_ctx_close(rocd_ctx);
452}
static int rocm_cleanup_eventset(hwd_control_state_t *ctl)
Definition: rocm.c:274
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_native_events()

int update_native_events ( rocm_control_t ctl,
NativeInfo_t ntv_info,
int  ntv_count 
)
static

Definition at line 392 of file rocm.c.

394{
395 int papi_errno = PAPI_OK;
396 struct event_map_item sorted_events[PAPI_ROCM_MAX_COUNTERS];
397
398 if (ntv_count != ctl->num_events) {
399 ctl->events_id = papi_realloc(ctl->events_id,
400 ntv_count * sizeof(*ctl->events_id));
401 if (ctl->events_id == NULL) {
402 papi_errno = PAPI_ENOMEM;
403 goto fn_fail;
404 }
405
406 ctl->num_events = ntv_count;
407 }
408
409 int i;
410 for (i = 0; i < ntv_count; ++i) {
411 sorted_events[i].event_id = ntv_info[i].ni_event;
412 sorted_events[i].frontend_idx = i;
413 }
414
415 qsort(sorted_events, ntv_count, sizeof(struct event_map_item), compare);
416
417 for (i = 0; i < ntv_count; ++i) {
418 ctl->events_id[i] = sorted_events[i].event_id;
419 ntv_info[sorted_events[i].frontend_idx].ni_position = i;
420 }
421
422 fn_exit:
423 return papi_errno;
424 fn_fail:
425 ctl->num_events = 0;
426 goto fn_exit;
427}
int i
#define PAPI_ENOMEM
Definition: f90papi.h:16
#define papi_realloc(a, b)
Definition: papi_memory.h:36
#define PAPI_ROCM_MAX_COUNTERS
static int compare(const void *a, const void *b)
Definition: rocm.c:384
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _rocm_vector

papi_vector_t _rocm_vector

Definition at line 74 of file rocm.c.