Esempio n. 1
0
void
init_multiplex( void )
{
	int retval;
	const PAPI_hw_info_t *hw_info;
	const PAPI_component_info_t *cmpinfo;

	/* Initialize the library */

	/* for now, assume multiplexing on CPU compnent only */
	cmpinfo = PAPI_get_component_info( 0 );
	if ( cmpinfo == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 );

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

	if ( ( strstr( cmpinfo->name, "perfctr.c" ) ) && (hw_info !=NULL) &&
		 strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
		retval = PAPI_set_domain( PAPI_DOM_ALL );
		if ( retval != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
	}
	retval = PAPI_multiplex_init(  );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI multiplex init fail\n", retval );
}
Esempio n. 2
0
int
main( int argc, char **argv )
{
	int nthreads = 8, ret, i;
	PAPI_event_info_t info;
	pthread_t *threads;
	const PAPI_hw_info_t *hw_info;

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

	if ( !TESTS_QUIET ) {
		if ( argc > 1 ) {
			int tmp = atoi( argv[1] );
			if ( tmp >= 1 )
				nthreads = tmp;
		}
	}

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

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

	if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
		ret = PAPI_set_domain( PAPI_DOM_ALL );
		if ( ret != PAPI_OK ) {
			test_fail( __FILE__, __LINE__, "PAPI_set_domain", ret );
		}
	}

	ret = PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self );
	if ( ret != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
	}

	ret = PAPI_multiplex_init(  );
	if ( ret != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", ret );
	}

	/* Fill up the event set with as many non-derived events as we can */

	i = PAPI_PRESET_MASK;
	do {
		if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
			if ( info.count == 1 ) {
				events[numevents++] = ( int ) info.event_code;
				printf( "Added %s\n", info.symbol );
			} else {
				printf( "Skipping derived event %s\n", info.symbol );
			}
		}
	} while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK )
			  && ( numevents < PAPI_MPX_DEF_DEG ) );

	printf( "Found %d events\n", numevents );

	do_stuff(  );

	printf( "Creating %d threads:\n", nthreads );

	threads =
		( pthread_t * ) malloc( ( size_t ) nthreads * sizeof ( pthread_t ) );
	if ( threads == NULL ) {
		test_fail( __FILE__, __LINE__, "malloc", PAPI_ENOMEM );
	}

	/* Create the threads */
	for ( i = 0; i < nthreads; i++ ) {
		ret = pthread_create( &threads[i], NULL, thread, NULL );
		if ( ret != 0 ) {
			test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
		}
	}

	/* Wait for thread completion */
	for ( i = 0; i < nthreads; i++ ) {
		ret = pthread_join( threads[i], NULL );
		if ( ret != 0 ) {
			test_fail( __FILE__, __LINE__, "pthread_join", PAPI_ESYS );
		}
	}

	printf( "Done." );
	test_pass( __FILE__, NULL, 0 );
	pthread_exit( NULL );
	exit( 0 );
}
Esempio n. 3
0
int main(int argc, char **argv) {

    int retval,max_multiplex,i,EventSet=PAPI_NULL;
    PAPI_event_info_t info;
    int added=0;
    int events_tried=0;

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

    /* Initialize the library */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
        test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
    }

    retval = PAPI_multiplex_init(  );
    if ( retval != PAPI_OK) {
        test_fail(__FILE__, __LINE__, "Multiplex not supported", 1);
    }

    max_multiplex=PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL );

    if (!TESTS_QUIET) {
        printf("Maximum multiplexed counters=%d\n",max_multiplex);
    }

    if (!TESTS_QUIET) {
        printf("Trying to multiplex as many as possible:\n");
    }

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

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

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


    i = 0 | PAPI_PRESET_MASK;
    PAPI_enum_event( &i, PAPI_ENUM_FIRST );
    do {
        retval = PAPI_get_event_info( i, &info );
        if (retval==PAPI_OK) {
            if (!TESTS_QUIET) printf("Adding %s: ",info.symbol);
        }

        retval = PAPI_add_event( EventSet, info.event_code );
        if (retval!=PAPI_OK) {
            if (!TESTS_QUIET) printf("Fail!\n");
        }
        else {
            if (!TESTS_QUIET) printf("Success!\n");
            added++;
        }
        events_tried++;

    } while (PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK );

    PAPI_shutdown(  );

    if (!TESTS_QUIET) {
        printf("Added %d of theoretical max %d\n",added,max_multiplex);
    }

    if (events_tried<max_multiplex) {
        if (!TESTS_QUIET) {
            printf("Ran out of events before we ran out of room\n");
        }
    }
    else if (added!=max_multiplex) {
        test_fail(__FILE__, __LINE__,
                  "Couldn't max out multiplexed events", 1);
    }

    test_pass( __FILE__, NULL, 0 );
    exit( 0 );
}
int main(int argc, char **argv)
{
   PAPI_event_info_t info;
   int i, j, retval;
   int iters = 10000000;
   double x = 1.1, y;
   long long t1, t2;
   long long values[MAXEVENTS], refvalues[MAXEVENTS];
   int sleep_time = SLEEPTIME;
   double valsqsum[MAXEVENTS];
   double valsum[MAXEVENTS];
   double spread[MAXEVENTS];
   int nevents = MAXEVENTS;
   int eventset = PAPI_NULL;
   int events[MAXEVENTS];

   events[0] = PAPI_BR_NTK;
   events[1] = PAPI_BR_PRC;
   events[2] = PAPI_BR_INS;
   events[3] = PAPI_BR_MSP;
/*
  events[3]=PAPI_BR_CN; 
  events[4]=PAPI_BR_UCN;*/
   /*events[5]=PAPI_BR_TKN; */


   for (i = 0; i < MAXEVENTS; i++) {
      values[i] = 0;
      valsqsum[i] = 0;
      valsum[i] = 0;
   }

   if (argc > 1) {
      if (!strcmp(argv[1], "TESTS_QUIET"))
         tests_quiet(argc, argv);
      else {
         sleep_time = atoi(argv[1]);
         if (sleep_time <= 0)
            sleep_time = SLEEPTIME;
      }
   }

   if (!TESTS_QUIET) {
      printf("\nAccuracy check of branch presets.\n");
      printf("Comparing a measurement with separate measurements.\n\n");
   }

   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)))
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

