Page 1 of 1

Measurement differences between high and low interface

PostPosted: Mon Nov 08, 2010 10:52 am
by fbarisione
Hello,
i've made several simple programs to test the L1 Cache Misses in order to optimize the excecution of some big code i had.

I really don't know why, but i've got differents results when i use the high level interface compared to the the low level methods. the most probable thing is that i've made something wrong.

i attached the src which i've been working, but independant of my implementation, i need to know if there some difference in the perf count number gave by the high level api or the low.

thanks.

Re: A Simple question

PostPosted: Mon Nov 08, 2010 5:47 pm
by vweaver1
can you give some more details, such as what kind of processor you are using, and what version of the operating system? Also, I can't seem to download the code you attached. Is it small enough to just cut and paste into place?

Re: A Simple question

PostPosted: Mon Nov 08, 2010 8:51 pm
by fbarisione
Of course,
I'm testing the code on an Intel(R) Core(TM)2 CPU T5500 @ 1.66GHz using Linux 2.6.32-25 (Ubuntu 10.4).
Technical spec can be found on http://ark.intel.com/Product.aspx?id=29758.

Finally, here's my code:
High Level
==========

Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<papi.h>

#define NEvents 3

long long counters[NEvents];
int events[] = { PAPI_L1_DCA, PAPI_L1_DCH, PAPI_L1_DCM };

void main(){
   //papi initialization
   if (PAPI_VER_CURRENT != PAPI_library_init(PAPI_VER_CURRENT)){
      printf("Error in papi version");
      exit(-1);
   }

   PAPI_start_counters(events, NEvents);

   if (PAPI_OK != PAPI_read_counters(counters, NEvents))
      printf("Problem reading counters");

   PAPI_stop_counters(counters, NEvents);

   printf ("L1 data cache access: %lld\t L1 data cache hits: %lli\t : L1 data cache misses: %lld\n", counters[0], counters[1], counters[2]);
}


Low level
========

Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<papi.h>

#define NEvents 3

long long counters[NEvents];
int events[] = { PAPI_L1_DCA, PAPI_L1_DCH, PAPI_L1_DCM };
const PAPI_hw_info_t *hwinfo = NULL;
int EventSet = PAPI_NULL;
int retval = 0;

void initPapi(){
   /**
   * 1. Init PAPI
   */
   if( (retval = PAPI_library_init( PAPI_VER_CURRENT) ) != PAPI_VER_CURRENT){
      printf("Error in papi version\n");
      exit(-1);
   }
   if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL ) {
      printf("Error PAPI_get_hardware_info\n");
      exit(-1);
   }

   if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ){
      printf("Error PAPI_create_eventset %d\n", retval );
      exit(-1);
   }
   
}


void startPapi(){

   /**
   *2.starting PAPI
   */

   if ( PAPI_add_events( EventSet, events, NEvents ) != PAPI_OK )
      printf("Error PAPI_add_event \n" );

   if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
      printf("Error PAPI_start %d\n", retval );
}

void endPapi(){
   /**
   * 3. Stop and destroy PAPI
   */
   if ( ( retval = PAPI_stop( EventSet, NULL ) ) != PAPI_OK )
      printf( "Error PAPI_stop %d\n", retval );

   if( (  retval = PAPI_cleanup_eventset(EventSet) ) != PAPI_OK )
      printf("Error PAPI_cleanup_eventset %d\n", retval); 

        if ( ( retval = PAPI_destroy_eventset( &EventSet ) ) != PAPI_OK )
      printf("Error PAPI_destroy_eventset %d\n", retval );
}

void main(){

       initPapi();
       startPapi();

   if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
      printf("Error PAPI_reset %d\n", retval );   

   if ( ( retval = PAPI_read( EventSet, counters ) ) != PAPI_OK )
      printf("Error PAPI_read %d\n", retval );

   endPapi();
   printf ("L1 data cache access: %lld\t L1 data cache hits: %lli\t : L1 data cache misses: %lld\n", counters[0], counters[1], counters[2]);
}


Finally, some executions of the codes show the following results:

High Level ----
L1 data cache access: 1015 L1 data cache hits: 996 : L1 data cache misses: 19
L1 data cache access: 1005 L1 data cache hits: 988 : L1 data cache misses: 17
L1 data cache access: 1019 L1 data cache hits: 1001 : L1 data cache misses: 18


Low Level ----
L1 data cache access: 885 L1 data cache hits: 874 : L1 data cache misses: 11
L1 data cache access: 869 L1 data cache hits: 860 : L1 data cache misses: 9
L1 data cache access: 892 L1 data cache hits: 882 : L1 data cache misses: 10

Thanks.

Re: A Simple question

PostPosted: Tue Nov 09, 2010 6:28 pm
by vweaver1
From what I can tell your numbers look reasonable. PAPI unfortunately has a certain amount of overhead inherent in its library calls. The high-level interface is likely to have a slightly higher overhead, as you noticed.