combine PAPI_flops with PAPI_add_events possible?

Open discussion of PAPI.

combine PAPI_flops with PAPI_add_events possible?

Postby bravegag » Mon Jun 04, 2012 12:35 pm

Hello,

I have an use-case where I was already using PAPI_flops and now need to simultaneously also monitor other counters e.g. cache. The problem is that PAPI_flops and PAPI_add_events seem not to work along well together.

My use-case is detailed in the snippet below. I would like to be able to monitor all these events while at the same time enjoy the comfort of using PAPI_flops. If I do that all my events come out zero. Is there a way to make these two work together or do I have to renounce to use PAPI_flops?

How can I do that?

UPDATE: sorry missed looking at the error output, I get "PAPI_create_eventset error (-1): PAPI_EINVAL" is there a way around this and have the two work together?

Many TIA,
Best regards,
Giovanni

Code: Select all
   // first two are set implicitly
   const int PAPI_L1_DCA_INDEX = 2;
   const int PAPI_L1_DCM_INDEX = 3;
   const int PAPI_L2_DCA_INDEX = 4;
   const int PAPI_L2_DCM_INDEX = 5;

   const int NUM_EVENTS = 6;
   long long values[NUM_EVENTS] = {0, 0, 0, 0, 0, 0};
   int event_set = PAPI_NULL;
   int extra_events[NUM_EVENTS] = {PAPI_L1_DCA, PAPI_L1_DCM, PAPI_L2_DCA, PAPI_L2_DCM};
   int error_code;
   char error_string[PAPI_MAX_STR_LEN + 1];

   // initialize PAPI
   error_code = PAPI_flops(&real_time, &cpu_time, &fp_ins, &mflops);
   if (error_code != PAPI_OK) {
      PAPI_perror(error_code, error_string, PAPI_MAX_STR_LEN);
      fprintf(stderr, "PAPI_flops error (%d): %s\n", error_code, error_string);
   }

   // try adding new extra events
   error_code = PAPI_create_eventset(&event_set);
   if (error_code != PAPI_OK) {
      PAPI_perror(error_code, error_string, PAPI_MAX_STR_LEN);
      fprintf(stderr, "PAPI_create_eventset error (%d): %s\n", error_code, error_string);
   }

   error_code = PAPI_add_events(event_set, extra_events, NUM_EVENTS - 2);
   if (error_code != PAPI_OK) {
      PAPI_perror(error_code, error_string, PAPI_MAX_STR_LEN);
      fprintf(stderr, "PAPI_add_events(...) error (%d): %s\n", error_code, error_string);
   }

   // ...

Last edited by bravegag on Mon Jun 04, 2012 12:54 pm, edited 1 time in total.
bravegag
 
Posts: 5
Joined: Mon Jun 04, 2012 10:05 am

Re: combine PAPI_flops with PAPI_add_events possible?

Postby danterpstra » Mon Jun 04, 2012 12:52 pm

You are trying to combine calls to the PAPI high level interface with calls to the low level interface. Although this can be done, if you're very careful, you are probably better off just using the low level interface, since you need it to measure cache events anyway. Simply add PAPI_FP_OPS and PAPI_TOT_CYC to your list of events and measure everything together. You may need to do a little computing to get the same values produced by PAPI_flops, but that's pretty easy. Instead of measuring PAPI_TOT_CYC, you could wrap your code with calls to PAPI_get_real_msec and PAPI_get_virt_msec to measure the times reported in PAPI_flops.
I don't know what machine you're running on, but many machines may not have enough counters to measure all of these events at once. You may need to play around a bit.

Good luck!
danterpstra
 
Posts: 63
Joined: Wed Jun 23, 2010 2:21 pm

Re: combine PAPI_flops with PAPI_add_events possible?

Postby bravegag » Mon Jun 04, 2012 12:57 pm

Hi, thanks! :)

My system:
Linux bravegag-MacBookPro 3.0.0-21-generic #35-Ubuntu SMP Fri May 25 17:57:41 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
CPU: Intel 2 Core Duo T9900 among the lucky ones where perfmon2 works :)

You mention combining the two APIs is possible, how can I do that? it might save me from maybe hours debugging that all works again as before.

Many TIA,
Best regards,
Giovanni
bravegag
 
Posts: 5
Joined: Mon Jun 04, 2012 10:05 am

Re: combine PAPI_flops with PAPI_add_events possible?

Postby danterpstra » Mon Jun 04, 2012 1:44 pm

You really don't want to do that. You'd be exchanging hours of debugging stuff that used to work for hours of debugging why the high level and low level calls don't work together the way you expect. I'd recommend that you re-implement your current code using low level calls, and then add the extra events that you're interested in. Use the /ctests/calibrate tests case as an example of measuring FLOPS with low level calls.
BTW, Intel Core 2 supports 5 counters, IIRC. Two are fixed function and 3 are programmable. That means you will be able to measure at most 5 events at a time, and more likely only 4. You may need to make two passes through your code, one measuring flops and L1 behavior; the second measuring flops and L2 behavior.
danterpstra
 
Posts: 63
Joined: Wed Jun 23, 2010 2:21 pm

Re: combine PAPI_flops with PAPI_add_events possible?

Postby bravegag » Mon Jun 04, 2012 3:31 pm

hi again,

Thank you! Ok I did separate "benchmark passes" one for PAPI_flops, another for computing L1 cache hit ratio and yet another for computing L2 cache hit ratio and it is all good now, (the L2 doesn't work though).

Best regards,
Giovanni
bravegag
 
Posts: 5
Joined: Mon Jun 04, 2012 10:05 am


Return to General discussion

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron