rapl_basic.c File Reference

Include dependency graph for rapl_basic.c:

Go to the source code of this file.

Defines

#define MAX_RAPL_EVENTS   64
 Tests basic functionality of RAPL component.
#define MATRIX_SIZE   1024

Functions

void run_test (int quiet)
int main (int argc, char **argv)

Variables

static double a [MATRIX_SIZE][MATRIX_SIZE]
static double b [MATRIX_SIZE][MATRIX_SIZE]
static double c [MATRIX_SIZE][MATRIX_SIZE]

Define Documentation

#define MATRIX_SIZE   1024

Definition at line 35 of file rapl_basic.c.

#define MAX_RAPL_EVENTS   64
Author:
Vince Weaver

test case for RAPL component

Definition at line 18 of file rapl_basic.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 80 of file rapl_basic.c.

00081 {
00082 
00083     int retval,cid,rapl_cid=-1,numcmp;
00084     int EventSet = PAPI_NULL;
00085     long long *values;
00086     int num_events=0;
00087     int code;
00088     char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN];
00089     char units[MAX_RAPL_EVENTS][PAPI_MIN_STR_LEN];
00090     int data_type[MAX_RAPL_EVENTS];
00091     int r,i;
00092     const PAPI_component_info_t *cmpinfo = NULL;
00093     PAPI_event_info_t evinfo;
00094     long long before_time,after_time;
00095     double elapsed_time;
00096 
00097 #ifdef WRAP_TEST
00098 
00099     int do_wrap=0;
00100 
00101     if ( argc > 1 ) {
00102         if ( strstr( argv[1], "-w" ) ) {
00103             do_wrap = 1;
00104         }
00105     }
00106 
00107 #endif
00108 
00109         /* Set TESTS_QUIET variable */
00110      tests_quiet( argc, argv );
00111 
00112     /* PAPI Initialization */
00113      retval = PAPI_library_init( PAPI_VER_CURRENT );
00114      if ( retval != PAPI_VER_CURRENT ) {
00115     test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
00116      }
00117 
00118      if (!TESTS_QUIET) {
00119         printf("Trying all RAPL events\n");
00120      }
00121 
00122      numcmp = PAPI_num_components();
00123 
00124      for(cid=0; cid<numcmp; cid++) {
00125 
00126     if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
00127        test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
00128     }
00129 
00130     if (strstr(cmpinfo->name,"rapl")) {
00131 
00132        rapl_cid=cid;
00133 
00134        if (!TESTS_QUIET) {
00135           printf("Found rapl component at cid %d\n",rapl_cid);
00136        }
00137 
00138            if (cmpinfo->disabled) {
00139           if (!TESTS_QUIET) {
00140          printf("RAPL component disabled: %s\n",
00141                         cmpinfo->disabled_reason);
00142           }
00143               test_skip(__FILE__,__LINE__,"RAPL component disabled",0);
00144            }
00145        break;
00146     }
00147      }
00148 
00149      /* Component not found */
00150      if (cid==numcmp) {
00151        test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
00152      }
00153 
00154      /* Create EventSet */
00155      retval = PAPI_create_eventset( &EventSet );
00156      if (retval != PAPI_OK) {
00157     test_fail(__FILE__, __LINE__,
00158                               "PAPI_create_eventset()",retval);
00159      }
00160 
00161      /* Add all events */
00162 
00163      code = PAPI_NATIVE_MASK;
00164 
00165      r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid );
00166 
00167      while ( r == PAPI_OK ) {
00168 
00169         retval = PAPI_event_code_to_name( code, event_names[num_events] );
00170     if ( retval != PAPI_OK ) {
00171        printf("Error translating %#x\n",code);
00172        test_fail( __FILE__, __LINE__,
00173                             "PAPI_event_code_to_name", retval );
00174     }
00175 
00176     retval = PAPI_get_event_info(code,&evinfo);
00177     if (retval != PAPI_OK) {
00178       test_fail( __FILE__, __LINE__,
00179              "Error getting event info\n",retval);
00180     }
00181 
00182     strncpy(units[num_events],evinfo.units,sizeof(units[0])-1);
00183     // buffer must be null terminated to safely use strstr operation on it below
00184     units[num_events][sizeof(units[0])-1] = '\0';
00185 
00186     data_type[num_events] = evinfo.data_type;
00187 
00188         retval = PAPI_add_event( EventSet, code );
00189         if (retval != PAPI_OK) {
00190       break; /* We've hit an event limit */
00191     }
00192     num_events++;
00193 
00194         r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid );
00195      }
00196 
00197      values=calloc(num_events,sizeof(long long));
00198      if (values==NULL) {
00199     test_fail(__FILE__, __LINE__,
00200                               "No memory",retval);
00201      }
00202 
00203      if (!TESTS_QUIET) {
00204     printf("\nStarting measurements...\n\n");
00205      }
00206 
00207      /* Start Counting */
00208      before_time=PAPI_get_real_nsec();
00209      retval = PAPI_start( EventSet);
00210      if (retval != PAPI_OK) {
00211     test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00212      }
00213 
00214      /* Run test */
00215      run_test(TESTS_QUIET);
00216 
00217      /* Stop Counting */
00218      after_time=PAPI_get_real_nsec();
00219      retval = PAPI_stop( EventSet, values);
00220      if (retval != PAPI_OK) {
00221     test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
00222      }
00223 
00224      elapsed_time=((double)(after_time-before_time))/1.0e9;
00225 
00226      if (!TESTS_QUIET) {
00227         printf("\nStopping measurements, took %.3fs, gathering results...\n\n",
00228            elapsed_time);
00229 
00230         printf("Scaled energy measurements:\n");
00231 
00232         for(i=0;i<num_events;i++) {
00233            if (strstr(units[i],"nJ")) {
00234 
00235               printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
00236                 event_names[i],
00237                 (double)values[i]/1.0e9,
00238                 ((double)values[i]/1.0e9)/elapsed_time);
00239            }
00240         }
00241 
00242         printf("\n");
00243         printf("Energy measurement counts:\n");
00244 
00245         for(i=0;i<num_events;i++) {
00246            if (strstr(event_names[i],"ENERGY_CNT")) {
00247               printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
00248            }
00249         }
00250 
00251         printf("\n");
00252         printf("Scaled Fixed values:\n");
00253 
00254         for(i=0;i<num_events;i++) {
00255            if (!strstr(event_names[i],"ENERGY")) {
00256              if (data_type[i] == PAPI_DATATYPE_FP64) {
00257 
00258                  union {
00259                    long long ll;
00260                    double fp;
00261                  } result;
00262 
00263                 result.ll=values[i];
00264                 printf("%-40s%12.3f %s\n", event_names[i], result.fp, units[i]);
00265               }
00266            }
00267         }
00268 
00269         printf("\n");
00270         printf("Fixed value counts:\n");
00271 
00272         for(i=0;i<num_events;i++) {
00273            if (!strstr(event_names[i],"ENERGY")) {
00274               if (data_type[i] == PAPI_DATATYPE_UINT64) {
00275                 printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
00276               }
00277            }
00278         }
00279 
00280      }
00281 
00282 #ifdef WRAP_TEST
00283     double max_time;
00284     unsigned long long max_value = 0;
00285     int repeat;
00286 
00287     for(i=0;i<num_events;i++) {
00288         if (strstr(event_names[i],"ENERGY_CNT")) {
00289             if (max_value < (unsigned) values[i]) {
00290                 max_value = values[i];
00291             }
00292         }
00293     }
00294     max_time = elapsed_time * ( (double)0xffffffff / (double)max_value );
00295     printf("\n");
00296     printf ("Approximate time to energy measurement wraparound: %.3f sec or %.3f min.\n", 
00297         max_time, max_time/60);
00298 
00299     if (do_wrap) {
00300          printf ("Beginning wraparound execution.");
00301          /* Start Counting */
00302          before_time=PAPI_get_real_nsec();
00303          retval = PAPI_start( EventSet);
00304          if (retval != PAPI_OK) {
00305             test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00306          }
00307 
00308          /* Run test */
00309         repeat = (int)(max_time/elapsed_time);
00310         for (i=0;i< repeat;i++) {
00311             run_test(1);
00312             printf("."); fflush(stdout);
00313         }
00314         printf("\n");
00315 
00316          /* Stop Counting */
00317          after_time=PAPI_get_real_nsec();
00318          retval = PAPI_stop( EventSet, values);
00319          if (retval != PAPI_OK) {
00320             test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
00321          }
00322 
00323         elapsed_time=((double)(after_time-before_time))/1.0e9;
00324         printf("\nStopping measurements, took %.3fs\n\n", elapsed_time);
00325 
00326         printf("Scaled energy measurements:\n");
00327 
00328         for(i=0;i<num_events;i++) {
00329            if (strstr(units[i],"nJ")) {
00330 
00331               printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
00332                 event_names[i],
00333                 (double)values[i]/1.0e9,
00334                 ((double)values[i]/1.0e9)/elapsed_time);
00335            }
00336         }
00337         printf("\n");
00338         printf("Energy measurement counts:\n");
00339 
00340         for(i=0;i<num_events;i++) {
00341            if (strstr(event_names[i],"ENERGY_CNT")) {
00342               printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
00343            }
00344         }
00345     }
00346 
00347 #endif
00348 
00349      /* Done, clean up */
00350      retval = PAPI_cleanup_eventset( EventSet );
00351      if (retval != PAPI_OK) {
00352     test_fail(__FILE__, __LINE__,
00353                               "PAPI_cleanup_eventset()",retval);
00354      }
00355 
00356      retval = PAPI_destroy_eventset( &EventSet );
00357      if (retval != PAPI_OK) {
00358     test_fail(__FILE__, __LINE__,
00359                               "PAPI_destroy_eventset()",retval);
00360      }
00361 
00362      test_pass( __FILE__, NULL, 0 );
00363 
00364      return 0;
00365 }

