Measurement differences between high and low interface

Measurement differences between high and low interface

Postby fbarisione » Mon Nov 08, 2010 10:52 am

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.
Attachments
code.zip
(1.2 KiB) Downloaded 90 times
Last edited by fbarisione on Wed Jul 13, 2011 11:26 am, edited 1 time in total.
fbarisione
 
Posts: 6
Joined: Mon Nov 08, 2010 8:19 am

Re: A Simple question

Postby vweaver1 » Mon Nov 08, 2010 5:47 pm

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?
vweaver1
 
Posts: 50
Joined: Wed Feb 17, 2010 4:02 pm

Re: A Simple question

Postby fbarisione » Mon Nov 08, 2010 8:51 pm

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.
fbarisione
 
Posts: 6
Joined: Mon Nov 08, 2010 8:19 am

Re: A Simple question

Postby vweaver1 » Tue Nov 09, 2010 6:28 pm

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.
vweaver1
 
Posts: 50
Joined: Wed Feb 17, 2010 4:02 pm


Return to Classic PAPI

Who is online

Users browsing this forum: No registered users and 1 guest

cron