void papi_init( int argc, char **argv ) { const PAPI_hw_info_t *hwinfo = NULL; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ /*for(i=0;i<argc;i++) */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); retval = PAPI_set_debug( PAPI_VERB_ECONT ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval ); retval = papi_print_header ( "Event Chooser: Available events which can be added with given events.\n", 0, &hwinfo ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { fprintf( stderr, "PAPI_create_eventset error\n" ); exit( 1 ); } }
void initTimers() { #if USING_PERFCTR == 0 int retval; fprintf(stderr, "1\n"); if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) { printf("PAPI Library initialization error! \n"); exit(1); } fprintf(stderr, "2\n"); if ((retval = PAPI_set_debug(PAPI_VERB_ESTOP)) != PAPI_OK) { printf("PAPI set debug error! \n"); exit(1); } fprintf(stderr, "3\n"); if (PAPI_thread_init(pthread_self) != PAPI_OK) { printf("PAPI thread Library initialisation error! \n"); exit(1); } fprintf(stderr, "4\n"); PAPI_thread_init(gettid); PAPI_register_thread(); #else PERFCTR_initialize(); PERFCTR_register_thread(); #endif gettimeofday(&program_start, NULL); }
int main(int argc, char **argv) { pthread_t master; pthread_t slave1; int result_m, result_s, rc, i; int retval; /* Setup a random number so compilers can't optimize it out */ count = rand(); result_m = count; rank = 0; for (i = 0; i < LOOPS; i++) { result_m = 2 * result_m - i; } result_s = result_m; for (i = 0; i < LOOPS; i++) { result_s += i; } if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) { printf("Library initialization error! \n"); exit(-1); } if ((retval = PAPI_set_debug(PAPI_VERB_ECONT)) != PAPI_OK) ERROR_RETURN(retval); PAPI_lock(PAPI_USR2_LOCK); rc = pthread_create(&master, NULL, Master, NULL); if (rc) { retval = PAPI_ESYS; ERROR_RETURN(retval); } rc = pthread_create(&slave1, NULL, Slave, NULL); if (rc) { retval = PAPI_ESYS; ERROR_RETURN(retval); } pthread_join(master, NULL); printf("Master: Expected: %d Recieved: %d\n", result_m, count); if (result_m != count) ERROR_RETURN(1); PAPI_unlock(PAPI_USR2_LOCK); pthread_join(slave1, NULL); printf("Slave: Expected: %d Recieved: %d\n", result_s, count); if (result_s != count) ERROR_RETURN(1); exit(0); }
int main(int argc, char **argv) { int i,j; int retval; int print_avail_only = 0; PAPI_event_info_t info; const PAPI_hw_info_t *hwinfo = NULL; tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ for (i = 0; i < argc; i++) if (argv[i]) { if (strstr(argv[i], "-a")) print_avail_only = PAPI_PRESET_ENUM_AVAIL; if (strstr(argv[i], "-h")) { print_help(); exit(1); } } retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); if (!TESTS_QUIET) { retval = PAPI_set_debug(PAPI_VERB_ECONT); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_set_debug", retval); } if ((hwinfo = PAPI_get_hardware_info()) == NULL) test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2); i = PAPI_PRESET_MASK; printf("name,derived,postfix,short_descr,long_descr,note,[native,...]\n\n"); do { if (PAPI_get_event_info(i, &info) == PAPI_OK) { printf("%s,%s,%s,", info.symbol, info.derived, info.postfix); if (info.short_descr[0]) { printf("\"%s\",", info.short_descr); } else { printf(","); } if (info.long_descr[0]) { printf("\"%s\",", info.long_descr); } else { printf(","); } if (info.note[0]) printf("\"%s\"", info.note); for (j=0;j<(int)info.count;j++) printf(",%s",info.name[j]); printf("\n"); } } while (PAPI_enum_event(&i, print_avail_only) == PAPI_OK); exit(1); }
void tests_quiet( int argc, char **argv ) { if ( ( argc > 1 ) && ( ( strcasecmp( argv[1], "TESTS_QUIET" ) == 0 ) || ( strcasecmp( argv[1], "-q" ) == 0 ) ) ) { TESTS_QUIET = 1; } else { int retval; retval = PAPI_set_debug( PAPI_VERB_ECONT ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval ); } if (getenv("TESTS_COLOR")!=NULL) { TESTS_COLOR=1; } }
int main( int argc, char **argv ) { int i, j = 0, k; int retval; PAPI_event_info_t info; const PAPI_hw_info_t *hwinfo = NULL; command_flags_t flags; int enum_modifier; int numcmp, cid; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Initialize before parsing the input arguments */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } /* Parse the command-line arguments */ parse_args( argc, argv, &flags ); /* Set enum modifier mask */ if ( flags.dear ) enum_modifier = PAPI_NTV_ENUM_DEAR; else if ( flags.darr ) enum_modifier = PAPI_NTV_ENUM_DARR; else if ( flags.iear ) enum_modifier = PAPI_NTV_ENUM_IEAR; else if ( flags.iarr ) enum_modifier = PAPI_NTV_ENUM_IARR; else if ( flags.opcm ) enum_modifier = PAPI_NTV_ENUM_OPCM; else enum_modifier = PAPI_ENUM_EVENTS; if ( !TESTS_QUIET ) { retval = PAPI_set_debug( PAPI_VERB_ECONT ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval ); } } retval = papi_print_header( "Available native events and hardware information.\n", &hwinfo ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); } /* Do this code if an event name was specified on the commandline */ if ( flags.named ) { if ( PAPI_event_name_to_code( flags.name, &i ) == PAPI_OK ) { if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) { printf( "%-30s%s\n%-30s%d\n", "Event name:", info.symbol, "Number of Register Values:", info.count ); printf( "%-29s|%s|\n", "Description:", info.long_descr ); for ( k = 0; k < ( int ) info.count; k++ ) printf( " Register[%2d]: |%s|\n", k, info.name[k] ); /* if unit masks exist but none specified, process all */ if ( !strchr( flags.name, ':' ) ) { if ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { printf( "\nUnit Masks:\n" ); do { retval = PAPI_get_event_info( i, &info ); if ( retval == PAPI_OK ) { if ( parse_unit_masks( &info ) ) { printf( "%-29s|%s|%s|\n", " Mask Info:", info.symbol, info.long_descr ); for ( k = 0; k < ( int ) info.count; k++ ) printf( " Register[%2d]: 0x%08x |%s|\n", k, info.code[k], info.name[k] ); } } } while ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } } } } else { printf("Sorry, an event by the name '%s' could not be found.\n", flags.name); printf("Is it typed correctly?\n\n"); exit( 1 ); } } else { /* Print *ALL* available events */ numcmp = PAPI_num_components( ); j = 0; for ( cid = 0; cid < numcmp; cid++ ) { const PAPI_component_info_t *component; component=PAPI_get_component_info(cid); /* Skip if requested enumeration not available */ if (( flags.dear ) && !( component->cntr_DEAR_events )) { continue; } if (( flags.darr ) && !( component->data_address_range)) { continue; } if (( flags.iear ) && !( component->cntr_IEAR_events )) { continue; } if (( flags.iarr ) && !( component->instr_address_range )) { continue; } if (( flags.opcm ) && !( component->cntr_OPCM_events )) { continue; } printf( "===============================================================================\n" ); printf( " Events in Component: %s\n",component->name); printf( "===============================================================================\n" ); /* Always ASK FOR the first event */ /* Don't just assume it'll be the first numeric value */ i = 0 | PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK( cid ); /* UGH PAPI_enum_event() really needs a component field */ PAPI_enum_event( &i, PAPI_ENUM_FIRST ); do { memset( &info, 0, sizeof ( info ) ); retval = PAPI_get_event_info( i, &info ); /* This event may not exist */ if ( retval != PAPI_OK ) continue; /* count only events that as supported by host cpu */ j++; print_event( &info, 0 ); /* Does this matter on anything but perfctr? */ if ( flags.details ) { for ( k = 0; k < ( int ) info.count; k++ ) { if ( strlen( info.name[k] ) ) { printf( " Register[%d] Name: %-20s Value: 0x%-28x|\n", k, info.name[k], info.code[k] ); } } } /* modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a groups id for each group in which this native event lives, in bits 16 - 23 of event code terminating with PAPI_ENOEVNT at the end of the list. */ /* This is an IBM Power issue */ if ( flags.groups ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) == PAPI_OK ) { printf( "Groups: " ); do { printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >> PAPI_NTV_GROUP_SHIFT ) - 1 ); } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) ==PAPI_OK ); printf( "\n" ); } } /* Print umasks */ /* components that don't have them can just ignore */ if ( flags.umask ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { do { retval = PAPI_get_event_info( k, &info ); if ( retval == PAPI_OK ) { if ( parse_unit_masks( &info ) ) print_event( &info, 2 ); } } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } } printf( "--------------------------------------------------------------------------------\n" ); } while ( PAPI_enum_event( &i, enum_modifier ) == PAPI_OK ); }
int main(int argc, char **argv) { int i, retval, EventSet = PAPI_NULL; int bins = 100; int show_dist = 0, show_std_dev = 0; long long totcyc, values[2]; long long *array; tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ for (i = 0; i < argc; i++) { if (argv[i]) { if (strstr(argv[i], "-b")) { bins = atoi(argv[i+1]); if (bins) i++; else { printf ("-b requires a bin count!\n"); exit(1); } } if (strstr(argv[i], "-d")) show_dist = 1; if (strstr(argv[i], "-h")) { print_help(); exit(1); } if (strstr(argv[i], "-s")) show_std_dev = 1; if (strstr(argv[i], "-t")) { num_iters = atol(argv[i+1]); if (num_iters) i++; else { printf ("-t requires a threshold value!\n"); exit(1); } } } } printf("Cost of execution for PAPI start/stop, read and accum.\n"); printf("This test takes a while. Please be patient...\n"); if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); if ((retval = PAPI_set_debug(PAPI_VERB_ECONT)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_set_debug", retval); if ((retval = PAPI_query_event(PAPI_TOT_CYC)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_query_event", retval); if ((retval = PAPI_query_event(PAPI_TOT_INS)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_query_event", retval); if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); if ((retval = PAPI_add_event(EventSet, PAPI_TOT_CYC)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); if ((retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK) if ((retval = PAPI_add_event(EventSet, PAPI_TOT_IIS)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); /* Make sure no errors and warm up */ totcyc = PAPI_get_real_cyc(); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); if ((retval = PAPI_stop(EventSet, NULL)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); array = (long long *)malloc(num_iters*sizeof(long long)); if (array == NULL ) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); /* Determine clock latency */ printf("\nPerforming loop latency test...\n"); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } do_output(0, array, bins, show_std_dev, show_dist); /* Start the start/stop eval */ printf("\nPerforming start/stop test...\n"); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); PAPI_start(EventSet); PAPI_stop(EventSet, values); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } do_output(1, array, bins, show_std_dev, show_dist); /* Start the read eval */ printf("\nPerforming read test...\n"); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); PAPI_read(EventSet, values); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); PAPI_read(EventSet, values); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); do_output(2, array, bins, show_std_dev, show_dist); /* Start the read with timestamp eval */ printf("\nPerforming read with timestamp test...\n"); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); PAPI_read_ts(EventSet, values, &totcyc); for (i = 0; i < num_iters; i++) { PAPI_read_ts(EventSet, values, &array[i]); } if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); /* post-process the timing array */ for (i = num_iters - 1; i > 0 ; i--) { array[i] -= array[i-1]; } array[0] -= totcyc; do_output(3, array, bins, show_std_dev, show_dist); /* Start the accum eval */ printf("\nPerforming accum test...\n"); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); PAPI_accum(EventSet, values); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); PAPI_accum(EventSet, values); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); do_output(4, array, bins, show_std_dev, show_dist); /* Start the reset eval */ printf("\nPerforming reset test...\n"); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); PAPI_reset(EventSet); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); do_output(5, array, bins, show_std_dev, show_dist); free(array); test_pass(__FILE__, NULL, 0); exit(1); }
int main(int argc, char **argv) { int retval, num_tests = 2, eventcnt, events[2], i, tmp; int EventSet1 = PAPI_NULL, EventSet2 = PAPI_NULL; int PAPI_event; long_long values1[2], values2[2]; long_long elapsed_cyc; char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN]; retval = PAPI_library_init(PAPI_VER_CURRENT); retval = PAPI_set_debug(PAPI_VERB_ECONT); /* query and set up the right instruction to monitor */ if (PAPI_query_event(PAPI_FP_OPS) == PAPI_OK) PAPI_event = PAPI_FP_OPS; else PAPI_event = PAPI_TOT_INS; retval = PAPI_event_code_to_name(PAPI_event, event_name); sprintf(add_event_str, "PAPI_add_event[%s]", event_name); retval = PAPI_create_eventset(&EventSet1); /* Add the events */ retval = PAPI_add_event(EventSet1, PAPI_event); retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC); /* Add them reversed to EventSet2 */ retval = PAPI_create_eventset(&EventSet2); eventcnt = 2; retval = PAPI_list_events(EventSet1, events, &eventcnt); for (i = eventcnt - 1; i >= 0; i--) { retval = PAPI_event_code_to_name(events[i], event_name); retval = PAPI_add_event(EventSet2, events[i]); } elapsed_cyc = PAPI_get_real_cyc(); retval = PAPI_start(EventSet1); do_flops(NUM_FLOPS); retval = PAPI_stop(EventSet1, values1); retval = PAPI_start(EventSet2); do_flops(NUM_FLOPS); retval = PAPI_stop(EventSet2, values2); elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc; retval = PAPI_cleanup_eventset(EventSet1); /* JT */ retval = PAPI_destroy_eventset(&EventSet1); retval = PAPI_cleanup_eventset(EventSet2); /* JT */ retval = PAPI_destroy_eventset(&EventSet2); printf("Test case 0: start, stop.\n"); printf("-----------------------------------------------\n"); tmp = PAPI_get_opt(PAPI_DEFDOM, NULL); tmp = PAPI_get_opt(PAPI_DEFGRN, NULL); printf("Using %d iterations of c += a*b\n", NUM_FLOPS); printf ("-------------------------------------------------------------------------\n"); printf("Test type : \t 1\t 2\n"); printf("%ld %ld\n", values1[0], values2[1]); printf("%d %d\n", "PAPI_TOT_INS : \t", values1[1], values2[0]); printf("%ld\n", "Real cycles : \t", elapsed_cyc); printf ("-------------------------------------------------------------------------\n"); printf("Verification: none\n"); exit(1); }