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

Defines

#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

Author:
Philip Mucci mucci@cs.utk.edu
Kevin London london@cs.utk.edu
dan terpstra terpstra@cs.utk.edu

Definition in file papi_hl.c.


Define Documentation

#define HL_ACCUM   7

Definition at line 33 of file papi_hl.c.

#define HL_EPC   5

Definition at line 31 of file papi_hl.c.

#define HL_FLIP   2

Definition at line 28 of file papi_hl.c.

#define HL_FLOP   3

Definition at line 29 of file papi_hl.c.

#define HL_IPC   4

Definition at line 30 of file papi_hl.c.

#define HL_READ   6

Definition at line 32 of file papi_hl.c.

#define HL_START   1

Definition at line 27 of file papi_hl.c.

#define HL_STOP   0

Definition at line 26 of file papi_hl.c.


Function Documentation

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 405 of file papi_hl.c.

00407 {
00408     long long rt, pt; // current elapsed real and process times in usec
00409     int num_events = 2;
00410     int retval = 0;
00411     HighLevelInfo *state = NULL;
00412 
00413     if ( ( retval = _internal_check_state( &state ) ) != PAPI_OK ) {
00414         return ( retval );
00415     }
00416     
00417     if ( state->running != HL_STOP && state->running != mode ) {
00418         return PAPI_EINVAL;
00419     }
00420 
00421     if ( state->running == HL_STOP ) {
00422     
00423         switch (mode) {
00424             case HL_FLOP:
00425             case HL_FLIP:
00426                 num_events = 1;
00427                 break;
00428             case HL_IPC:
00429                 break;
00430             case HL_EPC:
00431                 if ( events[2] != 0 ) num_events = 3;
00432                 break;
00433             default:
00434                 return PAPI_EINVAL;
00435         }
00436         if (( retval = PAPI_add_events( state->EventSet, events, num_events )) != PAPI_OK ) {
00437             _internal_cleanup_hl_info( state );
00438             PAPI_cleanup_eventset( state->EventSet );
00439             return retval;
00440         }
00441 
00442         state->total_ins = 0;
00443         state->initial_real_time = state->last_real_time = PAPI_get_real_usec( );
00444         state->initial_proc_time = state->last_proc_time = PAPI_get_virt_usec( );
00445 
00446         if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) {
00447             return retval;
00448         }
00449         
00450         /* Initialize the interface */
00451         state->running = mode;
00452         *real_time  = 0.0;
00453         *proc_time  = 0.0;
00454         *rate       = 0.0;
00455 
00456     } else {
00457         if ( ( retval = PAPI_stop( state->EventSet, values ) ) != PAPI_OK ) {
00458             state->running = HL_STOP;
00459             return retval;
00460         }
00461 
00462         /* Read elapsed real and process times  */
00463         rt = PAPI_get_real_usec();
00464         pt = PAPI_get_virt_usec();
00465 
00466         /* Convert to seconds with multiplication because it is much faster */
00467         *real_time = ((float)( rt - state->initial_real_time )) * .000001;
00468         *proc_time = ((float)( pt - state->initial_proc_time )) * .000001;
00469 
00470         state->total_ins += values[0];
00471 
00472         switch (mode) {
00473             case HL_FLOP:
00474             case HL_FLIP:
00475                 /* Calculate MFLOP and MFLIP rates */
00476                 if ( pt > 0 ) {
00477                      *rate = (float)values[0] / (pt - state->last_proc_time);
00478                 } else *rate = 0;
00479                 break;
00480             case HL_IPC:
00481             case HL_EPC:
00482                 /* Calculate IPC */
00483                 if (values[1]!=0) {
00484                     *rate = (float) ((float)values[0] / (float) ( values[1]));
00485                 }
00486                 break;
00487             default:
00488                 return PAPI_EINVAL;
00489         }
00490         state->last_real_time = rt;
00491         state->last_proc_time = pt;
00492     
00493         if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) {
00494             state->running = HL_STOP;
00495             return retval;
00496         }
00497     }
00498     *ins = state->total_ins;
00499     return PAPI_OK;
00500 }