#ifdef MPX
   if ((retval = PAPI_multiplex_init()))
      test_fail(__FILE__, __LINE__, "PAPI_multiplex_init", retval);

   if ((retval = PAPI_set_multiplex(eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval);
#endif

   nevents = 0;

   for (i = 0; i < MAXEVENTS; i++) {
      if (PAPI_query_event(events[i]) != PAPI_OK)
         continue;
      if (PAPI_add_event(eventset, events[i]) == PAPI_OK) {
         events[nevents] = events[i];
         nevents++;
      }
   }

   if (nevents < 1)
      test_skip(__FILE__, __LINE__, "Not enough events left...", 0);

   /* Find a reasonable number of iterations (each 
    * event active 20 times) during the measurement
    */
   t2 = 10000 * 20 * nevents;   /* Target: 10000 usec/multiplex, 20 repeats */
   if (t2 > 30e6)
      test_skip(__FILE__, __LINE__, "This test takes too much time", retval);

   /* Measure one run */
   t1 = PAPI_get_real_usec();
   y = dummy3(x, iters);
   t1 = PAPI_get_real_usec() - t1;

   if (t2 > t1)                 /* Scale up execution time to match t2 */
      iters = iters * (int)(t2 / t1);
   else if (t1 > 30e6)          /* Make sure execution time is < 30s per repeated test */
      test_skip(__FILE__, __LINE__, "This test takes too much time", retval);

   x = 1.0;

   if (!TESTS_QUIET)
      printf("\nFirst run: Together.\n");

   t1 = PAPI_get_real_usec();
   if ((retval = PAPI_start(eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);
   y = dummy3(x, iters);
   if ((retval = PAPI_stop(eventset, values)))
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);
   t2 = PAPI_get_real_usec();

   if (!TESTS_QUIET) {
      printf("\tOperations= %.1f Mflop", y * 1e-6);
      printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1)));
      printf("PAPI grouped measurement:\n");
   }
   for (j = 0; j < nevents; j++) {
      PAPI_get_event_info(events[j], &info);
      if (!TESTS_QUIET) {
         printf("%20s = ", info.short_descr);
         printf(LLDFMT, values[j]);
         printf("\n");
      }
   }
   if (!TESTS_QUIET)
      printf("\n");


   if ((retval = PAPI_remove_events(eventset, events, nevents)))
      test_fail(__FILE__, __LINE__, "PAPI_remove_events", retval);
   if ((retval = PAPI_destroy_eventset(&eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval);
   eventset = PAPI_NULL;
   if ((retval = PAPI_create_eventset(&eventset)))
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

   for (i = 0; i < nevents; i++) {

      if ((retval = PAPI_cleanup_eventset(eventset)))
         test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval);
      if ((retval = PAPI_add_event(eventset, events[i])))
         test_fail(__FILE__, __LINE__, "PAPI_add_event", retval);

      x = 1.0;

      if (!TESTS_QUIET)
         printf("\nReference measurement %d (of %d):\n", i + 1, nevents);

      t1 = PAPI_get_real_usec();
      if ((retval = PAPI_start(eventset)))
         test_fail(__FILE__, __LINE__, "PAPI_start", retval);
      y = dummy3(x, iters);
      if ((retval = PAPI_stop(eventset, &refvalues[i])))
         test_fail(__FILE__, __LINE__, "PAPI_stop", retval);
      t2 = PAPI_get_real_usec();

      if (!TESTS_QUIET) {
         printf("\tOperations= %.1f Mflop", y * 1e-6);
         printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1)));
      }
      PAPI_get_event_info(events[i], &info);
      if (!TESTS_QUIET) {
         printf("PAPI results:\n%20s = ", info.short_descr);
         printf(LLDFMT, refvalues[i]);
         printf("\n");
      }
   }
   if (!TESTS_QUIET)
      printf("\n");


   if (!TESTS_QUIET) {
      printf("\n\nRelative accuracy:\n");
      for (j = 0; j < nevents; j++)
         printf("   Event %.2d", j);
      printf("\n");
   }

   for (j = 0; j < nevents; j++) {
      spread[j] = abs((int)(refvalues[j] - values[j]));
      if (values[j])
         spread[j] /= (double) values[j];
      if (!TESTS_QUIET)
         printf("%10.3g ", spread[j]);
      /* Make sure that NaN get counted as errors */
      if (spread[j] < MPX_TOLERANCE)
         i--;
      else if (refvalues[j] < MINCOUNTS)        /* Neglect inprecise results with low counts */
         i--;
   }
   if (!TESTS_QUIET)
      printf("\n\n");

   if (i)
      test_fail(__FILE__, __LINE__, "Values outside threshold", i);
   else
      test_pass(__FILE__, NULL, 0);

   return 0;
}
Esempio n. 5
0
int main()
{
    double *a;
    double *b;
    double *c;
    int i = 0, j = 0, k = 0;
    int *events;                        // Array of events
    long long *values;                  // Array of values events
    int EventSet = PAPI_NULL;           // Handle for a PAPI event set as created by PAPI_create_eventset (3) 
    int retval;                         // Test fail function
    int num_event = 0;                  // Number of events
    int max_event;                      // Number of available events
    int EventCode = 0;                  // Event code
    PAPI_event_info_t pset;             // PAPI_event_info_t Struct Reference
    char evname[PAPI_MAX_STR_LEN];      // Symbol event
   
    /* Memory asignament to matrixs*/   
    if((a = (double *)malloc(mrows * ncolumns * sizeof(double))) == NULL)
        printf("Error malloc matrix a[%d]\n",mrows * ncolumns);
    if((b = (double *)malloc(ncolumns * pcolumns * sizeof(double))) == NULL)
        printf("Error malloc matrix b[%d]\n",mrows * ncolumns);
    if((c = (double *)malloc(mrows * pcolumns * sizeof(double))) == NULL)
        printf("Error malloc matrix c[%d]\n",mrows * ncolumns);

    /* Initialize the Matrix arrays */
    initmat(a, b, mrows, ncolumns, pcolumns);

    /* Initialize the PAPI library */
    retval = PAPI_library_init(PAPI_VER_CURRENT);
    if (retval != PAPI_VER_CURRENT)
        test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

    /* Enable and initialize multiplex support */
    retval = PAPI_multiplex_init();
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval );
 
    /* Create an EventSet */
    retval = PAPI_create_eventset(&EventSet);
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
 
    /* Assign it to the CPU component */
    retval = PAPI_assign_eventset_component(EventSet, 0);
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
 
    /* Convert the EventSet to a multiplexed event set */
    retval = PAPI_set_multiplex(EventSet);
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );

    /* Obtaining the number of available events */
    max_event = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL );
    printf("\nNumber of available events: %d", max_event );
 
    /* Fill up the event set with as many non-derived events as we can */
    EventCode = PAPI_PRESET_MASK;
    do {
        if ( PAPI_get_event_info( EventCode, &pset ) == PAPI_OK ) {
            if ( pset.count && ( strcmp( pset.derived, "NOT_DERIVED" ) == 0 ) ) {
                retval = PAPI_add_event( EventSet, ( int ) pset.event_code );
                if ( retval != PAPI_OK )
                    test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
                else {
                    //printf( "Added %s\n", pset.symbol );
                    num_event++;
                }
            }
        }
    } while ( ( PAPI_enum_event( &EventCode, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ) && ( num_event < max_event ) );
    
    /* Memory asignament to values and events*/    
    events = ( int * ) malloc( ( size_t ) num_event * sizeof ( int ) );
    if ( events == NULL )
        test_fail( __FILE__, __LINE__, "Error malloc events", 0 );
    values = ( long long * ) malloc( ( size_t ) num_event * sizeof ( long long ) );
    if ( values == NULL )
        test_fail( __FILE__, __LINE__, "Erro malloc values", 0 );

    /* Start counting events */
    if ((retval=PAPI_start(EventSet)) != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_start", retval);

    /* Matrix-Matrix multiply */
    matmul(a, b, c, mrows, ncolumns, pcolumns);

    /* Read the counters */
    if ((retval=PAPI_read( EventSet, values )) != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_read_counters", retval);
   
    /* Stop counting events */
    if ((retval=PAPI_stop( EventSet, values )) != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_stop_counters", retval);

    /* List the events in the event set */
    retval = PAPI_list_events( EventSet, events, &num_event );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_list_events", retval );

    /* Print results */
    printf("\nNumber of non-zero events: %d\n", num_event );
    printf( "\nCounts of non-zero available events........................................................\n" );
    printf("Name: \t\t\t  Value: \t Description:\n");
    for ( i = 0; i < num_event; i++ ) {
        PAPI_event_code_to_name( events[i], evname );   // Obtaining name of available events
        PAPI_get_event_info(events[i], &pset);
        if ( values[i] != 0 )  printf("%s \t %15lld \t %s\n", evname, values[i], pset.long_descr);
    }
    printf( "\nCounts of zero available events............................................................\n" );
    printf("Name: \t\t\t  Value: \t Description:\n");
    for ( i = 0; i < num_event; i++ ) {
        PAPI_event_code_to_name( events[i], evname );   // Obtaining name of available events
        PAPI_get_event_info(events[i], &pset);
        if ( values[i] == 0 )  printf("%s \t %15lld \t %s\n", evname, values[i], pset.long_descr);
    }

    /* Check if counter pair(s) had identical values */
    for ( i = 0; i < num_event; i++ ) {
        for ( i = j+1; j < num_event; j++ ) {
            if ( ( i != j ) && ( values[i] == values[j] ) ) k++;  
        }
    }
    if ( k != 0 ) {
        printf( "\nCaution: %d counter pair(s) had identical values\n", k );
    }
    printf("\n");

    /* Free memory */
    free( events );
    free( values );
    free( a );
    free( b );
    free( c );

    /* Cleaning events */
    retval = PAPI_cleanup_eventset( EventSet );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
    
    /* Destroying events */
    retval = PAPI_destroy_eventset( &EventSet );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

    return 0;
}
Esempio n. 6
0
int GPTLcreate_and_start_events (const int t)  /* thread number */
{
  int ret; /* return code */
  int n;   /* loop index over events */
  char eventname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_name */

  /* Create the event set */

  if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK)
    return GPTLerror ("GPTLcreate_and_start_events: thread %d failure creating eventset: %s\n", 
		      t, PAPI_strerror (ret));

  if (verbose)
    printf ("GPTLcreate_and_start_events: successfully created eventset for thread %d\n", t);

  /* Add requested events to the event set */

  for (n = 0; n < npapievents; n++) {
    if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) {
      if (verbose) {
	fprintf (stderr, "%s\n", PAPI_strerror (ret));
	ret = PAPI_event_code_to_name (papieventlist[n], eventname);
	fprintf (stderr, "GPTLcreate_and_start_events: failure adding event:%s\n",
		 eventname);
      }

      if (enable_multiplexing) {
        if (verbose)
	  printf ("Trying multiplexing...\n");
	is_multiplexed = true;
	break;
      } else
	return GPTLerror ("enable_multiplexing is false: giving up\n");
    }
  }

  if (is_multiplexed) {

    /* Cleanup the eventset for multiplexing */

    if ((ret = PAPI_cleanup_eventset (EventSet[t])) != PAPI_OK)
      return GPTLerror ("GPTLcreate_and_start_events: %s\n", PAPI_strerror (ret));
    
    if ((ret = PAPI_destroy_eventset (&EventSet[t])) != PAPI_OK)
      return GPTLerror ("GPTLcreate_and_start_events: %s\n", PAPI_strerror (ret));

    if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK)
      return GPTLerror ("GPTLcreate_and_start_events: failure creating eventset: %s\n", 
			PAPI_strerror (ret));

    if ((ret = PAPI_multiplex_init ()) != PAPI_OK)
      return GPTLerror ("GPTLcreate_and_start_events: failure from PAPI_multiplex_init%s\n", 
			PAPI_strerror (ret));

    if ((ret = PAPI_set_multiplex (EventSet[t])) != PAPI_OK)
      return GPTLerror ("GPTLcreate_and_start_events: failure from PAPI_set_multiplex: %s\n", 
			PAPI_strerror (ret));

    for (n = 0; n < npapievents; n++) {
      if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) {
	ret = PAPI_event_code_to_name (papieventlist[n], eventname);
	return GPTLerror ("GPTLcreate_and_start_events: failure adding event:%s\n"
			  "  Error was: %s\n", eventname, PAPI_strerror (ret));
      }
    }
  }

  /* Start the event set.  It will only be read from now on--never stopped */

  if ((ret = PAPI_start (EventSet[t])) != PAPI_OK)
    return GPTLerror ("GPTLcreate_and_start_events: failed to start event set: %s\n", 
		      PAPI_strerror (ret));

  return 0;
}
Esempio n. 7
0
/*
** GPTLcreate_and_start_events: Create and start the PAPI eventset.
**   Threaded routine to create the "event set" (PAPI terminology) and start
**   the counters. This is only done once, and is called from get_thread_num
**   for the first time for the thread.
** 
** Input args: 
**   t: thread number
**
** Return value: 0 (success) or GPTLerror (failure)
*/
int GPTLcreate_and_start_events (const int t)  /* thread number */
{
  int ret; /* return code */
  int n;   /* loop index over events */
  char eventname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_name */
  static const char *thisfunc = "GPTLcreate_and_start_events";

  /* 
  ** Set the domain to count all contexts. Only needs to be set once for all threads
  */
  if ((ret = PAPI_set_domain (PAPI_DOM_ALL)) != PAPI_OK)
    return GPTLerror ("%s: thread %d failure setting PAPI domain: %s\n", 
		      thisfunc, t, PAPI_strerror (ret));
  
  /* Create the event set */
  if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK)
    return GPTLerror ("%s: thread %d failure creating eventset: %s\n", 
		      thisfunc, t, PAPI_strerror (ret));

  if (verbose)
    printf ("%s: successfully created eventset for thread %d\n", thisfunc, t);

  /* Add requested events to the event set */
  for (n = 0; n < npapievents; n++) {
    if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) {
      if (verbose) {
	fprintf (stderr, "%s\n", PAPI_strerror (ret));
	ret = PAPI_event_code_to_name (papieventlist[n], eventname);
	fprintf (stderr, "%s: failure adding event:%s\n", thisfunc, eventname);
      }

      if (enable_multiplexing) {
        if (verbose)
	  printf ("Trying multiplexing...\n");
	is_multiplexed = true;
	break;
      } else
	return GPTLerror ("enable_multiplexing is false: giving up\n");
    }
  }

  if (is_multiplexed) {

    /* Cleanup the eventset for multiplexing */
    if ((ret = PAPI_cleanup_eventset (EventSet[t])) != PAPI_OK)
      return GPTLerror ("%s: %s\n", thisfunc, PAPI_strerror (ret));
    
    if ((ret = PAPI_destroy_eventset (&EventSet[t])) != PAPI_OK)
      return GPTLerror ("%s: %s\n", thisfunc, PAPI_strerror (ret));

    if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK)
      return GPTLerror ("%s: failure creating eventset: %s\n", thisfunc, PAPI_strerror (ret));
			
    /* 
    ** Assign EventSet to component 0 (cpu). This step is MANDATORY in recent PAPI releases
    ** in order to enable event multiplexing
    */
    if ((ret = PAPI_assign_eventset_component (EventSet[t], 0)) != PAPI_OK)
      return GPTLerror ("%s: thread %d failure in PAPI_assign_eventset_component: %s\n", 
			thisfunc, t, PAPI_strerror (ret));

    if ((ret = PAPI_multiplex_init ()) != PAPI_OK)
      return GPTLerror ("%s: failure from PAPI_multiplex_init%s\n", thisfunc, PAPI_strerror (ret));

    if ((ret = PAPI_set_multiplex (EventSet[t])) != PAPI_OK)
      return GPTLerror ("%s: failure from PAPI_set_multiplex: %s\n", thisfunc, PAPI_strerror (ret));

    for (n = 0; n < npapievents; n++) {
      if ((ret = PAPI_add_event (EventSet[t], papieventlist[n])) != PAPI_OK) {
	ret = PAPI_event_code_to_name (papieventlist[n], eventname);
	return GPTLerror ("%s: failure adding event:%s Error was: %s\n", 
			  thisfunc, eventname, PAPI_strerror (ret));
      }
    }
  }

  /* Start the event set.  It will only be read from now on--never stopped */
  if ((ret = PAPI_start (EventSet[t])) != PAPI_OK)
    return GPTLerror ("%s: failed to start event set: %s\n", thisfunc, PAPI_strerror (ret));

  return 0;
}
void *watch_process(void* _pid) {


  pid_t pid = *((pid_t*)_pid);
  printf("%d\n", pid);
  int retval, EventSet = PAPI_NULL;

  //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "MEM_LOAD_RETIRED:L1D_HIT", "MEM_LOAD_RETIRED:L2_HIT", "LLC_REFERENCES"};
  //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "MEM_LOAD_RETIRED:L2_HIT", "L2_RQSTS:LOADS", "L2_DATA_RQSTS:ANY"};
  //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "L1I:READS", "L1D_CACHE_LD:MESI", "L1D_CACHE_ST:MESI"};
  //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "L1D_CACHE_LD:MESI", "L1D_CACHE_ST:MESI", "L2_DATA_RQSTS:ANY" };
  char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "L1I:READS", "L1D_CACHE_LD:MESI", "L1D_CACHE_ST:MESI", "MEM_LOAD_RETIRED:L2_HIT", "L2_RQSTS:LOADS", "L2_DATA_RQSTS:ANY", "BR_INST_RETIRED:ALL_BRANCHES", "BR_INST_EXEC:ANY", "BR_MISP_EXEC:ANY" };
  unsigned int native_events[NB_EVENTS];
  long long values[NB_EVENTS];


  int err;
  /* Initialize the library */
  if ( (err = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) {
    fprintf(stderr, "PAPI library init error! %d\n", err);
    exit(1);
  }

  if ( (err = PAPI_multiplex_init()) != PAPI_OK) {
    fprintf(stderr, "PAPI multiplex init error! %d\n", err);
    exit(1);
  }

  
  if (PAPI_thread_init(pthread_self) != PAPI_OK) {
    fprintf(stderr, "PAPI thread init error! %d\n", err);
    exit(1);
  }


  //sched_setaffinity(0, 0);
  //if ((retval = PAPI_set_granularity(PAPI_GRN_MAX)) != PAPI_OK) {
  //  fprintf(stderr, "PAPI set granurality error! %d, %d, %d, %d, %d\n", retval, PAPI_EINVAL, PAPI_ENOEVST, PAPI_ENOCMP, PAPI_EISRUN);
  //  exit(1);
  //}

  // Traduction des string en code
  name_to_code(events_name, NB_EVENTS, native_events);
  // Vérification des évènements
  check_events(native_events, NB_EVENTS);
  
  if (PAPI_create_eventset(&EventSet) != PAPI_OK) {    
    fprintf(stderr, "PAPI EventSet init error!\n");
    exit(1);
  }

  if ( (err = PAPI_assign_eventset_component( EventSet, 0 ) ) != PAPI_OK ) {
    fprintf(stderr, "PAPI assign component error!\n%s\n", PAPI_strerror(err));
    exit(1);
  }

  if ( ( err = PAPI_set_multiplex(EventSet) ) != PAPI_OK) {    
    fprintf(stderr, "PAPI set multiplex error!\n%s\n", PAPI_strerror(err));
    exit(1);
  }

  if ( (retval = PAPI_add_events(EventSet, native_events, NB_EVENTS) ) != PAPI_OK) {
    fprintf(stderr, "PAPI add events error!\n%s\n", PAPI_strerror(retval) );
    exit(1);
  }

  if (PAPI_attach(EventSet, pid) != PAPI_OK)
    exit(1);

  while(while_watch) {
    /* Start counting */
    if (PAPI_start(EventSet) != PAPI_OK) {
      fprintf(stderr, "PAPI start error!\n");
      exit(1);
    }
    usleep(1000000);

    if (PAPI_stop(EventSet, values) != PAPI_OK) {
      fprintf(stderr, "PAPI stop error!\n");
      exit(1);
    }

    print_values(events_name, values, NB_EVENTS);


  }

	return 0;
}
Esempio n. 9
0
int main(int argc, char **argv)
{
	#if defined(PARALLEL)  || defined(PARTIALPAR) 
		omp_set_num_threads(initParams::nprocs);
		size_t                      threadID;
		std::vector<size_t>         neighbourThreadId;
		std::vector<size_t>         workingThreadId;
		std::vector<cv::KeyPoint>   globalKeypoints;
		cv::Mat                     globalDescriptors;
		std::vector<size_t>         globalIdx(initParams::nprocs/2,   0);
		std::vector<size_t>         levelThreadIdx;
	#endif

	cv::Mat 		frame;
	cv::VideoCapture 	cap;
	class initParams 	params;
	// Set motion field norm threshold. If intra-frame motion greater than this threshold carry out outlier classification, rotation compensation, FOE and TTC computations
	#if !defined(PARALLEL) 
	const float 		OFThresh = 10.0f;
	#endif
	
	#ifdef USE_PAPI
	int events[NUM_EVENTS] = {
					PAPI_L1_DCM,
					PAPI_L2_DCA,
					PAPI_L2_DCM
				 };

	long long values[NUM_EVENTS+1];
	long long start_time = PAPI_get_real_usec();
	double total_time = 0.0f;
	#endif

	// Initialization of parameters
	params.set();
	if (argc < 3)
	{
		std::cerr << "Run Configuration :\n\t./[program name] [input video file] [Total # of frames in video file, 798 for data set-1 and 977 for data set-2]\n";
		exit(EXIT_FAILURE);
	}

	cap.open(argv[1]);
	if(!cap.isOpened()){
		std::cerr << "Could not access video file: " << argv[1] << std::endl;
		exit(EXIT_FAILURE);
	}
	size_t frameTotal = (size_t) std::atoi(argv[2]);

	class agast 			objExtractor;
	class FindRobustFeatures	rFeatures(&objExtractor, &params);

	cv::Mat tmpDescriptors;
	std::vector<cv::KeyPoint> tmpKeypoints;

	#ifdef WRITEDATA
	analysis::TTCvector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0.0f);
	analysis::kpVector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0);
	analysis::outliersVector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0);
	analysis::matchOutliersVector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0);
	analysis::OFNorm.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0);
	analysis::keypointsVector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0);
	#endif
	#if defined(PROF) || defined(WRITEDATA)
	time_t          rawtime;
        char            buffer[80];
        time(&rawtime);
        struct  tm      * timeinfo      = localtime(&rawtime);
        strftime(buffer,80, "%d-%m-%y_%H-%M-%S", timeinfo);
	analysis::timeStamp       = std::string(buffer);
	#endif
	#ifdef PROF
	analysis::perfTime.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), std::vector<float>(3, 0.0f));
	#endif

	#ifdef USE_PAPI
	//********** PAPI Module initialization for performance analysis***********//
	// Setup PAPI library
	int ret = PAPI_library_init(PAPI_VER_CURRENT);
	if (ret != PAPI_VER_CURRENT) {
		printf("Problem while initializing PAPI library: %s\n", PAPI_strerror(ret));
		exit(EXIT_FAILURE);
	}
	// Init multiplexer
	ret = PAPI_multiplex_init();
	if (ret != PAPI_OK) {
		printf("Problem while initializing PAPI multiplexer: %s\n", PAPI_strerror(ret));
		exit(1);
	}
	// Create event set for the events that we want to measure
	int eventset = PAPI_NULL;
	ret = PAPI_create_eventset(&eventset);
	if (ret != PAPI_OK) {
		printf("Problem while creating PAPI event set: %s\n", PAPI_strerror(ret));
		exit(1);
	}
	ret = PAPI_add_event(eventset, PAPI_L1_DCA);
	if (ret != PAPI_OK) {
		printf("Problem while adding first PAPI event: %s\n", PAPI_strerror(ret));
		exit(1);
	}
	// set multiplexer for event set
 	ret = PAPI_set_multiplex(eventset);
	if (ret != PAPI_OK) {
		printf("Problem while setting PAPI multiplex: %s\n", PAPI_strerror(ret));
		exit(1);
	}
	// Add events to event set
	ret = PAPI_add_events(eventset, events, NUM_EVENTS);
	if (ret != PAPI_OK) {
		printf("Problem while adding PAPI events: %s\n", PAPI_strerror(ret));
		exit(1);
	}
	//********** END INITIALIZATION **********//

	// Start measuring computation runtime
	start_time = PAPI_get_real_usec();
	// Start measuring events in event set
	ret = PAPI_start(eventset);
	if (ret != PAPI_OK) {
		printf("Problem while starting PAPI eventset: %s\n", PAPI_strerror(ret));
		exit(1);
	}
	#endif

	try
	{	
		while(( (size_t)cap.get(CV_CAP_PROP_POS_FRAMES) + initParams::frameDelay ) <  frameTotal)
		{

			/****************************PARALLEL-REGION************************************/
			#if defined(PARALLEL) || defined(PARTIALPAR)
				globalIdx.resize(initParams::nprocs/2, 0);
				analysis::refFrameCount = cap.get(CV_CAP_PROP_POS_FRAMES);
				analysis::frameCount    = cap.get(CV_CAP_PROP_POS_FRAMES);
				for (size_t i = 0; i < initParams::nprocs; ++i) 
				{ 
					if (i % 2 == 0) { workingThreadId.push_back(i); }
					else 		{ neighbourThreadId.push_back(i); }
				}

				#pragma omp parallel num_threads(initParams::nprocs) private(threadID, frame) shared(globalIdx, params, neighbourThreadId, workingThreadId, objExtractor)
				{
					threadID         = omp_get_thread_num();
					// get index of the frame to be handled by a particular thread executed only once:
					size_t myFrameID = 0;

					#pragma omp for ordered schedule(static,1)
					for (size_t i = 0; i < initParams::nprocs; ++i)
					{
						#pragma omp ordered
						myFrameID = threadID + analysis::frameCount;
						analysis::frameCount++;
					}


					class agast objExtractorLoc;

					while(cap.get(CV_CAP_PROP_POS_FRAMES) != myFrameID) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); }

					// get first frame and extract new features:
					cap >> objExtractorLoc.frame;
					objExtractorLoc.extractFeatures();

					if (threadID == initParams::nprocs-1) { objExtractorLoc.frame.copyTo(objExtractor.frame); }

					#pragma omp master
					{	
						// keep ref. of the first keypoints and their descriptors:
						objExtractor.descriptorsOld    = objExtractorLoc.descriptors.clone();
						objExtractor.keypointsOld      = objExtractorLoc.keypoints;
						#ifdef VISUALIZE
						objExtractorLoc.frame.copyTo(objExtractor.frameOld);
						#endif
					}

					// follow keypoints over the next framedelay # of frames:
					objExtractorLoc.swap();
					cap >> objExtractorLoc.frame;
					objExtractorLoc.extractFeatures();
					objExtractorLoc.featureMatching();
					#if ! defined(WRITEDATA)
					objExtractorLoc.homographyRANSAC(3.0f);
					#else 
					objExtractorLoc.homographyRANSAC(3.0f, analysis::outliers, analysis::frameCount, analysis::outliersVector);
					#endif
					if((size_t)objExtractorLoc.goodMatches.size() > 5)
						objExtractorLoc.swapGM();

					if (!globalIdx.empty())
					{	
						helperFunc::storeGlobal(globalKeypoints, globalDescriptors, objExtractorLoc, threadID, globalIdx, neighbourThreadId);
						#pragma omp barrier
						helperFunc::recomputeInterThreadGoodMatches(globalKeypoints, globalDescriptors, objExtractorLoc, workingThreadId, globalIdx, threadID, neighbourThreadId);
					}
					
					#pragma omp master
					{
						// re-swaping into global extractors' new points, due to swaping carried out at the end of inter thread matching:
						objExtractor.keypoints   = objExtractorLoc.keypointsOld;
						objExtractor.descriptors = objExtractorLoc.descriptorsOld.clone();
						
						objExtractor.featureMatching();
						rFeatures.homographyRANSAC(3.0f, true);

						#ifdef VISUALIZE
						analysis::frameCount    = cap.get(CV_CAP_PROP_POS_FRAMES) - 1;
						#endif

					}
				}
				//Compute velocity projection vectors:
				rFeatures.compute();
				
				objExtractor.goodMatches.clear();
				
				#ifdef VISUALIZE
				//Analyze and verify data if necessary:
				if((char)cv::waitKey(cap.get(CV_CAP_PROP_FPS))==27) break;
				cv::waitKey(10);
				#endif

			/****************************SERIAL-REGION**************************************/
			#else
				//Get first frame and extract new features:
				analysis::refFrameCount = cap.get(CV_CAP_PROP_POS_FRAMES);
				#if defined(VISUALIZE) || defined(WRITEIMAGE)
				cv::Mat refFrame;
				#endif
				cap >> objExtractor.frame;
				#if defined(VISUALIZE) || defined(WRITEIMAGE)
				objExtractor.frame.copyTo(refFrame);
				#endif
				objExtractor.extractFeatures();
				#ifdef PROF
				analysis::perfTime[analysis::frameCount][2] = objExtractor.elapsedTime.count();
				#endif

				// Keep ref. of the first keypoints and their descriptors:
				objExtractor.descriptors.copyTo(tmpDescriptors);
				tmpKeypoints            = objExtractor.keypoints;
				// Specify initial features as old features:
				objExtractor.swap();

				// Follow keypoints over the next frames:
				while((size_t)cap.get(CV_CAP_PROP_POS_FRAMES) < frameTotal ) 
				{
					analysis::frameCount = cap.get(CV_CAP_PROP_POS_FRAMES);
					analysis::outliers = 0; 

					cap >> objExtractor.frame;
					objExtractor.extractFeatures();

					#ifdef PROF
					analysis::perfTime[analysis::frameCount][2] = objExtractor.elapsedTime.count();
					analysis::start = std::chrono::high_resolution_clock::now();
					#endif

					// FLANN based matching of keypoints:
					objExtractor.featureMatching();

					#ifdef PROF
					analysis::stop                              = std::chrono::high_resolution_clock::now();
					analysis::elapsedTime                       = analysis::stop - analysis::start;
					analysis::perfTime[analysis::frameCount][0] = analysis::elapsedTime.count();
					#endif

					#ifdef VISUALIZE
					analysis::visMatchingPts(objExtractor);
					cv::waitKey(5);
					#endif

					#ifdef WRITEDATA
					analysis::keypointsVector[analysis::frameCount]     = std::min((size_t)objExtractor.keypoints.size(), (size_t)objExtractor.keypointsOld.size());
					analysis::matchOutliersVector[analysis::frameCount] = analysis::keypointsVector[analysis::frameCount] - (size_t)objExtractor.goodMatches.size();
					#endif

					#ifdef PROF
					analysis::start = std::chrono::high_resolution_clock::now();
					#endif

					// RANSAC based outlier classification:
					rFeatures.homographyRANSAC(1.2f, true);

					#ifdef PROF
					analysis::stop                              = std::chrono::high_resolution_clock::now();
					analysis::elapsedTime                       = analysis::stop - analysis::start;
					analysis::perfTime[analysis::frameCount][1] = analysis::elapsedTime.count();
					#endif

					#ifdef VISUALIZE
					analysis::visMatchingPts(objExtractor);
					cv::waitKey(5);
					#endif
					
					float OF = 0.0f;
					// Calculation of motion field norm makes sense only if matching points are greater than 3
					if ((size_t)objExtractor.goodMatches.size() > 3)
					{
						// Calculate intra-frame motion flow norm
						OF = helperFunc::calcMeanOFNorm(objExtractor.keypoints, objExtractor.keypointsOld, objExtractor.goodMatches);
					}
					#ifdef WRITEDATA
					analysis::OFNorm[analysis::frameCount] = helperFunc::calcMeanOFNorm(objExtractor.keypoints, objExtractor.keypointsOld, objExtractor.goodMatches);
					#endif

					// Different cases of computation: 
					if ((size_t)objExtractor.goodMatches.size() < 5 || OF >= OFThresh) 
					{
						// Case 1: Matching(refFrame(n) , refFrame(n+1)) lead to no good matches
						if (analysis::refFrameCount == (analysis::frameCount - 1) ) 
						{ 
							// If large motion field norm was the case then compute ttc: 
							if (OF >= OFThresh)
							{	
								//Compute velocity projection vectors and ttc:
								rFeatures.compute();
							}
							// Define latest frame as refFrame 
							analysis::refFrameCount = analysis::frameCount;
							objExtractor.descriptors.copyTo(tmpDescriptors);
							tmpKeypoints            = objExtractor.keypoints;
							#if defined(VISUALIZE) || defined(WRITEIMAGE)
							refFrame = objExtractor.frame.clone();
							#endif

							// Move latest frame data to old
							objExtractor.swap();   
						}
						// Case 2: Matching(refFrame(n+i) , refFrame(n+i+1)) lead to no good matches
						else 
						{
							// In case of motion flow greater than threshold compute ttc for the given intra-frame motion otherwise move consistent features and compute motion flow
							if (OF >= OFThresh)
							{	
								// Compute velocity projection vectors:
								rFeatures.compute();
								// Define latest frame as refFrame 
								analysis::refFrameCount = analysis::frameCount;
								objExtractor.descriptors.copyTo(tmpDescriptors);
								tmpKeypoints            = objExtractor.keypoints;
								#if defined(VISUALIZE) || defined(WRITEIMAGE)
								refFrame = objExtractor.frame.clone();
								#endif

								// Move latest frame data to old
								objExtractor.swap();
							}
							else 	
							{

								// Move consistent good matching features to new
								objExtractor.keypoints.swap(objExtractor.keypointsOld);
								objExtractor.keypointsOld.swap(tmpKeypoints);

								cv::Mat placeHolder(objExtractor.descriptors.size(), objExtractor.descriptors.type());
								#ifdef OPTIMIZED
								objExtractor.descriptors.copyTo(placeHolder);
								#else
								placeHolder = objExtractor.descriptors.clone();
								#endif
								objExtractor.descriptors.resize(0);
								objExtractor.descriptorsOld.copyTo(objExtractor.descriptors); 
								tmpDescriptors.copyTo(objExtractor.descriptorsOld );
								tmpDescriptors.resize(0);
								#ifdef OPTIMIZED
								placeHolder.copyTo(tmpDescriptors);
								#else
								tmpDescriptors = placeHolder.clone();
								#endif
								placeHolder.release();
								#if defined(VISUALIZE) || defined(WRITEIMAGE)
								cv::Mat tmpFrame;
								tmpFrame = objExtractor.frame.clone();
								objExtractor.frame    = objExtractor.frameOld.clone();
								objExtractor.frameOld = refFrame.clone();
								refFrame              = tmpFrame.clone();
								tmpFrame.release();
								#endif
								
								// Match refFrame features with consistent good matching features uptil refFrame(n+i)
								objExtractor.featureMatching();

								#ifdef VISUALIZE
								analysis::visMatchingPts(objExtractor, "Using Consistent Features");
								cv::waitKey(10);
								#endif

								// Calculate Motion Flow norm
								OF = helperFunc::calcMeanOFNorm(objExtractor.keypoints, objExtractor.keypointsOld, objExtractor.goodMatches);

								if( OF > OFThresh ) 
								{
									// Compute motion flow and ttc:
									rFeatures.compute();
								}
								objExtractor.goodMatches.clear();
								objExtractor.keypointsOld = tmpKeypoints;
								tmpDescriptors.copyTo(objExtractor.descriptorsOld);	

								// Define latest frame as refFrame 
								analysis::refFrameCount = analysis::frameCount;
							}
						}
					}
					else { objExtractor.swapGM(); }
					#ifdef VISUALIZE
					if((char)cv::waitKey(cap.get(CV_CAP_PROP_FPS))==27) break;
					cv::waitKey(10);
					#endif
				}				
			#endif
		}
	}
	catch(cv::Exception) { std::cerr << "Exception @ frame : " << cap.get(CV_CAP_PROP_POS_FRAMES) << "\n"; }

	#ifdef USE_PAPI
	// Collect data from the event set
 	if ( PAPI_stop(eventset, values) != PAPI_OK ) {
		printf("Problem while reading PAPI event set!\n");
		exit(EXIT_FAILURE);
	}
	// Print results
	total_time = ((double)(PAPI_get_real_usec() - start_time))/1000000;
	printf("Computation execution time: %lf seconds\n", total_time);
	printf("L1 Cache miss rate = %lf \n",((double)values[1])/(values[0]));
	printf("L2 Cache miss rate = %lf \n",((double)values[3])/(values[2]));
	#endif

			/*************************WRITE DATA TO FILE BLOCK********************************/

	/*<---------------------------- REGQUIRES SETTING OF PERSONAL PATH TO SAVING GENERATED DATA -------------------------->*/
	#ifdef WRITEDATA
	std::ofstream file;
	std::string fileName;
	fileName = "/home/ragesam/gitThesis/testCase/poseFeatures/build/ttc_" + analysis::timeStamp + ".dat"; 
	std::cout << "\nWRITING TTC DATA TO FILE \n";
	file.open(fileName);
	if(!file.is_open())
	{
		std::cout << "\nCan not write TTC to file\n";
		std::exit(EXIT_FAILURE);
	}
	else
	{
		for (size_t i = 0; i < (size_t)analysis::TTCvector.size(); ++i)
		{
			file << i << "\t" << analysis::TTCvector[i] << "\t" << analysis::kpVector[i]  <<"\n";
		}
	}
	file.close();

	fileName = "/home/ragesam/gitThesis/testCase/poseFeatures/build/outliers_" + analysis::timeStamp + ".dat"; 
	std::cout << "\nWRITING OUTLIER DATA TO FILE \n";
	file.open(fileName);
	if(!file.is_open())
	{
		std::cout << "\nCan not write outliers to file\n";
		std::exit(EXIT_FAILURE);
	}
	else
	{
		file << "Frame #\t# of Keypoints\tFLANN based outliers\tRANSAC based outliers\tIntra-fram projection vector norm\n";
		for (size_t i = 0; i < (size_t)analysis::outliersVector.size(); ++i)
		{
			file << i << "\t" << analysis::keypointsVector[i] << "\t" << analysis::matchOutliersVector[i] << "\t"  << analysis::outliersVector[i] << "\t" << analysis::OFNorm[i]  <<"\n";
		}
	}
	file.close();
	#endif
	
	#ifdef PROF
	std::ofstream fileProf;
	std::string fileNameProf;
	fileNameProf = "/home/ragesam/gitThesis/testCase/poseFeatures/build/profile_" + analysis::timeStamp + ".dat"; 
	std::cout << "\nWRITING PROFILING DATA TO FILE \n";
	fileProf.open(fileNameProf);
	if(!fileProf.is_open())
	{
		std::cout << "\nCan not write profiling data to file\n";
		std::exit(EXIT_FAILURE);
	}
	else
	{
		fileProf << "Frame #\telapsedTime Matching\telapsedTime RANSAC\telapsedTimeDetection\n";
		for (size_t i = 0; i < (size_t)analysis::perfTime.size(); ++i)
		{
			fileProf << i << "\t" << analysis::perfTime[i][0]  << "\t" << analysis::perfTime[i][1]  << "\t" << analysis::perfTime[i][2]  << "\n";
		}
	}
	fileProf.close();

	#endif

	cap.release();

	return 0;

}
Esempio n. 10
0
File: papi.c Progetto: DundalkIT/pcp
static int
papi_internal_init(pmdaInterface *dp)
{
    int ec;
    int sts;
    PAPI_event_info_t info;
    char entry[PAPI_HUGE_STR_LEN+12]; // the length papi uses for the symbol name
    unsigned int i = 0;
    pmID pmid;

    sts = sprintf(papi_version, "%d.%d.%d", PAPI_VERSION_MAJOR(PAPI_VERSION),
	    PAPI_VERSION_MINOR(PAPI_VERSION), PAPI_VERSION_REVISION(PAPI_VERSION));
    if (sts < 0) {
	__pmNotifyErr(LOG_ERR, "%s failed to create papi version metric.\n",pmProgname);
	return PM_ERR_GENERIC;
    }

    if ((sts = __pmNewPMNS(&papi_tree)) < 0) {
	__pmNotifyErr(LOG_ERR, "%s failed to create dynamic papi pmns: %s\n",
		      pmProgname, pmErrStr(sts));
	papi_tree = NULL;
	return PM_ERR_GENERIC;
    }

    number_of_counters = PAPI_num_counters();
    if (number_of_counters < 0) {
	__pmNotifyErr(LOG_ERR, "hardware does not support performance counters\n");
	return PM_ERR_APPVERSION;
    }
    else if (number_of_counters == 0) {
	__pmNotifyErr(LOG_WARNING, "no performance counters\n");
    }

    sts = PAPI_library_init(PAPI_VER_CURRENT);
    if (sts != PAPI_VER_CURRENT) {
	__pmNotifyErr(LOG_ERR, "PAPI_library_init error (%d)\n", sts);
	return PM_ERR_GENERIC;
    }

    ec = PAPI_PRESET_MASK;
    PAPI_enum_event(&ec, PAPI_ENUM_FIRST);
    do {
	if (PAPI_get_event_info(ec, &info) == PAPI_OK) {
	    if (info.count && PAPI_PRESET_ENUM_AVAIL) {
		expand_papi_info(i);
		memcpy(&papi_info[i].info, &info, sizeof(PAPI_event_info_t));
		memcpy(&papi_info[i].papi_string_code, info.symbol + 5, strlen(info.symbol)-5);
		snprintf(entry, sizeof(entry),"papi.system.%s", papi_info[i].papi_string_code);
		pmid = pmid_build(dp->domain, CLUSTER_PAPI, i);
		papi_info[i].pmid = pmid;
		__pmAddPMNSNode(papi_tree, pmid, entry);
		memset(&entry[0], 0, sizeof(entry));
		papi_info[i].position = -1;
		papi_info[i].metric_enabled = 0;
		expand_values(i);
		i++;
	    }
	}
    } while(PAPI_enum_event(&ec, 0) == PAPI_OK);

#if defined(HAVE_PAPI_DISABLED_COMP)
    char *tokenized_string;
    int number_of_components;
    int component_id;
    int native;

    number_of_components = PAPI_num_components();
    native = 0 | PAPI_NATIVE_MASK;
    for (component_id = 0; component_id < number_of_components; component_id++) {
	const PAPI_component_info_t *component;
	component = PAPI_get_component_info(component_id);
	if (component->disabled || (strcmp("perf_event", component->name)
				    && strcmp("perf_event_uncore", component->name)))
	    continue;
	sts = PAPI_enum_cmp_event (&native, PAPI_ENUM_FIRST, component_id);
	if (sts == PAPI_OK)
	do {
	    if (PAPI_get_event_info(native, &info) == PAPI_OK) {
		char local_native_metric_name[PAPI_HUGE_STR_LEN] = "";
		int was_tokenized = 0;
		expand_papi_info(i);
		memcpy(&papi_info[i].info, &info, sizeof(PAPI_event_info_t));
		tokenized_string = strtok(info.symbol, "::: -");
		while (tokenized_string != NULL) {
		    size_t remaining = sizeof(local_native_metric_name) -
			strlen(local_native_metric_name) - 1;
		    if (remaining < 1)
			break;
		    strncat(local_native_metric_name, tokenized_string, remaining);
		    was_tokenized = 1;
		    tokenized_string=strtok(NULL, "::: -");
		    if (tokenized_string) {
			remaining = sizeof(local_native_metric_name) -
			    strlen(local_native_metric_name) - 1;
			if (remaining < 1)
			    break;
			strncat(local_native_metric_name, ".", remaining);
		    }
		}
		if (!was_tokenized) {
		    strncpy(papi_info[i].papi_string_code, info.symbol,
			    sizeof(papi_info[i].papi_string_code) - 1);
		}
		else {
		    strncpy(papi_info[i].papi_string_code,
			    local_native_metric_name,
			    sizeof(papi_info[i].papi_string_code) - 1);
		}
		snprintf(entry, sizeof(entry),"papi.system.%s", papi_info[i].papi_string_code);
		pmid = pmid_build(dp->domain, CLUSTER_PAPI, i);
		papi_info[i].pmid = pmid;
		__pmAddPMNSNode(papi_tree, pmid, entry);
		memset(&entry[0], 0, sizeof(entry));
		papi_info[i].position = -1;
		papi_info[i].metric_enabled = 0;
		expand_values(i);
		i++;
	    }
	} while (PAPI_enum_cmp_event(&native, PAPI_ENUM_EVENTS, component_id) == PAPI_OK);
    }
#endif
    pmdaTreeRebuildHash(papi_tree, number_of_events);

    /* Set one-time settings for all future EventSets. */
    if ((sts = PAPI_set_domain(PAPI_DOM_ALL)) != PAPI_OK) {
	handle_papi_error(sts, 0);
	return PM_ERR_GENERIC;
    }
    if ((sts = PAPI_multiplex_init()) != PAPI_OK) {
	handle_papi_error(sts, 0);
	return PM_ERR_GENERIC;
    }

    sts = refresh_metrics(0);
    if (sts != PAPI_OK)
	return PM_ERR_GENERIC;
    return 0;
}