|
PAPI
5.3.0.0
|
00001 /* This file performs the same tests as the reset test 00002 but does it with the events multiplexed. 00003 00004 This is mostly to test perf_event, where resetting 00005 multiplexed events is handled differently than grouped events. 00006 00007 */ 00008 00009 #include "papi_test.h" 00010 00011 int 00012 main( int argc, char **argv ) 00013 { 00014 int retval, num_tests = 9, num_events, tmp, i; 00015 long long **values; 00016 int EventSet = PAPI_NULL; 00017 int PAPI_event, mask; 00018 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN]; 00019 00020 /* Set TESTS_QUIET variable */ 00021 tests_quiet( argc, argv ); 00022 00023 /* Init the PAPI library */ 00024 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00025 if ( retval != PAPI_VER_CURRENT ) { 00026 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00027 } 00028 00029 retval = PAPI_multiplex_init( ); 00030 if ( retval == PAPI_ENOSUPP) { 00031 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1); 00032 } 00033 else if ( retval != PAPI_OK ) { 00034 test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval ); 00035 } 00036 00037 00038 /* add PAPI_TOT_CYC and one of the events in 00039 PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, 00040 depending on the availability of the event 00041 on the platform */ 00042 EventSet = add_two_events( &num_events, &PAPI_event, &mask ); 00043 00044 /* Set multiplexing on the eventset */ 00045 00046 retval = PAPI_set_multiplex( EventSet ); 00047 if ( retval != PAPI_OK) { 00048 test_fail(__FILE__, __LINE__, "Setting multiplex", retval); 00049 } 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 values = allocate_test_space( num_tests, num_events ); 00058 00059 /*===== Test 1: Start/Stop =======================*/ 00060 00061 retval = PAPI_start( EventSet ); 00062 if ( retval != PAPI_OK ) { 00063 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00064 } 00065 00066 do_flops( NUM_FLOPS ); 00067 00068 retval = PAPI_stop( EventSet, values[0] ); 00069 if ( retval != PAPI_OK ) { 00070 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00071 } 00072 00073 /*===== Test 2 Start/Stop =======================*/ 00074 00075 retval = PAPI_start( EventSet ); 00076 if ( retval != PAPI_OK ) { 00077 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00078 } 00079 00080 do_flops( NUM_FLOPS ); 00081 00082 retval = PAPI_stop( EventSet, values[1] ); 00083 if ( retval != PAPI_OK ) { 00084 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00085 } 00086 00087 /*===== Test 3: Reset/Start/Stop =======================*/ 00088 00089 retval = PAPI_reset( EventSet ); 00090 if ( retval != PAPI_OK ) { 00091 test_fail( __FILE__, __LINE__, "PAPI_reset", retval ); 00092 } 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[2] ); 00102 if ( retval != PAPI_OK ) { 00103 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00104 } 00105 00106 /*===== Test 4: Start/Read =======================*/ 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 / 2 ); 00114 00115 retval = PAPI_read( EventSet, values[3] ); 00116 if ( retval != PAPI_OK ) { 00117 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00118 } 00119 00120 /*===== Test 5: Read =======================*/ 00121 00122 do_flops( NUM_FLOPS / 2 ); 00123 00124 retval = PAPI_read( EventSet, values[4] ); 00125 if ( retval != PAPI_OK ) { 00126 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00127 } 00128 00129 /*===== Test 6: Read/Accum =======================*/ 00130 00131 do_flops( NUM_FLOPS / 2 ); 00132 00133 retval = PAPI_read( EventSet, values[5] ); 00134 if ( retval != PAPI_OK ) { 00135 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00136 } 00137 00138 retval = PAPI_accum( EventSet, values[5] ); 00139 00140 if ( retval != PAPI_OK ) { 00141 test_fail( __FILE__, __LINE__, "PAPI_accum", retval ); 00142 } 00143 00144 /*===== Test 7: Read =======================*/ 00145 00146 do_flops( NUM_FLOPS / 2 ); 00147 00148 retval = PAPI_read( EventSet, values[6] ); 00149 if ( retval != PAPI_OK ) { 00150 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00151 } 00152 00153 /*===== Test 8 Reset/Stop =======================*/ 00154 retval = PAPI_reset( EventSet ); 00155 if ( retval != PAPI_OK ) { 00156 test_fail( __FILE__, __LINE__, "PAPI_reset", retval ); 00157 } 00158 00159 do_flops( NUM_FLOPS / 2 ); 00160 00161 retval = PAPI_stop( EventSet, values[7] ); 00162 if ( retval != PAPI_OK ) { 00163 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00164 } 00165 00166 /*===== Test 9: Reset/Read =======================*/ 00167 retval = PAPI_reset( EventSet ); 00168 if ( retval != PAPI_OK ) { 00169 test_fail( __FILE__, __LINE__, "PAPI_reset", retval ); 00170 } 00171 00172 retval = PAPI_read( EventSet, values[8] ); 00173 if ( retval != PAPI_OK ) { 00174 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00175 } 00176 00177 remove_test_events( &EventSet, mask ); 00178 00179 printf( "Test case: Start/Stop/Read/Accum/Reset.\n" ); 00180 printf( "----------------------------------------------------------------\n" ); 00181 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL ); 00182 printf( "Default domain is: %d (%s)\n", tmp, 00183 stringify_all_domains( tmp ) ); 00184 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL ); 00185 printf( "Default granularity is: %d (%s)\n", tmp, 00186 stringify_granularity( tmp ) ); 00187 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); 00188 printf( "-------------------------------------------------------------------------\n" ); 00189 00190 sprintf( add_event_str, "%s:", event_name ); 00191 printf( " PAPI_TOT_CYC %s\n", event_name ); 00192 printf( "1. start,ops,stop %10lld %10lld\n", values[0][0], 00193 values[0][1] ); 00194 printf( "2. start,ops,stop %10lld %10lld\n", values[1][0], 00195 values[1][1] ); 00196 printf( "3. reset,start,ops,stop %10lld %10lld\n", values[2][0], 00197 values[2][1] ); 00198 printf( "4. start,ops/2,read %10lld %10lld\n", values[3][0], 00199 values[3][1] ); 00200 printf( "5. ops/2,read %10lld %10lld\n", values[4][0], 00201 values[4][1] ); 00202 printf( "6. ops/2,accum %10lld %10lld\n", values[5][0], 00203 values[5][1] ); 00204 printf( "7. ops/2,read %10lld %10lld\n", values[6][0], 00205 values[6][1] ); 00206 printf( "8. reset,ops/2,stop %10lld %10lld\n", values[7][0], 00207 values[7][1] ); 00208 printf( "9. reset,read %10lld %10lld\n", values[8][0], 00209 values[8][1] ); 00210 printf 00211 ( "-------------------------------------------------------------------------\n" ); 00212 printf( "Verification:\n" ); 00213 printf( "Row 1 approximately equals rows 2 and 3 \n" ); 00214 printf( "Row 4 approximately equals 1/2 of row 3\n" ); 00215 printf( "Row 5 approximately equals twice row 4\n" ); 00216 printf( "Row 6 approximately equals 6 times row 4\n" ); 00217 printf( "Rows 7 and 8 approximately equal row 4\n" ); 00218 printf( "Row 9 equals 0\n" ); 00219 printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC", 00220 100.0 * ( float ) values[0][0] / ( float ) values[1][0] ); 00221 printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str, 00222 100.0 * ( float ) values[0][1] / ( float ) values[1][1] ); 00223 00224 00225 for ( i = 0; i <= 1; i++ ) { 00226 if ( !approx_equals 00227 ( ( double ) values[0][i], ( double ) values[1][i] ) ) 00228 test_fail( __FILE__, __LINE__, 00229 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00230 if ( !approx_equals 00231 ( ( double ) values[1][i], ( double ) values[2][i] ) ) 00232 test_fail( __FILE__, __LINE__, 00233 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00234 if ( !approx_equals 00235 ( ( double ) values[2][i], ( double ) values[3][i] * 2.0 ) ) 00236 test_fail( __FILE__, __LINE__, 00237 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00238 if ( !approx_equals 00239 ( ( double ) values[2][i], ( double ) values[4][i] ) ) 00240 test_fail( __FILE__, __LINE__, 00241 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00242 if ( !approx_equals 00243 ( ( double ) values[5][i], ( double ) values[3][i] * 6.0 ) ) 00244 test_fail( __FILE__, __LINE__, 00245 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00246 if ( !approx_equals 00247 ( ( double ) values[6][i], ( double ) values[3][i] ) ) 00248 test_fail( __FILE__, __LINE__, 00249 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00250 if ( !approx_equals 00251 ( ( double ) values[7][i], ( double ) values[3][i] ) ) 00252 test_fail( __FILE__, __LINE__, 00253 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00254 if ( values[8][i] != 0LL ) 00255 test_fail( __FILE__, __LINE__, 00256 ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 ); 00257 } 00258 00259 test_pass( __FILE__, values, num_tests ); 00260 return 0; 00261 }