@@ -19,13 +19,9 @@ enum {
19
19
int drhook_papi_state = drhook_papi_notstarted ;
20
20
int drhook_papi_rank = 0 ; /* C style! */
21
21
22
- /* hardwired for now */
23
- const char * hookCounters [NPAPICNTRS ][2 ]= {
24
- {"PAPI_TOT_CYC" ,"Cycles" },
25
- {"PAPI_FP_OPS" ,"FP Operations" },
26
- {"PAPI_L1_DCA" ,"L1 Access" },
27
- {"PAPI_L2_DCM" ,"L2 Miss" }
28
- };
22
+ static int papi_counter_event_codes [MAXNPAPICNTRS ];
23
+ static char * papi_counter_names [MAXNPAPICNTRS ];
24
+ static int papi_counters_count ;
29
25
30
26
/* function to use for thread id
31
27
- it should be better than omp_get_thread_num!
@@ -34,8 +30,16 @@ unsigned long safe_thread_num(){
34
30
return oml_my_thread ()- 1 ;
35
31
}
36
32
37
- const char * drhook_papi_counter_name (int c ,int t ){
38
- return hookCounters [c ][t ];
33
+ int drhook_papi_max_num_counters () {
34
+ return MAXNPAPICNTRS ;
35
+ }
36
+
37
+ int drhook_papi_max_name_len () {
38
+ return PAPI_MAX_STR_LEN ;
39
+ }
40
+
41
+ void drhook_papi_counter_name (int c , char * event_name ){
42
+ PAPI_event_code_to_name (papi_counter_event_codes [c ], event_name );
39
43
}
40
44
41
45
void drhook_papi_cpy (long_long * a ,long_long * b ){
@@ -56,8 +60,12 @@ void drhook_papi_print(char* s, long_long* a, int header){
56
60
char fmt [STD_MSG_LEN ];
57
61
sprintf (fmt ,"%%%lds" ,strlen (s ));
58
62
sprintf (msg ,fmt ," " );
59
- for (int i = 0 ;i < drhook_papi_num_counters ();i ++ )
60
- sprintf (& msg [strlen (msg )]," %16s" ,hookCounters [ i ][1 ]);
63
+ for (int i = 0 ;i < drhook_papi_num_counters ();i ++ ) {
64
+ char event_name [PAPI_MAX_STR_LEN ];
65
+
66
+ PAPI_event_code_to_name (papi_counter_event_codes [i ], event_name );
67
+ sprintf (& msg [strlen (msg )]," %16s" ,event_name );
68
+ }
61
69
printf ("%s\n" ,msg );
62
70
}
63
71
@@ -94,7 +102,12 @@ void drhook_papi_add(long_long* a,long_long* b, long_long* c){
94
102
95
103
// number of counters available to read
96
104
int drhook_papi_num_counters (){
97
- return NPAPICNTRS ;
105
+ return papi_counters_count ;
106
+ }
107
+
108
+ void drhook_papi_add_counter_name (const char * counter_name ) {
109
+ papi_counter_names [papi_counters_count ] = counter_name ;
110
+ papi_counters_count ++ ;
98
111
}
99
112
100
113
long_long drhook_papi_read (int counterId ){
@@ -205,12 +218,14 @@ int drhook_papi_init(int rank){
205
218
206
219
drhook_papi_event_set = malloc (nthreads * sizeof (int ));
207
220
208
- int prof_papi_numcntrs ;
209
- bool failed = false;
210
-
211
- drhook_run_omp_parallel_papi_startup (drhook_papi_event_set ,nthreads );
212
-
213
- /* if (failed){ drhook_papi_state=drhook_papi_failed ; return 0;} */
221
+ int rcout ;
222
+ drhook_run_omp_parallel_papi_startup (drhook_papi_event_set ,nthreads , & rcout );
223
+ if (rcout )
224
+ return 0 ;
225
+
226
+ for (int i = 0 ; i < drhook_papi_max_num_counters (); i ++ )
227
+ free (papi_counter_names [i ]);
228
+
214
229
drhook_papi_state = drhook_papi_running ;
215
230
if (drhook_papi_rank == 0 && !silent ) printf ("DRHOOK:PAPI: Initialisation sucess\n" );
216
231
return 1 ;
@@ -231,42 +246,42 @@ int dr_hook_papi_start_threads(int* events){
231
246
232
247
if (!silent ) printf ("DRHOOK:PAPI: Event set %d created for thread %d\n" ,events [thread ],thread );
233
248
234
- int prof_papi_numcntrs = NPAPICNTRS ;
235
249
if (!silent && drhook_papi_rank == 0 && thread == 0 )
236
250
printf ("DRHOOK:PAPI: Attempting to add events to event set:\n" );
237
251
238
- for (int counter = 0 ; counter < prof_papi_numcntrs ; counter ++ ){
252
+ for (int counter = 0 ; counter < drhook_papi_num_counters () ; counter ++ ){
239
253
int eventCode ;
240
254
241
255
if (!silent && drhook_papi_rank == 0 && thread == 0 ) {
242
- snprintf (pmsg ,STD_MSG_LEN ,"DRHOOK:PAPI: %s (%s)" , hookCounters [counter ][ 0 ], hookCounters [ counter ][ 1 ]);
256
+ snprintf (pmsg ,STD_MSG_LEN ,"DRHOOK:PAPI: %s" , papi_counter_names [counter ]);
243
257
printf ("%s\n" ,pmsg );
244
258
}
245
259
246
- papiErr = PAPI_event_name_to_code (hookCounters [counter ][ 0 ], & eventCode );
260
+ papiErr = PAPI_event_name_to_code (papi_counter_names [counter ], & eventCode );
247
261
if (papiErr != PAPI_OK ){
248
- snprintf (pmsg ,STD_MSG_LEN ,"DRHOOK:PAPI: Error, event name to code failed (%s)" ,PAPI_strerror (papiErr ));
262
+ snprintf (pmsg ,STD_MSG_LEN ,"DRHOOK:PAPI: Error, event name to code failed for %s (%s)" , papi_counter_names [ counter ], PAPI_strerror (papiErr ));
249
263
printf ("%s\n" ,pmsg );
250
264
PAPI_perror ("initPapi" );
251
265
return 0 ;
252
266
}
253
267
268
+ papi_counter_event_codes [counter ] = eventCode ;
254
269
papiErr = PAPI_add_event (events [thread ],eventCode );
255
270
if (papiErr != PAPI_OK ){
256
271
snprintf (pmsg ,STD_MSG_LEN ,"DRHOOK:PAPI: Error, add_event failed: %d (%s)" ,papiErr ,PAPI_strerror (papiErr ));
257
272
printf ("%s\n" ,pmsg );
258
273
if (papiErr == PAPI_EINVAL )
259
- printf ("Invalid argument" );
274
+ printf ("Invalid argument\n " );
260
275
else if (papiErr == PAPI_ENOMEM )
261
- printf ("Out of memory" );
276
+ printf ("Out of memory\n " );
262
277
else if (papiErr == PAPI_ENOEVST )
263
- printf ("EventSet does not exist" );
278
+ printf ("EventSet does not exist\n " );
264
279
else if (papiErr == PAPI_EISRUN )
265
- printf ("EventSet is running" );
280
+ printf ("EventSet is running\n " );
266
281
else if (papiErr == PAPI_ECNFLCT )
267
- printf ("Conflict" );
282
+ printf ("Conflict\n " );
268
283
else if (papiErr == PAPI_ENOEVNT )
269
- printf ("Preset not available" );
284
+ printf ("Preset not available\n " );
270
285
return 0 ;
271
286
}
272
287
else {
@@ -279,8 +294,8 @@ int dr_hook_papi_start_threads(int* events){
279
294
}
280
295
}
281
296
282
- int number = prof_papi_numcntrs ;
283
- int * checkEvents = malloc (prof_papi_numcntrs * sizeof (int ));
297
+ int number = drhook_papi_num_counters () ;
298
+ int * checkEvents = malloc (drhook_papi_num_counters () * sizeof (int ));
284
299
papiErr = PAPI_list_events (events [thread ], checkEvents , & number );
285
300
if (papiErr != PAPI_OK ){
286
301
snprintf (pmsg ,STD_MSG_LEN ,"DRHOOK:PAPI: Error querying events - %d=%s" ,papiErr ,PAPI_strerror (papiErr ));
@@ -294,8 +309,8 @@ int dr_hook_papi_start_threads(int* events){
294
309
}
295
310
#endif
296
311
297
- if (number != prof_papi_numcntrs ){
298
- snprintf (pmsg ,STD_MSG_LEN ,"DRHOOK:PAPI: Error checking events - expected=%d got=%d" ,prof_papi_numcntrs ,number );
312
+ if (number != drhook_papi_num_counters () ){
313
+ snprintf (pmsg ,STD_MSG_LEN ,"DRHOOK:PAPI: Error checking events - expected=%d got=%d" ,drhook_papi_num_counters () ,number );
299
314
printf ("%s\n" ,pmsg );
300
315
}
301
316
0 commit comments