|
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 00010 1 00011 - Start counters 00012 - Do flops 00013 - Stop counters 00014 00015 2 00016 - Start counters 00017 - Do flops 00018 - Stop counters (should duplicate above) 00019 00020 3 00021 - Reset counters (should be redundant if stop works properly) 00022 - Start counters 00023 - Do flops 00024 - Stop counters 00025 00026 4 00027 - Start counters 00028 - Do flops/2 00029 - Read counters (flops/2;counters keep counting) 00030 00031 5 00032 - Do flops/2 00033 - Read counters (2flops/2; counters keep counting) 00034 00035 6 00036 - Do flops/2 00037 - Read counters (3*flops/2; counters keep counting) 00038 - Accum counters (2*(3*flops.2); counters clear and counting) 00039 00040 7 00041 - Do flops/2 00042 - Read counters (flops/2; counters keep counting) 00043 00044 8 00045 - Reset (counters set to zero; still counting) 00046 - Stop counters (flops/2; counters stopped) 00047 00048 9 00049 - Reset (counters set to zero; still counting) 00050 - Do flops/2 00051 - Stop counters (flops/2; counters stopped) 00052 00053 9 00054 - Reset (counters set to zero and stopped) 00055 - Read counters (should be zero) 00056 */ 00057 00058 #include "papi_test.h" 00059 00060 int 00061 main( int argc, char **argv ) 00062 { 00063 int retval, num_tests = 9, num_events, tmp, i; 00064 long long **values; 00065 int EventSet = PAPI_NULL; 00066 int PAPI_event, mask; 00067 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN]; 00068 00069 /* Set TESTS_QUIET variable */ 00070 tests_quiet( argc, argv ); 00071 00072 /* Init the PAPI library */ 00073 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00074 if ( retval != PAPI_VER_CURRENT ) { 00075 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00076 } 00077 00078 /* add PAPI_TOT_CYC and one of the events in 00079 PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, 00080 depending on the availability of the event 00081 on the platform */ 00082 EventSet = add_two_events( &num_events, &PAPI_event, &mask ); 00083 00084 retval = PAPI_event_code_to_name( PAPI_event, event_name ); 00085 if ( retval != PAPI_OK ) { 00086 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00087 } 00088 sprintf( add_event_str, "PAPI_add_event[%s]", event_name ); 00089 00090 values = allocate_test_space( num_tests, num_events ); 00091 00092 /*===== Test 1: Start/Stop =======================*/ 00093 00094 retval = PAPI_start( EventSet ); 00095 if ( retval != PAPI_OK ) { 00096 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00097 } 00098 00099 do_flops( NUM_FLOPS ); 00100 00101 retval = PAPI_stop( EventSet, values[0] ); 00102 if ( retval != PAPI_OK ) { 00103 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00104 } 00105 00106 /*===== Test 2 Start/Stop =======================*/ 00107 00108 retval = PAPI_start( EventSet ); 00109 if ( retval != PAPI_OK ) { 00110 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00111 } 00112 00113 do_flops( NUM_FLOPS ); 00114 00115 retval = PAPI_stop( EventSet, values[1] ); 00116 if ( retval != PAPI_OK ) { 00117 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00118 } 00119 00120 /*===== Test 3: Reset/Start/Stop =======================*/ 00121 00122 retval = PAPI_reset( EventSet ); 00123 if ( retval != PAPI_OK ) { 00124 test_fail( __FILE__, __LINE__, "PAPI_reset", retval ); 00125 } 00126 00127 retval = PAPI_start( EventSet ); 00128 if ( retval != PAPI_OK ) { 00129 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00130 } 00131 00132 do_flops( NUM_FLOPS ); 00133 00134 retval = PAPI_stop( EventSet, values[2] ); 00135 if ( retval != PAPI_OK ) { 00136 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00137 } 00138 00139 /*===== Test 4: Start/Read =======================*/ 00140 00141 retval = PAPI_start( EventSet ); 00142 if ( retval != PAPI_OK ) { 00143 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00144 } 00145 00146 do_flops( NUM_FLOPS / 2 ); 00147 00148 retval = PAPI_read( EventSet, values[3] ); 00149 if ( retval != PAPI_OK ) { 00150 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00151 } 00152 00153 /*===== Test 5: Read =======================*/ 00154 00155 do_flops( NUM_FLOPS / 2 ); 00156 00157 retval = PAPI_read( EventSet, values[4] ); 00158 if ( retval != PAPI_OK ) { 00159 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00160 } 00161 00162 /*===== Test 6: Read/Accum =======================*/ 00163 00164 do_flops( NUM_FLOPS / 2 ); 00165 00166 retval = PAPI_read( EventSet, values[5] ); 00167 if ( retval != PAPI_OK ) { 00168 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00169 } 00170 00171 retval = PAPI_accum( EventSet, values[5] ); 00172 00173 if ( retval != PAPI_OK ) { 00174 test_fail( __FILE__, __LINE__, "PAPI_accum", retval ); 00175 } 00176 00177 /*===== Test 7: Read =======================*/ 00178 00179 do_flops( NUM_FLOPS / 2 ); 00180 00181 retval = PAPI_read( EventSet, values[6] ); 00182 if ( retval != PAPI_OK ) { 00183 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00184 } 00185 00186 /*===== Test 8 Reset/Stop =======================*/ 00187 retval = PAPI_reset( EventSet ); 00188 if ( retval != PAPI_OK ) { 00189 test_fail( __FILE__, __LINE__, "PAPI_reset", retval ); 00190 } 00191 00192 do_flops( NUM_FLOPS / 2 ); 00193 00194 retval = PAPI_stop( EventSet, values[7] ); 00195 if ( retval != PAPI_OK ) { 00196 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00197 } 00198 00199 /*===== Test 9: Reset/Read =======================*/ 00200 retval = PAPI_reset( EventSet ); 00201 if ( retval != PAPI_OK ) { 00202 test_fail( __FILE__, __LINE__, "PAPI_reset", retval ); 00203 } 00204 00205 retval = PAPI_read( EventSet, values[8] ); 00206 if ( retval != PAPI_OK ) { 00207 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00208 } 00209 00210 remove_test_events( &EventSet, mask ); 00211 00212 printf( "Test case: Start/Stop/Read/Accum/Reset.\n" ); 00213 printf( "----------------------------------------------------------------\n" ); 00214 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL ); 00215 printf( "Default domain is: %d (%s)\n", tmp, 00216 stringify_all_domains( tmp ) ); 00217 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL ); 00218 printf( "Default granularity is: %d (%s)\n", tmp, 00219 stringify_granularity( tmp ) ); 00220 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); 00221 printf( "-------------------------------------------------------------------------\n" ); 00222 00223 sprintf( add_event_str, "%s:", event_name ); 00224 printf( " PAPI_TOT_CYC %s\n", event_name ); 00225 printf( "1. start,ops,stop %10lld %10lld\n", values[0][0], 00226 values[0][1] ); 00227 printf( "2. start,ops,stop %10lld %10lld\n", values[1][0], 00228 values[1][1] ); 00229 printf( "3. reset,start,ops,stop %10lld %10lld\n", values[2][0], 00230 values[2][1] ); 00231 printf( "4. start,ops/2,read %10lld %10lld\n", values[3][0], 00232 values[3][1] ); 00233 printf( "5. ops/2,read %10lld %10lld\n", values[4][0], 00234 values[4][1] ); 00235 printf( "6. ops/2,accum %10lld %10lld\n", values[5][0], 00236 values[5][1] ); 00237 printf( "7. ops/2,read %10lld %10lld\n", values[6][0], 00238 values[6][1] ); 00239 printf( "8. reset,ops/2,stop %10lld %10lld\n", values[7][0], 00240 values[7][1] ); 00241 printf( "9. reset,read %10lld %10lld\n", values[8][0], 00242 values[8][1] ); 00243 printf 00244 ( "-------------------------------------------------------------------------\n" ); 00245 printf( "Verification:\n" ); 00246 printf( "Row 1 approximately equals rows 2 and 3 \n" ); 00247 printf( "Row 4 approximately equals 1/2 of row 3\n" ); 00248 printf( "Row 5 approximately equals twice row 4\n" ); 00249 printf( "Row 6 approximately equals 6 times row 4\n" ); 00250 printf( "Rows 7 and 8 approximately equal row 4\n" ); 00251 printf( "Row 9 equals 0\n" ); 00252 printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC", 00253 100.0 * ( float ) values[0][0] / ( float ) values[1][0] ); 00254 printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str, 00255 100.0 * ( float ) values[0][1] / ( float ) values[1][1] ); 00256 00257 00258 for ( i = 0; i <= 1; i++ ) { 00259 if ( !approx_equals 00260 ( ( double ) values[0][i], ( double ) values[1][i] ) ) 00261 test_fail( __FILE__, __LINE__, 00262 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00263 if ( !approx_equals 00264 ( ( double ) values[1][i], ( double ) values[2][i] ) ) 00265 test_fail( __FILE__, __LINE__, 00266 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00267 if ( !approx_equals 00268 ( ( double ) values[2][i], ( double ) values[3][i] * 2.0 ) ) 00269 test_fail( __FILE__, __LINE__, 00270 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00271 if ( !approx_equals 00272 ( ( double ) values[2][i], ( double ) values[4][i] ) ) 00273 test_fail( __FILE__, __LINE__, 00274 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00275 if ( !approx_equals 00276 ( ( double ) values[5][i], ( double ) values[3][i] * 6.0 ) ) 00277 test_fail( __FILE__, __LINE__, 00278 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00279 if ( !approx_equals 00280 ( ( double ) values[6][i], ( double ) values[3][i] ) ) 00281 test_fail( __FILE__, __LINE__, 00282 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00283 if ( !approx_equals 00284 ( ( double ) values[7][i], ( double ) values[3][i] ) ) 00285 test_fail( __FILE__, __LINE__, 00286 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00287 if ( values[8][i] != 0LL ) 00288 test_fail( __FILE__, __LINE__, 00289 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00290 } 00291 00292 test_pass( __FILE__, values, num_tests ); 00293 return 0; 00294 }