Here is the call graph for this function:

Here is the caller graph for this function:

int _internal_check_state ( HighLevelInfo **  outgoing  ) 

For internal use only.

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.

00101 {
00102     int retval;
00103     HighLevelInfo *state = NULL;
00104 
00105     /* Only allow one thread at a time in here */
00106     if ( init_level == PAPI_NOT_INITED ) {
00107         retval = PAPI_library_init( PAPI_VER_CURRENT );
00108         if ( retval != PAPI_VER_CURRENT ) {
00109             return ( retval );
00110         } else {
00111             _papi_hwi_lock( HIGHLEVEL_LOCK );
00112             init_level = PAPI_HIGH_LEVEL_INITED;
00113             _papi_hwi_unlock( HIGHLEVEL_LOCK );
00114         }
00115     }
00116 
00117     /*
00118      * Do we have the thread specific data setup yet?
00119      */
00120     if ( ( retval =
00121            PAPI_get_thr_specific( PAPI_HIGH_LEVEL_TLS, ( void * ) &state ) )
00122          != PAPI_OK || state == NULL ) {
00123         state = ( HighLevelInfo * ) papi_malloc( sizeof ( HighLevelInfo ) );
00124         if ( state == NULL )
00125             return ( PAPI_ENOMEM );
00126 
00127         memset( state, 0, sizeof ( HighLevelInfo ) );
00128         state->EventSet = -1;
00129 
00130         if ( ( retval = PAPI_create_eventset( &state->EventSet ) ) != PAPI_OK )
00131             return ( retval );
00132 
00133         if ( ( retval =
00134                PAPI_set_thr_specific( PAPI_HIGH_LEVEL_TLS,
00135                                       state ) ) != PAPI_OK )
00136             return ( retval );
00137     }
00138     *outgoing = state;
00139     return ( PAPI_OK );
00140 }

Here is the call graph for this function:

Here is the caller graph for this function:

void _internal_cleanup_hl_info ( HighLevelInfo state  ) 

Definition at line 152 of file papi_hl.c.

00153 {
00154     state->num_evts = 0;
00155     state->running = HL_STOP;
00156     state->initial_real_time = -1;
00157     state->initial_proc_time = -1;
00158     state->total_ins = 0;
00159     return;
00160 }

Here is the caller graph for this function:

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

Definition at line 639 of file papi_hl.c.

00640 {
00641     int retval;
00642     HighLevelInfo *state = NULL;
00643 
00644     if ( ( retval = _internal_check_state( &state ) ) != PAPI_OK )
00645         return ( retval );
00646 
00647     if ( state->running != HL_START || array_len < state->num_evts )
00648         return ( PAPI_EINVAL );
00649 
00650     if ( flag == HL_ACCUM )
00651         return ( PAPI_accum( state->EventSet, values ) );
00652     else if ( flag == HL_READ ) {
00653         if ( ( retval = PAPI_read( state->EventSet, values ) ) != PAPI_OK )
00654             return ( retval );
00655         return ( PAPI_reset( state->EventSet ) );
00656     }
00657 
00658     /* Invalid flag passed in */
00659     return ( PAPI_EINVAL );
00660 }

Here is the call graph for this function:

Here is the caller graph for this function:

int _internal_start_hl_counters ( HighLevelInfo state  ) 

For internal use only.

Make sure to allocate space for values

Definition at line 146 of file papi_hl.c.

00147 {
00148     return ( PAPI_start( state->EventSet ) );
00149 }

Here is the call graph for this function:

Here is the caller graph for this function:

void _papi_hwi_shutdown_highlevel (  ) 

Definition at line 836 of file papi_hl.c.

00837 {
00838     HighLevelInfo *state = NULL;
00839 
00840     if ( PAPI_get_thr_specific( PAPI_HIGH_LEVEL_TLS, ( void * ) &state ) ==
00841          PAPI_OK ) {
00842         if ( state )
00843             papi_free( state );
00844     }
00845 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1