|
Packit |
577717 |
/* This file performs the following test:
|
|
Packit |
577717 |
start, read, stop and again functionality
|
|
Packit |
577717 |
|
|
Packit |
577717 |
- It attempts to use the following three counters.
|
|
Packit |
577717 |
It may use fewer depending on hardware counter resource limitations.
|
|
Packit |
577717 |
These are counted in the default counting domain and default granularity,
|
|
Packit |
577717 |
depending on the platform.
|
|
Packit |
577717 |
Usually this is the user domain (PAPI_DOM_USER) and
|
|
Packit |
577717 |
thread context (PAPI_GRN_THR).
|
|
Packit |
577717 |
+ PAPI_FP_INS (or PAPI_TOT_INS if PAPI_FP_INS doesn't exist)
|
|
Packit |
577717 |
+ PAPI_TOT_CYC
|
|
Packit |
577717 |
- Start counters
|
|
Packit |
577717 |
- Do flops
|
|
Packit |
577717 |
- Read counters
|
|
Packit |
577717 |
- Reset counters
|
|
Packit |
577717 |
- Do flops
|
|
Packit |
577717 |
- Read counters
|
|
Packit |
577717 |
- Do flops
|
|
Packit |
577717 |
- Read counters
|
|
Packit |
577717 |
- Do flops
|
|
Packit |
577717 |
- Stop and read counters
|
|
Packit |
577717 |
- Read counters
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <string.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "papi.h"
|
|
Packit |
577717 |
#include "papi_test.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "do_loops.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
main( int argc, char **argv )
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
int retval, num_tests = 5, num_events, tmp;
|
|
Packit |
577717 |
long long **values;
|
|
Packit |
577717 |
int EventSet = PAPI_NULL;
|
|
Packit |
577717 |
char event_name1[]="PAPI_TOT_CYC";
|
|
Packit |
577717 |
char event_name2[]="PAPI_TOT_INS";
|
|
Packit |
577717 |
char add_event_str[PAPI_MAX_STR_LEN];
|
|
Packit |
577717 |
long long min, max;
|
|
Packit |
577717 |
int quiet;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Set TESTS_QUIET variable */
|
|
Packit |
577717 |
quiet = tests_quiet( argc, argv );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Init PAPI library */
|
|
Packit |
577717 |
retval = PAPI_library_init( PAPI_VER_CURRENT );
|
|
Packit |
577717 |
if ( retval != PAPI_VER_CURRENT ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* create the eventset */
|
|
Packit |
577717 |
retval = PAPI_create_eventset( &EventSet );
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_add_named_event( EventSet, event_name1);
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
if (!quiet) printf("Couldn't add %s\n",event_name1);
|
|
Packit |
577717 |
test_skip(__FILE__,__LINE__,"Couldn't add PAPI_TOT_CYC",0);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_add_named_event( EventSet, event_name2);
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
if (!quiet) printf("Couldn't add %s\n",event_name2);
|
|
Packit |
577717 |
test_skip(__FILE__,__LINE__,"Couldn't add PAPI_TOT_INS",0);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
num_events=2;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
sprintf( add_event_str, "PAPI_add_event[%s]", event_name2 );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Allocate space for results */
|
|
Packit |
577717 |
values = allocate_test_space( num_tests, num_events );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Start PAPI */
|
|
Packit |
577717 |
retval = PAPI_start( EventSet );
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_start", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Benchmark code */
|
|
Packit |
577717 |
do_flops( NUM_FLOPS );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* read results 0 */
|
|
Packit |
577717 |
retval = PAPI_read( EventSet, values[0] );
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_read", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Reset */
|
|
Packit |
577717 |
retval = PAPI_reset( EventSet );
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Benchmark some more */
|
|
Packit |
577717 |
do_flops( NUM_FLOPS );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Read Results 1 */
|
|
Packit |
577717 |
retval = PAPI_read( EventSet, values[1] );
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_read", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Benchmark some more */
|
|
Packit |
577717 |
do_flops( NUM_FLOPS );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Read results 2 */
|
|
Packit |
577717 |
retval = PAPI_read( EventSet, values[2] );
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_read", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Benchmark some more */
|
|
Packit |
577717 |
do_flops( NUM_FLOPS );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Read results 3 */
|
|
Packit |
577717 |
retval = PAPI_stop( EventSet, values[3] );
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Read results 4 */
|
|
Packit |
577717 |
retval = PAPI_read( EventSet, values[4] );
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_read", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* remove results. We never stop??? */
|
|
Packit |
577717 |
PAPI_remove_named_event(EventSet,event_name1);
|
|
Packit |
577717 |
PAPI_remove_named_event(EventSet,event_name2);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( !quiet ) {
|
|
Packit |
577717 |
printf( "Test case 1: Non-overlapping start, stop, read.\n" );
|
|
Packit |
577717 |
printf( "-----------------------------------------------\n" );
|
|
Packit |
577717 |
tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
|
|
Packit |
577717 |
printf( "Default domain is: %d (%s)\n", tmp,
|
|
Packit |
577717 |
stringify_all_domains( tmp ) );
|
|
Packit |
577717 |
tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
|
|
Packit |
577717 |
printf( "Default granularity is: %d (%s)\n", tmp,
|
|
Packit |
577717 |
stringify_granularity( tmp ) );
|
|
Packit |
577717 |
printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
|
|
Packit |
577717 |
printf( "-------------------------------------------------------------------------\n" );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
printf( "Test type : 1 2 3 4 5\n" );
|
|
Packit |
577717 |
sprintf( add_event_str, "%s:", event_name2 );
|
|
Packit |
577717 |
printf( TAB5, add_event_str,
|
|
Packit |
577717 |
values[0][1], values[1][1], values[2][1],
|
|
Packit |
577717 |
values[3][1], values[4][1] );
|
|
Packit |
577717 |
printf( TAB5, "PAPI_TOT_CYC:",
|
|
Packit |
577717 |
values[0][0], values[1][0], values[2][0],
|
|
Packit |
577717 |
values[3][0], values[4][0] );
|
|
Packit |
577717 |
printf( "-------------------------------------------------------------------------\n" );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
printf( "Verification:\n" );
|
|
Packit |
577717 |
printf( "Row 1 Column 1 at least %d\n", NUM_FLOPS );
|
|
Packit |
577717 |
printf( "%% difference between %s 1 & 2: %.2f\n",
|
|
Packit |
577717 |
add_event_str,
|
|
Packit |
577717 |
100.0 * ( float ) values[0][1] /
|
|
Packit |
577717 |
( float ) values[1][1] );
|
|
Packit |
577717 |
printf( "%% difference between %s 1 & 2: %.2f\n",
|
|
Packit |
577717 |
"PAPI_TOT_CYC",
|
|
Packit |
577717 |
100.0 * ( float ) values[0][0] /
|
|
Packit |
577717 |
( float ) values[1][0] );
|
|
Packit |
577717 |
printf( "Column 1 approximately equals column 2\n" );
|
|
Packit |
577717 |
printf( "Column 3 approximately equals 2 * column 2\n" );
|
|
Packit |
577717 |
printf( "Column 4 approximately equals 3 * column 2\n" );
|
|
Packit |
577717 |
printf( "Column 4 exactly equals column 5\n" );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Validation */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Check cycles constraints */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
min = ( long long ) ( ( double ) values[1][0] * .8 );
|
|
Packit |
577717 |
max = ( long long ) ( ( double ) values[1][0] * 1.2 );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Check constraint Col1=Col2 */
|
|
Packit |
577717 |
if ( values[0][0] > max || values[0][0] < min ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "Cycle Col1!=Col2", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
/* Check constraint col3 == 2*col2 */
|
|
Packit |
577717 |
if ( (values[2][0] > ( 2 * max )) ||
|
|
Packit |
577717 |
(values[2][0] < ( 2 * min )) ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "Cycle Col3!=2*Col2", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
/* Check constraint col4 == 3*col2 */
|
|
Packit |
577717 |
if ( (values[3][0] > ( 3 * max )) ||
|
|
Packit |
577717 |
(values[3][0] < ( 3 * min )) ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "Cycle Col3!=3*Col2", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
/* Check constraint col4 == col5 */
|
|
Packit |
577717 |
if ( values[3][0] != values[4][0] ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "Cycle Col4!=Col5", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Check FLOP constraints */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
min = ( long long ) ( ( double ) values[1][1] * .9 );
|
|
Packit |
577717 |
max = ( long long ) ( ( double ) values[1][1] * 1.1 );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Check constraint Col1=Col2 */
|
|
Packit |
577717 |
if ( values[0][1] > max || values[0][1] < min ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "FLOP Col1!=Col2", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
/* Check constraint col3 == 2*col2 */
|
|
Packit |
577717 |
if ( (values[2][1] > ( 2 * max )) ||
|
|
Packit |
577717 |
(values[2][1] < ( 2 * min )) ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "FLOP Col3!=2*Col2", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
/* Check constraint col4 == 3*col2 */
|
|
Packit |
577717 |
if ( (values[3][1] > ( 3 * max )) ||
|
|
Packit |
577717 |
(values[3][1] < ( 3 * min )) ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "FLOP Col4!=3*Col2", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
/* Check constraint col4 == col5 */
|
|
Packit |
577717 |
if (values[3][1] != values[4][1]) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "FLOP Col4!=Col5", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
/* Check flops are sane */
|
|
Packit |
577717 |
if (values[0][1] < ( long long ) NUM_FLOPS ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "FLOP sanity", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
test_pass( __FILE__ );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
}
|