PAPI 7.1.0.0
Loading...
Searching...
No Matches
roc_common.c File Reference
Include dependency graph for roc_common.c:

Go to the source code of this file.

Functions

static int load_hsa_sym (void)
 
static int unload_hsa_sym (void)
 
static int init_device_table (void)
 
static void init_thread_id_fn (void)
 
int rocc_init (void)
 
int rocc_shutdown (void)
 
int rocc_err_get_last (const char **err_string)
 
int rocc_dev_get_map (rocc_dev_get_map_cb query_dev_id, uint64_t *events_id, int num_events, rocc_bitmap_t *bitmap)
 
int rocc_dev_acquire (rocc_bitmap_t bitmap)
 
int rocc_dev_release (rocc_bitmap_t bitmap)
 
static int dev_get_count (rocc_bitmap_t bitmap, int *num_devices)
 
int rocc_dev_get_count (rocc_bitmap_t bitmap, int *num_devices)
 
int rocc_dev_get_id (rocc_bitmap_t bitmap, int dev_count, int *device_id)
 
int rocc_dev_get_agent_id (hsa_agent_t agent, int *dev_id)
 
int rocc_dev_set (rocc_bitmap_t *bitmap, int i)
 
int rocc_dev_check (rocc_bitmap_t bitmap, int i)
 
int rocc_thread_get_id (unsigned long *tid)
 
static hsa_status_t get_agent_handle_cb (hsa_agent_t, void *)
 

Variables

hsa_status_t(* hsa_init_p )(void)
 
hsa_status_t(* hsa_shut_down_p )(void)
 
hsa_status_t(* hsa_iterate_agents_p )(hsa_status_t(*)(hsa_agent_t, void *), void *)
 
hsa_status_t(* hsa_system_get_info_p )(hsa_system_info_t, void *)
 
hsa_status_t(* hsa_agent_get_info_p )(hsa_agent_t, hsa_agent_info_t, void *)
 
hsa_status_t(* hsa_queue_destroy_p )(hsa_queue_t *)
 
hsa_status_t(* hsa_status_string_p )(hsa_status_t, const char **)
 
static void * hsa_dlp
 
char error_string [PAPI_MAX_STR_LEN]
 
static device_table_t device_table
 
device_table_tdevice_table_p
 
static rocc_bitmap_t global_device_map
 
static unsigned long(* thread_id_fn )(void)
 

Function Documentation

◆ dev_get_count()

int dev_get_count ( rocc_bitmap_t  bitmap,
int num_devices 
)
static

Definition at line 127 of file roc_common.c.

128{
129 *num_devices = 0;
130
131 while (bitmap) {
132 bitmap -= bitmap & (~bitmap + 1);
133 ++(*num_devices);
134 }
135
136 return PAPI_OK;
137}
#define PAPI_OK
Definition: f90papi.h:73
Here is the caller graph for this function:

◆ get_agent_handle_cb()

hsa_status_t get_agent_handle_cb ( hsa_agent_t  agent,
void *  device_table 
)
static

Definition at line 291 of file roc_common.c.

292{
293 hsa_device_type_t type;
294 device_table_t *device_table_ = (device_table_t *) device_table;
295
296 hsa_status_t hsa_errno = hsa_agent_get_info_p(agent, HSA_AGENT_INFO_DEVICE, &type);
297 if (hsa_errno != HSA_STATUS_SUCCESS) {
298 return hsa_errno;
299 }
300
301 if (type == HSA_DEVICE_TYPE_GPU) {
302 assert(device_table_->count < PAPI_ROCM_MAX_DEV_COUNT);
303 device_table_->devices[device_table_->count] = agent;
304 ++device_table_->count;
305 }
306
307 return HSA_STATUS_SUCCESS;
308}
uint16_t type
static device_table_t device_table
Definition: roc_common.c:18
hsa_status_t(* hsa_agent_get_info_p)(hsa_agent_t, hsa_agent_info_t, void *)
Definition: roc_common.c:12
#define PAPI_ROCM_MAX_DEV_COUNT
Definition: roc_common.h:16
hsa_agent_t devices[PAPI_ROCM_MAX_DEV_COUNT]
Definition: roc_common.h:23
Here is the caller graph for this function:

◆ init_device_table()

int init_device_table ( void  )
static

