void my_papi_close(void) { #ifdef PAPI_MONITOR PAPI_shutdown(); fprintf(stderr,"PAPI library shutdown ... \n"); #endif /*PAPI_MONITOR */ }
int main( int argc, char **argv ) { int retval; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ if ( ( argc > 1 ) && ( strcmp( argv[1], "xxx" ) == 0 ) ) { retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "execed PAPI_library_init", retval ); } else { retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "main PAPI_library_init", retval ); PAPI_shutdown( ); if ( execlp( argv[0], argv[0], "xxx", NULL ) == -1 ) test_fail( __FILE__, __LINE__, "execlp", PAPI_ESYS ); } test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
static void test_fail(char *file, int line, char *call, int retval) { char buf[128]; memset(buf, '\0', sizeof(buf)); if (retval != 0) fprintf (stdout,"%-40s FAILED\nLine # %d\n", file, line); else { fprintf (stdout,"%-40s SKIPPED\n", file); fprintf (stdout,"Line # %d\n", line); } if (retval == PAPI_ESYS) { sprintf (buf, "System error in %s", call); perror (buf); } else if (retval > 0) fprintf (stdout,"Error: %s\n", call); else if (retval == 0) fprintf (stdout,"Error: %s\n", call); else { char errstring[PAPI_MAX_STR_LEN]; PAPI_perror (retval, errstring, PAPI_MAX_STR_LEN); fprintf (stdout,"Error in %s: %s\n", call, errstring); } fprintf (stdout,"\n"); if (PAPI_is_initialized ()) PAPI_shutdown (); exit (1); }
int main() { float real_time, proc_time,ipc; long long ins; float real_time_i, proc_time_i, ipc_i; long long ins_i; int retval; if((retval = PAPI_ipc(&real_time_i, &proc_time_i, &ins_i, &ipc_i)) < PAPI_OK) { printf("Could not initialise PAPI_ipc \n"); printf("retval: %d\n", retval); exit(1); } double ans = your_slow_code(); if((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK) { printf("retval: %d\n", retval); exit(1); } printf("Real_time: %f Proc_time: %f Total instructions: %lld IPC: %f\n", real_time, proc_time, ins, ipc); /* clean up */ PAPI_shutdown(); printf("Ans = %f\n", ans); exit(0); }
int main(int argc, char **argv) { extern void dummy(void *); float matrixa[INDEX][INDEX], matrixb[INDEX][INDEX], mresult[INDEX][INDEX]; float real_time, proc_time, mflops; long long flpins; int retval; int i,j,k; /* Initialize the Matrix arrays */ for ( i=0; i<INDEX*INDEX; i++ ) { mresult[0][i] = 0.0; matrixa[0][i] = matrixb[0][i] = rand()*(float)1.1; } /* Setup PAPI library and begin collecting data from the counters */ if((retval=PAPI_flops( &real_time, &proc_time, &flpins, &mflops))<PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_flops", retval); /* Matrix-Matrix multiply */ for (i=0; i<INDEX; i++) for(j=0; j<INDEX; j++) for(k=0; k<INDEX; k++) mresult[i][j]=mresult[i][j] + matrixa[i][k]*matrixb[k][j]; /* Collect the data into the variables passed in */ if((retval=PAPI_flops( &real_time, &proc_time, &flpins, &mflops))<PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_flops", retval); printf("Real_time:\t%f\nProc_time:\t%f\nTotal flpins:\t%lld\nMFLOPS:\t\t%f\n", real_time, proc_time, flpins, mflops); printf("%s\tPASSED\n", __FILE__); PAPI_shutdown(); exit(0); }
void free_energy_data(pwr_ctx_t *ctx) { if (ctx == NULL) { return; } if (!pwr_is_initialized(ctx, PWR_MODULE_ENERGY)) { ctx->error = PWR_UNINITIALIZED; return; } if (ctx->emeas_running) { pwr_stop_energy_count(ctx); } PAPI_cleanup_eventset(ctx->event_set); PAPI_destroy_eventset(&ctx->event_set); PAPI_shutdown(); for (unsigned int i = 0; i < ctx->emeas->nbValues; ++i) { free(ctx->emeas->units[i]); free(ctx->emeas->names[i]); } free(ctx->emeas->values); free(ctx->emeas->units); free(ctx->emeas->names); free(ctx->emeas); ctx->error = PWR_OK; }
/* Initialize htable with the metrics known by the system */ int init_known_metrics() { /* Initialize PAPI library */ int retval; retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { fprintf(stderr, "Error! PAPI_library_init %d\n",retval); PAPI_shutdown(); } /* Initialize custom metrics storage */ HASH_CLEAR(hh, callbacks_storage); for(int i = 0; i < available_metrics_no; ++i) { htable *new_pair = NULL; new_pair = malloc(sizeof(htable)); if (!new_pair) { fprintf(stderr, "can't alloc memory for the new pair\n"); exit(-1); } strcpy(new_pair->key, callbacks[i].alias); new_pair->value = callbacks[i].func; /* insert the new pair in callbacks_storage */ HASH_ADD_STR(callbacks_storage, key, new_pair); } return 0; }
void perf_lib_cleanup() { for (int i = 0; i < NUM_EVENTS; i++) free(PERF_EVENT_NAMES[i]); free(PERF_EVENT_NAMES); PAPI_shutdown(); }
/* This routine mimics the previous implementation of test_fail() by exiting on completion. It caused problems for threaded apps. If you are not threaded and want to exit, replace calls to test_fail() with calls to test_fail_exit(). */ void test_fail_exit( char *file, int line, char *call, int retval ) { test_fail( file, line, call, retval ); if ( PAPI_is_initialized( ) ) PAPI_shutdown( ); exit( 1 ); }
void destroy() { int ret; ret = PAPI_cleanup_eventset(eventSet); CHECK_PAPI_ERROR(ret, "PAPI_cleanup_eventset"); ret = PAPI_destroy_eventset(&eventSet); CHECK_PAPI_ERROR(ret, "PAPI_destroy_eventset"); PAPI_shutdown(); }
void vt_metric_close() { int i; for ( i = 0; i < nmetrics; i++ ) { free (metricv[i]->name); free(metricv[i]); } if ( nmetrics > 0 ) PAPI_shutdown(); }
int main(int argc, char **argv) { int retval; retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { fprintf(stderr,"Error! PAPI_library_init %d\n", retval); } retval = PAPI_query_event(PAPI_TOT_INS); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_TOT_INS not supported\n"); exit(1); } int i; int events[1],result; long long counts[1]; long long total=0,average,max=0,min=0x7ffffffffffffffULL; events[0]=PAPI_TOT_INS; PAPI_start_counters(events,1); for(i=0;i<NUM_RUNS;i++) { result=instructions_million(); PAPI_read_counters(counts,1); results[i]=counts[0]; } PAPI_stop_counters(counts,1); PAPI_shutdown(); for(i=0;i<NUM_RUNS;i++) { total+=results[i]; if (results[i]>max) max=results[i]; if (results[i]<min) min=results[i]; } average=total/NUM_RUNS; printf("Average=%lld max=%lld min=%lld\n",average,max,min); (void) result; return 0; }
void end_record_cache_access(RRecord & rr) { int retVal; retVal = PAPI_stop(g_event_set, endRecords); assert(retVal == PAPI_OK); retVal = PAPI_cleanup_eventset(g_event_set); assert(retVal == PAPI_OK); retVal = PAPI_destroy_eventset(&g_event_set); assert(retVal == PAPI_OK); PAPI_shutdown(); rr.put("L1-cache-misss", endRecords[0] - startRecords[0]); rr.put("L1-cache-access", endRecords[1] - startRecords[1]); }
void HWCBE_PAPI_CleanUp (unsigned nthreads) { UNREFERENCED_PARAMETER(nthreads); if (PAPI_is_initialized()) { int state; int i; unsigned t; if (PAPI_state (HWCEVTSET(THREADID), &state) == PAPI_OK) { if (state & PAPI_RUNNING) { long long tmp[MAX_HWC]; PAPI_stop (HWCEVTSET(THREADID), tmp); } } for (i = 0; i < HWC_num_sets; i++) { for (t = 0; t < nthreads; t++) { /* Remove all events in the eventset and destroy the eventset */ PAPI_cleanup_eventset(HWC_sets[i].eventsets[t]); PAPI_destroy_eventset(&HWC_sets[i].eventsets[t]); } xfree (HWC_sets[i].eventsets); } #if defined(PAPI_SAMPLING_SUPPORT) for (i = 0; i < HWC_num_sets; i++) { /* Free extra allocated memory */ if (HWC_sets[i].NumOverflows > 0) { xfree (HWC_sets[i].OverflowValue); xfree (HWC_sets[i].OverflowCounter); } } #endif xfree (HWC_sets); PAPI_shutdown(); } }
int main() { long long s,s1, e, e1; int retval; /**************************************************************************** * This part initializes the library and compares the version number of the * * header file, to the version of the library, if these don't match then it * * is likely that PAPI won't work correctly.If there is an error, retval * * keeps track of the version number. * ****************************************************************************/ if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT ) { printf("Library initialization error! \n"); exit(1); } /* Here you get initial cycles and time */ /* No error checking is done here because this function call is always successful */ s = PAPI_get_virt_cyc(); your_slow_code(); /*Here you get final cycles and time */ e = PAPI_get_virt_cyc(); s1= PAPI_get_virt_usec(); your_slow_code(); e1= PAPI_get_virt_usec(); printf("Virtual cycles : %lld\nVirtual time(ms): %lld\n",e-s,e1-s1); /* clean up */ PAPI_shutdown(); exit(0); }
void polybench_papi_close() { # ifdef _OPENMP #pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; if ((retval = PAPI_destroy_eventset (&polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_destroy_eventset", retval); if (PAPI_is_initialized ()) PAPI_shutdown (); # ifdef _OPENMP } } #pragma omp barrier # endif }
int main(int argc, char **argv) { int events[1]; long long counts[1]; int retval,quiet; char test_string[]="Testing PAPI_SYC_INS predefined event..."; quiet=test_quiet(); retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { if (!quiet) printf("Error! PAPI_library_init %d\n",retval); test_fail(test_string); } retval = PAPI_query_event(PAPI_SYC_INS); if (retval != PAPI_OK) { if (!quiet) printf("PAPI_SYC_INS not available\n"); test_skip(test_string); } events[0]=PAPI_SYC_INS; PAPI_start_counters(events,1); PAPI_stop_counters(counts,1); if (counts[0]<1) { if (!quiet) printf("Error! Count too low\n"); test_fail(test_string); } PAPI_shutdown(); test_unimplemented(test_string); return 0; }
void test_pass( char *file, long long **values, int num_tests ) { int line_pad; line_pad=(int)(50-strlen(file)); if (line_pad<0) line_pad=0; if ( TEST_WARN ) { if (TESTS_COLOR) { fprintf( stdout, "%-*s %sPASSED with WARNING%s\n", line_pad, file, YELLOW, NORMAL); } else { fprintf( stdout, "%-*s PASSED with WARNING\n", line_pad, file ); } } else { if (TESTS_COLOR) { fprintf( stdout, "%-*s %sPASSED%s\n", line_pad, file, GREEN, NORMAL ); } else { fprintf( stdout, "%-*s PASSED\n", line_pad, file ); } } if ( values ) free_test_space( values, num_tests ); if ( PAPI_is_initialized( ) ) PAPI_shutdown( ); exit( 0 ); }
int main(int argc, char *argv[]) { std::string s = "/home/sherry/FF_VS/SSCA2v2.2/dumpbc.data"; //std::string s = "/Users/xuepengfan/git/SSCA2v2.2/dumpbc.data"; graph g = read_data(s); std::cout<<"G.n : "<<g.n<<std::endl; std::cout<<"G.m : "<<g.m<<std::endl; std::cout<<"k4approx: "<<g.k4approx<<std::endl; #ifdef CACHE_EVAL /*Add papi to trace cache miss*/ int EventSet,retVal; long long startRecords[2], endRecords[2]; retVal = PAPI_library_init(PAPI_VER_CURRENT); assert(retVal == PAPI_VER_CURRENT); EventSet = PAPI_NULL; retVal = PAPI_create_eventset(&EventSet); assert(retVal == PAPI_OK); //L2 TCM & TCA retVal = PAPI_add_event(EventSet, PAPI_L2_TCM); assert(retVal == PAPI_OK); retVal = PAPI_add_event(EventSet, PAPI_L2_TCA); assert(retVal == PAPI_OK); retVal = PAPI_start(EventSet); assert(retVal == PAPI_OK); retVal = PAPI_read(EventSet, startRecords); assert(retVal == PAPI_OK); /*Add papi to trace cache miss*/ #endif auto bc = ff_get_bc(g); //auto bc = seq_get_bc(g); //bc = ff_get_bc(g); #ifdef CACHE_EVAL /*Stop papi trace*/ retVal = PAPI_stop(EventSet, endRecords); assert(retVal == PAPI_OK); retVal = PAPI_cleanup_eventset(EventSet); assert(retVal == PAPI_OK); retVal = PAPI_destroy_eventset(&EventSet); assert(retVal == PAPI_OK); PAPI_shutdown(); //L2 result std::cout << "L2 total cache miss = " << endRecords[0] - startRecords[0] << std::endl; std::cout << "L2 total cache access = " << endRecords[1] - startRecords[1] << std::endl; /*Stop papi trace*/ #endif //auto bc = boost::shared_ptr<DOUBLE_T[]>(new DOUBLE_T[g.n]); //betweennessCentrality(&g, bc.get()); double sum1 = 0; double sum_origin = 0; for(int i = 0; i < g.n; i++) { sum1 += bc[i]; sum_origin += g.BC[i]; } std::cout<<"BC FF: "<<sum1<<std::endl; std::cout<<"BC Origin: "<<sum_origin<<std::endl; return 0; }
int main(int argc, char **argv) { int retval; int i; int EventSet=PAPI_NULL; int event; long long *counts; struct timespec before,after; struct timespec start_before; struct timespec stop_after; long long init_ns=0,eventset_ns=0; long long ns=0; int count; char *machine_name; if (argc>2) { count=atoi(argv[2]); machine_name=strdup(argv[1]); } else { count=1; machine_name=strdup("core2"); } counts=calloc(count,sizeof(long long)); if (!strncmp(machine_name,"core2",5)) { memcpy(event_names,core2_events,16*64); } else if (!strncmp(machine_name,"nehalem",7)) { memcpy(event_names,nehalem_events,16*64); } else if (!strncmp(machine_name,"atom",4)) { memcpy(event_names,atom_events,16*64); } else if (!strncmp(machine_name,"amd0fh",6)) { memcpy(event_names,amd0fh_events,16*64); } else if (!strncmp(machine_name,"amd10h",6)) { memcpy(event_names,amd10h_events,16*64); } else if (!strncmp(machine_name,"power6",6)) { memcpy(event_names,power6_events,16*64); } else if (!strncmp(machine_name,"cortexA9",8)) { memcpy(event_names,cortexA9_events,16*64); } else { fprintf(stderr,"Unknown machine name %s\n",machine_name); exit(0); } /* measure init latency */ clock_gettime(CLOCK_REALTIME,&before); retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { fprintf(stderr,"ERROR: PAPI_library_init %d\n", retval); } clock_gettime(CLOCK_REALTIME,&after); init_ns=convert_to_ns(&before,&after); printf("PAPI_library_init_latency: %lld ns\n",init_ns); /* measure eventset creation */ clock_gettime(CLOCK_REALTIME,&before); retval = PAPI_create_eventset(&EventSet); if (retval!=PAPI_OK) { fprintf(stderr,"PAPI_create_eventset failed\n"); } for(i=0;i<count;i++) { retval=PAPI_event_name_to_code(event_names[i],&event); if (retval!=PAPI_OK) { fprintf(stderr,"PAPI_event_name_to_code failed %s\n",event_names[i]); } retval=PAPI_add_event(EventSet,event); if (retval!=PAPI_OK) { //fprintf(stderr,"PAPI_add_event failed %x\n",event); count=i; printf("Eventset_creation_%d: %lld ns\n",i,0LL); printf("PAPI_start/stop/read latency: %lld ns\n",0LL); exit(1); } } clock_gettime(CLOCK_REALTIME,&after); eventset_ns=convert_to_ns(&before,&after); printf("Eventset_creation_%d: %lld ns\n",i,eventset_ns); clock_gettime(CLOCK_REALTIME,&start_before); PAPI_start(EventSet); PAPI_stop(EventSet,counts); clock_gettime(CLOCK_REALTIME,&stop_after); ns=convert_to_ns(&start_before,&stop_after); printf("PAPI_start/stop/read latency: %lld ns\n",ns); for(i=0;i<count;i++) { printf("%s %lld\n",event_names[i],counts[i]); } PAPI_shutdown(); return 0; }
int main(int argc, char **argv) { int retval,max_multiplex,i,EventSet=PAPI_NULL; PAPI_event_info_t info; int added=0; int events_tried=0; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Initialize the library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } retval = PAPI_multiplex_init( ); if ( retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "Multiplex not supported", 1); } max_multiplex=PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ); if (!TESTS_QUIET) { printf("Maximum multiplexed counters=%d\n",max_multiplex); } if (!TESTS_QUIET) { printf("Trying to multiplex as many as possible:\n"); } retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval ); } 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_OK ) { test_fail(__FILE__, __LINE__, "PAPI_create_multiplex", retval ); } i = 0 | PAPI_PRESET_MASK; PAPI_enum_event( &i, PAPI_ENUM_FIRST ); do { retval = PAPI_get_event_info( i, &info ); if (retval==PAPI_OK) { if (!TESTS_QUIET) printf("Adding %s: ",info.symbol); } retval = PAPI_add_event( EventSet, info.event_code ); if (retval!=PAPI_OK) { if (!TESTS_QUIET) printf("Fail!\n"); } else { if (!TESTS_QUIET) printf("Success!\n"); added++; } events_tried++; } while (PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ); PAPI_shutdown( ); if (!TESTS_QUIET) { printf("Added %d of theoretical max %d\n",added,max_multiplex); } if (events_tried<max_multiplex) { if (!TESTS_QUIET) { printf("Ran out of events before we ran out of room\n"); } } else if (added!=max_multiplex) { test_fail(__FILE__, __LINE__, "Couldn't max out multiplexed events", 1); } test_pass( __FILE__, NULL, 0 ); exit( 0 ); }
void mainloop( int arg ) { int retval, num_tests = 1; int EventSet1 = PAPI_NULL; int mask1 = 0x0; int num_events1; long long **values; int PAPI_event; char event_name[PAPI_MAX_STR_LEN]; ( void ) arg; if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, depending on the availability of the event on the platform */ EventSet1 = add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 ); values = allocate_test_space( num_tests, num_events1 ); if ( ( retval = PAPI_overflow( EventSet1, PAPI_event, THRESHOLD, 0, handler ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); do_stuff( ); if ( ( retval = PAPI_start( EventSet1 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_stuff( ); if ( ( retval = PAPI_stop( EventSet1, values[0] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); /* clear the papi_overflow event */ if ( ( retval = PAPI_overflow( EventSet1, PAPI_event, 0, 0, NULL ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); if ( ( retval = PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); if ( !TESTS_QUIET ) { printf( "Thread %#x %s : \t%lld\n", ( int ) pthread_self( ), event_name, ( values[0] )[0] ); printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", ( int ) pthread_self( ), ( values[0] )[1] ); } retval = PAPI_cleanup_eventset( EventSet1 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); retval = PAPI_destroy_eventset( &EventSet1 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); free_test_space( values, num_tests ); PAPI_shutdown( ); }
int main(){ int retval,i; int EventSet=PAPI_NULL; int event_code=PAPI_TOT_INS; /* By default monitor total instructions */ char errstring[PAPI_MAX_STR_LEN]; char event_name[PAPI_MAX_STR_LEN]; float a[1000],b[1000],c[1000]; long long values; /* This initializes the library and checks the version number of the * header file, to the version of the library, if these don't match * then it is likely that PAPI won't work correctly. */ if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT ){ /* This call loads up what the error means into errstring * if retval == PAPI_ESYS then it might be beneficial * to call perror as well to see what system call failed */ PAPI_perror("PAPI_library_init"); exit(-1); } /* Create space for the EventSet */ if ( (retval=PAPI_create_eventset( &EventSet ))!=PAPI_OK){ PAPI_perror(retval, errstring, PAPI_MAX_STR_LEN); exit(-1); } /* After this call if the environment variable PAPI_EVENT is set, * event_code may contain something different than total instructions. */ if ( (retval=PAPI_add_env_event(&EventSet, &event_code, "PAPI_EVENT"))!=PAPI_OK){ PAPI_perror("PAPI_add_env_event"); exit(-1); } /* Now lets start counting */ if ( (retval = PAPI_start(EventSet)) != PAPI_OK ){ PAPI_perror("PAPI_start"); exit(-1); } /* Some work to take up some time, the PAPI_start/PAPI_stop (and/or * PAPI_read) should surround what you want to monitor. */ for ( i=0;i<1000;i++){ a[i] = b[i]-c[i]; c[i] = a[i]*1.2; } if ( (retval = PAPI_stop(EventSet, &values) ) != PAPI_OK ){ PAPI_perror("PAPI_stop"); exit(-1); } if ( (retval=PAPI_event_code_to_name( event_code, event_name))!=PAPI_OK){ PAPI_perror("PAPI_event_code_to_name"); exit(-1); } printf("Ending values for %s: %lld\n", event_name,values); /* Remove PAPI instrumentation, this is necessary on platforms * that need to release shared memory segments and is always * good practice. */ PAPI_shutdown(); exit(0); }
int main(int argc, char **argv) { int events[1],i; long long counts[1]; int retval,quiet; int l1_size,l2_size,l1_linesize,l2_entries; int arraysize; char test_string[]="Testing PAPI_L2_DCM predefined event..."; quiet=test_quiet(); retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { if (!quiet) printf("Error! PAPI_library_init %d\n",retval); test_fail(test_string); } retval = PAPI_query_event(PAPI_L2_DCM); if (retval != PAPI_OK) { if (!quiet) printf("PAPI_L2_DCM not available\n"); test_skip(test_string); } events[0]=PAPI_L2_DCM; l1_size=get_cachesize(L1D_CACHE,quiet,test_string); l1_linesize=get_linesize(L1D_CACHE,quiet,test_string); l2_size=get_cachesize(L2_CACHE,quiet,test_string); l2_entries=get_entries(L2_CACHE,quiet,test_string); /*******************************************************************/ /* Test if the C compiler uses a sane number of data cache acceess */ /*******************************************************************/ arraysize=l2_size/sizeof(double); double *array; double aSumm = 0.0; if (!quiet) { printf("Allocating %ld bytes of memory (%d doubles)\n", arraysize*sizeof(double),arraysize); } array=calloc(arraysize,sizeof(double)); if (array==NULL) { if (!quiet) printf("Error! Can't allocate memory\n"); test_fail(test_string); } if (!quiet) printf("Write test:\n"); PAPI_start_counters(events,1); for(i=0; i<arraysize; i++) { array[i]=(double)i; } PAPI_stop_counters(counts,1); if (!quiet) { printf("\tL2 D misses: %lld\n",counts[0]); printf("\tShould be roughly (%d/(%d/%ld)): %ld\n", arraysize,l1_linesize,sizeof(double), arraysize/(l1_linesize/sizeof(double))); } PAPI_start_counters(events,1); for(i=0; i<arraysize; i++) { aSumm += array[i]; } PAPI_stop_counters(counts,1); if (!quiet) { printf("Read test (%lf):\n",aSumm); printf("\tL2 D misses: %lld\n",counts[0]); printf("\tShould be roughly (%d/(%d/%ld)): %ld\n", arraysize,l1_linesize,sizeof(double), arraysize/(l1_linesize/sizeof(double))); } PAPI_shutdown(); test_pass(test_string); return 0; }
int main(int argc, char **argv) { int retval,quiet,result; int num_runs=100; long long high=0,low=0,average=0,expected=1000000; double error; int num_random_branches=500000; int i; int events[1]; long long counts[1],total=0; char test_string[]="Testing PAPI_BR_PRC predefined event..."; quiet=test_quiet(); retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { if (!quiet) printf("Error: PAPI_library_init %d\n", retval); test_fail(test_string); } retval = PAPI_query_event(PAPI_BR_PRC); if (retval != PAPI_OK) { if (!quiet) printf("PAPI_BR_PRC not supported %d\n", retval); test_skip(test_string); } if (!quiet) { printf("\n"); printf("Testing a simple loop with %lld branches (%d times):\n", expected,num_runs); printf("Nearly all the branches should be predicted correctly.\n"); } events[0]=PAPI_BR_PRC; high=0; low=0; for(i=0;i<num_runs;i++) { PAPI_start_counters(events,1); result=branches_testcode(); PAPI_stop_counters(counts,1); if (result==CODE_UNIMPLEMENTED) { if (!quiet) printf("\tNo test code for this architecture\n"); test_skip(test_string); } if (counts[0]>high) high=counts[0]; if ((low==0) || (counts[0]<low)) low=counts[0]; total+=counts[0]; } average=total/num_runs; error=display_error(average,high,low,expected,quiet); if ((error > 1.0) || (error<-1.0)) { if (!quiet) printf("Instruction count off by more than 1%%\n"); test_fail(test_string); } if (!quiet) printf("\n"); /*******************/ high=0; low=0; total=0; events[0]=PAPI_BR_CN; for(i=0;i<num_runs;i++) { PAPI_start_counters(events,1); result=random_branches_testcode(num_random_branches,1); PAPI_stop_counters(counts,1); if (counts[0]>high) high=counts[0]; if ((low==0) || (counts[0]<low)) low=counts[0]; total+=counts[0]; } average=total/num_runs; expected=average; if (!quiet) { printf("\nTesting a function that branches based on a random number\n"); printf(" The loop has %lld conditional branches.\n",expected); printf(" %d are random branches; %d of those were taken\n",num_random_branches,result); } high=0; low=0; total=0; events[0]=PAPI_BR_PRC; for(i=0;i<num_runs;i++) { PAPI_start_counters(events,1); result=random_branches_testcode(num_random_branches,1); PAPI_stop_counters(counts,1); if (counts[0]>high) high=counts[0]; if ((low==0) || (counts[0]<low)) low=counts[0]; total+=counts[0]; } average=total/num_runs; if (!quiet) { printf("\nOut of %lld branches, %lld predicted correctly\n",expected,average); printf("Assuming a good random number generator and no freaky luck\n"); printf("The TOTAL - CORRECT value is %lld\n",expected-average); printf("This value should be roughly between %d and %d\n", num_random_branches/4,(num_random_branches/4)*3); } if ( (expected-average) < (num_random_branches/4)) { if (!quiet) printf("Correct predicts too low\n"); test_fail(test_string); } if ( (expected-average) > (num_random_branches/4)*3) { if (!quiet) printf("Correct predicts too high\n"); test_fail(test_string); } if (!quiet) printf("\n"); PAPI_shutdown(); test_pass(test_string); return 0; }
int main() { unsigned long length; caddr_t start, end; PAPI_sprofil_t * prof; int EventSet = PAPI_NULL; /*must be initialized to PAPI_NULL before calling PAPI_create_event*/ int PAPI_event,i,tmp = 0; char event_name[PAPI_MAX_STR_LEN]; /*These are going to be used as buffers */ unsigned short *profbuf; long long values[2]; const PAPI_exe_info_t *prginfo = NULL; int retval; /**************************************************************************** * This part initializes the library and compares the version number of the * * header file, to the version of the library, if these don't match then it * * is likely that PAPI won't work correctly.If there is an error, retval * * keeps track of the version number. * ****************************************************************************/ if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT ) { printf("Library initialization error! \n"); exit(1); } if ((prginfo = PAPI_get_executable_info()) == NULL) { fprintf(stderr, "Error in get executable information \n"); exit(1); } start = prginfo->address_info.text_start; end = prginfo->address_info.text_end; length = (end - start); /* for PAPI_PROFIL_BUCKET_16 and scale = 65536, profile buffer length == program address length. Larger bucket sizes would increase the buffer length. Smaller scale factors would decrease it. Handle with care... */ profbuf = (unsigned short *)malloc(length); if (profbuf == NULL) { fprintf(stderr, "Not enough memory \n"); exit(1); } memset(profbuf,0x00,length); /* Creating the eventset */ if ( (retval = PAPI_create_eventset(&EventSet)) != PAPI_OK) ERROR_RETURN(retval); PAPI_event = PAPI_TOT_INS; /* Add Total Instructions Executed to our EventSet */ if ( (retval = PAPI_add_event(EventSet, PAPI_event)) != PAPI_OK) ERROR_RETURN(retval); /* Add Total Cycles Executed to our EventSet */ if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_CYC)) != PAPI_OK) ERROR_RETURN(retval); /* enable the collection of profiling information */ if ((retval = PAPI_profil(profbuf, length, start, 65536, EventSet, PAPI_event, THRESHOLD, PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16)) != PAPI_OK) ERROR_RETURN(retval); /* let's rock and roll */ if ((retval=PAPI_start(EventSet)) != PAPI_OK) ERROR_RETURN(retval); code_to_monitor(); if ((retval=PAPI_stop(EventSet, values)) != PAPI_OK) ERROR_RETURN(retval); /* disable the collection of profiling information by setting threshold to 0 */ if ((retval = PAPI_profil(profbuf, length, start, 65536, EventSet, PAPI_event, 0, PAPI_PROFIL_POSIX)) != PAPI_OK) ERROR_RETURN(retval); printf("-----------------------------------------------------------\n"); printf("Text start: %p, Text end: %p, \n", prginfo->address_info.text_start,prginfo->address_info.text_end); printf("Data start: %p, Data end: %p\n", prginfo->address_info.data_start,prginfo->address_info.data_end); printf("BSS start : %p, BSS end: %p\n", prginfo->address_info.bss_start,prginfo->address_info.bss_end); printf("------------------------------------------\n"); printf("Test type : \tPAPI_PROFIL_POSIX\n"); printf("------------------------------------------\n\n\n"); printf("PAPI_profil() hash table.\n"); printf("address\t\tflat \n"); for (i = 0; i < (int) length/2; i++) { if (profbuf[i]) printf("0x%lx\t%d \n", (unsigned long) start + (unsigned long) (2 * i), profbuf[i]); } printf("-----------------------------------------\n"); retval = 0; for (i = 0; i < (int) length/2; i++) retval = retval || (profbuf[i]); if (retval) printf("Test succeeds! \n"); else printf( "No information in buffers\n"); /* clean up */ PAPI_shutdown(); exit(0); }
int main( int argc, char **argv ) { int num_tests=1; int num_events=1; int retval; int cpu_num = 1; int EventSet1 = PAPI_NULL; long long **values; char event_name[PAPI_MAX_STR_LEN] = "PAPI_TOT_CYC"; PAPI_option_t opts; // user can provide cpu number on which to count events as arg 1 if (argc > 1) { retval = atoi(argv[1]); if (retval >= 0) { cpu_num = retval; } } retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval ); retval = PAPI_create_eventset(&EventSet1); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval ); // Force event set to be associated with component 0 (perf_events component provides all core events) retval = PAPI_assign_eventset_component( EventSet1, 0 ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); // Attach this event set to cpu 1 opts.cpu.eventset = EventSet1; opts.cpu.cpu_num = cpu_num; retval = PAPI_set_opt( PAPI_CPU_ATTACH, &opts ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_set_opt", retval ); retval = PAPI_add_named_event(EventSet1, event_name); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_add_named_event", retval ); // get space for counter values (this needs to do this call because it malloc's space that test_pass and friends free) values = allocate_test_space( num_tests, num_events); retval = PAPI_start( EventSet1 ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); // do some work do_flops(NUM_FLOPS); retval = PAPI_stop( EventSet1, values[0] ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); printf ("Event: %s: %8lld on Cpu: %d\n", event_name, values[0][0], cpu_num); PAPI_shutdown( ); test_pass( __FILE__, values, 1 ); return PAPI_OK; }
int main(int nargs, char** args) { real T=5.0, h=0.005, h_alpha; int j, k, N,i; real *a, *b, *y, c_j; real sum_a, sum_b, yp_jp1; clock_t start, finish; if (nargs>1) h = atof(args[1]); if (nargs>1) T = atof(args[2]); N = (int)(T/h+0.5); printf("Serial LoopFusion version---------------\n"); printf("T=%g, h=%g, N=%d\n", T,h,N); a = (real*)malloc((N+1)*sizeof(real)); b = (real*)malloc((N+1)*sizeof(real)); y = (real*)malloc((N+1)*sizeof(real)); h_alpha = pow(h,alpha); start = clock(); for (j=N; j>=0; j--) { b[j] = (pow(j+1,alpha)-pow(j,alpha))/gamma1; a[j] = (pow(j+2,alpha+1)-2.*pow(j+1,alpha+1)+pow(j,alpha+1))/gamma2; } y[0] = y0; int Events[] = {PAPI_L1_TCA,PAPI_L2_TCA,}; int NUM_EVENTS = sizeof(Events)/sizeof(Events[0]); long long res_papi[NUM_EVENTS]; char EventName[128]; int num_hwcntrs = 0; int EventSet = PAPI_NULL; int retval; retval = PAPI_library_init( PAPI_VER_CURRENT ); retval = PAPI_create_eventset( &EventSet ); if (PAPI_add_events( EventSet, Events, NUM_EVENTS) != PAPI_OK){ printf("PAPI_add_events failed\n"); } for (i=0; i<NUM_EVENTS; i++){ res_papi[i] = 0; } if ( PAPI_start( EventSet ) != PAPI_OK){ printf("PAPI_read_counters failed\n"); } for (j=0; j<N; j++) { sum_b = b[j]*f(y[0]); c_j = (pow(j,alpha+1)-(j-alpha)*pow(j+1,alpha))/gamma2; sum_a = c_j*f(y[0]); for (k=1; k<=j; k++) { sum_b += b[j-k]*f(y[k]); sum_a += a[j-k]*f(y[k]); } yp_jp1 = prefix + h_alpha*sum_b; y[j+1] = prefix + h_alpha*(sum_a + f(yp_jp1)/gamma2); } if ( PAPI_stop( EventSet, res_papi ) != PAPI_OK){ printf("PAPI_accum_counters failed\n"); } for (i = 0; i<NUM_EVENTS; i++){ PAPI_event_code_to_name(Events[i], EventName); printf("PAPI Event name: %s, value: %lld\n", EventName, res_papi[i]); } finish=clock(); printf("y[%d]=%e",N,y[N]); printf(" timeusage=%g",(finish-start)/1e6); printf(" GFLOPs=%g\n",2.0*N*(N+1)/(finish-start)/1000.0); free(a); free(b); free(y); PAPI_shutdown (); return 0; }
int main () { int EventSet = PAPI_NULL; /* must be set to null before calling PAPI_create_eventset */ char errstring[PAPI_MAX_STR_LEN]; long long (values[2])[2]; int retval, i; double tmp = 0; int PAPI_event; /* a place holder for an event preset */ char event_name[PAPI_MAX_STR_LEN]; /**************************************************************************** * This part initializes the library and compares the version number of the * * header file, to the version of the library, if these don't match then it * * is likely that PAPI won't work correctly.If there is an error, retval * * keeps track of the version number. * ****************************************************************************/ if ((retval = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) { printf("Library initialization error! \n"); exit(1); } /* Here we create the eventset */ if ((retval=PAPI_create_eventset (&EventSet)) != PAPI_OK) ERROR_RETURN(retval); PAPI_event = PAPI_TOT_INS; /* Here we are querying for the existence of the PAPI presets */ if (PAPI_query_event (PAPI_TOT_INS) != PAPI_OK) { PAPI_event = PAPI_TOT_CYC; if ((retval=PAPI_query_event (PAPI_TOT_INS)) != PAPI_OK) ERROR_RETURN(retval); printf ("PAPI_TOT_INS not available on this platform."); printf (" so subst PAPI_event with PAPI_TOT_CYC !\n\n"); } /* PAPI_event_code_to_name is used to convert a PAPI preset from its integer value to its string name. */ if ((retval = PAPI_event_code_to_name (PAPI_event, event_name)) != PAPI_OK) ERROR_RETURN(retval); /* add event to the event set */ if ((retval = PAPI_add_event (EventSet, PAPI_event)) != PAPI_OK) ERROR_RETURN(retval); /* register overflow and set up threshold */ /* The threshold "THRESHOLD" was set to 100000 */ if ((retval = PAPI_overflow (EventSet, PAPI_event, THRESHOLD, 0, handler)) != PAPI_OK) ERROR_RETURN(retval); printf ("Here are the addresses at which overflows occured and overflow vectors \n"); printf ("--------------------------------------------------------------\n"); /* Start counting */ if ( (retval=PAPI_start (EventSet)) != PAPI_OK) ERROR_RETURN(retval); for (i = 0; i < 2000000; i++) { tmp = 1.01 + tmp; tmp++; } /* Stops the counters and reads the counter values into the values array */ if ( (retval=PAPI_stop (EventSet, values[0])) != PAPI_OK) ERROR_RETURN(retval); printf ("The total no of overflows was %d\n", total); /* clear the overflow status */ if ((retval = PAPI_overflow (EventSet, PAPI_event, 0, 0, handler)) != PAPI_OK) ERROR_RETURN(retval); /************************************************************************ * PAPI_cleanup_eventset can only be used after the counter has been * * stopped then it remove all events in the eventset * ************************************************************************/ if ( (retval=PAPI_cleanup_eventset (EventSet)) != 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(); exit(0); }
int main( int argc, char **argv ) { int retval,i,j; int EventSet[EVENTS_TO_TRY][MAX_PACKAGES]; long long values[EVENTS_TO_TRY][MAX_PACKAGES]; char event_name[BUFSIZ]; char uncore_base[BUFSIZ]; char uncore_event[BUFSIZ]; int uncore_cidx=-1; int max_cbox=0; int core_to_use=0; const PAPI_hw_info_t *hwinfo; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Init the PAPI library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } /* Find the uncore PMU */ uncore_cidx=PAPI_get_component_index("perf_event_uncore"); if (uncore_cidx<0) { test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0); } /* Get hardware info */ hwinfo = PAPI_get_hardware_info(); if ( hwinfo == NULL ) { test_fail(__FILE__,__LINE__,"PAPI_get_hardware_info()",retval); } /* Get event to use */ if (hwinfo->vendor == PAPI_VENDOR_INTEL) { if ( hwinfo->cpuid_family == 6) { switch(hwinfo->cpuid_model) { case 45: /* SandyBridge EP */ strncpy(event_name,"UNC_C_TOR_OCCUPANCY:ALL",BUFSIZ); strncpy(uncore_base,"snbep_unc_cbo",BUFSIZ); break; case 58: /* IvyBridge */ strncpy(event_name,"UNC_CBO_CACHE_LOOKUP:STATE_I:ANY_FILTER",BUFSIZ); strncpy(uncore_base,"ivb_unc_cbo",BUFSIZ); break; default: test_skip( __FILE__, __LINE__, "We only support IVB and SNB-EP for now", PAPI_ENOSUPP ); } } else { test_skip( __FILE__, __LINE__, "We only support IVB and SNB-EP for now", PAPI_ENOSUPP ); } } else { test_skip( __FILE__, __LINE__, "This test only supported Intel chips", PAPI_ENOSUPP ); } if (!TESTS_QUIET) { printf("Trying for %d sockets\n",hwinfo->sockets); printf("threads %d cores %d ncpus %d\n", hwinfo->threads,hwinfo->cores, hwinfo->ncpu); } for(i=0;i < hwinfo->sockets; i++) { /* perf_event provides which to use in "cpumask" */ /* but libpfm4 doesn't report this back to us (yet) */ core_to_use=i*hwinfo->threads*hwinfo->cores; if (!TESTS_QUIET) { printf("Using core %d for socket %d\n",core_to_use,i); } for(j=0;j<EVENTS_TO_TRY;j++) { /* Create an eventset */ EventSet[j][i]=PAPI_NULL; retval = PAPI_create_eventset(&EventSet[j][i]); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); } /* Set a component for the EventSet */ retval = PAPI_assign_eventset_component(EventSet[j][i], uncore_cidx); if (retval!=PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component",retval); } /* we need to set to a certain cpu for uncore to work */ PAPI_cpu_option_t cpu_opt; cpu_opt.eventset=EventSet[j][i]; cpu_opt.cpu_num=core_to_use; retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt); if (retval != PAPI_OK) { test_skip( __FILE__, __LINE__, "this test; trying to PAPI_CPU_ATTACH; need to run as root", retval); } /* Default Granularity should work */ /* Default domain should work */ /* Add our uncore event */ sprintf(uncore_event,"%s%d::%s",uncore_base,j,event_name); retval = PAPI_add_named_event(EventSet[j][i], uncore_event); if (retval != PAPI_OK) { max_cbox=j; break; } if (!TESTS_QUIET) printf("Added %s for socket %d\n",uncore_event,i); } } for(i=0;i < hwinfo->sockets; i++) { for(j=0;j<max_cbox;j++) { if (!TESTS_QUIET) printf("Starting EventSet %d\n",EventSet[j][i]); /* Start PAPI */ retval = PAPI_start( EventSet[j][i] ); if ( retval != PAPI_OK ) { printf("Error starting socket %d cbox %d\n",i,j); test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } } } /* our work code */ do_flops( NUM_FLOPS ); /* Stop PAPI */ for(i=0;i < hwinfo->sockets; i++) { for(j=0;j<max_cbox;j++) { retval = PAPI_stop( EventSet[j][i],&values[j][i] ); if ( retval != PAPI_OK ) { printf("Error stopping socket %d cbox %d\n",i,j); test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } } } /* Print Results */ if ( !TESTS_QUIET ) { for(i=0;i < hwinfo->sockets; i++) { printf("Socket %d\n",i); for(j=0;j<max_cbox;j++) { printf("\t%s%d::%s %lld\n",uncore_base,j,event_name,values[j][i]); } } } PAPI_shutdown(); test_pass( __FILE__, NULL, 0 ); return 0; }