PAPI  5.7.0.0
papi_cost.c File Reference
Include dependency graph for papi_cost.c:

Go to the source code of this file.

Functions

static int find_derived (int i, char *type)
 
static int find_derived_add (int i)
 
static int find_derived_postfix (int i)
 
static void print_help (void)
 
static void print_stats (int i, long long min, long long max, double average, double std)
 
static void print_std_dev (int *s)
 
static void print_dist (long long min, long long max, int bins, int *d)
 
static void print_percentile (long long percent25, long long percent50, long long percent75, long long percent99)
 
static void do_output (int test_type, long long *array, int bins, int show_std_dev, int show_dist, int show_percentile)
 
int main (int argc, char **argv)
 

Function Documentation

◆ do_output()

static void do_output ( int  test_type,
long long *  array,
int  bins,
int  show_std_dev,
int  show_dist,
int  show_percentile 
)
static

Definition at line 166 of file papi_cost.c.

168 {
169  int s[10];
170  long long min, max;
171  double average, std;
172  long long percent25,percent50,percent75,percent99;
173 
174  std = do_stats( array, &min, &max, &average );
175  print_stats( test_type, min, max, average, std );
176 
177  if (show_percentile) {
178  do_percentile(array,&percent25,&percent50,&percent75,&percent99);
179  print_percentile(percent25,percent50,percent75,percent99);
180  }
181 
182  if ( show_std_dev ) {
183  do_std_dev( array, s, std, average );
184  print_std_dev( s );
185  }
186 
187  if ( show_dist ) {
188  int *d;
189  d = calloc( bins , sizeof ( int ) );
190  do_dist( array, min, max, bins, d );
191  print_dist( min, max, bins, d );
192  free( d );
193  }
194 }
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
static void print_dist(long long min, long long max, int bins, int *d)
Definition: papi_cost.c:137
double do_stats(long long *array, long long *min, long long *max, double *average)
Definition: cost_utils.c:12
static void print_percentile(long long percent25, long long percent50, long long percent75, long long percent99)
Definition: papi_cost.c:157
static void print_std_dev(int *s)
Definition: papi_cost.c:124
double s
Definition: byte_profile.c:36
#define min(x, y)
Definition: darwin-common.h:4
static void print_stats(int i, long long min, long long max, double average, double std)
Definition: papi_cost.c:103
void do_dist(long long *a, long long min, long long max, int bins, int *d)
Definition: cost_utils.c:56
void do_std_dev(long long *a, int *s, double std, double ave)
Definition: cost_utils.c:37
int do_percentile(long long *a, long long *percent25, long long *percent50, long long *percent75, long long *percent99)
Definition: cost_utils.c:96
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_derived()

static int find_derived ( int  i,
char *  type 
)
static

Definition at line 45 of file papi_cost.c.

46 {
47  PAPI_event_info_t info;
48 
50 
51  do {
52  if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
53 
54  if ( strcmp( info.derived, type) == 0 ) {
55  return i;
56  }
57  }
58  } while ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK );
59 
60  return PAPI_NULL;
61 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1152
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:996
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
#define PAPI_NULL
Definition: fpapi.h:13
int i
Definition: fileop.c:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_derived_add()

static int find_derived_add ( int  i)
static

Definition at line 66 of file papi_cost.c.

67 {
68  int ret;
69 
70  ret = find_derived( i, "DERIVED_ADD");
71  if (ret != PAPI_NULL) {
72  return ret;
73  }
74 
75  return find_derived( i, "DERIVED_SUB");
76 }
static int find_derived(int i, char *type)
Definition: papi_cost.c:45
#define PAPI_NULL
Definition: fpapi.h:13
long long ret
Definition: iozone.c:1346
int i
Definition: fileop.c:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_derived_postfix()

static int find_derived_postfix ( int  i)
static

Definition at line 79 of file papi_cost.c.

80 {
81  return ( find_derived ( i, "DERIVED_POSTFIX" ) );
82 }
static int find_derived(int i, char *type)
Definition: papi_cost.c:45
int i
Definition: fileop.c:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 198 of file papi_cost.c.

