|
PAPI
5.0.1.0
|
00001 /* This file performs the following test: start, stop and timer functionality 00002 00003 - It attempts to use the following two counters. It may use less depending on 00004 hardware counter resource limitations. These are counted in the default counting 00005 domain and default granularity, depending on the platform. Usually this is 00006 the user domain (PAPI_DOM_USER) and thread context (PAPI_GRN_THR). 00007 + PAPI_FP_INS 00008 + PAPI_TOT_CYC 00009 - Get us. 00010 - Start counters 00011 - Do flops 00012 - Stop and read counters 00013 - Get us. 00014 */ 00015 00016 #include "papi_test.h" 00017 00018 extern int TESTS_QUIET; /* Declared in test_utils.c */ 00019 00020 int 00021 main( int argc, char **argv ) 00022 { 00023 int retval, num_tests = 2, eventcnt, events[2], i, tmp; 00024 int EventSet1 = PAPI_NULL, EventSet2 = PAPI_NULL; 00025 int PAPI_event; 00026 long long values1[2], values2[2]; 00027 long long elapsed_us, elapsed_cyc; 00028 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN]; 00029 00030 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00031 00032 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00033 if ( retval != PAPI_VER_CURRENT ) 00034 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00035 00036 /* query and set up the right instruction to monitor */ 00037 if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK ) 00038 PAPI_event = PAPI_FP_OPS; 00039 else 00040 PAPI_event = PAPI_TOT_INS; 00041 00042 retval = PAPI_event_code_to_name( PAPI_event, event_name ); 00043 if ( retval != PAPI_OK ) 00044 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00045 sprintf( add_event_str, "PAPI_add_event[%s]", event_name ); 00046 00047 retval = PAPI_create_eventset( &EventSet1 ); 00048 if ( retval != PAPI_OK ) 00049 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00050 00051 /* Add the events */ 00052 printf( "Adding: %s\n", event_name ); 00053 retval = PAPI_add_event( EventSet1, PAPI_event ); 00054 if ( retval != PAPI_OK ) 00055 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00056 00057 retval = PAPI_add_event( EventSet1, PAPI_TOT_CYC ); 00058 if ( retval != PAPI_OK ) 00059 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00060 00061 /* Add them reversed to EventSet2 */ 00062 00063 retval = PAPI_create_eventset( &EventSet2 ); 00064 if ( retval != PAPI_OK ) 00065 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00066 00067 eventcnt = 2; 00068 retval = PAPI_list_events( EventSet1, events, &eventcnt ); 00069 if ( retval != PAPI_OK ) 00070 test_fail( __FILE__, __LINE__, "PAPI_list_events", retval ); 00071 00072 for ( i = eventcnt - 1; i >= 0; i-- ) { 00073 retval = PAPI_event_code_to_name( events[i], event_name ); 00074 if ( retval != PAPI_OK ) 00075 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00076 00077 retval = PAPI_add_event( EventSet2, events[i] ); 00078 if ( retval != PAPI_OK ) 00079 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00080 } 00081 00082 elapsed_us = PAPI_get_real_usec( ); 00083 00084 elapsed_cyc = PAPI_get_real_cyc( ); 00085 00086 retval = PAPI_start( EventSet1 ); 00087 if ( retval != PAPI_OK ) 00088 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00089 00090 do_flops( NUM_FLOPS ); 00091 00092 retval = PAPI_stop( EventSet1, values1 ); 00093 if ( retval != PAPI_OK ) 00094 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00095 00096 retval = PAPI_start( EventSet2 ); 00097 if ( retval != PAPI_OK ) 00098 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00099 00100 do_flops( NUM_FLOPS ); 00101 00102 retval = PAPI_stop( EventSet2, values2 ); 00103 if ( retval != PAPI_OK ) 00104 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00105 00106 elapsed_us = PAPI_get_real_usec( ) - elapsed_us; 00107 00108 elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; 00109 00110 retval = PAPI_cleanup_eventset( EventSet1 ); /* JT */ 00111 if ( retval != PAPI_OK ) 00112 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); 00113 00114 retval = PAPI_destroy_eventset( &EventSet1 ); 00115 if ( retval != PAPI_OK ) 00116 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); 00117 00118 retval = PAPI_cleanup_eventset( EventSet2 ); /* JT */ 00119 if ( retval != PAPI_OK ) 00120 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); 00121 00122 retval = PAPI_destroy_eventset( &EventSet2 ); 00123 if ( retval != PAPI_OK ) 00124 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); 00125 00126 if ( !TESTS_QUIET ) { 00127 printf( "Test case 0: start, stop.\n" ); 00128 printf( "-----------------------------------------------\n" ); 00129 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL ); 00130 printf( "Default domain is: %d (%s)\n", tmp, 00131 stringify_all_domains( tmp ) ); 00132 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL ); 00133 printf( "Default granularity is: %d (%s)\n", tmp, 00134 stringify_granularity( tmp ) ); 00135 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); 00136 printf 00137 ( "-------------------------------------------------------------------------\n" ); 00138 00139 printf( "Test type : \t 1\t 2\n" ); 00140 00141 sprintf( add_event_str, "%-12s : \t", event_name ); 00142 printf( TAB2, add_event_str, values1[0], values2[1] ); 00143 printf( TAB2, "PAPI_TOT_CYC : \t", values1[1], values2[0] ); 00144 printf( TAB1, "Real usec : \t", elapsed_us ); 00145 printf( TAB1, "Real cycles : \t", elapsed_cyc ); 00146 00147 printf 00148 ( "-------------------------------------------------------------------------\n" ); 00149 00150 printf( "Verification: none\n" ); 00151 } 00152 test_pass( __FILE__, NULL, num_tests ); 00153 exit( 1 ); 00154 }