Here is the call graph for this function:

void run_test ( int  quiet  ) 

Definition at line 42 of file rapl_basic.c.

00042                          {
00043 
00044        double s;
00045        int i,j,k;
00046 
00047        if (!quiet) {
00048             printf("Doing a naive %dx%d MMM...\n",MATRIX_SIZE,MATRIX_SIZE);
00049        }
00050 
00051        for(i=0;i<MATRIX_SIZE;i++) {
00052      for(j=0;j<MATRIX_SIZE;j++) {
00053        a[i][j]=(double)i*(double)j;
00054        b[i][j]=(double)i/(double)(j+5);
00055      }
00056        }
00057 
00058        for(j=0;j<MATRIX_SIZE;j++) {
00059      for(i=0;i<MATRIX_SIZE;i++) {
00060        s=0;
00061        for(k=0;k<MATRIX_SIZE;k++) {
00062          s+=a[i][k]*b[k][j];
00063        }
00064        c[i][j] = s;
00065      }
00066        }
00067 
00068        s=0.0;
00069        for(i=0;i<MATRIX_SIZE;i++) {
00070         for(j=0;j<MATRIX_SIZE;j++) {
00071             s+=c[i][j];
00072         }
00073        }
00074 
00075        if (!quiet) printf("Matrix multiply sum: s=%lf\n",s);
00076 }


Variable Documentation

double a[MATRIX_SIZE][MATRIX_SIZE] [static]

Definition at line 37 of file rapl_basic.c.

double b[MATRIX_SIZE][MATRIX_SIZE] [static]

Definition at line 38 of file rapl_basic.c.

double c[MATRIX_SIZE][MATRIX_SIZE] [static]

Definition at line 39 of file rapl_basic.c.


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1