PAPI 7.1.0.0
Loading...
Searching...
No Matches
flops_validation.c
Go to the documentation of this file.
1/* flops.c, based on the hl_rates.c ctest
2 *
3 * This test runs a "classic" matrix multiply
4 * and then runs it again with the inner loop swapped.
5 * the swapped version should have better MFLIPS/MFLOPS/IPC and we test that.
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10
11#include "papi.h"
12#include "papi_test.h"
13
14#include "testcode.h"
15
16int
17main( int argc, char **argv )
18{
19 int retval;
20 double rtime, ptime, mflips, mflops, ipc;
21 long long flips=0, flops=0, ins[2];
22
23 double rtime_start,rtime_end;
24 double ptime_start,ptime_end;
25
26 double rtime_classic,rtime_swapped;
27 double mflips_classic,mflips_swapped;
28 double mflops_classic,mflops_swapped;
29 double ipc_classic,ipc_swapped;
30
31 int quiet,event_added_flips,event_added_flops,event_added_ipc;
32
33 int eventset=PAPI_NULL;
34
35 /* Set TESTS_QUIET variable */
36 quiet=tests_quiet( argc, argv );
37
38
39 /* Init the PAPI library */
41 if ( retval != PAPI_VER_CURRENT ) {
42 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
43 }
44
45 /* Create the eventset */
47 if (retval!=PAPI_OK) {
48 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
49 }
50
51 /* Initialize the test matrix */
53
54 /************************/
55 /* FLIPS */
56 /************************/
57
58 if (!quiet) {
59 printf( "\n----------------------------------\n" );
60 printf( "PAPI_flips\n");
61 }
62
63 /* Add FP_INS event */
64 retval=PAPI_add_named_event(eventset,"PAPI_FP_INS");
65 if (retval!=PAPI_OK) {
66 if (!quiet) fprintf(stderr,"PAPI_FP_INS not available!\n");
67 event_added_flips=0;
68 }
69 else {
70 event_added_flips=1;
71 }
72
73 if (event_added_flips) {
74 PAPI_start(eventset);
75 }
76
77 rtime_start=PAPI_get_real_usec();
78 ptime_start=PAPI_get_virt_usec();
79
80 // Flips classic
82
83 rtime_end=PAPI_get_real_usec();
84 ptime_end=PAPI_get_virt_usec();
85
86 if (event_added_flips) {
87 PAPI_stop(eventset,&flips);
88 }
89
90 rtime=rtime_end-rtime_start;
91 ptime=ptime_end-ptime_start;
92
93 mflips=flips/rtime;
94
95 if (!quiet) {
96 printf( "\nClassic\n");
97 printf( "real time: %lf\n", rtime);
98 printf( "process time: %lf\n", ptime);
99 printf( "FP Instructions: %lld\n", flips);
100 printf( "MFLIPS %lf\n", mflips);
101 }
102 mflips_classic=mflips;
103
104
105 // Flips swapped
106 rtime_start=PAPI_get_real_usec();
107 ptime_start=PAPI_get_virt_usec();
108
109 if (event_added_flips) {
110 PAPI_reset(eventset);
111 PAPI_start(eventset);
112 }
113
115
116 rtime_end=PAPI_get_real_usec();
117 ptime_end=PAPI_get_virt_usec();
118
119 if (event_added_flips) {
120 PAPI_stop(eventset,&flips);
121 }
122
123 rtime=rtime_end-rtime_start;
124 ptime=ptime_end-ptime_start;
125
126 mflips=flips/rtime;
127
128 if (!quiet) {
129 printf( "\nSwapped\n");
130 printf( "real time: %f\n", rtime);
131 printf( "process time: %f\n", ptime);
132 printf( "FP Instructions: %lld\n", flips);
133 printf( "MFLIPS %f\n", mflips);
134 }
135 mflips_swapped=mflips;
136
137 // turn off flips
138 if (event_added_flips) {
139 retval=PAPI_remove_named_event(eventset,"PAPI_FP_INS");
140 if (retval!=PAPI_OK) {
141 test_fail( __FILE__, __LINE__,
142 "PAPI_remove_named_event", retval );
143 }
144 }
145
146 /************************/
147 /* FLOPS */
148 /************************/
149
150 if (!quiet) {
151 printf( "\n----------------------------------\n" );
152 printf( "PAPI_flops\n");
153 }
154
155 /* Add FP_OPS event */
156 retval=PAPI_add_named_event(eventset,"PAPI_FP_OPS");
157 if (retval!=PAPI_OK) {
158 if (!quiet) fprintf(stderr,"PAPI_FP_OPS not available!\n");
159 event_added_flops=0;
160 }
161 else {
162 event_added_flops=1;
163 }
164
165 if (event_added_flops) {
166 PAPI_start(eventset);
167 }
168
169 rtime_start=PAPI_get_real_usec();
170 ptime_start=PAPI_get_virt_usec();
171
172 // Classic flops
174
175 rtime_end=PAPI_get_real_usec();
176 ptime_end=PAPI_get_virt_usec();
177
178 if (event_added_flops) {
179 PAPI_stop(eventset,&flops);
180 }
181
182 rtime=rtime_end-rtime_start;
183 ptime=ptime_end-ptime_start;
184
185 mflops=flops/rtime;
186
187 if (!quiet) {
188 printf( "\nClassic\n");
189 printf( "real time: %f\n", rtime);
190 printf( "process time: %f\n", ptime);
191 printf( "FP Operations: %lld\n", flops);
192 printf( "MFLOPS %f\n", mflops);
193 }
194 mflops_classic=mflops;
195
196 // Swapped flops
197
198 rtime_start=PAPI_get_real_usec();
199 ptime_start=PAPI_get_virt_usec();
200
201 if (event_added_flops) {
202 PAPI_reset(eventset);
203 PAPI_start(eventset);
204 }
205
207
208 rtime_end=PAPI_get_real_usec();
209 ptime_end=PAPI_get_virt_usec();
210
211 if (event_added_flops) {
212 PAPI_stop(eventset,&flops);
213 }
214
215 rtime=rtime_end-rtime_start;
216 ptime=ptime_end-ptime_start;
217
218 mflops=flops/rtime;
219
220 if (!quiet) {
221 printf( "\nSwapped\n");
222 printf( "real time: %f\n", rtime);
223 printf( "process time: %f\n", ptime);
224 printf( "FP Operations: %lld\n", flops);
225 printf( "MFLOPS %f\n", mflops);
226 }
227 mflops_swapped=mflops;
228
229 // turn off flops
230 if (event_added_flops) {
231 retval=PAPI_remove_named_event(eventset,"PAPI_FP_OPS");
232 if (retval!=PAPI_OK) {
233 test_fail( __FILE__, __LINE__,
234 "PAPI_remove_named_event", retval );
235 }
236 }
237
238 /************************/
239 /* IPC */
240 /************************/
241
242 if (!quiet) {
243 printf( "\n----------------------------------\n" );
244 printf( "PAPI_ipc\n");
245 }
246
247 /* Add PAPI_TOT_INS event */
248 retval=PAPI_add_named_event(eventset,"PAPI_TOT_INS");
249 if (retval!=PAPI_OK) {
250 if (!quiet) fprintf(stderr,"PAPI_TOT_INS not available!\n");
251 event_added_ipc=0;
252 }
253 else {
254 event_added_ipc=1;
255 }
256
257 if (event_added_ipc) {
258 /* Add PAPI_TOT_CYC event */
259 retval=PAPI_add_named_event(eventset,"PAPI_TOT_CYC");
260 if (retval!=PAPI_OK) {
261 if (!quiet) fprintf(stderr,"PAPI_TOT_CYC not available!\n");
262 event_added_ipc=0;
263 }
264 else {
265 event_added_ipc=1;
266 }
267 }
268
269 if (event_added_ipc) {
270 PAPI_start(eventset);
271 }
272
273 rtime_start=PAPI_get_real_usec();
274 ptime_start=PAPI_get_virt_usec();
275
276 // Classic ipc
278
279 rtime_end=PAPI_get_real_usec();
280 ptime_end=PAPI_get_virt_usec();
281
282 if (event_added_ipc) {
283 PAPI_stop(eventset,ins);
284 }
285
286 rtime=rtime_end-rtime_start;
287 ptime=ptime_end-ptime_start;
288
289 ipc=(double)ins[0]/(double)ins[1];
290
291 if (!quiet) {
292 printf( "\nClassic\n");
293 printf( "real time: %lf\n", rtime);
294 printf( "process time: %lf\n", ptime);
295 printf( "Instructions: %lld\n", ins[0]);
296 printf( "Cycles: %lld\n", ins[1]);
297 printf( "IPC %lf\n", ipc);
298 }
299 ipc_classic=ipc;
300 rtime_classic=rtime;
301
302 // Swapped ipc
303
304 if (event_added_ipc) {
305 PAPI_reset(eventset);
306 PAPI_start(eventset);
307 }
308
309 rtime_start=PAPI_get_real_usec();
310 ptime_start=PAPI_get_virt_usec();
311
312
314
315 rtime_end=PAPI_get_real_usec();
316 ptime_end=PAPI_get_virt_usec();
317
318 if (event_added_ipc) {
319 PAPI_stop(eventset,ins);
320 }
321
322 rtime=rtime_end-rtime_start;
323 ptime=ptime_end-ptime_start;
324
325 ipc=(double)ins[0]/(double)ins[1];
326
327 if (!quiet) {
328 printf( "\nSwapped\n");
329 printf( "real time: %lf\n", rtime);
330 printf( "process time: %lf\n", ptime);
331 printf( "Instructions: %lld\n", ins[0]);
332 printf( "Cycles: %lld\n", ins[1]);
333 printf( "IPC %lf\n", ipc);
334 }
335 ipc_swapped=ipc;
336 rtime_swapped=rtime;
337
338
339 /* Validate */
340 if (event_added_flips) {
341 if (mflips_swapped<mflips_classic) {
342 test_fail(__FILE__,__LINE__,
343 "FLIPS should be better when swapped",0);
344 }
345 }
346
347 if (event_added_flops) {
348 if (mflops_swapped<mflops_classic) {
349 test_fail(__FILE__,__LINE__,
350 "FLOPS should be better when swapped",0);
351 }
352 }
353
354 if (event_added_ipc) {
355 if (ipc_swapped<ipc_classic) {
356 test_fail(__FILE__,__LINE__,
357 "IPC should be better when swapped",0);
358 }
359 }
360
361 if (rtime_swapped>rtime_classic) {
362 test_fail(__FILE__,__LINE__,
363 "time should be better when swapped",0);
364 }
365
366 test_pass( __FILE__ );
367
368 return 0;
369}
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
get real time counter value in microseconds
get virtual time counter values in microseconds
initialize the PAPI library.
removes a named hardware event from a PAPI event set.
Reset the hardware event counts in an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
float flops_float_swapped_matrix_matrix_multiply(void)
float flops_float_matrix_matrix_multiply(void)
int flops_float_init_matrix(void)
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
Return codes and api definitions.
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
int retval
Definition: zero_fork.c:53