Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revisionBoth sides next revision | ||
doku:papi [2016/06/16 14:01] – sh | doku:papi [2016/07/06 12:24] – ir | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== VSC-3: papi version 5.4.3 ===== | + | ====== PAPI ====== |
+ | < | ||
+ | </ | ||
+ | ===== Synopsis ===== | ||
+ | [[http:// | ||
+ | PAPI is an event-based profiling library providing access to hardware performance counters of critical events, e.g., cache misses, number of CYCLES, number of floating point instructions (flpins), or floating point operations per second (FLOPs). These events can be monitored for selected sections of the code allowing for the analysis of the efficiency of mapping the code to the underlying hardware architecture. | ||
+ | ==== Types of events | ||
+ | **Native events** | ||
+ | are countable by the CPU and can such be accessed directly or by the PAPI low-level interface delivering a CPU-specific bit pattern. | ||
+ | **Preset or predefined events** | ||
+ | are software abstractions of architecture-dependent native events that are accessible through the PAPI interface. | ||
+ | '' | ||
+ | However, due to hardware implementation differences, | ||
- | ==== Synopsis: | + | ===== Usage of PAPI ===== |
- | [[http:// | + | The user will have to modify the source code and insert |
- | + | ||
- | + | ||
- | + | ||
- | ==== Usage of papi: ==== | + | |
- | The user will have to modify the source code and insert | + | |
| | ||
| | ||
+ | and, to compile the user's code while linking the PAPI library ('' | ||
gcc my_program.c -lpapi | gcc my_program.c -lpapi | ||
- | | + | |
- | | + | |
or for Fortran users, | or for Fortran users, | ||
- | |||
- | | ||
- | | ||
| | ||
| | ||
- | + | ==== Interfacing with PAPI : Low level interface | |
- | ==== Interfacing with papi : ==== | + | In general, some code section to be analyzed with PAPI needs to be wrapped into a sequence of standard |
- | In general, some code section to be analyzed with '' | + | * [[doku: |
+ | * [[doku: | ||
+ | As stated in the comment of the C code above, it is best to analyze one particular event at a time. This advice is given because the CPU has limitations in combining arbitrary counters at a time. | ||
+ | ==== Interfacing with PAPI : High level interface ==== | ||
+ | The high level API combines the counters for a specified list of PAPI preset events, only. The set of implemented high level functions is quite limited and can be found in the section '' | ||
+ | The high level API can also be used in conjunction with the low level API. | ||
- | # | + | Example code: |
- | // PAPI variables | + | * [[doku: |
- | // best is to analyze one particular event at a time | + | * [[doku: |
- | int eventset; | + | |
- | long long value, time0, time1, cyc0, cyc1; | + | |
- | + | ||
- | // PAPI Initialization | + | |
- | | + | |
- | if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) { | + | |
- | printf(" | + | |
- | exit(993); | + | |
- | } | + | |
- | // PAPI Event Set Creation | + | |
- | if (PAPI_create_eventset(& | + | |
- | printf(" | + | |
- | exit(994); | + | |
- | } | + | |
- | // PAPI Specify a Particular Target Event to Analyze | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | // | + | |
- | if (PAPI_add_event(eventset, | + | |
- | printf(" | + | |
- | exit(995); | + | |
- | } | + | |
- | // PAPI Time Estimators Initialization | + | |
- | time0 = PAPI_get_real_usec(); | + | |
- | cyc0 = PAPI_get_real_cyc(); | + | |
- | // PAPI Counting Start | + | |
- | if (PAPI_start(eventset) != PAPI_OK) { | + | |
- | printf(" | + | |
- | exit(996); | + | |
- | } | + | |
- | + | ||
- | //*** Here follows the original code section to be analyzed *** | + | |
- | + | ||
- | // PAPI Counting Stop | + | |
- | if (PAPI_stop(eventset, | + | |
- | printf(" | + | |
- | exit(997); | + | |
- | } | + | |
- | // PAPI Time Estimators Stop | + | |
- | time1 = PAPI_get_real_usec(); | + | |
- | cyc1 = PAPI_get_real_cyc(); | + | |
- | // PAPI Results | + | |
- | | + | |
- | | + | |
- | | + | |
- | // PAPI Free Event Set | + | |
- | if (PAPI_cleanup_eventset(eventset) != PAPI_OK) { | + | |
- | printf(" | + | |
- | exit(998); | + | |
- | } | + | |
- | if (PAPI_destroy_eventset(& | + | |
- | printf(" | + | |
- | exit(999); | + | |
- | } | + | |
- | // PAPI Finalize | + | |
- | | + | |
- | + | ||
- | or similarly for Fortran | + | |
- | | ||
- | | ||
- | | ||
- | |||
- | check = PAPI_NULL | ||
- | C | ||
- | | ||
- | C | ||
- | check = PAPI_VER_CURRENT | ||
- | call PAPIF_library_init(check) | ||
- | if (check.ne.PAPI_VER_CURRENT) then | ||
- | write(6,*) 'PAPI init error' | ||
- | write(6,*) '00 check:', | ||
- | stop | ||
- | endif | ||
- | C | ||
- | | ||
- | C | ||
- | | ||
- | call PAPIF_create_eventset(evntst, | ||
- | if (check.ne.PAPI_OK) then | ||
- | write(6,*) 'PAPI event set creation error' | ||
- | write(6,*) '01 check:', | ||
- | stop | ||
- | endif | ||
- | C | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | C | ||
- | call PAPIF_add_event(evntst, | ||
- | if (check.ne.PAPI_OK) then | ||
- | write(6,*) 'PAPI event set adding error' | ||
- | write(6,*) '02 check:', | ||
- | stop | ||
- | endif | ||
- | C | ||
- | | ||
- | | ||
- | call PAPIF_get_real_usec(t0) | ||
- | call PAPIF_get_real_cyc(c0) | ||
- | C | ||
- | | ||
- | | ||
- | call PAPIF_start(evntst, | ||
- | if (check.ne.PAPI_OK) then | ||
- | write(6,*) 'PAPI start error !' | ||
- | write(6,*) '03 check:', | ||
- | stop | ||
- | endif | ||
- | |||
- | C | ||
- | | ||
- | C | ||
- | |||
- | | ||
- | | ||
- | | ||
- | call PAPIF_stop(evntst, | ||
- | if (check.ne.PAPI_OK) then | ||
- | write(6,*) 'PAPI stop error !' | ||
- | write(6,*) '04 check:', | ||
- | stop | ||
- | endif | ||
- | | ||
- | | ||
- | | ||
- | call PAPIF_get_real_usec(t1) | ||
- | call PAPIF_get_real_cyc(c1) | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | call PAPIF_cleanup_eventset(evntst, | ||
- | if (check.ne.PAPI_OK) then | ||
- | write(6,*) 'PAPI event set cleanup error !' | ||
- | write(6,*) '05 check:', | ||
- | stop | ||
- | endif | ||
- | call PAPIF_destroy_eventset(evntst, | ||
- | if (check.ne.PAPI_OK) then | ||
- | write(6,*) 'PAPI event set destruction error !' | ||
- | write(6,*) '06 check:', | ||
- | stop | ||
- | endif | ||
- | | ||
- | | ||
- | | ||
- | call PAPIF_shutdown(check) | ||
- | if (check.ne.PAPI_OK) then | ||
- | write(6,*) 'PAPI finalize failed !' | ||
- | write(6,*) '07 check:', | ||
- | stop | ||
- | endif | ||
- | |||
- | |||
- | |||
==== Practical tips: ==== | ==== Practical tips: ==== | ||
- | * A quick overview of supported events and corresponding | + | * A quick overview of supported events and corresponding |
- | * Measuring the specific event '' | + | * Measuring the specific event '' |
* Evaluating floating point performance on Intel ivy bridge: [[https:// | * Evaluating floating point performance on Intel ivy bridge: [[https:// | ||
* Useful notes on Intel' | * Useful notes on Intel' | ||
- | * Occasionally it is useful to '' | + | * Occasionally, it is useful to PAPI-analyze an application within two steps: |
+ | |||
+ | |||