void polybench_papi_stop_counter(int evid) { # ifdef _OPENMP # pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; long_long values[1]; values[0] = 0; if ((retval = PAPI_read (polybench_papi_eventset, &values[0])) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_read", retval); if ((retval = PAPI_stop (polybench_papi_eventset, NULL)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_stop", retval); polybench_papi_values[evid] = values[0]; if ((retval = PAPI_remove_event (polybench_papi_eventset, polybench_papi_eventlist[evid])) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_remove_event", retval); # ifdef _OPENMP } } #pragma omp barrier # endif }
static void measure_event( int index, PAPI_option_t * option ) { int retval; long long value; if ( ( retval = PAPI_add_event( EventSet, PAPI_event[index] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( index == 0 ) { /* if ((retval = PAPI_get_opt(PAPI_DATA_ADDRESS, option)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_get_opt(PAPI_DATA_ADDRESS)", retval); */ printf ( "Requested Start Address: %p; Start Offset: 0x%5x; Actual Start Address: %p\n", option->addr.start, option->addr.start_off, option->addr.start - option->addr.start_off ); printf ( "Requested End Address: %p; End Offset: 0x%5x; Actual End Address: %p\n", option->addr.end, option->addr.end_off, option->addr.end + option->addr.end_off ); } PAPI_start( EventSet ); do_malloc_work( NUM ); do_static_work( NUM ); PAPI_stop( EventSet, &value ); printf( "%s: %lld\n", event_name[index], value ); if ( ( retval = PAPI_remove_event( EventSet, PAPI_event[index] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval ); }
void inline papi_end(){ end_time = PAPI_get_virt_usec(); fprintf(stdout, "%s\t", inf.symbol); fprintf(stdout, "\t%llu\t", event_value[0]); fprintf(stdout, "\t%llu\n", end_time - start_time); papi_safe(PAPI_remove_event(event_set, papi_events[current_event]), ERR_PAPI_REMOVE_EVENT); }
void * my_thread( void *v ) { long num = ( long ) v; int n; int EventSet = PAPI_NULL; long long value; int retval = PAPI_register_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); pthread_setspecific( key, v ); count[num] = 0; iter[num] = 0; last[num] = start; if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 ); if ( PAPI_add_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event failed", 1 ); if ( PAPI_overflow( EventSet, EVENT, threshold, 0, my_handler ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 ); if ( PAPI_start( EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 ); printf( "launched timer in thread %ld\n", num ); for ( n = 1; n <= program_time; n++ ) { do_cycles( num, 1 ); print_rate( num ); } PAPI_stop( EventSet, &value ); retval = PAPI_overflow( EventSet, EVENT, 0, 0, my_handler); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed to reset the overflow handler", retval ); if ( PAPI_remove_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_remove_event", 1 ); if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", 1 ); if ( PAPI_unregister_thread( ) != PAPI_OK != retval ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", 1 ); return ( NULL ); }
static int add_remove_event(int EventSet, int evt) { int retval; if((retval=PAPI_add_event(EventSet, evt)) != PAPI_OK) { printf("Error adding event.\n"); } else { if((retval=PAPI_remove_event(EventSet,evt))!=PAPI_OK) printf("Error removing event.\n"); } return(retval); }
int main( int argc, char **argv ) { int retval, i; int EventSet = PAPI_NULL, count = 0, err_count = 0; long long values; PAPI_event_info_t info; char errstring[PAPI_MAX_STR_LEN]; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) { if ( PAPI_get_event_info( PAPI_PRESET_MASK | i, &info ) != PAPI_OK ) continue; if ( !( info.count ) ) continue; printf( "Adding %-14s", info.symbol ); retval = PAPI_add_event( EventSet, ( int ) info.event_code ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error: %s\n", errstring ); err_count++; } else { retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error Starting: %s\n", errstring ); err_count++; } else { retval = PAPI_stop( EventSet, &values ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error Stopping: %s\n", errstring ); err_count++; } else { printf( "successful\n" ); count++; } } retval = PAPI_remove_event( EventSet, ( int ) info.event_code ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval ); } } retval = PAPI_destroy_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); printf( "Successfully added, started and stopped %d events.\n", count ); if ( err_count ) printf( "Failed to add, start or stop %d events.\n", err_count ); if ( count > 0 ) test_pass( __FILE__, NULL, 0 ); else test_fail( __FILE__, __LINE__, "No events added", 1 ); exit( 1 ); }
int main(int argc, char **argv) { PAPI_event_info_t info; char name2[PAPI_MAX_STR_LEN]; int i, j, retval, idx, repeats; int iters = NUM_FLOPS; double x = 1.1, y, dtmp; long long t1, t2; long long values[MAXEVENTS], refvals[MAXEVENTS]; int nsamples[MAXEVENTS], truelist[MAXEVENTS], ntrue; #ifdef STARTSTOP long long dummies[MAXEVENTS]; #endif int sleep_time = SLEEPTIME; double valsample[MAXEVENTS][REPEATS]; double valsum[MAXEVENTS]; double avg[MAXEVENTS]; double spread[MAXEVENTS]; int nevents = MAXEVENTS, nev1; int eventset = PAPI_NULL; int events[MAXEVENTS]; int eventidx[MAXEVENTS]; int eventmap[MAXEVENTS]; int fails; events[0] = PAPI_FP_INS; events[1] = PAPI_TOT_CYC; events[2] = PAPI_TOT_INS; events[3] = PAPI_TOT_IIS; events[4] = PAPI_INT_INS; events[5] = PAPI_STL_CCY; events[6] = PAPI_BR_INS; events[7] = PAPI_SR_INS; events[8] = PAPI_LD_INS; for (i = 0; i < MAXEVENTS; i++) { values[i] = 0; valsum[i] = 0; nsamples[i] = 0; } if (argc > 1) { if (!strcmp(argv[1], "TESTS_QUIET")) tests_quiet(argc, argv); else { sleep_time = atoi(argv[1]); if (sleep_time <= 0) sleep_time = SLEEPTIME; } } if (!TESTS_QUIET) { printf("\nFunctional check of multiplexing routines.\n"); printf("Adding and removing events from an event set.\n\n"); } if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); #ifdef MPX init_multiplex(); #endif if ((retval = PAPI_create_eventset(&eventset))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); #ifdef MPX /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ retval = PAPI_assign_eventset_component(eventset, 0); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ((retval = PAPI_set_multiplex(eventset))) test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval); #endif nevents = MAXEVENTS; for (i = 0; i < nevents; i++) { if ((retval = PAPI_add_event(eventset, events[i]))) { for (j = i; j < MAXEVENTS; j++) events[j] = events[j + 1]; nevents--; i--; } } if (nevents < 3) test_skip(__FILE__, __LINE__, "Not enough events left...", 0); /* Find a reasonable number of iterations (each * event active 20 times) during the measurement */ t2 = 10000 * 20 * nevents; /* Target: 10000 usec/multiplex, 20 repeats */ if (t2 > 30e6) test_skip(__FILE__, __LINE__, "This test takes too much time", retval); /* Measure one run */ t1 = PAPI_get_real_usec(); y = dummy3(x, iters); t1 = PAPI_get_real_usec() - t1; if (t2 > t1) /* Scale up execution time to match t2 */ iters = iters * (int)(t2 / t1); else if (t1 > 30e6) /* Make sure execution time is < 30s per repeated test */ test_skip(__FILE__, __LINE__, "This test takes too much time", retval); j = nevents; for (i = 1; i < nevents; i = i + 2) eventidx[--j] = i; for (i = 0; i < nevents; i = i + 2) eventidx[--j] = i; assert(j == 0); for (i = 0; i < nevents; i++) eventmap[i] = i; x = 1.0; if (!TESTS_QUIET) printf("\nReference run:\n"); t1 = PAPI_get_real_usec(); if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); y = dummy3(x, iters); PAPI_read(eventset, refvals); t2 = PAPI_get_real_usec(); ntrue = nevents; PAPI_list_events(eventset, truelist, &ntrue); if (!TESTS_QUIET) { printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); printf("%20s %16s %-15s %-15s\n", "PAPI measurement:", "Acquired count", "Expected event", "PAPI_list_events"); } if (!TESTS_QUIET) { for (j = 0; j < nevents; j++) { PAPI_get_event_info(events[j], &info); PAPI_event_code_to_name(truelist[j], name2); if (!TESTS_QUIET) printf("%20s = %16lld %-15s %-15s %s\n", info.short_descr, refvals[j], info.symbol, name2, strcmp(info.symbol, name2) ? "*** MISMATCH ***" : ""); } printf("\n"); } nev1 = nevents; repeats = nevents * 4; for (i = 0; i < repeats; i++) { if ((i % nevents) + 1 == nevents) continue; if (!TESTS_QUIET) printf("\nTest %d (of %d):\n", i + 1 - i / nevents, repeats - 4); if ((retval = PAPI_stop(eventset, values))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); j = eventidx[i % nevents]; if ((i / nevents) % 2 == 0) { PAPI_get_event_info(events[j], &info); if (!TESTS_QUIET) printf("Removing event[%d]: %s\n", j, info.short_descr); if ((retval = PAPI_remove_event(eventset, events[j]))) test_fail(__FILE__, __LINE__, "PAPI_remove_event", retval); nev1--; for (idx = 0; eventmap[idx] != j; idx++); for (j = idx; j < nev1; j++) eventmap[j] = eventmap[j + 1]; } else { PAPI_get_event_info(events[j], &info); if (!TESTS_QUIET) printf("Adding event[%d]: %s\n", j, info.short_descr); if ((retval = PAPI_add_event(eventset, events[j]))) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); eventmap[nev1] = j; nev1++; } if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); x = 1.0; #ifndef STARTSTOP if ((retval = PAPI_reset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_reset", retval); #else if ((retval = PAPI_stop(eventset, dummies))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); #endif t1 = PAPI_get_real_usec(); y = dummy3(x, iters); PAPI_read(eventset, values); t2 = PAPI_get_real_usec(); if (!TESTS_QUIET) { printf("\n(calculated independent of PAPI)\n"); printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); printf("%20s %16s %-15s %-15s\n", "PAPI measurement:", "Acquired count", "Expected event", "PAPI_list_events"); } ntrue = nev1; PAPI_list_events(eventset, truelist, &ntrue); for (j = 0; j < nev1; j++) { idx = eventmap[j]; /* printf("Mapping: Counter %d -> slot %d.\n",j,idx); */ PAPI_get_event_info(events[idx], &info); PAPI_event_code_to_name(truelist[j], name2); if (!TESTS_QUIET) printf("%20s = %16lld %-15s %-15s %s\n", info.short_descr, values[j], info.symbol, name2, strcmp(info.symbol, name2) ? "*** MISMATCH ***" : ""); dtmp = (double) values[j]; valsum[idx] += dtmp; valsample[idx][nsamples[idx]] = dtmp; nsamples[idx]++; } if (!TESTS_QUIET) printf("\n"); } if (!TESTS_QUIET) { printf("\n\nEstimated variance relative to average counts:\n"); for (j = 0; j < nev1; j++) printf(" Event %.2d", j); printf("\n"); } fails = nevents; /* Due to limited precision of floating point cannot really use typical standard deviation compuation for large numbers with very small variations. Instead compute the std devation problems with precision. */ for (j = 0; j < nev1; j++) { avg[j] = valsum[j] / nsamples[j]; spread[j] = 0; for (i=0; i < nsamples[j]; ++i) { double diff = (valsample[j][i] - avg[j]); spread[j] += diff * diff; } spread[j] = sqrt(spread[j] / nsamples[j]) / avg[j]; if (!TESTS_QUIET) printf("%9.2g ", spread[j]); /* Make sure that NaN get counted as errors */ if (spread[j] < MPX_TOLERANCE) fails--; else if (values[j] < MINCOUNTS) /* Neglect inprecise results with low counts */ fails--; } if (!TESTS_QUIET) { printf("\n\n"); for (j = 0; j < nev1; j++) { PAPI_get_event_info(events[j], &info); printf("Event %.2d: mean=%10.0f, sdev/mean=%7.2g nrpt=%2d -- %s\n", j, avg[j], spread[j], nsamples[j], info.short_descr); } printf("\n\n"); } if (fails) test_fail(__FILE__, __LINE__, "Values differ from reference", fails); else test_pass(__FILE__, NULL, 0); return 0; }
int remove_test_events( int *EventSet, int mask ) { int retval = PAPI_OK; if ( mask & MASK_L1_DCA ) { retval = PAPI_remove_event( *EventSet, PAPI_L1_DCA ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_L1_DCW ) { retval = PAPI_remove_event( *EventSet, PAPI_L1_DCW ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_L1_DCR ) { retval = PAPI_remove_event( *EventSet, PAPI_L1_DCR ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_L2_TCH ) { retval = PAPI_remove_event( *EventSet, PAPI_L2_TCH ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_L2_TCA ) { retval = PAPI_remove_event( *EventSet, PAPI_L2_TCA ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_L2_TCM ) { retval = PAPI_remove_event( *EventSet, PAPI_L2_TCM ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_L1_DCM ) { retval = PAPI_remove_event( *EventSet, PAPI_L1_DCM ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_L1_ICM ) { retval = PAPI_remove_event( *EventSet, PAPI_L1_ICM ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_L1_TCM ) { retval = PAPI_remove_event( *EventSet, PAPI_L1_TCM ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_FP_OPS ) { retval = PAPI_remove_event( *EventSet, PAPI_FP_OPS ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_FP_INS ) { retval = PAPI_remove_event( *EventSet, PAPI_FP_INS ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_TOT_INS ) { retval = PAPI_remove_event( *EventSet, PAPI_TOT_INS ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_TOT_IIS ) { retval = PAPI_remove_event( *EventSet, PAPI_TOT_IIS ); if ( retval < PAPI_OK ) return ( retval ); } if ( mask & MASK_TOT_CYC ) { retval = PAPI_remove_event( *EventSet, PAPI_TOT_CYC ); if ( retval < PAPI_OK ) return ( retval ); } return ( PAPI_destroy_eventset( EventSet ) ); }
void mainloop( int arg ) { int allvalid; long long *values; int EventSet = PAPI_NULL; int retval, i, j = 2, skipped_counters=0; PAPI_event_info_t pset; ( void ) arg; /* Initialize the library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); init_multiplex( ); retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ retval = PAPI_assign_eventset_component( EventSet, 0 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); retval = PAPI_set_multiplex( EventSet ); if ( retval == PAPI_ENOSUPP) { test_skip(__FILE__, __LINE__, "Multiplex not supported", 1); } else if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); if ( ( retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) ) ) != PAPI_OK ) { if ( retval == PAPI_ECMP ) test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval ); else test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval ); } retval = PAPI_add_event( EventSet, PAPI_TOT_INS ); if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( !TESTS_QUIET ) { printf( "Added %s\n", "PAPI_TOT_INS" ); } retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ); if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( !TESTS_QUIET ) { printf( "Added %s\n", "PAPI_TOT_CYC" ); } values = ( long long * ) malloc( MAX_TO_ADD * sizeof ( long long ) ); if ( values == NULL ) test_fail( __FILE__, __LINE__, "malloc", 0 ); for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) { retval = PAPI_get_event_info( i | PAPI_PRESET_MASK, &pset ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval ); if ( pset.count ) { printf( "Adding %s\n", pset.symbol ); retval = PAPI_add_event( EventSet, ( int ) pset.event_code ); if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( retval == PAPI_OK ) { printf( "Added %s\n", pset.symbol ); } else { printf( "Could not add %s\n", pset.symbol ); } do_stuff( ); if ( retval == PAPI_OK ) { retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_stuff( ); retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); if ( values[j] ) { if ( ++j >= MAX_TO_ADD ) break; } else { retval = PAPI_remove_event( EventSet, ( int ) pset.event_code ); if ( retval == PAPI_OK ) printf( "Removed %s\n", pset.symbol ); /* This added because the test */ /* can take a long time if mplexing */ /* is broken and all values are 0 */ skipped_counters++; if (skipped_counters>MAX_TO_ADD) break; } } } } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_stuff( ); retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); test_print_event_header( "multiplex3_pthreads:\n", EventSet ); allvalid = 0; for ( i = 0; i < MAX_TO_ADD; i++ ) { printf( ONENUM, values[i] ); if ( values[i] != 0 ) allvalid++; } printf( "\n" ); if ( !allvalid ) test_fail( __FILE__, __LINE__, "all counter registered no counts", 1 ); retval = PAPI_cleanup_eventset( EventSet ); /* JT */ if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); retval = PAPI_destroy_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); free( values ); PAPI_shutdown( ); }
int main(int argc, char **argv) { int retval, num_tests = 6, tmp; long long **values; int EventSet=PAPI_NULL; const PAPI_hw_info_t *hw_info; #ifndef PENTIUM4 test_skip(__FILE__, __LINE__, "This test is intended only for Pentium 4.", 1); #endif tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); hw_info = PAPI_get_hardware_info(); if (hw_info == NULL) test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2); retval = PAPI_create_eventset(&EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); values = allocate_test_space(num_tests, 2); /* First test: just PAPI_LD_INS */ retval = PAPI_add_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[0]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval); /* Second test: just PAPI_SR_INS */ retval = PAPI_add_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[1]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval); /* Third test: just PAPI_LST_INS */ retval = PAPI_add_event(EventSet, PAPI_LST_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LST_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[2]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); /* Fourth test: PAPI_LST_INS and PAPI_LD_INS */ retval = PAPI_add_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[3]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval); /* Fifth test: PAPI_LST_INS and PAPI_SR_INS */ retval = PAPI_add_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[4]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval); retval = PAPI_remove_event(EventSet, PAPI_LST_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LST_INS", retval); /* Sixth test: PAPI_LD_INS and PAPI_SR_INS */ retval = PAPI_add_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval); retval = PAPI_add_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[5]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval); retval = PAPI_remove_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval); if (!TESTS_QUIET) { printf("Pentium 4 Load / Store tests.\n"); printf("These PAPI events are counted by setting a tag at the front of the pipeline,\n"); printf("and counting tags at the back of the pipeline. All the tags are the same 'color'\n"); printf("and can't be distinguished from each other. Therefore, PAPI_LD_INS and PAPI_SR_INS\n"); printf("cannot be counted with the other two events, or the answer will always == PAPI_LST_INS.\n"); printf("-------------------------------------------------------------------------------------------\n"); tmp = PAPI_get_opt(PAPI_DEFDOM, NULL); printf("Default domain is: %d (%s)\n", tmp, stringify_all_domains(tmp)); tmp = PAPI_get_opt(PAPI_DEFGRN, NULL); printf("Default granularity is: %d (%s)\n", tmp, stringify_granularity(tmp)); printf("Using %d iterations of c += a*b\n", NUM_FLOPS/10); printf("-------------------------------------------------------------------------------------------\n"); printf("Test: 1 2 3 4 5 6\n"); printf("%s %12lld %12s %12s %12lld %12s %12lld\n", "PAPI_LD_INS: ", (values[0])[0], "------", "------", (values[3])[1], "------", (values[5])[0]); printf("%s %12s %12lld %12s %12s %12lld %12lld\n", "PAPI_SR_INS: ", "------", (values[1])[0], "------", "------", (values[4])[1], (values[5])[1]); printf("%s %12s %12s %12lld %12lld %12lld %12s\n", "PAPI_LST_INS:", "------", "------", (values[2])[0], (values[3])[0], (values[4])[0], "------"); printf("-------------------------------------------------------------------------------------------\n"); printf("Test 1: PAPI_LD_INS only.\n"); printf("Test 2: PAPI_SR_INS only.\n"); printf("Test 3: PAPI_LST_INS only.\n"); printf("Test 4: PAPI_LD_INS and PAPI_LST_INS.\n"); printf("Test 5: PAPI_SR_INS and PAPI_LST_INS.\n"); printf("Test 6: PAPI_LD_INS and PAPI_SR_INS.\n"); printf("Verification: Values within each column should be the same.\n"); printf(" R3C3 ~= (R1C1 + R2C2) ~= all other entries.\n"); } test_pass(__FILE__, values, num_tests); exit(1); }
int main() { init(); std::cout << sizeof(D) << std::endl; #ifdef WITH_PAPI int EventSet = PAPI_NULL; int retval; char errstring[PAPI_MAX_STR_LEN]; long long values[NUM_EVENTS]; if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT ) { fprintf(stderr, "Error: %s\n", errstring); exit(1); } /* Creating event set */ if ((retval=PAPI_create_eventset(&EventSet)) != PAPI_OK) ERROR_RETURN(retval); /* Add the array of events PAPI_TOT_INS and PAPI_TOT_CYC to the eventset*/ if ((retval=PAPI_add_event(EventSet, PAPI_L1_DCM)) != PAPI_OK) ERROR_RETURN(retval); if ( PAPI_add_event( EventSet, PAPI_L2_DCM ) != PAPI_OK) printf("Error PAPI_add_event \n" ); /* Start counting */ if ( (retval=PAPI_start(EventSet)) != PAPI_OK) ERROR_RETURN(retval); #endif for(int i = 0; i <= n; i++) { for(int j = 0; j <= n; j++) { // Calculate D if(i > 0 && j > 0) { D[i][j] = D[i-1][j]; if(G[i-1][j] + GI < D[i][j]) { D[i][j] = G[i-1][j] + GI; } D[i][j] += GE; } if(i == 0 && j > 0) { D[i][j] = G[0][j] + GE; } // Calculate I if(i > 0 && j > 0) { I[i][j] = I[i][j-1]; if(G[i][j-1] + GI < I[i][j]) { I[i][j] = G[i][j-1] + GI; } I[i][j] += GE; } if(i > 0 && j == 0) { I[i][j] = G[i][0] + GE; } // Calculate G if(i > 0 && j > 0) { G[i][j] = G[i-1][j-1]+S(X[i-1],Y[j-1]); if(D[i][j] < G[i][j]) { G[i][j] = D[i][j]; } if(I[i][j] < G[i][j]) { G[i][j] = I[i][j]; } } } } #ifdef WITH_PAPI if ( (retval=PAPI_stop(EventSet,values)) != PAPI_OK) ERROR_RETURN(retval); std::cout << "L1 Misses: " << values[0] << " L2 Misses: " << values[1] << std::endl; /* double tot_access = 4 * n * n *n; double miss_ratio = values[0] / tot_access; printf("%d\t%f\n",n,miss_ratio); */ if ( (retval=PAPI_remove_event(EventSet,PAPI_L1_DCM))!=PAPI_OK) ERROR_RETURN(retval); if ( (retval=PAPI_remove_event(EventSet,PAPI_L2_DCM))!=PAPI_OK) ERROR_RETURN(retval); /* Free all memory and data structures, EventSet must be empty. */ if ( (retval=PAPI_destroy_eventset(&EventSet)) != PAPI_OK) ERROR_RETURN(retval); /* free the resources used by PAPI */ PAPI_shutdown(); #endif std::cout << G[n][n] << std::endl; reconstruct_path(); clean_up(); }