Definition at line 270 of file roc_common.c.

271{
272 int papi_errno = PAPI_OK;
273
274 hsa_status_t hsa_errno = hsa_iterate_agents_p(get_agent_handle_cb, &device_table);
275 if (hsa_errno != HSA_STATUS_SUCCESS) {
276 const char *error_string_p;
277 hsa_status_string_p(hsa_errno, &error_string_p);
278 snprintf(error_string, PAPI_MAX_STR_LEN, "%s", error_string_p);
279 goto fn_fail;
280 }
281
282 fn_exit:
283 return papi_errno;
284 fn_fail:
285 papi_errno = PAPI_EMISC;
287 goto fn_exit;
288}
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_EMISC
Definition: f90papi.h:122
hsa_status_t(* hsa_status_string_p)(hsa_status_t, const char **)
Definition: roc_common.c:14
char error_string[PAPI_MAX_STR_LEN]
Definition: roc_common.c:17
hsa_status_t(* hsa_iterate_agents_p)(hsa_status_t(*)(hsa_agent_t, void *), void *)
Definition: roc_common.c:10
static hsa_status_t get_agent_handle_cb(hsa_agent_t, void *)
Definition: roc_common.c:291
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_thread_id_fn()

void init_thread_id_fn ( void  )
static

Definition at line 311 of file roc_common.c.

312{
313 if (thread_id_fn) {
314 return;
315 }
316
319}
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
static unsigned long(* thread_id_fn)(void)
Definition: roc_common.c:26
unsigned long _papi_getpid(void)
Definition: threads.c:634
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_hsa_sym()

int load_hsa_sym ( void  )
static

Definition at line 200 of file roc_common.c.

