Skip to content

Commit

Permalink
rocm: add rocp_evt_code_to_info support
Browse files Browse the repository at this point in the history
This function is needed to allow papi_native_avail to extract qualifier
descriptions for the event identifier.
  • Loading branch information
gcongiu committed Dec 4, 2023
1 parent 510da80 commit eb62862
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/rocm/roc_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ rocd_evt_code_to_name(uint64_t event_code, char *name, int len)
return rocp_evt_code_to_name(event_code, name, len);
}

int
rocd_evt_code_to_info(uint64_t event_code, PAPI_event_info_t *info)
{
return rocp_evt_code_to_info(event_code, info);
}

int
rocd_err_get_last(const char **error_str)
{
Expand Down
2 changes: 2 additions & 0 deletions src/components/rocm/roc_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef __ROC_DISPATCH_H__
#define __ROC_DISPATCH_H__

#include "papi.h"
#include "roc_profiler_config.h"

typedef struct rocd_ctx *rocd_ctx_t;
Expand All @@ -24,6 +25,7 @@ int rocd_evt_enum(uint64_t *event_code, int modifier);
int rocd_evt_code_to_descr(uint64_t event_code, char *descr, int len);
int rocd_evt_name_to_code(const char *name, uint64_t *event_code);
int rocd_evt_code_to_name(uint64_t event_code, char *name, int len);
int rocd_evt_code_to_info(uint64_t event_code, PAPI_event_info_t *info);

/* error handling interfaces */
int rocd_err_get_last(const char **error_str);
Expand Down
48 changes: 48 additions & 0 deletions src/components/rocm/roc_profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,54 @@ rocp_evt_code_to_name(uint64_t event_code, char *name, int len)
return evt_code_to_name(event_code, name, len);
}

/* rocp_evt_code_to_info - get event info */
int
rocp_evt_code_to_info(uint64_t event_code, PAPI_event_info_t *info)
{
int papi_errno;

event_info_t inf;
papi_errno = evt_id_to_info(event_code, &inf);
if (papi_errno != PAPI_OK) {
return papi_errno;
}

switch (inf.flags) {
case 0:
sprintf(info->symbol, "%s", ntv_table_p->events[inf.nameid].name);
sprintf(info->long_descr, "%s", ntv_table_p->events[inf.nameid].descr);
break;
case (DEVICE_FLAG | INSTAN_FLAG):
sprintf(info->symbol, "%s:device=%i:instance=%i", ntv_table_p->events[inf.nameid].name, inf.device, inf.instance);
sprintf(info->long_descr, "%s", ntv_table_p->events[inf.nameid].descr);
break;
case DEVICE_FLAG:
{
int i;
char devices[PAPI_MAX_STR_LEN] = { 0 };
for (i = 0; i < device_table_p->count; ++i) {
if (rocc_dev_check(ntv_table_p->events[inf.nameid].device_map, i)) {
sprintf(devices + strlen(devices), "%i,", i);
}
}
*(devices + strlen(devices) - 1) = 0;
sprintf(info->symbol, "%s:device=%i", ntv_table_p->events[inf.nameid].name, inf.device);
sprintf(info->long_descr, "%s masks:Mandatory device qualifier [%s]",
ntv_table_p->events[inf.nameid].descr, devices);
break;
}
case INSTAN_FLAG:
sprintf(info->symbol, "%s:instance=%i", ntv_table_p->events[inf.nameid].name, inf.instance);
sprintf(info->long_descr, "%s masks:Mandatory instance qualifier in range [0-%i]",
ntv_table_p->events[inf.nameid].descr, ntv_table_p->events[inf.nameid].instances - 1);
break;
default:
papi_errno = PAPI_EINVAL;
}

return papi_errno;
}

/* rocp_ctx_open - open a profiling context for the requested events */
int
rocp_ctx_open(uint64_t *events_id, int num_events, rocp_ctx_t *rocp_ctx)
Expand Down
3 changes: 3 additions & 0 deletions src/components/rocm/roc_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef __ROC_PROFILER_H__
#define __ROC_PROFILER_H__

#include "papi.h"

typedef struct rocd_ctx *rocp_ctx_t;

/* init and shutdown interfaces */
Expand All @@ -19,6 +21,7 @@ int rocp_evt_enum(uint64_t *event_code, int modifier);
int rocp_evt_code_to_descr(uint64_t event_code, char *descr, int len);
int rocp_evt_name_to_code(const char *name, uint64_t *event_code);
int rocp_evt_code_to_name(uint64_t event_code, char *name, int len);
int rocp_evt_code_to_info(uint64_t event_code, PAPI_event_info_t *info);

/* profiling context handling interfaces */
int rocp_ctx_open(uint64_t *events_id, int num_events, rocp_ctx_t *ctx);
Expand Down
20 changes: 20 additions & 0 deletions src/components/rocm/rocm.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ 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;
Expand Down Expand Up @@ -118,6 +119,7 @@ papi_vector_t _rocm_vector = {
.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);
Expand Down Expand Up @@ -652,6 +654,24 @@ rocm_ntv_code_to_descr(unsigned int event_code, char *descr, int len)
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)
{
Expand Down

0 comments on commit eb62862

Please sign in to comment.