PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hl_rates.c
Go to the documentation of this file.
1 /* file hl_rates.c
2  * This test exercises the four PAPI High Level rate calls:
3  * PAPI_flops, PAPI_flips, PAPI_ipc, and PAPI_epc
4  * flops and flips report cumulative real and process time since the first call,
5  * and either floating point operations or instructions since the first call.
6  * Also reported is incremental flop or flip rate since the last call.
7  *
8  * PAPI_ipc reports the same cumulative information, substituting total instructions
9  * for flops or flips, and also reports instructions per (process) cycle as
10  * a measure of execution efficiency.
11  *
12  * PAPI_epc is new in PAPI 5.2. It reports the same information as PAPI_IPC, but
13  * for an arbitrary event instead of total cycles. It also reports incremental
14  * core and (where available) reference cycles to allow the computation of
15  * effective clock rates in the presence of clock scaling like speed step or turbo-boost.
16  *
17  * This test computes a 1000 x 1000 matrix multiply for orders of indexing for
18  * each of the four rate calls. It also accepts a command line parameter for the
19  * event to be measured for PAPI_epc. If not provided, PAPI_TOT_INS is measured.
20  */
21 
22 #include "papi_test.h"
23 
24 #define ROWS 1000 // Number of rows in each matrix
25 #define COLUMNS 1000 // Number of columns in each matrix
26 
28 
29 static void init_mat()
30 {
31  // Initialize the two matrices
32  int i, j;
33  for (i = 0; i < ROWS; i++) {
34  for (j = 0; j < COLUMNS; j++) {
35  matrix_a[i][j] = (float) rand() / RAND_MAX;
36  matrix_b[i][j] = (float) rand() / RAND_MAX;
37  }
38  }
39 
40 }
41 
42 static void classic_matmul()
43 {
44  // Multiply the two matrices
45  int i, j, k;
46  for (i = 0; i < ROWS; i++) {
47  for (j = 0; j < COLUMNS; j++) {
48  float sum = 0.0;
49  for (k = 0; k < COLUMNS; k++) {
50  sum +=
51  matrix_a[i][k] * matrix_b[k][j];
52  }
53  matrix_c[i][j] = sum;
54  }
55  }
56 }
57 
58 static void swapped_matmul()
59 {
60  // Multiply the two matrices
61  int i, j, k;
62  for (i = 0; i < ROWS; i++) {
63  for (k = 0; k < COLUMNS; k++) {
64  for (j = 0; j < COLUMNS; j++) {
65  matrix_c[i][j] +=
66  matrix_a[i][k] * matrix_b[k][j];
67  }
68  }
69  }
70 }
71 
72 int
73 main( int argc, char **argv )
74 {
75  int retval, event = 0;
76  float rtime, ptime, mflips, mflops, ipc, epc;
77  long long flpins, flpops, ins, ref, core, evt;
78 
79  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
80 
81  init_mat();
82 
83  printf( "\n----------------------------------\n" );
84  printf( "PAPI_flips\n");
85  if ( PAPI_flips(&rtime, &ptime, &flpins, &mflips) != PAPI_OK )
86  PAPI_perror( "PAPI_flips" );
87  printf( "\nStart\n");
88  printf( "real time: %f\n", rtime);
89  printf( "process time: %f\n", ptime);
90  printf( "FP Instructions: %lld\n", flpins);
91  printf( "MFLIPS %f\n", mflips);
93  if ( PAPI_flips(&rtime, &ptime, &flpins, &mflips) != PAPI_OK )
94  PAPI_perror( "PAPI_flips" );
95  printf( "\nClassic\n");
96  printf( "real time: %f\n", rtime);
97  printf( "process time: %f\n", ptime);
98  printf( "FP Instructions: %lld\n", flpins);
99  printf( "MFLIPS %f\n", mflips);
100  swapped_matmul();
101  if ( PAPI_flips(&rtime, &ptime, &flpins, &mflips) != PAPI_OK )
102  PAPI_perror( "PAPI_flips" );
103  printf( "\nSwapped\n");
104  printf( "real time: %f\n", rtime);
105  printf( "process time: %f\n", ptime);
106  printf( "FP Instructions: %lld\n", flpins);
107  printf( "MFLIPS %f\n", mflips);
108 
109  // turn off flips
110  if ( PAPI_stop_counters(NULL, 0) != PAPI_OK )
111  PAPI_perror( "PAPI_stop_counters" );
112  printf( "\n----------------------------------\n" );
113 
114  printf( "PAPI_flops\n");
115  if ( PAPI_flops(&rtime, &ptime, &flpops, &mflops) != PAPI_OK )
116  PAPI_perror( "PAPI_flops" );
117  printf( "\nStart\n");
118  printf( "real time: %f\n", rtime);
119  printf( "process time: %f\n", ptime);
120  printf( "FP Operations: %lld\n", flpops);
121  printf( "MFLOPS %f\n", mflops);
122  classic_matmul();
123  if ( PAPI_flops(&rtime, &ptime, &flpops, &mflops) != PAPI_OK )
124  PAPI_perror( "PAPI_flops" );
125  printf( "\nClassic\n");
126  printf( "real time: %f\n", rtime);
127  printf( "process time: %f\n", ptime);
128  printf( "FP Operations: %lld\n", flpops);
129  printf( "MFLOPS %f\n", mflops);
130  swapped_matmul();
131  if ( PAPI_flops(&rtime, &ptime, &flpops, &mflops) != PAPI_OK )
132  PAPI_perror( "PAPI_flops" );
133  printf( "\nSwapped\n");
134  printf( "real time: %f\n", rtime);
135  printf( "process time: %f\n", ptime);
136  printf( "FP Operations: %lld\n", flpops);
137  printf( "MFLOPS %f\n", mflops);
138 
139  // turn off flops
140  if ( PAPI_stop_counters(NULL, 0) != PAPI_OK )
141  PAPI_perror( "PAPI_stop_counters" );
142  printf( "\n----------------------------------\n" );
143 
144  printf( "PAPI_ipc\n");
145  if ( PAPI_ipc(&rtime, &ptime, &ins, &ipc) != PAPI_OK )
146  PAPI_perror( "PAPI_ipc" );
147  printf( "\nStart\n");
148  printf( "real time: %f\n", rtime);
149  printf( "process time: %f\n", ptime);
150  printf( "Instructions: %lld\n", ins);
151  printf( "IPC %f\n", ipc);
152  classic_matmul();
153  if ( PAPI_ipc(&rtime, &ptime, &ins, &ipc) != PAPI_OK )
154  PAPI_perror( "PAPI_ipc" );
155  printf( "\nClassic\n");
156  printf( "real time: %f\n", rtime);
157  printf( "process time: %f\n", ptime);
158  printf( "Instructions: %lld\n", ins);
159  printf( "IPC %f\n", ipc);
160  swapped_matmul();
161  if ( PAPI_ipc(&rtime, &ptime, &ins, &ipc) != PAPI_OK )
162  PAPI_perror( "PAPI_ipc" );
163  printf( "\nSwapped\n");
164  printf( "real time: %f\n", rtime);
165  printf( "process time: %f\n", ptime);
166  printf( "Instructions: %lld\n", ins);
167  printf( "IPC %f\n", ipc);
168 
169  // turn off ipc
170  if ( PAPI_stop_counters(NULL, 0) != PAPI_OK )
171  PAPI_perror( "PAPI_stop_counters" );
172  printf( "\n----------------------------------\n" );
173 
174  printf( "PAPI_epc\n");
175 
176  if ( argc >= 2) {
177  retval = PAPI_event_name_to_code( argv[1], &event );
178  if (retval != PAPI_OK) {
179  PAPI_perror("PAPI_event_name_to_code");
180  printf("Can't find %s; Using PAPI_TOT_INS\n", argv[1]);
181  event = 0;
182  } else {
183  printf("Using event %s\n", argv[1]);
184  }
185  }
186 
187  if ( PAPI_epc(event, &rtime, &ptime, &ref, &core, &evt, &epc) != PAPI_OK )
188  PAPI_perror( "PAPI_epc" );
189  printf( "\nStart\n");
190  printf( "real time: %f\n", rtime);
191  printf( "process time: %f\n", ptime);
192  printf( "Ref Cycles: %lld\n", ref);
193  printf( "Core Cycles: %lld\n", core);
194  printf( "Events: %lld\n", evt);
195  printf( "EPC: %f\n", epc);
196  classic_matmul();
197  if ( PAPI_epc(event, &rtime, &ptime, &ref, &core, &evt, &epc) != PAPI_OK )
198  PAPI_perror( "PAPI_epc" );
199  printf( "\nClassic\n");
200  printf( "real time: %f\n", rtime);
201  printf( "process time: %f\n", ptime);
202  printf( "Ref Cycles: %lld\n", ref);
203  printf( "Core Cycles: %lld\n", core);
204  printf( "Events: %lld\n", evt);
205  printf( "EPC: %f\n", epc);
206  swapped_matmul();
207  if ( PAPI_epc(event, &rtime, &ptime, &ref, &core, &evt, &epc) != PAPI_OK )
208  PAPI_perror( "PAPI_epc" );
209  printf( "\nSwapped\n");
210  printf( "real time: %f\n", rtime);
211  printf( "process time: %f\n", ptime);
212  printf( "Ref Cycles: %lld\n", ref);
213  printf( "Core Cycles: %lld\n", core);
214  printf( "Events: %lld\n", evt);
215  printf( "EPC: %f\n", epc);
216 
217  // turn off epc
218  if ( PAPI_stop_counters(NULL, 0) != PAPI_OK )
219  PAPI_perror( "PAPI_stop_counters" );
220  printf( "\n----------------------------------\n" );
221  exit( 1 );
222 }
void PAPI_perror(char *msg)
Definition: papi.c:4533
static void swapped_matmul()
Definition: hl_rates.c:58
int PAPI_ipc(float *rtime, float *ptime, long long *ins, float *ipc)
Definition: papi_hl.c:316
#define ROWS
Definition: hl_rates.c:24
int PAPI_flops(float *rtime, float *ptime, long long *flpops, float *mflops)
Definition: papi_hl.c:259
device[deviceId] domain[domainId] event
Definition: linux-cuda.c:306
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
int int argc
Definition: iozone.c:1609
static float matrix_a[ROWS][COLUMNS]
Definition: hl_rates.c:27
char ** argv
Definition: iozone.c:1610
int PAPI_flips(float *rtime, float *ptime, long long *flpins, float *mflips)
Definition: papi_hl.c:204
int PAPI_epc(int event, float *rtime, float *ptime, long long *ref, long long *core, long long *evt, float *epc)
Definition: papi_hl.c:383
static void init_mat()
Definition: hl_rates.c:29
int i
Definition: fileop.c:140
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:803
int k
Definition: iozone.c:19136
static void classic_matmul()
Definition: hl_rates.c:42
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
static float matrix_b[ROWS][COLUMNS]
Definition: hl_rates.c:27
static float matrix_c[ROWS][COLUMNS]
Definition: hl_rates.c:27
#define COLUMNS
Definition: hl_rates.c:25
int rand()
long j
Definition: iozone.c:19135
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
void exit()