|
PAPI
5.0.1.0
|
00001 /* This test exercises the PAPI_{query, add, remove}_event APIs for PRESET events. 00002 It more or less duplicates the functionality of the classic "zero" test. 00003 */ 00004 00005 #include "papi_test.h" 00006 00007 int 00008 main( int argc, char **argv ) 00009 { 00010 int retval, num_tests = 1, tmp; 00011 int EventSet = PAPI_NULL; 00012 int num_events = 2; 00013 long long **values; 00014 long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc; 00015 char *event_names[] = {"PAPI_TOT_CYC","PAPI_TOT_INS"}; 00016 char add_event_str[PAPI_MAX_STR_LEN]; 00017 double cycles_error; 00018 00019 /* Set TESTS_QUIET variable */ 00020 tests_quiet( argc, argv ); 00021 00022 /* Init the PAPI library */ 00023 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00024 if ( retval != PAPI_VER_CURRENT ) { 00025 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00026 } 00027 00028 /* Verify that the named events exist */ 00029 retval = PAPI_query_named_event(event_names[0]); 00030 if ( retval == PAPI_OK) 00031 retval = PAPI_query_named_event(event_names[1]); 00032 if ( retval != PAPI_OK ) 00033 test_fail( __FILE__, __LINE__, "PAPI_query_named_event", retval ); 00034 00035 /* Create an empty event set */ 00036 retval = PAPI_create_eventset( &EventSet ); 00037 if ( retval != PAPI_OK ) 00038 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00039 00040 /* add the events named above */ 00041 retval = PAPI_add_named_event( EventSet, event_names[0] ); 00042 if ( retval != PAPI_OK ) { 00043 sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] ); 00044 test_fail( __FILE__, __LINE__, add_event_str, retval ); 00045 } 00046 00047 retval = PAPI_add_named_event( EventSet, event_names[1] ); 00048 if ( retval != PAPI_OK ) { 00049 sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] ); 00050 test_fail( __FILE__, __LINE__, add_event_str, retval ); 00051 } 00052 00053 values = allocate_test_space( num_tests, num_events ); 00054 00055 /* Gather before stats */ 00056 elapsed_us = PAPI_get_real_usec( ); 00057 elapsed_cyc = PAPI_get_real_cyc( ); 00058 elapsed_virt_us = PAPI_get_virt_usec( ); 00059 elapsed_virt_cyc = PAPI_get_virt_cyc( ); 00060 00061 /* Start PAPI */ 00062 retval = PAPI_start( EventSet ); 00063 if ( retval != PAPI_OK ) { 00064 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00065 } 00066 00067 /* our test code */ 00068 do_flops( NUM_FLOPS ); 00069 00070 /* Stop PAPI */ 00071 retval = PAPI_stop( EventSet, values[0] ); 00072 if ( retval != PAPI_OK ) { 00073 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00074 } 00075 00076 /* Calculate total values */ 00077 elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us; 00078 elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc; 00079 elapsed_us = PAPI_get_real_usec( ) - elapsed_us; 00080 elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; 00081 00082 /* remove PAPI_TOT_CYC and PAPI_TOT_INS */ 00083 retval = PAPI_remove_named_event( EventSet, event_names[0] ); 00084 if ( retval != PAPI_OK ) { 00085 sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] ); 00086 test_fail( __FILE__, __LINE__, add_event_str, retval ); 00087 } 00088 00089 retval = PAPI_remove_named_event( EventSet, event_names[1] ); 00090 if ( retval != PAPI_OK ) { 00091 sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] ); 00092 test_fail( __FILE__, __LINE__, add_event_str, retval ); 00093 } 00094 00095 if ( !TESTS_QUIET ) { 00096 printf( "PAPI_{query, add, remove}_named_event API test.\n" ); 00097 printf( "-----------------------------------------------\n" ); 00098 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL ); 00099 printf( "Default domain is: %d (%s)\n", tmp, 00100 stringify_all_domains( tmp ) ); 00101 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL ); 00102 printf( "Default granularity is: %d (%s)\n", tmp, 00103 stringify_granularity( tmp ) ); 00104 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); 00105 printf( "-------------------------------------------------------------------------\n" ); 00106 00107 printf( "Test type : \t 1\n" ); 00108 00109 /* cycles is first, other event second */ 00110 sprintf( add_event_str, "%-12s : \t", event_names[0] ); 00111 printf( TAB1, add_event_str, values[0][0] ); 00112 sprintf( add_event_str, "%-12s : \t", event_names[1] ); 00113 printf( TAB1, add_event_str, values[0][1] ); 00114 00115 printf( TAB1, "Real usec : \t", elapsed_us ); 00116 printf( TAB1, "Real cycles : \t", elapsed_cyc ); 00117 printf( TAB1, "Virt usec : \t", elapsed_virt_us ); 00118 printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc ); 00119 00120 printf( "-------------------------------------------------------------------------\n" ); 00121 00122 printf( "Verification: PAPI_TOT_CYC should be roughly real_cycles\n" ); 00123 cycles_error=100.0*((double)values[0][0] - (double)elapsed_cyc)/ 00124 (double)values[0][0]; 00125 if (cycles_error>10.0) { 00126 printf("Error of %.2f%%\n",cycles_error); 00127 test_fail( __FILE__, __LINE__, "validation", 0 ); 00128 } 00129 00130 } 00131 test_pass( __FILE__, values, num_tests ); 00132 00133 return 0; 00134 }