199 {
200  int i, retval, EventSet = PAPI_NULL;
201  int retval_start,retval_stop;
202  int bins = 100;
203  int show_dist = 0, show_std_dev = 0, show_percent = 0;
204  long long totcyc, values[2];
205  long long *array;
206  int event;
207  PAPI_event_info_t info;
208  int c;
209 
210  /* Check command-line arguments */
211 
212  while ( (c=getopt(argc, argv, "hb:dpst:") ) != -1) {
213 
214  switch(c) {
215 
216  case 'h':
217  print_help();
218  exit(1);
219  case 'b':
220  bins=atoi(optarg);
221  break;
222  case 'd':
223  show_dist=1;
224  break;
225  case 'p':
226  show_percent=1;
227  break;
228  case 's':
229  show_std_dev=1;
230  break;
231  case 't':
233  break;
234  default:
235  print_help();
236  exit(1);
237  break;
238  }
239 
240  }
241 
242  printf( "Cost of execution for PAPI start/stop, read and accum.\n" );
243  printf( "This test takes a while. Please be patient...\n" );
244 
246  if (retval != PAPI_VER_CURRENT ) {
247  fprintf(stderr,"PAPI_library_init\n");
248  exit(retval);
249  }
251  if (retval != PAPI_OK ) {
252  fprintf(stderr,"PAPI_set_debug\n");
253  exit(retval);
254  }
256  if (retval != PAPI_OK ) {
257  fprintf(stderr,"PAPI_query_event\n");
258  exit(retval);
259  }
261  if (retval != PAPI_OK ) {
262  fprintf(stderr,"PAPI_query_event\n");
263  exit(retval);
264  }
266  if (retval != PAPI_OK ) {
267  fprintf(stderr,"PAPI_create_eventset\n");
268  exit(retval);
269  }
271  if (retval != PAPI_OK ) {
272  fprintf(stderr,"PAPI_add_event\n");
273  exit(retval);
274  }
276  if (retval != PAPI_OK ) {
278  if (retval != PAPI_OK ) {
279  fprintf(stderr,"PAPI_add_event\n");
280  exit(retval);
281  }
282  }
283 
284  /* Make sure no errors and warm up */
285 
286  totcyc = PAPI_get_real_cyc( );
287  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
288  fprintf(stderr,"PAPI_start");
289  exit(retval);
290  }
291  if ( ( retval = PAPI_stop( EventSet, NULL ) ) != PAPI_OK ) {
292  fprintf(stderr,"PAPI_stop");
293  exit(retval);
294  }
295 
296  array = ( long long * ) malloc( ( size_t ) num_iters * sizeof ( long long ) );
297  if ( array == NULL ) {
298  fprintf(stderr,"Error allocating memory for results\n");
299  exit(retval);
300  }
301 
302  /* Determine clock latency */
303 
304  printf( "\nPerforming loop latency test...\n" );
305 
306  for ( i = 0; i < num_iters; i++ ) {
307  totcyc = PAPI_get_real_cyc( );
308  totcyc = PAPI_get_real_cyc( ) - totcyc;
309  array[i] = totcyc;
310  }
311 
312  do_output( 0, array, bins, show_std_dev, show_dist, show_percent );
313 
314  /* Start the start/stop eval */
315 
316  printf( "\nPerforming start/stop test...\n" );
317 
318  for ( i = 0; i < num_iters; i++ ) {
319  totcyc = PAPI_get_real_cyc( );
320  retval_start=PAPI_start( EventSet );
321  retval_stop=PAPI_stop( EventSet, values );
322  totcyc = PAPI_get_real_cyc( ) - totcyc;
323  array[i] = totcyc;
324  if (retval_start || retval_stop) {
325  fprintf(stderr,"PAPI start/stop\n");
326  exit(retval_start );
327  }
328  }
329 
330  do_output( 1, array, bins, show_std_dev, show_dist, show_percent );
331 
332  /* Start the read eval */
333  printf( "\nPerforming read test...\n" );
334 
335  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
336  fprintf(stderr,"PAPI_start");
337  exit(retval);
338  }
340 
341  for ( i = 0; i < num_iters; i++ ) {
342  totcyc = PAPI_get_real_cyc( );
344  totcyc = PAPI_get_real_cyc( ) - totcyc;
345  array[i] = totcyc;
346  }
347  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) {
348  fprintf(stderr,"PAPI_stop");
349  exit(retval);
350  }
351 
352  do_output( 2, array, bins, show_std_dev, show_dist, show_percent );
353 
354  /* Start the read with timestamp eval */
355  printf( "\nPerforming read with timestamp test...\n" );
356 
357  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
358  fprintf(stderr,"PAPI_start");
359  exit(retval);
360  }
361  PAPI_read_ts( EventSet, values, &totcyc );
362 
363  for ( i = 0; i < num_iters; i++ ) {
365  }
366  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) {
367  fprintf(stderr,"PAPI_stop");
368  exit(retval);
369  }
370 
371  /* post-process the timing array */
372  for ( i = num_iters - 1; i > 0; i-- ) {
373  array[i] -= array[i - 1];
374  }
375  array[0] -= totcyc;
376 
377  do_output( 3, array, bins, show_std_dev, show_dist, show_percent );
378 
379  /* Start the accum eval */
380  printf( "\nPerforming accum test...\n" );
381 
382  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
383  fprintf(stderr,"PAPI_start");
384  exit(retval);
385  }
387 
388  for ( i = 0; i < num_iters; i++ ) {
389  totcyc = PAPI_get_real_cyc( );
391  totcyc = PAPI_get_real_cyc( ) - totcyc;
392  array[i] = totcyc;
393  }
394  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) {
395  fprintf(stderr,"PAPI_stop");
396  exit(retval);
397  }
398 
399  do_output( 4, array, bins, show_std_dev, show_dist, show_percent );
400 
401  /* Start the reset eval */
402  printf( "\nPerforming reset test...\n" );
403 
404  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
405  fprintf(stderr,"PAPI_start");
406  exit(retval);
407  }
408 
409  for ( i = 0; i < num_iters; i++ ) {
410  totcyc = PAPI_get_real_cyc( );
411  PAPI_reset( EventSet );
412  totcyc = PAPI_get_real_cyc( ) - totcyc;
413  array[i] = totcyc;
414  }
415  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) {
416  fprintf(stderr,"PAPI_stop");
417  exit(retval);
418  }
419 
420  do_output( 5, array, bins, show_std_dev, show_dist, show_percent );
421 
422  /* Derived POSTFIX event test */
424 
425  event = 0 | PAPI_PRESET_MASK;
426 
427  event = find_derived_postfix( event );
428  if ( event != PAPI_NULL ) {
429 
430  PAPI_get_event_info(event, &info);
431  printf( "\nPerforming DERIVED_POSTFIX "
432  "PAPI_read(%d counters) test (%s)...",
433  info.count, info.symbol );
434 
435  retval = PAPI_add_event( EventSet, event);
436  if ( retval != PAPI_OK ) {
437  fprintf(stderr,"PAPI_add_event");
438  exit(retval);
439  }
440 
442  if ( retval != PAPI_OK ) {
443  fprintf(stderr,"PAPI_start");
444  exit(retval);
445  }
446 
448 
449  for ( i = 0; i < num_iters; i++ ) {
450  totcyc = PAPI_get_real_cyc( );
452  totcyc = PAPI_get_real_cyc( ) - totcyc;
453  array[i] = totcyc;
454  }
455 
457  if ( retval != PAPI_OK ) {
458  fprintf(stderr,"PAPI_stop");
459  exit(retval);
460  }
461 
462  do_output( 6, array, bins, show_std_dev, show_dist, show_percent );
463 
464  } else {
465  printf("\tI was unable to find a DERIVED_POSTFIX preset event "
466  "to test on this architecture, skipping.\n");
467  }
468 
469  /* Find a derived ADD event */
471 
472  event = 0 | PAPI_PRESET_MASK;
473 
474  event = find_derived_add( event );
475  if ( event != PAPI_NULL ) {
476 
477  PAPI_get_event_info(event, &info);
478  printf( "\nPerforming DERIVED_[ADD|SUB] "
479  "PAPI_read(%d counters) test (%s)...",
480  info.count, info.symbol );
481 
482  retval = PAPI_add_event( EventSet, event);
483  if ( retval != PAPI_OK ) {
484  fprintf(stderr,"PAPI_add_event\n");
485  exit(retval);
486  }
487 
489  if ( retval != PAPI_OK ) {
490  fprintf(stderr,"PAPI_start");
491  exit(retval);
492  }
493 
495 
496  for ( i = 0; i < num_iters; i++ ) {
497  totcyc = PAPI_get_real_cyc( );
499  totcyc = PAPI_get_real_cyc( ) - totcyc;
500  array[i] = totcyc;
501  }
502 
504  if ( retval != PAPI_OK ) {
505  fprintf(stderr,"PAPI_stop");
506  exit(retval);
507  }
508 
509  do_output( 7, array, bins, show_std_dev, show_dist, show_percent );
510  } else {
511  printf("\tI was unable to find a suitable DERIVED_[ADD|SUB] "
512  "event to test, skipping.\n");
513  }
514 
515  free( array );
516 
517  return 0;
518 }
#define PAPI_OK
Definition: fpapi.h:105
int atoi()
unsigned int count
Definition: papi.h:988
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
static int find_derived_add(int i)
Definition: papi_cost.c:66
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
int PAPI_reset(int EventSet)
Definition: papi.c:2459
static void do_output(int test_type, long long *array, int bins, int show_std_dev, int show_dist, int show_percentile)
Definition: papi_cost.c:166
static void print_help(void)
Definition: papi_cost.c:85
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet
#define PAPI_PRESET_MASK
int retval
Definition: zero_fork.c:53
static int find_derived_postfix(int i)
Definition: papi_cost.c:79
double c
Definition: multiplex.c:22
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
int PAPI_accum(int EventSet, long long *values)
Definition: papi.c:2745
int PAPI_library_init(int version)
Definition: papi.c:500
#define PAPI_TOT_INS
Definition: fpapi.h:186
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:967
#define PAPI_TOT_IIS
Definition: fpapi.h:185
#define PAPI_VERB_ECONT
Definition: fpapi.h:39
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_query_event(int EventCode)
Definition: papi.c:684
int PAPI_read_ts(int EventSet, long long *values, long long *cycles)
Definition: papi.c:2648
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define PAPI_TOT_CYC
Definition: fpapi.h:195
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void exit()
int PAPI_set_debug(int level)
Definition: papi.c:3126
char * optarg
int i
Definition: fileop.c:140
int num_iters
Definition: cost_utils.c:8
Here is the call graph for this function:

◆ print_dist()

static void print_dist ( long long  min,
long long  max,
int  bins,
int *  d 
)
static

Definition at line 137 of file papi_cost.c.

138 {
139  int i, j;
140  int step = ( int ) ( max - min ) / bins;
141 
142  printf( "\nCost distribution profile\n\n" );
143  for ( i = 0; i < bins; i++ ) {
144  printf( "%8d:", ( int ) min + ( step * i ) );
145  if ( d[i] > 100 ) {
146  printf( "**************************** %d counts ****************************",
147  d[i] );
148  } else {
149  for ( j = 0; j < d[i]; j++ )
150  printf( "*" );
151  }
152  printf( "\n" );
153  }
154 }
#define min(x, y)
Definition: darwin-common.h:4
int i
Definition: fileop.c:140
Here is the caller graph for this function:

◆ print_help()

static void print_help ( void  )
static

Definition at line 85 of file papi_cost.c.

86 {
87  printf( "This is the PAPI cost program.\n" );
88  printf( "It computes min / max / mean / std. deviation for PAPI start/stop pairs; for PAPI reads, and for PAPI_accums. Usage:\n\n" );
89  printf( " cost [options] [parameters]\n" );
90  printf( " cost TESTS_QUIET\n\n" );
91  printf( "Options:\n\n" );
92  printf( " -b BINS set the number of bins for the graphical distribution of costs. Default: 100\n" );
93  printf( " -d show a graphical distribution of costs\n" );
94  printf( " -h print this help message\n" );
95  printf( " -p print 25/50/75th percentile results for making boxplots\n");
96  printf( " -s show number of iterations above the first 10 std deviations\n" );
97  printf( " -t THRESHOLD set the threshold for the number of iterations. Default: 1,000,000\n" );
98  printf( "\n" );
99 }
Here is the caller graph for this function:

◆ print_percentile()

static void print_percentile ( long long  percent25,
long long  percent50,
long long  percent75,
long long  percent99 
)
static

Definition at line 157 of file papi_cost.c.

159 {
160  printf("25%% cycles : %lld\n50%% cycles : %lld\n"
161  "75%% cycles : %lld\n99%% cycles : %lld\n",
162  percent25,percent50,percent75,percent99);
163 }
Here is the caller graph for this function:

◆ print_stats()

static void print_stats ( int  i,
long long  min,
long long  max,
double  average,
double  std 
)
static

Definition at line 103 of file papi_cost.c.

104 {
105  char *test[] = {
106  "loop latency",
107  "PAPI_start/stop (2 counters)",
108  "PAPI_read (2 counters)",
109  "PAPI_read_ts (2 counters)",
110  "PAPI_accum (2 counters)",
111  "PAPI_reset (2 counters)",
112  "PAPI_read (1 derived_postfix counter)",
113  "PAPI_read (1 derived_[add|sub] counter)"
114  };
115 
116  printf( "\nTotal cost for %s over %d iterations\n",
117  test[i], num_iters );
118  printf( "min cycles : %lld\nmax cycles : %lld\n"
119  "mean cycles : %lf\nstd deviation: %lf\n",
120  min, max, average, std );
121 }
#define min(x, y)
Definition: darwin-common.h:4
int i
Definition: fileop.c:140
int num_iters
Definition: cost_utils.c:8
Here is the caller graph for this function:

◆ print_std_dev()

static void print_std_dev ( int *  s)
static

Definition at line 124 of file papi_cost.c.

125 {
126  int i;
127 
128  printf( "\n" );
129  printf( " --------# Standard Deviations Above the Mean--------\n" );
130  printf( "0-------1-------2-------3-------4-------5-------6-------7-------8-------9-----10\n" );
131  for ( i = 0; i < 10; i++ )
132  printf( " %d\t", s[i] );
133  printf( "\n\n" );
134 }
double s
Definition: byte_profile.c:36
int i
Definition: fileop.c:140
Here is the caller graph for this function: