コード例 #1
0
void *Thread(void *arg)
{
   int retval, num_tests = 1;
   int EventSet1=PAPI_NULL;
   int mask1, papi_event;
   int num_events1;
   long long **values;
   long long elapsed_us, elapsed_cyc;
   char event_name[PAPI_MAX_STR_LEN];

   /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
      PAPI_TOT_INS, depends on the availability of the event on the 
      platform */
   EventSet1 = add_two_nonderived_events(&num_events1, &papi_event, hw_info, &mask1);

   expected[EventSet1] = *(int *)arg / mythreshold;
   myid[EventSet1] = PAPI_thread_id();

   values = allocate_test_space(num_tests, num_events1);

   elapsed_us = PAPI_get_real_usec();

   elapsed_cyc = PAPI_get_real_cyc();

   if ((retval = PAPI_overflow(EventSet1, papi_event, mythreshold, 0, handler))
                 != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

   /* start_timer(1); */
   if ((retval = PAPI_start(EventSet1)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_stuff();

   if ((retval = PAPI_stop(EventSet1, values[0])) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   elapsed_us = PAPI_get_real_usec() - elapsed_us;

   elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;

   if ((retval = PAPI_overflow(EventSet1, papi_event, 0, 0, NULL)) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

   remove_test_events(&EventSet1, mask1);

   if ((retval = PAPI_event_code_to_name(papi_event, event_name)) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);

   if (!TESTS_QUIET) {
      printf("Thread 0x%x %s : \t%lld\n", (int) pthread_self(), 
                     event_name, (values[0])[0]);
      printf("Thread 0x%x PAPI_TOT_CYC: \t%lld\n", (int) pthread_self(), (values[0])[1]);
      printf("Thread 0x%x Real usec   : \t%lld\n", (int) pthread_self(), elapsed_us);
      printf("Thread 0x%x Real cycles : \t%lld\n", (int) pthread_self(), elapsed_cyc);
   }
   free_test_space(values, num_tests);
   pthread_exit(NULL);
   return (NULL);
}
コード例 #2
0
ファイル: krentel_pthreads.c プロジェクト: arm-hpc/papi
void *
my_thread( void *v )
{
	long num = ( long ) v;
	int n;
	int EventSet = PAPI_NULL;
	long long value;

	int retval = PAPI_register_thread(  );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
	pthread_setspecific( key, v );

	count[num] = 0;
	iter[num] = 0;
	last[num] = start;
        
	if ( PAPI_create_eventset( &EventSet ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 );

	if ( PAPI_add_event( EventSet, EVENT ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event failed", 1 );

	if ( PAPI_overflow( EventSet, EVENT, threshold, 0, my_handler ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 );

	if ( PAPI_start( EventSet ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 );

	printf( "launched timer in thread %ld\n", num );

	for ( n = 1; n <= program_time; n++ ) {
		do_cycles( num, 1 );
		print_rate( num );
	}

	PAPI_stop( EventSet, &value );

        retval = PAPI_overflow( EventSet, EVENT, 0, 0, my_handler);
	if ( retval != PAPI_OK )
            test_fail( __FILE__, __LINE__, "PAPI_overflow failed to reset the overflow handler", retval );

	if ( PAPI_remove_event( EventSet, EVENT ) != PAPI_OK ) 
	    test_fail( __FILE__, __LINE__, "PAPI_remove_event", 1 );

	if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ) 
	    test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", 1 );

	if ( PAPI_unregister_thread( ) != PAPI_OK != retval ) 
		test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", 1 );

	return ( NULL );
}
コード例 #3
0
ファイル: rapl_overflow.c プロジェクト: pyrovski/papi-rapl
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long values0[2],values1[2],values2[2];
	int num_flops = 3000000, retval;
	int mythreshold = 1000000;
	char event_name1[PAPI_MAX_STR_LEN];
        int PAPI_event;
	int cid,numcmp,rapl_cid;
	const PAPI_component_info_t *cmpinfo = NULL;

	/* Set TESTS_QUIET variable */
	tests_quiet( argc, argv );      

	quiet=TESTS_QUIET;

	/* Init PAPI */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
	  test_fail(__FILE__, __LINE__,"PAPI_library_init",retval);
	}

	numcmp = PAPI_num_components();

	for(cid=0; cid<numcmp; cid++) {

	  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	    test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
	  }

	  if (strstr(cmpinfo->name,"linux-rapl")) {
	    rapl_cid=cid;
	    if (!TESTS_QUIET) printf("Found rapl component at cid %d\n",
				     rapl_cid);
	    if (cmpinfo->num_native_events==0) {
              test_skip(__FILE__,__LINE__,"No rapl events found",0);
	    }
	    break;
	  }
	}

	/* Component not found */
	if (cid==numcmp) {
	  test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
	}


	/* add PAPI_TOT_CYC and PAPI_TOT_INS */
	retval=PAPI_create_eventset(&EventSet);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval);
	}

	retval=PAPI_add_event(EventSet,PAPI_TOT_CYC);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}

	retval=PAPI_add_event(EventSet,PAPI_TOT_INS);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}

	/* Add some RAPL events */
	retval=PAPI_create_eventset(&EventSet2);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval);
	}

        retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE0");
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}

        retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE1");
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}
	
	PAPI_event=PAPI_TOT_CYC;

	/* arbitrary */
	mythreshold = 2000000;
	if (!TESTS_QUIET) {
	   printf("Using %x for the overflow event, threshold %d\n",
		  PAPI_event,mythreshold);
	}

	/* Start the run calibration run */
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_start",retval);
	}

	do_ints(num_flops,TESTS_QUIET);
	do_flops( 3000000 );

	/* stop the calibration run */
	retval = PAPI_stop( EventSet, values0 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_stop",retval);
	}


	/* set up overflow handler */
	retval = PAPI_overflow( EventSet,PAPI_event,mythreshold, 0, handler );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_overflow",retval);
	}

	/* Start overflow run */
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_start",retval);
	}
	retval = PAPI_start( EventSet2 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_start",retval);
	}

	do_ints(num_flops,TESTS_QUIET);
	do_flops( num_flops );

	/* stop overflow run */
	retval = PAPI_stop( EventSet, values1 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_stop",retval);
	}

	retval = PAPI_stop( EventSet2, values2 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_stop",retval);
	}

	retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_overflow",retval);
	}

	retval = PAPI_event_code_to_name( PAPI_event, event_name1 );
	if (retval != PAPI_OK) {
	   test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n", retval);
	}

	if (!TESTS_QUIET) {
	   printf("%s: %lld %lld\n",event_name1,values0[0],values1[0]);
	}

	retval = PAPI_event_code_to_name( PAPI_TOT_INS, event_name1 );
	if (retval != PAPI_OK) {
	  test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n",retval);
	}

	if (!TESTS_QUIET) {
	   printf("%s: %lld %lld\n",event_name1,values0[1],values1[1]);
	}

	retval = PAPI_cleanup_eventset( EventSet );
	if ( retval != PAPI_OK ) {
	  test_fail(__FILE__, __LINE__,"PAPI_cleanup_eventset",retval);
	}

	retval = PAPI_destroy_eventset( &EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_destroy_eventset",retval);
	}

	if (rapl_backward) {
	   test_fail(__FILE__, __LINE__,"RAPL counts went backward!",0);
	}

	test_pass( __FILE__, NULL, 0 );


	return 0;
}
コード例 #4
0
int HWCBE_PAPI_Start_Set (UINT64 countglops, UINT64 time, int numset, int threadid)
{
#if defined(PAPI_SAMPLING_SUPPORT)
	int i;
#endif
	int rc;

	/* The given set is a valid one? */
	if (numset < 0 || numset >= HWC_num_sets)
		return FALSE;

	HWC_current_changeat = HWC_sets[numset].change_at;
	HWC_current_changetype = HWC_sets[numset].change_type;
	HWC_current_timebegin[threadid] = time;
	HWC_current_glopsbegin[threadid] = countglops;

	/* Mark this counter set as the current set */
	HWCEVTSET(threadid) = HWC_sets[numset].eventsets[threadid];

#if defined(PAPI_SAMPLING_SUPPORT)
	for (i = 0; i < HWC_sets[numset].NumOverflows; i++)
	{
		if (HWC_sets[numset].OverflowCounter[i] != NO_COUNTER)
		{
			rc = PAPI_overflow (HWCEVTSET(threadid), HWC_sets[numset].OverflowCounter[i],
			  HWC_sets[numset].OverflowValue[i], 0, PAPI_sampling_handler);
			if (rc < 0)
			{
				setSamplingEnabled (FALSE);
				fprintf (stderr, PACKAGE_NAME": PAPI_overflow failed for thread %d - counter %x!\n", threadid, HWC_sets[numset].OverflowCounter[i]);
			}
			else
				setSamplingEnabled (TRUE);
		}
	}
#endif

	rc = PAPI_start (HWCEVTSET(threadid));
 	if (rc == PAPI_OK)
	{
		TRACE_EVENT (time, HWC_CHANGE_EV, numset);

#if defined(PAPI_SAMPLING_SUPPORT)
		if (HWC_sets[numset].NumOverflows > 0)
		{
			long long overflow_values[MAX_HWC];

			HARDWARE_COUNTERS_OVERFLOW(HWC_sets[numset].num_counters, 
			                           HWC_sets[numset].counters, 
			                           HWC_sets[numset].NumOverflows, 
			                           HWC_sets[numset].OverflowCounter,
			                           overflow_values);

			TRACE_EVENT_AND_GIVEN_COUNTERS (time, HWC_SET_OVERFLOW_EV, 0, MAX_HWC, overflow_values);
		}
#endif
	}
	else
	{
		fprintf (stderr, PACKAGE_NAME": PAPI_start failed to start eventset %d on thread %d! (error = %d)\n", numset+1, threadid, rc);
		if (rc == PAPI_ESYS)
		{
			perror ("PAPI_start");
			fprintf (stderr, PACKAGE_NAME": errno = %d\n", errno);
		}
	}

	return rc == PAPI_OK;
}
コード例 #5
0
void
mainloop( int arg )
{
	int retval, num_tests = 1;
	int EventSet1 = PAPI_NULL;
	int mask1 = 0x0;
	int num_events1;
	long long **values;
	int PAPI_event;
	char event_name[PAPI_MAX_STR_LEN];

	( void ) arg;

	if ( ( retval =
		   PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );


	/* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
	   PAPI_TOT_INS, depending on the availability of the event on the
	   platform */
	EventSet1 =
		add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 );

	values = allocate_test_space( num_tests, num_events1 );

	if ( ( retval =
		   PAPI_overflow( EventSet1, PAPI_event, THRESHOLD, 0,
						  handler ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	do_stuff(  );

	if ( ( retval = PAPI_start( EventSet1 ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_stuff(  );

	if ( ( retval = PAPI_stop( EventSet1, values[0] ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	/* clear the papi_overflow event */
	if ( ( retval =
		   PAPI_overflow( EventSet1, PAPI_event, 0, 0, NULL ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	if ( ( retval =
		   PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

	if ( !TESTS_QUIET ) {
		printf( "Thread %#x %s : \t%lld\n", ( int ) pthread_self(  ),
				event_name, ( values[0] )[0] );
		printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", ( int ) pthread_self(  ),
				( values[0] )[1] );
	}

	retval = PAPI_cleanup_eventset( EventSet1 );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

	retval = PAPI_destroy_eventset( &EventSet1 );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

	free_test_space( values, num_tests );
	PAPI_shutdown(  );
}
コード例 #6
0
int main(int argc, char **argv)
{
   int EventSet=PAPI_NULL;
   long long values[2] = { 0, 0 };
   long long min, max;
   int num_flops=NUM_FLOPS, retval;
   int PAPI_event=0, mythreshold;
   char event_name[PAPI_MAX_STR_LEN];
   const PAPI_hw_info_t *hw_info = NULL;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   hw_info = PAPI_get_hardware_info();
   if (hw_info == NULL)
     test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   if((!strncmp(hw_info->model_string, "UltraSPARC", 10) &&
       !(strncmp(hw_info->vendor_string, "SUN", 3))) ||
      (!strncmp(hw_info->model_string, "AMD K7", 6)) ||
      (!strncmp(hw_info->vendor_string, "Cray", 4)) ||
      (strstr(hw_info->model_string, "POWER3"))) {
   /* query and set up the right instruction to monitor */
      if (PAPI_query_event(PAPI_TOT_INS) == PAPI_OK) {
         PAPI_event = PAPI_TOT_INS;
      } else {
         test_fail(__FILE__, __LINE__, "PAPI_TOT_INS not available on this Sun platform!", 0);
      }
   } else {
   /* query and set up the right instruction to monitor */
      if (PAPI_query_event(PAPI_FP_INS) == PAPI_OK) {
         PAPI_event = PAPI_FP_INS;
      } else {
         if (PAPI_query_event(PAPI_FP_OPS) == PAPI_OK) 
            PAPI_event = PAPI_FP_OPS;
         else 
            PAPI_event = PAPI_TOT_INS;
      }
   }

   if ( PAPI_event == PAPI_FP_INS )
      mythreshold = THRESHOLD ;
   else 
#if defined(linux)
      mythreshold = hw_info->mhz*10000*2;
#else
      mythreshold = THRESHOLD*2;
#endif

   retval = PAPI_create_eventset(&EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

   retval = PAPI_add_event(EventSet, PAPI_event);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_add_event", retval);

   retval = PAPI_start(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_stop(EventSet, &values[0]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   retval = PAPI_overflow(EventSet, PAPI_event, mythreshold, 0, handler);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

   retval = PAPI_start(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_stop(EventSet, &values[1]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

#if defined(linux) || defined(__ia64__) || defined(_WIN32) || defined(_POWER4)
   num_flops *= 2;
#endif

   if (!TESTS_QUIET) {
      if ((retval = PAPI_event_code_to_name(PAPI_event, event_name)) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);

      printf("Test case: Overflow dispatch of 1st event in set with 1 event.\n");
      printf("--------------------------------------------------------------\n");
      printf("Threshold for overflow is: %d\n", mythreshold);
      printf("Using %d iterations of c += a*b\n", NUM_FLOPS);
      printf("-----------------------------------------------\n");

      printf("Test type    : %16d%16d\n", 1, 2);
      printf(OUT_FMT, event_name, values[0], values[1]);
      printf("Overflows    : %16s%16d\n", "", total);
      printf("-----------------------------------------------\n");

      printf("Verification:\n");
/*
	if (PAPI_event == PAPI_FP_INS)
		printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
	printf("Column 1 approximately equals column 2\n");
*/
      printf("Row 3 approximately equals %u +- %u %%\n",
             (unsigned) ((values[0]) / (long long) mythreshold),
             (unsigned) (OVR_TOLERANCE * 100.0));

   }

/*
  min = (long long)(values[0]*(1.0-TOLERANCE));
  max = (long long)(values[0]*(1.0+TOLERANCE));
  if ( values[1] > max || values[1] < min )
  	test_fail(__FILE__, __LINE__, event_name, 1);
*/

   min = (long long) ((values[0] * (1.0 - OVR_TOLERANCE)) / (long long) mythreshold);
   max = (long long) ((values[0] * (1.0 + OVR_TOLERANCE)) / (long long) mythreshold);
   if (total > max || total < min)
      test_fail(__FILE__, __LINE__, "Overflows", 1);

   test_pass(__FILE__, NULL, 0);
   exit(1);
}
コード例 #7
0
int main(int argc, char **argv)
{
   int EventSet=PAPI_NULL;
   long long(values[2])[2];
   long long min, max;
   int num_flops = NUM_FLOPS, retval;
   int PAPI_event, mythreshold=THRESHOLD;
   char event_name[PAPI_MAX_STR_LEN];
   const PAPI_hw_info_t *hw_info = NULL;
   int num_events, mask; 

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   hw_info = PAPI_get_hardware_info();
   if (hw_info == NULL)
     test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
      PAPI_TOT_INS, depending on the availability of the event on the
      platform */
   EventSet = add_two_nonderived_events(&num_events, &PAPI_event, hw_info, &mask);

   if ( PAPI_event == PAPI_FP_INS )
      mythreshold = THRESHOLD ;
   else 
#if defined(linux)
      mythreshold = hw_info->mhz*10000*2;
#else
      mythreshold = THRESHOLD*2;
#endif

   retval = PAPI_start(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_stop(EventSet, values[0]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   retval = PAPI_overflow(EventSet, PAPI_event, mythreshold, 0, handler);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

   retval = PAPI_start(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_flops(num_flops);

   retval = PAPI_stop(EventSet, values[1]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);
   retval = PAPI_overflow(EventSet, PAPI_event, 0, 0, handler);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

   if (!TESTS_QUIET) {
      if ((retval = PAPI_event_code_to_name(PAPI_event, event_name)) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);

      printf("Test case: Overflow dispatch of 2nd event in set with 2 events.\n");
      printf("---------------------------------------------------------------\n");
      printf("Threshold for overflow is: %d\n", mythreshold);
      printf("Using %d iterations of c += a*b\n", num_flops);
      printf("-----------------------------------------------\n");

      printf("Test type    : %16d%16d\n", 1, 2);
      printf(OUT_FMT, event_name, (values[0])[0], (values[1])[0]);
      printf(OUT_FMT, "PAPI_TOT_CYC", (values[0])[1], (values[1])[1]);
      printf("Overflows    : %16s%16d\n", "", total);
      printf("-----------------------------------------------\n");
   }

   retval = PAPI_cleanup_eventset(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval);

   retval = PAPI_destroy_eventset(&EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval);

   if (!TESTS_QUIET) {
      printf("Verification:\n");
#if defined(linux) || defined(__ia64__) || defined(_WIN32) || defined(_POWER4)
   num_flops *= 2;
#endif
      if (PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS){
         printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
      }
      printf("Column 1 approximately equals column 2\n");
      printf("Row 3 approximately equals %u +- %u %%\n",
             (unsigned) ((values[0])[0] / (long long) mythreshold),
             (unsigned) (OVR_TOLERANCE * 100.0));
   }
/*
  min = (long long)((values[0])[1]*(1.0-TOLERANCE));
  max = (long long)((values[0])[1]*(1.0+TOLERANCE));
  if ( (values[0])[1] > max || (values[0])[1] < min )
  	test_fail(__FILE__, __LINE__, event_name, 1);
*/

   min = (long long) (((values[0])[0] * (1.0 - OVR_TOLERANCE)) / (long long) mythreshold);
   max = (long long) (((values[0])[0] * (1.0 + OVR_TOLERANCE)) / (long long) mythreshold);
   printf("Overflows: total(%d) > max(%lld) || total(%d) < min(%lld) ", total, max, total, min);
   if (total > max || total < min)
      test_fail(__FILE__, __LINE__, "Overflows", 1);

   test_pass(__FILE__, NULL, 0);
   exit(1);
}
コード例 #8
0
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long *values;
	int num_flops, retval, i, j;
	int *events, mythreshold;
	char **names;
	const PAPI_hw_info_t *hw_info = NULL;
	int num_events, *ovt;
	char name[PAPI_MAX_STR_LEN];
	const PAPI_component_info_t *comp_info = NULL;
	int using_perfmon = 0;
	int using_aix = 0;
	int numcmp, cid;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
	   test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
	}

	hw_info = PAPI_get_hardware_info(  );
	if ( hw_info == NULL ) {
	   test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", retval );
	}

        numcmp = PAPI_num_components(  );

	for ( cid = 0; cid < numcmp; cid++ ) {

	    comp_info = PAPI_get_component_info( cid );
	    if ( comp_info == NULL ) {
	       test_fail( __FILE__, __LINE__, "PAPI_get_component_info", retval );
	    }

	    if ( strstr( comp_info->name, "perfmon.c" ) ) {
	       using_perfmon = 1;
	    }

	    if ( strstr( comp_info->name, "aix.c" ) ) {
	       using_aix = 1;
	    }
	}

	/* add PAPI_TOT_CYC and one of the events in */
	/* PAPI_FP_INS, PAPI_FP_OPS PAPI_TOT_INS,    */
        /* depending on the availability of the event*/
	/* on the platform */
	EventSet = enum_add_native_events( &num_events, &events, 1 , 1);

	if (!TESTS_QUIET) printf("Trying %d events\n",num_events);

	names = ( char ** ) calloc( ( unsigned int ) num_events, 
				    sizeof ( char * ) );

	for ( i = 0; i < num_events; i++ ) {
	   if ( PAPI_event_code_to_name( events[i], name ) != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__,"PAPI_event_code_to_name", retval);
	   }
	   else {
	      names[i] = strdup( name );
	      if (!TESTS_QUIET) printf("%i: %s\n",i,names[i]);
	   }
	}

	values = ( long long * )
		calloc( ( unsigned int ) ( num_events * ( num_events + 1 ) ),
				sizeof ( long long ) );
	ovt = ( int * ) calloc( ( unsigned int ) num_events, sizeof ( int ) );

#if defined(linux)
	{
		char *tmp = getenv( "THRESHOLD" );
		if ( tmp ) {
			mythreshold = atoi( tmp );
		}
		else if (hw_info->mhz!=0) {
		   mythreshold = ( int ) hw_info->mhz * 20000;
		  if (!TESTS_QUIET) printf("Using a threshold of %d (20,000 * MHz)\n",mythreshold);

		}
		else {
		  if (!TESTS_QUIET) printf("Using default threshold of %d\n",THRESHOLD);
		   mythreshold = THRESHOLD;
		}
	}
#else
	mythreshold = THRESHOLD;
#endif

	num_flops = NUM_FLOPS * 2;

	   /* initial test to make sure they all work */
	if (!TESTS_QUIET) printf("Testing that the events all work with no overflow\n");

       	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );
	}

	do_flops( num_flops );

	retval = PAPI_stop( EventSet, values );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	}

	/* done with initial test */

	/* keep adding events? */
	for ( i = 0; i < num_events; i++ ) {

	      /* Enable overflow */
	   if (!TESTS_QUIET) printf("Testing with overflow set on %s\n",
				   names[i]);

	   retval = PAPI_overflow( EventSet, events[i], 
					mythreshold, 0, handler );
	   if ( retval != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	   }

       	   retval = PAPI_start( EventSet );
	   if ( retval != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
	   }
		
	   do_flops( num_flops );

	   retval = PAPI_stop( EventSet, values + ( i + 1 ) * num_events );
	   if ( retval != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	   }

	      /* Disable overflow */
	   retval = PAPI_overflow( EventSet, events[i], 0, 0, handler );
	   if ( retval != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	   }
	   ovt[i] = total;
	   total = 0;
	}

	if ( !TESTS_QUIET ) {

	   printf("\nResults in Matrix-view:\n");
	   printf( "Test Overflow on %d counters with %d events.\n", 
		   num_events,num_events );
	   printf( "-----------------------------------------------\n" );
	   printf( "Threshold for overflow is: %d\n", mythreshold );
	   printf( "Using %d iterations of c += a*b\n", num_flops );
	   printf( "-----------------------------------------------\n" );

	   printf( "Test type                   : " );
	   for ( i = 0; i < num_events + 1; i++ ) {
	       printf( "%16d", i );
	   }
	   printf( "\n" );
	   for ( j = 0; j < num_events; j++ ) {
	       printf( "%-27s : ", names[j] );
	       for ( i = 0; i < num_events + 1; i++ ) {
		   printf( "%16lld", *( values + j + num_events * i ) );
	       }
	       printf( "\n" );
	   }
	   printf( "Overflows                   : %16s", "" );
	   for ( i = 0; i < num_events; i++ ) {
	       printf( "%16d", ovt[i] );
	   }
	   printf( "\n" );
	   printf( "-----------------------------------------------\n" );
	}

	/* validation */

	if ( !TESTS_QUIET ) {
	   printf("\nResults broken out for validation\n");
	}

	if (!TESTS_QUIET) {

	for ( j = 0; j < num_events+1; j++ ) {
	  if (j==0) {
             printf("Test results, no overflow:\n\t");
	  }
	  else {
	    printf("Overflow of event %d, %s\n\t",j-1,names[j-1]);
	  }
	  for(i=0; i < num_events; i++) {
	    if (i==j-1) {
	      printf("*%lld* ",values[(num_events*j)+i]);
	    }
	    else {
	      printf("%lld ",values[(num_events*j)+i]);
	    }
	  }
          printf("\n");
	  if (j!=0) {
	     printf("\tOverflow should be %lld / %d = %lld\n",
		 values[(num_events*j)+(j-1)],
		 mythreshold,
		 values[(num_events*j)+(j-1)]/mythreshold);
	     printf("\tOverflow was %d\n",ovt[j-1]);
	  }
	}
	}

	for ( j = 0; j < num_events; j++ ) {
		//printf("Validation: %lld / %d != %d (%lld)\n",
		//       *( values + j + num_events * (j+1) ) ,
		//       mythreshold,
		//       ovt[j],
		//       *(values+j+num_events*(j+1))/mythreshold);
		if ( *( values + j + num_events * ( j + 1 ) ) / mythreshold != ovt[j] ) {
			char error_string[BUFSIZ];

			if ( using_perfmon )
				test_warn( __FILE__, __LINE__,
						   "perfmon substrate handles overflow differently than perf_events",
						   1 );
			else if ( using_aix )
				test_warn( __FILE__, __LINE__,
						   "AIX (pmapi) substrate handles overflow differently than various other substrates",
						   1 );
			else {
				sprintf( error_string,
						 "Overflow value differs from expected %lld / %d != %d (%lld)",
						 *( values + j + num_events * ( j + 1 ) ), mythreshold,
						 ovt[j],
						 *( values + j +
							num_events * ( j + 1 ) ) / mythreshold );
				test_fail( __FILE__, __LINE__, error_string, 1 );
			}
		}
	}

	retval = PAPI_cleanup_eventset( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

	retval = PAPI_destroy_eventset( &EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

	free( ovt );
	for ( i = 0; i < num_events; i++ )
		free( names[i] );
	free( names );
	free( events );
	free( values );
	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
コード例 #9
0
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long ( values[3] )[2];
	int retval;
	int PAPI_event, k, idx[4];
	char event_name[3][PAPI_MAX_STR_LEN];
	int num_events1;
	int threshold = THRESHOLD;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	if ( ( retval =
		   PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	/* decide which of PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS to add,
	   depending on the availability and derived status of the event on
	   this platform */
	if ( ( PAPI_event = find_nonderived_event(  ) ) == 0 )
		test_fail( __FILE__, __LINE__, "no PAPI_event", 0 );

	if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
	if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_flops( NUM_FLOPS );

	if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	/* Set both overflows after adding both events (batch) */
	if ( ( retval =
		   PAPI_overflow( EventSet, PAPI_event, threshold, 0,
						  handler_batch ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	if ( ( retval =
		   PAPI_overflow( EventSet, PAPI_TOT_CYC, threshold, 0,
						  handler_batch ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_flops( NUM_FLOPS );

	retval = PAPI_stop( EventSet, values[1] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	num_events1 = 1;
	retval =
		PAPI_get_overflow_event_index( EventSet, 1, &idx[0], &num_events1 );
	if ( retval != PAPI_OK )
		printf( "PAPI_get_overflow_event_index error: %s\n",
				PAPI_strerror( retval ) );

	num_events1 = 1;
	retval =
		PAPI_get_overflow_event_index( EventSet, 2, &idx[1], &num_events1 );
	if ( retval != PAPI_OK )
		printf( "PAPI_get_overflow_event_index error: %s\n",
				PAPI_strerror( retval ) );

	if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

	/* Add each event and set its overflow (interleaved) */
	if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
	if ( ( retval =
		   PAPI_overflow( EventSet, PAPI_event, threshold, 0,
						  handler_interleaf ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
	if ( ( retval =
		   PAPI_overflow( EventSet, PAPI_TOT_CYC, threshold, 0,
						  handler_interleaf ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_flops( NUM_FLOPS );

	if ( ( retval = PAPI_stop( EventSet, values[2] ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	num_events1 = 1;
	retval =
		PAPI_get_overflow_event_index( EventSet, 1, &idx[2], &num_events1 );
	if ( retval != PAPI_OK )
		printf( "PAPI_get_overflow_event_index error: %s\n",
				PAPI_strerror( retval ) );

	num_events1 = 1;
	retval =
		PAPI_get_overflow_event_index( EventSet, 2, &idx[3], &num_events1 );
	if ( retval != PAPI_OK )
		printf( "PAPI_get_overflow_event_index error: %s\n",
				PAPI_strerror( retval ) );

	if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

	if ( ( retval =
		   PAPI_event_code_to_name( PAPI_event, event_name[0] ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

	if ( ( retval =
		   PAPI_event_code_to_name( PAPI_TOT_CYC, event_name[1] ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

	strcpy( event_name[2], "Unknown" );

	printf
		( "Test case: Overflow dispatch of both events in set with 2 events.\n" );
	printf
		( "---------------------------------------------------------------\n" );
	printf( "Threshold for overflow is: %d\n", threshold );
	printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
	printf( "-----------------------------------------------\n" );

	printf( "Test type    : %18s%18s%18s\n", "1 (no overflow)", "2 (batch)",
			"3 (interleaf)" );
	printf( OUT_FMT, event_name[0], ( values[0] )[0], ( values[1] )[0],
			( values[2] )[0] );
	printf( OUT_FMT, event_name[1], ( values[0] )[1], ( values[1] )[1],
			( values[2] )[1] );
	printf( "\n" );

	printf( "Predicted overflows at event %-12s : %6d\n", event_name[0],
			( int ) ( ( values[0] )[0] / threshold ) );
	printf( "Predicted overflows at event %-12s : %6d\n", event_name[1],
			( int ) ( ( values[0] )[1] / threshold ) );

	printf( "\nBatch overflows (add, add, over, over):\n" );
	for ( k = 0; k < 2; k++ ) {
		if ( overflow_counts[0][k].mask ) {
			printf( VEC_FMT, ( long long ) overflow_counts[0][k].mask,
					event_name[idx[k]], overflow_counts[0][k].count );
		}
	}

	printf( "\nInterleaved overflows (add, over, add, over):\n" );
	for ( k = 0; k < 2; k++ ) {
		if ( overflow_counts[1][k].mask )
			printf( VEC_FMT, 
				( long long ) overflow_counts[1][k].mask,
				event_name[idx[k + 2]], 
				overflow_counts[1][k].count );
	}

	printf( "\nCases 2+3 Unknown overflows: %d\n", total_unknown );
	printf( "-----------------------------------------------\n" );

	if ( overflow_counts[0][0].count == 0 || overflow_counts[0][1].count == 0 )
		test_fail( __FILE__, __LINE__, "a batch counter had no overflows", 1 );

	if ( overflow_counts[1][0].count == 0 || overflow_counts[1][1].count == 0 )
		test_fail( __FILE__, __LINE__,
				   "an interleaved counter had no overflows", 1 );

	if ( total_unknown > 0 )
		test_fail( __FILE__, __LINE__, "Unknown counter had overflows", 1 );

	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
コード例 #10
0
ファイル: PAPI_overflow.c プロジェクト: FMCalisto/SMP
int main ()
{
   int EventSet = PAPI_NULL;	
   /* must be set to null before calling PAPI_create_eventset */

   char errstring[PAPI_MAX_STR_LEN];
   long long (values[2])[2];
   int retval, i;
   double tmp = 0;
   int PAPI_event;		/* a place holder for an event preset */
   char event_name[PAPI_MAX_STR_LEN];


   /****************************************************************************
   *  This part initializes the library and compares the version number of the *
   * header file, to the version of the library, if these don't match then it  *
   * is likely that PAPI won't work correctly.If there is an error, retval     *
   * keeps track of the version number.                                        *
   ****************************************************************************/

   if ((retval = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
   {
      printf("Library initialization error! \n");
      exit(1);
   }

   /* Here we create the eventset */
   if ((retval=PAPI_create_eventset (&EventSet)) != PAPI_OK)
      ERROR_RETURN(retval);

   PAPI_event = PAPI_TOT_INS;

   /* Here we are querying for the existence of the PAPI presets  */
   if (PAPI_query_event (PAPI_TOT_INS) != PAPI_OK)
   {
      PAPI_event = PAPI_TOT_CYC;

      if ((retval=PAPI_query_event (PAPI_TOT_INS)) != PAPI_OK)
         ERROR_RETURN(retval);

      printf ("PAPI_TOT_INS not available on this platform.");
      printf (" so subst PAPI_event with PAPI_TOT_CYC !\n\n");

   }


   /* PAPI_event_code_to_name is used to convert a PAPI preset from 
     its integer value to its string name. */
   if ((retval = PAPI_event_code_to_name (PAPI_event, event_name)) != PAPI_OK)
      ERROR_RETURN(retval);

   /* add event to the event set */
   if ((retval = PAPI_add_event (EventSet, PAPI_event)) != PAPI_OK)
      ERROR_RETURN(retval);

   /* register overflow and set up threshold */
   /* The threshold "THRESHOLD" was set to 100000 */
   if ((retval = PAPI_overflow (EventSet, PAPI_event, THRESHOLD, 0,
		                       handler)) != PAPI_OK)
      ERROR_RETURN(retval);

   printf ("Here are the addresses at which overflows occured and overflow vectors \n");
  printf ("--------------------------------------------------------------\n");


  /* Start counting */

   if ( (retval=PAPI_start (EventSet)) != PAPI_OK)
      ERROR_RETURN(retval);

   for (i = 0; i < 2000000; i++)
   {
      tmp = 1.01 + tmp;
      tmp++;
   }

   /* Stops the counters and reads the counter values into the values array */
   if ( (retval=PAPI_stop (EventSet, values[0])) != PAPI_OK)
      ERROR_RETURN(retval);


   printf ("The total no of overflows was %d\n", total);

   /* clear the overflow status */
   if ((retval = PAPI_overflow (EventSet, PAPI_event, 0, 0,
		                       handler)) != PAPI_OK)
      ERROR_RETURN(retval);

   /************************************************************************
    * PAPI_cleanup_eventset can only be used after the counter has been    *
    * stopped then it remove all events in the eventset                    *
    ************************************************************************/
   if ( (retval=PAPI_cleanup_eventset (EventSet)) != PAPI_OK)
      ERROR_RETURN(retval);

   /* Free all memory and data structures, EventSet must be empty. */
   if ( (retval=PAPI_destroy_eventset(&EventSet)) != PAPI_OK)
      ERROR_RETURN(retval);

   /* free the resources used by PAPI */ 
   PAPI_shutdown();

   exit(0);
}
コード例 #11
0
int main(int argc, char **argv)
{
   int EventSet=PAPI_NULL;
   long long *values;
   int num_flops, retval, i, j;
   int *events, mythreshold;
   char **names;
   const PAPI_hw_info_t *hw_info = NULL;
   int num_events, *ovt; 
   char name[PAPI_MAX_STR_LEN];

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   hw_info = PAPI_get_hardware_info();
   if (hw_info == NULL)
     test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
      PAPI_TOT_INS, depending on the availability of the event on the
      platform */
   EventSet = enum_add_native_events(&num_events, &events);
   names = (char **)calloc(num_events, sizeof(char *));
   for(i=0;i<num_events;i++){
     if (PAPI_event_code_to_name(events[i], name) != PAPI_OK) 
       test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);
     else
       names[i] = strdup(name);
   }
   values = (long long *)calloc(num_events*(num_events+1), sizeof(long long));
   ovt = (int *)calloc(num_events, sizeof(int));

#if defined(linux)
     {
       char *tmp = getenv("THRESHOLD");
       if (tmp) 
	     mythreshold = atoi(tmp);
       else
	     mythreshold = hw_info->mhz*10000*2;
     }
#else
      mythreshold = THRESHOLD;
#endif

   num_flops = NUM_FLOPS*2;

   retval = PAPI_start(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_flops(num_flops);

   retval = PAPI_stop(EventSet, values);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   for(i=0;i<num_events;i++){
     retval = PAPI_overflow(EventSet, events[i], mythreshold, 0, handler);
     if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

     retval = PAPI_start(EventSet);
     if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_start", retval);

     do_flops(num_flops);

     retval = PAPI_stop(EventSet, values+(i+1)*num_events);
     if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_stop", retval);
     retval = PAPI_overflow(EventSet, events[i], 0, 0, handler);
     if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);
     ovt[i] = total;
     total=0;
   }

   if (!TESTS_QUIET) {

      printf("Test Overflow on %d counters with %d events.\n", num_events, num_events);
      printf("---------------------------------------------------------------\n");
      printf("Threshold for overflow is: %d\n", mythreshold);
      printf("Using %d iterations of c += a*b\n", num_flops);
      printf("-----------------------------------------------\n");

      printf("Test type                   : ");
      for(i=0;i<num_events+1;i++)
        printf("%16d", i);
      printf("\n");
      for(j=0;j<num_events;j++){
        printf("%-27s : ", names[j]);
        for(i=0;i<num_events+1;i++)
          printf("%16lld", *(values+j+num_events*i));
        printf("\n");
      }
      printf("Overflows                   : %16s", "");
      for(i=0;i<num_events;i++)
        printf("%16d", ovt[i]);
      printf("\n");
      printf("-----------------------------------------------\n");
   }

   retval = PAPI_cleanup_eventset(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval);

   retval = PAPI_destroy_eventset(&EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval);

   free(ovt);
   for(i=0;i<num_events;i++)
     free(names[i]);
   free(names);
   free(events);
   free(values);
   test_pass(__FILE__, NULL, 0);
   exit(1);
}
コード例 #12
0
ファイル: overflow_index.c プロジェクト: FMCalisto/SMP
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long ( values[3] )[2];
	int retval;
	int PAPI_event, k, i;
	char event_name[PAPI_MAX_STR_LEN];
	int index_array[2], number;
	int num_events1, mask1;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	/* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
	   PAPI_TOT_INS, depends on the availability of the event on the
	   platform */
	EventSet =
		add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 );

	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_flops( NUM_FLOPS );

	retval = PAPI_stop( EventSet, values[0] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	retval = PAPI_overflow( EventSet, PAPI_event, THRESHOLD, 0, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
	retval = PAPI_overflow( EventSet, PAPI_TOT_CYC, THRESHOLD, 0, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_flops( NUM_FLOPS );

	retval = PAPI_stop( EventSet, values[1] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	if ( ( retval =
		   PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

	printf
		( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
	printf
		( "---------------------------------------------------------------\n" );
	printf( "Threshold for overflow is: %d\n", THRESHOLD );
	printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
	printf( "-----------------------------------------------\n" );

	printf( "Test type    : %16d%16d\n", 1, 2 );
	printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] );
	printf( OUT_FMT, event_name, ( values[0] )[1], ( values[1] )[1] );

	if ( overflow_counts[0].count == 0 && overflow_counts[1].count == 0 )
		test_fail( __FILE__, __LINE__, "one counter had no overflows", 1 );

	for ( k = 0; k < 3; k++ ) {
		if ( overflow_counts[k].mask ) {
			number = 2;
			retval = PAPI_get_overflow_event_index( EventSet,
													overflow_counts[k].mask,
													index_array, &number );
			if ( retval != PAPI_OK )
				test_fail( __FILE__, __LINE__,
						   "PAPI_get_overflow_event_index", retval );
			printf( INDEX_FMT, ( long long ) overflow_counts[k].mask );
			printf( " counts: %d ", overflow_counts[k].count );
			for ( i = 0; i < number; i++ )
				printf( " Event Index %d ", index_array[i] );
			printf( "\n" );
		}
	}
	printf( "Case 2 %s Overflows: %d\n", "Unknown", total_unknown );
	printf( "-----------------------------------------------\n" );

	if ( total_unknown > 0 )
		test_fail( __FILE__, __LINE__, "Unknown counter had overflows", 1 );

	retval = PAPI_cleanup_eventset( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
コード例 #13
0
ファイル: overflow_values.c プロジェクト: FMCalisto/SMP
int
main( int argc, char *argv[] )
{
	int EventSet = PAPI_NULL;
	int retval, i, dash = 0, evt3 = PAPI_L1_DCM;
	PAPI_option_t options;
	PAPI_option_t options2;
	const PAPI_hw_info_t *hwinfo;
	long long lwrflow = 0, error, max_error = 0;
	long long vals[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT && retval > 0 )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	retval = PAPI_get_opt( PAPI_HWINFO, &options );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval );
	printf( "ovf_info = %d (%#x)\n", options.ovf_info.type,
			options.ovf_info.type );

	retval = PAPI_get_opt( PAPI_SUBSTRATEINFO, &options2 );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval );
	printf( "sub_info->hardware_intr = %d\n\n",
			options2.sub_info->hardware_intr );

	if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EMISC );

	printf( "Architecture %s, %d\n", hwinfo->model_string, hwinfo->model );

/* processing exceptions is a pain */
#if ((defined(linux) && (defined(__i386__) || (defined __x86_64__))) )
	if ( !strncmp( hwinfo->model_string, "Intel Pentium 4", 15 ) ) {
		evt3 = PAPI_L2_TCM;
	} else if ( !strncmp( hwinfo->model_string, "AMD K7", 6 ) ) {
		/* do nothing */
	} else if ( !strncmp( hwinfo->model_string, "AMD K8", 6 ) ) {
		/* do nothing */
	} else if ( !strncmp( hwinfo->model_string, "Intel Core", 10 ) ) {
		evt3 = 0;
	} else
		evt3 = 0;			 /* for default PIII */
#endif

	retval = PAPI_create_eventset( &EventSet );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	retval = PAPI_add_event( EventSet, PAPI_TOT_INS );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_INS", retval );
	retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_CYC", retval );
	if ( evt3 ) {
		retval = PAPI_add_event( EventSet, evt3 );
		if ( retval < 0 )
			test_fail( __FILE__, __LINE__, "PAPI_add_event:evt3", retval );
	}
	retval = PAPI_overflow( EventSet, PAPI_TOT_INS, OVRFLOW, 0, handler );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	retval = PAPI_start( EventSet );
	if ( retval < 0 )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	for ( i = 0; i < 1000000; i++ ) {
		if ( i % 1000 == 0 ) {
			int i;

			PAPI_read( EventSet, vals );
			if ( vals[0] % OVRFLOW > LOWERFLOW ||
				 vals[0] % OVRFLOW < UPPERFLOW ) {
				dash = 0;
				printf( "Main loop read vals :" );
				for ( i = 0; i < 3 /* 8 */ ; i++ )
					printf( "%lld ", vals[i] );
				printf( "\n" );
				if ( ovrflow ) {
					error = ovrflow - ( lwrflow + vals[0] ) / 2;
					printf( "Difference: %lld\n", error );
					ovrflow = 0;
					if ( abs( error ) > max_error )
						max_error = abs( error );
				}
				lwrflow = vals[0];
			} else if ( vals[0] % OVRFLOW > UPPERFLOW && !dash ) {
				dash = 1;
				printf( "---------------------\n" );
			}
		}
	}

	retval = PAPI_stop( EventSet, vals );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	retval = PAPI_cleanup_eventset( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

	retval = PAPI_destroy_eventset( &EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

	printf( "Verification:\n" );
	printf
		( "Maximum absolute difference between overflow value\nand adjacent measured values is: %lld\n",
		  max_error );
	if ( max_error >= ERRORFLOW ) {
		printf( "This exceeds the error limit: %d\n", ERRORFLOW );
		test_fail( __FILE__, __LINE__, "Overflows", 1 );
	}
	printf( "This is within the error limit: %d\n", ERRORFLOW );
	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
コード例 #14
0
ファイル: Knn_multihilos_papic.c プロジェクト: Cristofher/Knn
int main(int argc, char *argv[]) {


	float rtime1, rtime2, ptime1, ptime2, mflops;
	long long flpops;

	unsigned long int tid;
	int num_hwcntrs = 0;
	int fip = 0, retval;
	float real_time, proc_time;
	long long flpins;

	int i;
	unsigned int EventSet = PAPI_NULL; 
    int count = 0, err_count = 0;


    PAPI_event_info_t info;

    long long ( values2[2] )[2];
    long long min, max;
    int PAPI_event, mythreshold = THRESHOLD;
    char event_name1[PAPI_MAX_STR_LEN];
    const PAPI_hw_info_t *hw_info = NULL;
    int num_events, mask;
    int num_flops = NUM_FLOPS;
    long long elapsed_us, elapsed_cyc;



tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */



    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT )
      test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

  retval = PAPI_create_eventset( &EventSet );
  if ( retval != PAPI_OK )
      test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	/* Get hardware info */
  hw_info = PAPI_get_hardware_info(  );
  if ( hw_info == NULL )
      test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );

  EventSet = 	add_two_nonderived_events( &num_events, &PAPI_event, &mask );

  printf("Using %#x for the overflow event\n",PAPI_event);

  if ( PAPI_event == PAPI_FP_INS ) {
      mythreshold = THRESHOLD;
  }
  else {
		#if defined(linux)
      mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
		#else
      mythreshold = THRESHOLD * 2;
		#endif
  }

  retval = PAPI_start( EventSet );
  if ( retval != PAPI_OK )
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );

  do_flops( NUM_FLOPS );

	/* stop the calibration run */
  retval = PAPI_stop( EventSet, values2[0] );
  if ( retval != PAPI_OK )
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );


	/* set up overflow handler */
  retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
  if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
  }

	/* Start overflow run */
  retval = PAPI_start( EventSet );
  if ( retval != PAPI_OK ) {
      test_fail( __FILE__, __LINE__, "PAPI_start", retval );
  }

  do_flops( num_flops );

	/* stop overflow run */
  retval = PAPI_stop( EventSet, values2[1] );
  if ( retval != PAPI_OK )
      test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
  retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
  if ( retval != PAPI_OK )
      test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

  if ( !TESTS_QUIET ) {
      if ( ( retval =
         PAPI_event_code_to_name( PAPI_event, event_name1 ) ) != PAPI_OK )
         test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

     printf( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
     printf( "---------------------------------------------------------------\n" );
     printf( "Threshold for overflow is: %d\n", mythreshold );
     printf( "Using %d iterations\n", num_flops );
     printf( "-----------------------------------------------\n" );

     printf( "Test type    : %16d%16d\n", 1, 2 );
     printf( OUT_FMT, event_name1, ( values2[0] )[1], ( values2[1] )[1] );
     printf( OUT_FMT, "PAPI_TOT_CYC", ( values2[0] )[0], ( values2[1] )[0] );
     printf( "Overflows    : %16s%16d\n", "", total );
     printf( "-----------------------------------------------\n" );
 }

 retval = PAPI_cleanup_eventset( EventSet );
 if ( retval != PAPI_OK )
  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

retval = PAPI_destroy_eventset( &EventSet );
if ( retval != PAPI_OK )
  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

if ( !TESTS_QUIET ) {
  printf( "Verification:\n" );
#if defined(linux) || defined(__ia64__) || defined(_POWER4)
  num_flops *= 2;
#endif
  if ( PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS ) {
     printf( "Row 1 approximately equals %d %d\n", num_flops, num_flops );
 }
 printf( "Column 1 approximately equals column 2\n" );
 printf( "Row 3 approximately equals %u +- %u %%\n",( unsigned ) ( ( values2[0] )[1] / ( long long ) mythreshold ),( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
}

min =
( long long ) ( ( ( double ) values2[0][1] * ( 1.0 - OVR_TOLERANCE ) ) /
  ( double ) mythreshold );
max =
( long long ) ( ( ( double ) values2[0][1] * ( 1.0 + OVR_TOLERANCE ) ) /
  ( double ) mythreshold );
printf( "Overflows: total(%d) > max(%lld) || total(%d) < min(%lld) \n", total,
  max, total, min );
if ( total > max || total < min )
  test_fail( __FILE__, __LINE__, "Overflows", 1 );



printf("Initial thread id is: %lu\n",tid);

	/* Initialize the PAPI library and get the number of counters available */

if ((num_hwcntrs = PAPI_num_counters()) <= 0)  
  handle_error(1);



  /*  The installation supports PAPI, but has no counters */
if ((num_hwcntrs = PAPI_num_counters()) == 0 )
    fprintf(stderr,"Info:: This machine does not provide hardware counters.");

printf("This system has %d available counters.\n", num_hwcntrs);

if (num_hwcntrs > 2)
  num_hwcntrs = 2;

	 /* Start counting events */




if (PAPI_start_counters(Events, num_hwcntrs) != PAPI_OK)
  handle_error(1);

if (argc != 8) {
  printf("\nError :: Ejecutar como : a.out archivo_BD Num_elem archivo_queries Num_queries N_THREADS numero_K Dimension_objetos\n");
  return 0;
}
TOPK = atoi(argv[6]);
DIM = atoi(argv[7]);
double **DB;
	double **Consultas; //Cola de consultas
	int N_QUERIES, N_DB;
	char str_f[256];
	double dato[DIM];
	int j;
	FILE *f_dist, *fquery;
	Elem *heap, e_temp,*answer;
	int *acum, N_THREADS;


	//N_THREADS es el nro. de threads con el que se lanzará la región paralela
	N_THREADS = atoi(argv[5]);
	//N_QUERIES es el nro. de consultas
	N_QUERIES = atoi(argv[4]);
	N_DB = atoi(argv[2]);

	printf("\nN_QUERIES = %d\nN_THREADS = %d\n", N_QUERIES, N_THREADS);
	fflush(stdout);

	acum = (int *) malloc(sizeof (int)*N_THREADS);
	for (i = 0; i < N_THREADS; i++)
		acum[i] = 0;

	sprintf(str_f, "%s", argv[1]);
	printf("\nAbriendo %s... ", argv[1]);
	fflush(stdout);
	f_dist = fopen(str_f, "r");
	printf("OK\n");
	fflush(stdout);


	Consultas = (double **) malloc(sizeof (double *)*N_QUERIES);
	for (i = 0; i < N_QUERIES; i++)
		Consultas[i] = (double *) malloc(sizeof (double)*DIM);

	DB = (double **) malloc(sizeof (double *)*N_DB);
	for (i = 0; i < N_DB; i++)
		DB[i] = (double *) malloc(sizeof (double)*DIM);

	answer = (Elem *)malloc(sizeof(Elem)*N_QUERIES*TOPK);

	printf("\nCargando DB... ");
	fflush(stdout);
	for (i = 0; i < N_DB; i++) {
		//Usar leedato_cophir() cuando se utilice la BD Cophir para no tener problemas con las ","
		//if (leedato_cophir(dato, f_dist) == ERROR || feof(f_dist))
		if (leedato(dato, f_dist) == ERROR || feof(f_dist)) {
			printf("\n\nERROR :: N_DB mal establecido\n\n");
			fflush(stdout);
			fclose(f_dist);
			break;
		}
		copiavalor(DB[i], dato);
	}
	fclose(f_dist);
	printf("OK\n");
	fflush(stdout);

	if ((fquery = fopen(argv[3], "r")) == NULL)
		printf("Error al abrir para lectura el archivo de qeuries: %s\n", argv[3]);
	else
		printf("Abriendo  para lectura %s\n", argv[3]);
	printf("\nCargando Consultas... ");
	fflush(stdout);
	for (i = 0; i < N_QUERIES; i++) {
		//Usar leedato_cophir() cuando se utilice la BD Cophir para no tener problemas con las ","
		//if (leedato_cophir(dato, fquery) == ERROR || feof(fquery))
		if (leedato(dato, fquery) == ERROR || feof(fquery)) {
			printf("\n\nERROR :: N_QUERIES mal establecido, Menos queries que las indicadas\n\n");
			fflush(stdout);
			fclose(fquery);
			break;
		}
		copiavalor(Consultas[i], dato);
	}
	fclose(fquery);
	printf("OK\n");
	fflush(stdout);

	PAPI_start_counters((int*) Events, NUM_EVENTS);
	omp_set_num_threads(N_THREADS);

	elapsed_us = PAPI_get_real_usec(  );

	elapsed_cyc = PAPI_get_real_cyc(  );

	retval =
	PAPI_thread_init( ( unsigned
		long ( * )( void ) ) ( omp_get_thread_num ) );
	if ( retval != PAPI_OK ) {
		if ( retval == PAPI_ECMP )
			test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
		else
			test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
	}

#pragma omp parallel shared(Consultas, DB, N_QUERIES, N_DB, N_THREADS, acum, DIM)
	{
		float real_time;
		struct timeval t1, t2;
		int i, j;
		Elem *heap, e_temp;
		double d;
		int n_elem = 0;
		int trid = omp_get_thread_num(); //ID del thread
		int procs = omp_get_num_threads(); //Nro. total de threads
		double suma = 0;

		suma = 0;
		heap = (Elem *) malloc(sizeof (Elem) * TOPK);

#pragma omp barrier

#pragma omp master
		{
			gettimeofday(&t1, 0);
		}

		//Cada hilo accede a un subconjunto de las consultas. Cada hio accede de manera circular al arreglo de consultas.
        for (i = trid; i < N_QUERIES; i += procs) {
         n_elem = 0;
         for (j = 0; j < N_DB; j++) {

            d = distancia(Consultas[i], DB[j]);
				//Si la distancia del objeto a la consulta es menor que la raíz del heap, entonces se inserta en el heap. La raíz siempre mantiene la mayor de las distancias

            if(n_elem<TOPK){
               e_temp.dist = d;
               e_temp.ind = j;
               inserta2(heap, &e_temp, &n_elem);
           }
           if (n_elem==TOPK){
               if (d < topH(heap, &n_elem)) {
                  e_temp.dist = d;
                  e_temp.ind = j;
					//Si el heap no está lleno, se inserta el elemento
                  if (n_elem < TOPK)
                     inserta2(heap, &e_temp, &n_elem);
						//Si el heap está lleno, se inserta el elemento nuevo y se saca el que era antes de mayor de distancia. popush2() hace las operaciones de sacar el elemento mayor e insertar el nuevo.
                 else
                     popush2(heap, &n_elem, &e_temp);
             }}
         }

			//En este punto del código se tienen los K elemntos más cercanos a la consulta en 'heap'. Se pueden extraer con extraer2()
         for (j = 0; j < TOPK ; j++) {
           extrae2(heap, &n_elem, &e_temp);
           answer[i*TOPK+j].ind = e_temp.ind;
           answer[i*TOPK+j].dist = e_temp.dist;
       }
			//Realizamos una operación con los resultados para que el compilador no evite hacer instrucciones que considere que el usuario no utiliza. Simplemente cada hilo suma las distancias de los elementos mas cercanos a la consulta 
   }
   Thread( 1000000 * ( tid + 1 ) );



   fflush(stdout);

#pragma omp barrier

#pragma omp master
   {   

    if ( fip > 0 ) {
		/* Setup PAPI library and begin collecting data from the counters */
       if ( fip == 1 ) {
          if ( ( retval =
             PAPI_flips( &real_time, &proc_time, &flpins,
                &mflops ) ) < PAPI_OK )
             test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
     } else {
      if ( ( retval =
         PAPI_flops( &real_time, &proc_time, &flpins,
            &mflops ) ) < PAPI_OK )
         test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
 }

 gettimeofday(&t2, 0);
 real_time = (t2.tv_sec - t1.tv_sec) + (float) (t2.tv_usec - t1.tv_usec) / 1000000;

 Salida_Multihilo = fopen("Salida_Multihilo.txt", "w");
 for (i = 0; i < N_QUERIES; ++i){
  fprintf(Salida_Multihilo, "Consulta id:: %d\n",i);
  for (j = 0; j < TOPK; ++j){
     fprintf(Salida_Multihilo,"ind = %d :: dist = %f\n",answer[(i*TOPK)+j].ind,answer[(i*TOPK)+j].dist);
 }
 fprintf(Salida_Multihilo, "---------------------------------\n");
}
fclose(Salida_Multihilo);

printf("\n\nK = %d", TOPK);
printf("\nReal Time = %f segundos.\n", real_time);
fflush(stdout);


if ( fip == 1 ) {
  if ( ( retval =
     PAPI_flips( &real_time, &proc_time, &flpins,
        &mflops ) ) < PAPI_OK )
     test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
} else {
  if ( ( retval =
     PAPI_flops( &real_time, &proc_time, &flpins,
        &mflops ) ) < PAPI_OK )
     test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
}

if ( !TESTS_QUIET ) {
  if ( fip == 1 ) {
     printf( "Real_time: %f Proc_time: %f Total flpins: ", real_time,
        proc_time );
 } else {
     printf( "Real_time: %f Proc_time: %f Total flpops: ", real_time,
        proc_time );
 }
 printf( LLDFMT, flpins );
 printf( " MFLOPS: %f\n", mflops );
}
}

}
free(heap);



	}//end pragma omp parallel

	elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;
	elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;

	if ( !TESTS_QUIET ) {
		printf( "Master real usec   : \t%lld\n", elapsed_us );
		printf( "Master real cycles : \t%lld\n", elapsed_cyc );
	}

	const PAPI_hw_info_t *hwinfo = NULL;
	const PAPI_mh_tlb_info_t *mhinfo = NULL;
	const  PAPI_mh_cache_info_t *mhcacheinfo = NULL;
	const PAPI_mh_level_t *mhlevel = NULL;


	if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
		exit(1);
	if ((hwinfo = PAPI_get_hardware_info()) == NULL)
		exit(1);	
	if ((mhinfo = PAPI_get_hardware_info()) == NULL)
		exit(1);
	if ((mhcacheinfo = PAPI_get_hardware_info()) == NULL)
		exit(1);
	if ((mhlevel = PAPI_get_hardware_info()) == NULL)
		exit(1);

	printf("\n\nA continuación información actual del equipo\n\n");

	printf("MH Type %d - Num entries %d  - Associativity %d \n",mhinfo->type, mhinfo->num_entries, mhinfo->associativity);
	printf("Cache MH type %d size %d line size %d num_lines %d Associativity %d\n\n",mhcacheinfo->type, mhcacheinfo->size,mhcacheinfo->line_size, mhcacheinfo->num_lines, mhcacheinfo->associativity);



    retval=papi_print_header("Available PAPI preset and user defined events plus hardware information.\n",&hwinfo );


    printf("Total hardware flops = %lld\n",(float)values[1]);
    printf("L2 data cache misses is %lld\n", values[0]);






    retval = PAPI_stop_counters(values, NUM_EVENTS);
    return 0;
}
コード例 #15
0
ファイル: overflow2.c プロジェクト: jtombiamba/MABTools
int
main( int argc, char **argv )
{
    int EventSet = PAPI_NULL;
    long long ( values[2] )[2];
    long long min, max;
    int num_flops, retval;
    int PAPI_event, mythreshold;
    char event_name[PAPI_MAX_STR_LEN];
    const PAPI_hw_info_t *hw_info = NULL;

    tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT )
        test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

    hw_info = PAPI_get_hardware_info(  );
    if ( hw_info == NULL )
        test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );

#if defined(POWER3) || defined(__sparc__)
    PAPI_event = PAPI_TOT_INS;
#else
    /* query and set up the right instruction to monitor */
    PAPI_event = find_nonderived_event( );
#endif

    if (( PAPI_event == PAPI_FP_OPS ) || ( PAPI_event == PAPI_FP_INS ))
        mythreshold = THRESHOLD;
    else
#if defined(linux)
        mythreshold = ( int ) hw_info->cpu_max_mhz * 10000 * 2;
#else
        mythreshold = THRESHOLD * 2;
#endif

    retval = PAPI_create_eventset( &EventSet );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

    retval = PAPI_add_event( EventSet, PAPI_event );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

    retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

    retval = PAPI_start( EventSet );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_start", retval );

    do_flops( NUM_FLOPS );

    retval = PAPI_stop( EventSet, values[0] );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

    retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

    retval = PAPI_start( EventSet );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_start", retval );

    do_flops( NUM_FLOPS );

    retval = PAPI_stop( EventSet, values[1] );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

    retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

    num_flops = NUM_FLOPS;
#if defined(linux) || defined(__ia64__) || defined(_POWER4)
    num_flops *= 2;
#endif

    if ( !TESTS_QUIET ) {
        if ( ( retval =
                    PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
            test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

        printf
        ( "Test case: Overflow dispatch of 1st event in set with 2 events.\n" );
        printf
        ( "---------------------------------------------------------------\n" );
        printf( "Threshold for overflow is: %d\n", mythreshold );
        printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
        printf( "-----------------------------------------------\n" );

        printf( "Test type    : %16d%16d\n", 1, 2 );
        printf( OUT_FMT, event_name, ( values[0] )[0], ( values[1] )[0] );
        printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[1], ( values[1] )[1] );
        printf( "Overflows    : %16s%16d\n", "", total );
        printf( "-----------------------------------------------\n" );

        printf( "Verification:\n" );
        /*
        	if (PAPI_event == PAPI_FP_INS)
        		printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
        */
        /* Note that the second run prints output on stdout. On some systems
         * this is costly. PAPI_TOT_INS or PAPI_TOT_CYC are likely to be _very_
         * different between the two runs.
         * printf("Column 1 approximately equals column 2\n");
         */
        printf( "Row 3 approximately equals %u +- %u %%\n",
                ( unsigned ) ( ( values[0] )[0] / ( long long ) mythreshold ),
                ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
    }
    /*
      min = (long long)((values[0])[0]*(1.0-TOLERANCE));
      max = (long long)((values[0])[0]*(1.0+TOLERANCE));
      if ( (values[1])[0] > max || (values[1])[0] < min )
      	test_fail(__FILE__, __LINE__, event_name, 1);
    */

    min =
        ( long long ) ( ( ( double ) values[0][0] * ( 1.0 - OVR_TOLERANCE ) ) /
                        ( double ) mythreshold );
    max =
        ( long long ) ( ( ( double ) values[0][0] * ( 1.0 + OVR_TOLERANCE ) ) /
                        ( double ) mythreshold );
    if ( total > max || total < min )
        test_fail( __FILE__, __LINE__, "Overflows", 1 );

    test_pass( __FILE__, NULL, 0 );
    exit( 1 );
}
コード例 #16
0
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long hard_min, hard_max, soft_min, soft_max;
	int retval;
	int PAPI_event = 0, mythreshold;
	char event_name[PAPI_MAX_STR_LEN];
	PAPI_option_t opt;
	PAPI_event_info_t info;
	PAPI_option_t itimer;
	const PAPI_hw_info_t *hw_info = NULL;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	/* query and set up the right instruction to monitor */
	if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
		if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
			PAPI_get_event_info( PAPI_FP_INS, &info );
			if ( info.count == 1 || 
                             !strcmp( info.derived, "DERIVED_CMPD" ) )
				PAPI_event = PAPI_FP_INS;
		}
	}
	if ( PAPI_event == 0 ) {
		if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK ) {
			PAPI_get_event_info( PAPI_FP_OPS, &info );
			if ( info.count == 1 || 
                             !strcmp( info.derived, "DERIVED_CMPD" ) )
				PAPI_event = PAPI_FP_OPS;
		}
	}
	if ( PAPI_event == 0 ) {
		if ( PAPI_query_event( PAPI_TOT_INS ) == PAPI_OK ) {
			PAPI_get_event_info( PAPI_TOT_INS, &info );
			if ( info.count == 1 || 
                             !strcmp( info.derived, "DERIVED_CMPD" ) )
				PAPI_event = PAPI_TOT_INS;
		}
	}

	if ( PAPI_event == 0 )
		test_skip( __FILE__, __LINE__, "No suitable event for this test found!",
				   0 );

	hw_info = PAPI_get_hardware_info(  );
	if ( hw_info == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );

	if ( PAPI_event == PAPI_FP_INS )
		mythreshold = THRESHOLD;
	else
#if defined(linux)
		mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
#else
		mythreshold = THRESHOLD * 2;
#endif

	retval = PAPI_create_eventset( &EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	retval = PAPI_add_event( EventSet, PAPI_event );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

	retval = PAPI_get_opt( PAPI_COMPONENTINFO, &opt );
	if ( retval != PAPI_OK )
		test_skip( __FILE__, __LINE__,
				   "Platform does not support Hardware overflow", 0 );

	do_stuff(  );

	/* Do reference count */

	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_stuff(  );

	retval = PAPI_stop( EventSet, &values[use_total] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	use_total++;

	/* Now do hardware overflow reference count */

	retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_stuff(  );

	retval = PAPI_stop( EventSet, &values[use_total] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	use_total++;

	retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	/* Now do software overflow reference count, uses SIGPROF */

	retval =
		PAPI_overflow( EventSet, PAPI_event, mythreshold,
					   PAPI_OVERFLOW_FORCE_SW, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_stuff(  );

	retval = PAPI_stop( EventSet, &values[use_total] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	use_total++;

	retval =
		PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW,
					   handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	/* Now do software overflow with SIGVTALRM */

	memset( &itimer, 0, sizeof ( itimer ) );
	itimer.itimer.itimer_num = ITIMER_VIRTUAL;
	itimer.itimer.itimer_sig = SIGVTALRM;

	if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval );

	retval =
		PAPI_overflow( EventSet, PAPI_event, mythreshold,
					   PAPI_OVERFLOW_FORCE_SW, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_stuff(  );

	retval = PAPI_stop( EventSet, &values[use_total] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	use_total++;

	retval =
		PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW,
					   handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	/* Now do software overflow with SIGALRM */

	memset( &itimer, 0, sizeof ( itimer ) );
	itimer.itimer.itimer_num = ITIMER_REAL;
	itimer.itimer.itimer_sig = SIGALRM;
	if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval );

	retval =
		PAPI_overflow( EventSet, PAPI_event, mythreshold,
					   PAPI_OVERFLOW_FORCE_SW, handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	do_stuff(  );

	retval = PAPI_stop( EventSet, &values[use_total] );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	use_total++;

	retval =
		PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW,
					   handler );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );

	if ( !TESTS_QUIET ) {
		if ( ( retval =
			   PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );

		printf
			( "Test case: Software overflow of various types with 1 event in set.\n" );
		printf
			( "------------------------------------------------------------------------------\n" );
		printf( "Threshold for overflow is: %d\n", mythreshold );
		printf
			( "------------------------------------------------------------------------------\n" );

		printf( "Test type   : %11s%13s%13s%13s%13s\n", "Reference", "Hardware",
				"ITIMER_PROF", "ITIMER_VIRT", "ITIMER_REAL" );
		printf( "%-12s: %11lld%13lld%13lld%13lld%13lld\n", info.symbol,
				values[0], values[1], values[2], values[3], values[4] );
		printf( "Overflows   : %11d%13d%13d%13d%13d\n", total[0], total[1],
				total[2], total[3], total[4] );
		printf
			( "------------------------------------------------------------------------------\n" );

		printf( "Verification:\n" );

		printf
			( "Overflow in Column 2 greater than or equal to overflows in Columns 3, 4, 5\n" );
		printf( "Overflow in Columns 3, 4, 5 greater than 0\n" );
	}

	hard_min =
		( long long ) ( ( ( double ) values[0] * ( 1.0 - OVR_TOLERANCE ) ) /
						( double ) mythreshold );
	hard_max =
		( long long ) ( ( ( double ) values[0] * ( 1.0 + OVR_TOLERANCE ) ) /
						( double ) mythreshold );
	soft_min =
		( long long ) ( ( ( double ) values[0] * ( 1.0 - SOFT_TOLERANCE ) ) /
						( double ) mythreshold );
	soft_max =
		( long long ) ( ( ( double ) values[0] * ( 1.0 + SOFT_TOLERANCE ) ) /
						( double ) mythreshold );
	
	if ( total[1] > hard_max || total[1] < hard_min )
		test_fail( __FILE__, __LINE__, "Hardware Overflows outside limits", 1 );

	if ( total[2] > soft_max || total[3] > soft_max || total[4] > soft_max )
		test_fail( __FILE__, __LINE__,
				   "Software Overflows exceed theoretical maximum", 1 );

	if ( total[2] < soft_min || total[3] < soft_min || total[4] < soft_min )
		printf( "WARNING: Software Overflow occuring but suspiciously low\n" );

	if ( ( total[2] == 0 ) || ( total[3] == 0 ) || ( total[4] == 0 ) )
		test_fail( __FILE__, __LINE__, "Software Overflows", 1 );

	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}