|
PAPI
5.0.1.0
|
00001 /* This file performs the following test: start, read, stop and again functionality 00002 00003 - It attempts to use the following three 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 or PAPI_TOT_INS if PAPI_FP_INS doesn't exist 00008 + PAPI_TOT_CYC 00009 - Start counters 00010 - Do flops 00011 - Read counters 00012 - Reset counters 00013 - Do flops 00014 - Read counters 00015 - Do flops 00016 - Read counters 00017 - Do flops 00018 - Stop and read counters 00019 - Read counters 00020 */ 00021 00022 #include "papi_test.h" 00023 00024 extern int TESTS_QUIET; /* Declared in test_utils.c */ 00025 00026 int 00027 main( int argc, char **argv ) 00028 { 00029 int retval, num_tests = 5, num_events, tmp; 00030 long long **values; 00031 int EventSet = PAPI_NULL; 00032 int PAPI_event, mask; 00033 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN]; 00034 long long min, max; 00035 00036 /* Set TESTS_QUIET variable */ 00037 tests_quiet( argc, argv ); 00038 00039 /* Init PAPI library */ 00040 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00041 if ( retval != PAPI_VER_CURRENT ) { 00042 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00043 } 00044 00045 /* add PAPI_TOT_CYC and one of the events in 00046 PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, 00047 depending on the availability of the event 00048 on the platform */ 00049 EventSet = add_two_events( &num_events, &PAPI_event, &mask ); 00050 00051 retval = PAPI_event_code_to_name( PAPI_event, event_name ); 00052 if ( retval != PAPI_OK ) { 00053 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00054 } 00055 sprintf( add_event_str, "PAPI_add_event[%s]", event_name ); 00056 00057 /* Allocate space for results */ 00058 values = allocate_test_space( num_tests, num_events ); 00059 00060 /* Start PAPI */ 00061 retval = PAPI_start( EventSet ); 00062 if ( retval != PAPI_OK ) { 00063 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00064 } 00065 00066 /* Benchmark code */ 00067 do_flops( NUM_FLOPS ); 00068 00069 /* read results 0 */ 00070 retval = PAPI_read( EventSet, values[0] ); 00071 if ( retval != PAPI_OK ) { 00072 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00073 } 00074 00075 /* Reset */ 00076 retval = PAPI_reset( EventSet ); 00077 if ( retval != PAPI_OK ) { 00078 test_fail( __FILE__, __LINE__, "PAPI_reset", retval ); 00079 } 00080 00081 /* Benchmark some more */ 00082 do_flops( NUM_FLOPS ); 00083 00084 /* Read Results 1 */ 00085 retval = PAPI_read( EventSet, values[1] ); 00086 if ( retval != PAPI_OK ) { 00087 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00088 } 00089 00090 /* Benchmark some more */ 00091 do_flops( NUM_FLOPS ); 00092 00093 /* Read results 2 */ 00094 retval = PAPI_read( EventSet, values[2] ); 00095 if ( retval != PAPI_OK ) { 00096 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00097 } 00098 00099 /* Benchmark some more */ 00100 do_flops( NUM_FLOPS ); 00101 00102 /* Read results 3 */ 00103 retval = PAPI_stop( EventSet, values[3] ); 00104 if ( retval != PAPI_OK ) { 00105 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00106 } 00107 00108 /* Read results 4 */ 00109 retval = PAPI_read( EventSet, values[4] ); 00110 if ( retval != PAPI_OK ) { 00111 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00112 } 00113 00114 /* remove results. We never stop??? */ 00115 remove_test_events( &EventSet, mask ); 00116 00117 if ( !TESTS_QUIET ) { 00118 printf( "Test case 1: Non-overlapping start, stop, read.\n" ); 00119 printf( "-----------------------------------------------\n" ); 00120 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL ); 00121 printf( "Default domain is: %d (%s)\n", tmp, 00122 stringify_all_domains( tmp ) ); 00123 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL ); 00124 printf( "Default granularity is: %d (%s)\n", tmp, 00125 stringify_granularity( tmp ) ); 00126 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); 00127 printf( "-------------------------------------------------------------------------\n" ); 00128 00129 printf( "Test type : 1 2 3 4 5\n" ); 00130 sprintf( add_event_str, "%s:", event_name ); 00131 printf( TAB5, add_event_str, 00132 values[0][1], values[1][1], values[2][1], 00133 values[3][1], values[4][1] ); 00134 printf( TAB5, "PAPI_TOT_CYC:", 00135 values[0][0], values[1][0], values[2][0], 00136 values[3][0], values[4][0] ); 00137 printf( "-------------------------------------------------------------------------\n" ); 00138 00139 printf( "Verification:\n" ); 00140 printf( "Row 1 Column 1 at least %d\n", NUM_FLOPS ); 00141 printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str, 00142 100.0 * ( float ) values[0][1] / 00143 ( float ) values[1][1] ); 00144 printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC", 00145 100.0 * ( float ) values[0][0] / 00146 ( float ) values[1][0] ); 00147 printf( "Column 1 approximately equals column 2\n" ); 00148 printf( "Column 3 approximately equals 2 * column 2\n" ); 00149 printf( "Column 4 approximately equals 3 * column 2\n" ); 00150 printf( "Column 4 exactly equals column 5\n" ); 00151 } 00152 00153 /* Validation */ 00154 00155 /* Check cycles constraints */ 00156 00157 min = ( long long ) ( ( double ) values[1][0] * .8 ); 00158 max = ( long long ) ( ( double ) values[1][0] * 1.2 ); 00159 00160 /* Check constraint Col1=Col2 */ 00161 if ( values[0][0] > max || values[0][0] < min ) { 00162 test_fail( __FILE__, __LINE__, "Cycle Col1!=Col2", 1 ); 00163 } 00164 /* Check constraint col3 == 2*col2 */ 00165 if ( (values[2][0] > ( 2 * max )) || 00166 (values[2][0] < ( 2 * min )) ) { 00167 test_fail( __FILE__, __LINE__, "Cycle Col3!=2*Col2", 1 ); 00168 } 00169 /* Check constraint col4 == 3*col2 */ 00170 if ( (values[3][0] > ( 3 * max )) || 00171 (values[3][0] < ( 3 * min )) ) { 00172 test_fail( __FILE__, __LINE__, "Cycle Col3!=3*Col2", 1 ); 00173 } 00174 /* Check constraint col4 == col5 */ 00175 if ( values[3][0] != values[4][0] ) { 00176 test_fail( __FILE__, __LINE__, "Cycle Col4!=Col5", 1 ); 00177 } 00178 00179 00180 /* Check FLOP constraints */ 00181 00182 min = ( long long ) ( ( double ) values[1][1] * .9 ); 00183 max = ( long long ) ( ( double ) values[1][1] * 1.1 ); 00184 00185 /* Check constraint Col1=Col2 */ 00186 if ( values[0][1] > max || values[0][1] < min ) { 00187 test_fail( __FILE__, __LINE__, "FLOP Col1!=Col2", 1 ); 00188 } 00189 /* Check constraint col3 == 2*col2 */ 00190 if ( (values[2][1] > ( 2 * max )) || 00191 (values[2][1] < ( 2 * min )) ) { 00192 test_fail( __FILE__, __LINE__, "FLOP Col3!=2*Col2", 1 ); 00193 } 00194 /* Check constraint col4 == 3*col2 */ 00195 if ( (values[3][1] > ( 3 * max )) || 00196 (values[3][1] < ( 3 * min )) ) { 00197 test_fail( __FILE__, __LINE__, "FLOP Col4!=3*Col2", 1 ); 00198 } 00199 /* Check constraint col4 == col5 */ 00200 if (values[3][1] != values[4][1]) { 00201 test_fail( __FILE__, __LINE__, "FLOP Col4!=Col5", 1 ); 00202 } 00203 /* Check flops are sane */ 00204 if (values[0][1] < ( long long ) NUM_FLOPS ) { 00205 test_fail( __FILE__, __LINE__, "FLOP sanity", 1 ); 00206 } 00207 00208 00209 test_pass( __FILE__, values, num_tests ); 00210 return 0; 00211 00212 }