201{
202 int papi_errno = PAPI_OK;
203
204 char pathname[PATH_MAX] = { 0 };
205 char *rocm_root = getenv("PAPI_ROCM_ROOT");
206 if (rocm_root == NULL) {
207 snprintf(error_string, PAPI_MAX_STR_LEN, "Can't load libhsa-runtime64.so, PAPI_ROCM_ROOT not set.");
208 goto fn_fail;
209 }
210
211 sprintf(pathname, "%s/lib/libhsa-runtime64.so", rocm_root);
212
213 hsa_dlp = dlopen(pathname, RTLD_NOW | RTLD_GLOBAL);
214 if (hsa_dlp == NULL) {
215 snprintf(error_string, PAPI_MAX_STR_LEN, "%s", dlerror());
216 goto fn_fail;
217 }
218
219 hsa_init_p = dlsym(hsa_dlp, "hsa_init");
220 hsa_shut_down_p = dlsym(hsa_dlp, "hsa_shut_down");
221 hsa_iterate_agents_p = dlsym(hsa_dlp, "hsa_iterate_agents");
222 hsa_system_get_info_p = dlsym(hsa_dlp, "hsa_system_get_info");
223 hsa_agent_get_info_p = dlsym(hsa_dlp, "hsa_agent_get_info");
224 hsa_queue_destroy_p = dlsym(hsa_dlp, "hsa_queue_destroy");
225 hsa_status_string_p = dlsym(hsa_dlp, "hsa_status_string");
226
227 int hsa_not_initialized = (!hsa_init_p ||
234
235 papi_errno = (hsa_not_initialized) ? PAPI_EMISC : PAPI_OK;
236 if (papi_errno != PAPI_OK) {
237 snprintf(error_string, PAPI_MAX_STR_LEN, "Error while loading hsa symbols.");
238 }
239
240 fn_exit:
241 return papi_errno;
242 fn_fail:
243 papi_errno = PAPI_ENOSUPP;
244 goto fn_exit;
245}
#define PAPI_ENOSUPP
Definition: f90papi.h:244
hsa_status_t(* hsa_queue_destroy_p)(hsa_queue_t *)
Definition: roc_common.c:13
hsa_status_t(* hsa_init_p)(void)
Definition: roc_common.c:8
static void * hsa_dlp
Definition: roc_common.c:16
hsa_status_t(* hsa_system_get_info_p)(hsa_system_info_t, void *)
Definition: roc_common.c:11
hsa_status_t(* hsa_shut_down_p)(void)
Definition: roc_common.c:9
Here is the caller graph for this function:

◆ rocc_dev_acquire()

int rocc_dev_acquire ( rocc_bitmap_t  bitmap)

Definition at line 93 of file roc_common.c.

94{
95 rocc_bitmap_t device_map_acq = bitmap;
96
97 if (device_map_acq & global_device_map) {
98 return PAPI_EINVAL;
99 }
100 global_device_map |= device_map_acq;
101
102 return PAPI_OK;
103}
#define PAPI_EINVAL
Definition: f90papi.h:115
static rocc_bitmap_t global_device_map
Definition: roc_common.c:20
int64_t rocc_bitmap_t
Definition: roc_common.h:19
Here is the caller graph for this function:

◆ rocc_dev_check()

int rocc_dev_check ( rocc_bitmap_t  bitmap,
int  i 
)

Definition at line 187 of file roc_common.c.

188{
189 return (bitmap & (1ULL << i));
190}
int i
Here is the caller graph for this function:

◆ rocc_dev_get_agent_id()

int rocc_dev_get_agent_id ( hsa_agent_t  agent,
int dev_id 
)

Definition at line 169 of file roc_common.c.

170{
171 for (*dev_id = 0; *dev_id < device_table_p->count; ++(*dev_id)) {
172 if (memcmp(&device_table_p->devices[*dev_id], &agent, sizeof(agent)) == 0) {
173 break;
174 }
175 }
176 return PAPI_OK;
177}
device_table_t * device_table_p
Definition: roc_common.c:19
Here is the caller graph for this function:

◆ rocc_dev_get_count()

int rocc_dev_get_count ( rocc_bitmap_t  bitmap,
int num_devices 
)

Definition at line 121 of file roc_common.c.

122{
123 return dev_get_count(bitmap, num_devices);
124}
static int dev_get_count(rocc_bitmap_t bitmap, int *num_devices)
Definition: roc_common.c:127
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rocc_dev_get_id()

int rocc_dev_get_id ( rocc_bitmap_t  bitmap,
int  dev_count,
int device_id 
)

Definition at line 140 of file roc_common.c.

141{
142 int count = 0;
143
144 dev_get_count(bitmap, &count);
145 if (dev_count >= count) {
146 return PAPI_EMISC;
147 }
148
149 count = 0;
150 rocc_bitmap_t lsb = 0;
151 while (bitmap) {
152 lsb = bitmap & (~bitmap + 1);
153 bitmap -= lsb;
154 if (count++ == dev_count) {
155 break;
156 }
157 }
158
159 *device_id = 0;
160 while (!(lsb & 0x1)) {
161 ++(*device_id);
162 lsb >>= 1;
163 }
164
165 return PAPI_OK;
166}
static long count
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rocc_dev_get_map()

int rocc_dev_get_map ( rocc_dev_get_map_cb  query_dev_id,
uint64_t *  events_id,
int  num_events,
rocc_bitmap_t bitmap 
)

Definition at line 74 of file roc_common.c.

75{
76 int i;
77 rocc_bitmap_t device_map_acq = 0;
78
79 for (i = 0; i < num_events; ++i) {
80 int dev_id;
81 if (query_dev_id(events_id[i], &dev_id)) {
82 return PAPI_EMISC;
83 }
84
85 device_map_acq |= (1 << dev_id);
86 }
87
88 *bitmap = device_map_acq;
89 return PAPI_OK;
90}
static int num_events
uint64_t * events_id
Here is the caller graph for this function:

◆ rocc_dev_release()

int rocc_dev_release ( rocc_bitmap_t  bitmap)

Definition at line 106 of file roc_common.c.

107{
108 rocc_bitmap_t device_map_rel = bitmap;
109
110 if ((device_map_rel & global_device_map) != device_map_rel) {
111 return PAPI_EINVAL;
112 }
113 global_device_map &= ~device_map_rel;
114
115 return PAPI_OK;
116}
Here is the caller graph for this function:

◆ rocc_dev_set()

int rocc_dev_set ( rocc_bitmap_t bitmap,
int  i 
)

Definition at line 180 of file roc_common.c.

181{
182 *bitmap |= (1ULL << i);
183 return PAPI_OK;
184}
Here is the caller graph for this function:

◆ rocc_err_get_last()

int rocc_err_get_last ( const char **  err_string)

Definition at line 67 of file roc_common.c.

68{
69 *err_string = error_string;
70 return PAPI_OK;
71}
Here is the caller graph for this function:

◆ rocc_init()

int rocc_init ( void  )

Definition at line 29 of file roc_common.c.

30{
31 int papi_errno = load_hsa_sym();
32 if (papi_errno != PAPI_OK) {
33 goto fn_fail;
34 }
35
36 hsa_status_t status = hsa_init_p();
37 if (status != HSA_STATUS_SUCCESS) {
38 papi_errno = PAPI_EMISC;
39 goto fn_fail;
40 }
41
42 papi_errno = init_device_table();
43 if (papi_errno != PAPI_OK) {
44 (*hsa_shut_down_p)();
45 goto fn_fail;
46 }
47
50
51 fn_exit:
52 return papi_errno;
53 fn_fail:
55 goto fn_exit;
56}
static int unload_hsa_sym(void)
Definition: roc_common.c:248
static int load_hsa_sym(void)
Definition: roc_common.c:200
static void init_thread_id_fn(void)
Definition: roc_common.c:311
static int init_device_table(void)
Definition: roc_common.c:270
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rocc_shutdown()

int rocc_shutdown ( void  )

Definition at line 59 of file roc_common.c.

60{
63 return PAPI_OK;
64}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rocc_thread_get_id()

int rocc_thread_get_id ( unsigned long tid)

Definition at line 193 of file roc_common.c.

194{
195 *tid = thread_id_fn();
196 return PAPI_OK;
197}
Here is the caller graph for this function:

◆ unload_hsa_sym()

int unload_hsa_sym ( void  )
static

Definition at line 248 of file roc_common.c.

249{
250 if (hsa_dlp == NULL) {
251 return PAPI_OK;
252 }
253
254 hsa_init_p = NULL;
255 hsa_shut_down_p = NULL;
259 hsa_queue_destroy_p = NULL;
260 hsa_status_string_p = NULL;
261
262 dlclose(hsa_dlp);
263
264 return PAPI_OK;
265}
Here is the caller graph for this function:

Variable Documentation

◆ device_table

device_table_t device_table
static

Definition at line 18 of file roc_common.c.

◆ device_table_p

device_table_t* device_table_p

Definition at line 19 of file roc_common.c.

◆ error_string

char error_string[PAPI_MAX_STR_LEN]

Definition at line 17 of file roc_common.c.

◆ global_device_map

rocc_bitmap_t global_device_map
static

Definition at line 20 of file roc_common.c.

◆ hsa_agent_get_info_p

hsa_status_t(* hsa_agent_get_info_p) (hsa_agent_t, hsa_agent_info_t, void *) ( hsa_agent_t  ,
hsa_agent_info_t  ,
void *   
)

Definition at line 12 of file roc_common.c.

◆ hsa_dlp

void* hsa_dlp
static

Definition at line 16 of file roc_common.c.

◆ hsa_init_p

hsa_status_t(* hsa_init_p) (void) ( void  )

Definition at line 8 of file roc_common.c.

◆ hsa_iterate_agents_p

hsa_status_t(* hsa_iterate_agents_p) (hsa_status_t(*)(hsa_agent_t, void *), void *) ( hsa_status_t(*)(hsa_agent_t, void *)  ,
void *   
)

Definition at line 10 of file roc_common.c.

◆ hsa_queue_destroy_p

hsa_status_t(* hsa_queue_destroy_p) (hsa_queue_t *) ( hsa_queue_t *  )

Definition at line 13 of file roc_common.c.

◆ hsa_shut_down_p

hsa_status_t(* hsa_shut_down_p) (void) ( void  )

Definition at line 9 of file roc_common.c.

◆ hsa_status_string_p

hsa_status_t(* hsa_status_string_p) (hsa_status_t, const char **) ( hsa_status_t  ,
const char **   
)

Definition at line 14 of file roc_common.c.

◆ hsa_system_get_info_p

hsa_status_t(* hsa_system_get_info_p) (hsa_system_info_t, void *) ( hsa_system_info_t  ,
void *   
)

Definition at line 11 of file roc_common.c.

◆ thread_id_fn

unsigned long(* thread_id_fn) (void) ( void  )
static

Definition at line 26 of file roc_common.c.