PAPI  5.7.0.0
papi_hl.c File Reference

This file contains the 'high level' interface to PAPI. BASIC is a high level language. ;-) More...

Include dependency graph for papi_hl.c:

Go to the source code of this file.

Data Structures

struct  HighLevelInfo
 

Macros

#define HL_STOP   0
 
#define HL_START   1
 
#define HL_FLIP   2
 
#define HL_FLOP   3
 
#define HL_IPC   4
 
#define HL_EPC   5
 
#define HL_READ   6
 
#define HL_ACCUM   7
 

Functions

int _hl_rate_calls (float *real_time, float *proc_time, int *events, long long *values, long long *ins, float *rate, int mode)
 
void _internal_cleanup_hl_info (HighLevelInfo *state)
 
int _internal_check_state (HighLevelInfo **state)
 
int _internal_start_hl_counters (HighLevelInfo *state)
 
int _internal_hl_read_cnts (long long *values, int array_len, int flag)
 
int PAPI_flips (float *rtime, float *ptime, long long *flpins, float *mflips)
 
int PAPI_flops (float *rtime, float *ptime, long long *flpops, float *mflops)
 
int PAPI_ipc (float *rtime, float *ptime, long long *ins, float *ipc)
 
int PAPI_epc (int event, float *rtime, float *ptime, long long *ref, long long *core, long long *evt, float *epc)
 
int PAPI_num_counters (void)
 
int PAPI_start_counters (int *events, int array_len)
 
int PAPI_read_counters (long long *values, int array_len)
 
int PAPI_accum_counters (long long *values, int array_len)
 
int PAPI_stop_counters (long long *values, int array_len)
 
void _papi_hwi_shutdown_highlevel ()
 

Detailed Description

Macro Definition Documentation

◆ HL_ACCUM

#define HL_ACCUM   7

Definition at line 33 of file papi_hl.c.

◆ HL_EPC

#define HL_EPC   5

Definition at line 31 of file papi_hl.c.

◆ HL_FLIP

#define HL_FLIP   2

Definition at line 28 of file papi_hl.c.

◆ HL_FLOP

#define HL_FLOP   3

Definition at line 29 of file papi_hl.c.

◆ HL_IPC

#define HL_IPC   4

Definition at line 30 of file papi_hl.c.

◆ HL_READ

#define HL_READ   6

Definition at line 32 of file papi_hl.c.

◆ HL_START

#define HL_START   1

Definition at line 27 of file papi_hl.c.

◆ HL_STOP

#define HL_STOP   0

Definition at line 26 of file papi_hl.c.

Function Documentation

◆ _hl_rate_calls()

int _hl_rate_calls ( float *  real_time,
float *  proc_time,
int *  events,
long long *  values,
long long *  ins,
float *  rate,
int  mode 
)

Definition at line 409 of file papi_hl.c.

411 {
412  long long rt, pt; // current elapsed real and process times in usec
413  int num_events = 2;
414  int retval = 0;
415  HighLevelInfo *state = NULL;
416 
417  if ( ( retval = _internal_check_state( &state ) ) != PAPI_OK ) {
418  return ( retval );
419  }
420 
421  if ( state->running != HL_STOP && state->running != mode ) {
422  return PAPI_EINVAL;
423  }
424 
425  if ( state->running == HL_STOP ) {
426 
427  switch (mode) {
428  case HL_FLOP:
429  case HL_FLIP:
430  num_events = 1;
431  break;
432  case HL_IPC:
433  break;
434  case HL_EPC:
435  if ( events[2] != 0 ) num_events = 3;
436  break;
437  default:
438  return PAPI_EINVAL;
439  }
440  if (( retval = PAPI_add_events( state->EventSet, events, num_events )) != PAPI_OK ) {
441  _internal_cleanup_hl_info( state );
443  return retval;
444  }
445 
446  state->total_ins = 0;
449 
450  if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) {
451  return retval;
452  }
453 
454  /* Initialize the interface */
455  state->running = mode;
456  *real_time = 0.0;
457  *proc_time = 0.0;
458  *rate = 0.0;
459 
460  } else {
461  if ( ( retval = PAPI_stop( state->EventSet, values ) ) != PAPI_OK ) {
462  state->running = HL_STOP;
463  return retval;
464  }
465 
466  /* Read elapsed real and process times */
467  rt = PAPI_get_real_usec();
468  pt = PAPI_get_virt_usec();
469 
470  /* Convert to seconds with multiplication because it is much faster */
471  *real_time = ((float)( rt - state->initial_real_time )) * .000001;
472  *proc_time = ((float)( pt - state->initial_proc_time )) * .000001;
473 
474  state->total_ins += values[0];
475 
476  switch (mode) {
477  case HL_FLOP:
478  case HL_FLIP:
479  /* Calculate MFLOP and MFLIP rates */
480  if ( pt > 0 ) {
481  *rate = (float)values[0] / (pt - state->last_proc_time);
482  } else *rate = 0;
483  break;
484  case HL_IPC:
485  case HL_EPC:
486  /* Calculate IPC */
487  if (values[1]!=0) {
488  *rate = (float) ((float)values[0] / (float) ( values[1]));
489  }
490  break;
491  default:
492  return PAPI_EINVAL;
493  }
494  state->last_real_time = rt;
495  state->last_proc_time = pt;
496 
497  if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) {
498  state->running = HL_STOP;
499  return retval;
500  }
501  }
502  *ins = state->total_ins;
503  return PAPI_OK;
504 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
long long initial_proc_time
Definition: papi_hl.c:44
#define PAPI_EINVAL
Definition: fpapi.h:106
long long PAPI_get_virt_usec(void)
Definition: papi.c:6372
long long initial_real_time
Definition: papi_hl.c:43
#define HL_FLOP
Definition: papi_hl.c:29
static int num_events
int _internal_check_state(HighLevelInfo **state)
Definition: papi_hl.c:100
int retval
Definition: zero_fork.c:53
#define HL_EPC
Definition: papi_hl.c:31
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5843
char events[MAX_EVENTS][BUFSIZ]
#define HL_STOP
Definition: papi_hl.c:26
#define HL_IPC
Definition: papi_hl.c:30
long long last_proc_time
Definition: papi_hl.c:46
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
void _internal_cleanup_hl_info(HighLevelInfo *state)
Definition: papi_hl.c:152
short int running
Definition: papi_hl.c:42
#define HL_FLIP
Definition: papi_hl.c:28
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
long long total_ins
Definition: papi_hl.c:47
long long last_real_time
Definition: papi_hl.c:45
int EventSet
Definition: papi_hl.c:40
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _internal_check_state()

int _internal_check_state ( HighLevelInfo **  outgoing)

This function is called to determine the state of the system. We may as well set the HighLevelInfo so you don't have to look it up again.

Definition at line 100 of file papi_hl.c.

101 {
102  int retval;
103  HighLevelInfo *state = NULL;
104 
105  /* Only allow one thread at a time in here */
106  if ( init_level == PAPI_NOT_INITED ) {
108  if ( retval != PAPI_VER_CURRENT ) {
109  return ( retval );
110  } else {
114  }
115  }
116 
117  /*
118  * Do we have the thread specific data setup yet?
119  */
120  if ( ( retval =
121  PAPI_get_thr_specific( PAPI_HIGH_LEVEL_TLS, ( void ** ) &state ) )
122  != PAPI_OK || state == NULL ) {
123  state = ( HighLevelInfo * ) papi_malloc( sizeof ( HighLevelInfo ) );
124  if ( state == NULL )
125  return ( PAPI_ENOMEM );
126 
127  memset( state, 0, sizeof ( HighLevelInfo ) );
128  state->EventSet = -1;
129 
130  if ( ( retval = PAPI_create_eventset( &state->EventSet ) ) != PAPI_OK )
131  return ( retval );
132 
133  if ( ( retval =
135  state ) ) != PAPI_OK )
136  return ( retval );
137  }
138  *outgoing = state;
139  return ( PAPI_OK );
140 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_ENOMEM
Definition: fpapi.h:107
#define papi_malloc(a)
Definition: papi_memory.h:34
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
#define PAPI_HIGH_LEVEL_INITED
Definition: fpapi.h:19
int PAPI_get_thr_specific(int tag, void **ptr)
Definition: papi.c:362
int PAPI_library_init(int version)
Definition: papi.c:500
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
#define HIGHLEVEL_LOCK
Definition: papi_internal.h:89
int PAPI_set_thr_specific(int tag, void *ptr)
Definition: papi.c:438
#define PAPI_NOT_INITED
Definition: fpapi.h:17
int init_level
Definition: papi_internal.c:53
#define PAPI_HIGH_LEVEL_TLS
Definition: papi.h:322
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _internal_cleanup_hl_info()

void _internal_cleanup_hl_info ( HighLevelInfo state)

Definition at line 152 of file papi_hl.c.

153 {
154  state->num_evts = 0;
155  state->running = HL_STOP;
156  state->initial_real_time = -1;
157  state->initial_proc_time = -1;
158  state->total_ins = 0;
159  return;
160 }
long long initial_proc_time
Definition: papi_hl.c:44
long long initial_real_time
Definition: papi_hl.c:43
short int num_evts
Definition: papi_hl.c:41
#define HL_STOP
Definition: papi_hl.c:26
short int running
Definition: papi_hl.c:42
long long total_ins
Definition: papi_hl.c:47
Here is the caller graph for this function:

◆ _internal_hl_read_cnts()

int _internal_hl_read_cnts ( long long *  values,
int  array_len,
int  flag 
)

Definition at line 643 of file papi_hl.c.

644 {
645  int retval;
646  HighLevelInfo *state = NULL;
647 
648  if ( ( retval = _internal_check_state( &state ) ) != PAPI_OK )
649  return ( retval );
650 
651  if ( state->running != HL_START || array_len < state->num_evts )
652  return ( PAPI_EINVAL );
653 
654  if ( flag == HL_ACCUM )
655  return ( PAPI_accum( state->EventSet, values ) );
656  else if ( flag == HL_READ ) {
657  if ( ( retval = PAPI_read( state->EventSet, values ) ) != PAPI_OK )
658  return ( retval );
659  return ( PAPI_reset( state->EventSet ) );
660  }
661 
662  /* Invalid flag passed in */
663  return ( PAPI_EINVAL );
664 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
int PAPI_reset(int EventSet)
Definition: papi.c:2459
int _internal_check_state(HighLevelInfo **state)
Definition: papi_hl.c:100
int retval
Definition: zero_fork.c:53
#define HL_READ
Definition: papi_hl.c:32
int PAPI_accum(int EventSet, long long *values)
Definition: papi.c:2745
#define HL_ACCUM
Definition: papi_hl.c:33
#define HL_START
Definition: papi_hl.c:27
short int running
Definition: papi_hl.c:42
int EventSet
Definition: papi_hl.c:40
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _internal_start_hl_counters()

int _internal_start_hl_counters ( HighLevelInfo state)

Make sure to allocate space for values

Definition at line 146 of file papi_hl.c.

147 {
148  return ( PAPI_start( state->EventSet ) );
149 }
int EventSet
Definition: papi_hl.c:40
int PAPI_start(int EventSet)
Definition: papi.c:2096
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_hwi_shutdown_highlevel()

void _papi_hwi_shutdown_highlevel ( )

Definition at line 840 of file papi_hl.c.

841 {
842  HighLevelInfo *state = NULL;
843 
844  if ( PAPI_get_thr_specific( PAPI_HIGH_LEVEL_TLS, ( void ** ) &state ) ==
845  PAPI_OK ) {
846  if ( state )
847  papi_free( state );
848  }
849 }
#define PAPI_OK
Definition: fpapi.h:105
#define papi_free(a)
Definition: papi_memory.h:35
int PAPI_get_thr_specific(int tag, void **ptr)
Definition: papi.c:362
#define PAPI_HIGH_LEVEL_TLS
Definition: papi.h:322
Here is the call graph for this function: