PAPI 7.1.0.0
Loading...
Searching...
No Matches
branches.c File Reference
Include dependency graph for branches.c:

Go to the source code of this file.

Macros

#define MAXEVENTS   4
 
#define MINCOUNTS   100000
 
#define MPX_TOLERANCE   .20
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ MAXEVENTS

#define MAXEVENTS   4

Definition at line 33 of file branches.c.

◆ MINCOUNTS

#define MINCOUNTS   100000

Definition at line 34 of file branches.c.

◆ MPX_TOLERANCE

#define MPX_TOLERANCE   .20

Definition at line 35 of file branches.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 38 of file branches.c.

39{
41 int i, j, retval, errors=0;
42 int iters = 10000000;
43 double x = 1.1, y;
44 long long t1, t2;
45 long long values[MAXEVENTS], refvalues[MAXEVENTS];
46 double spread[MAXEVENTS];
47 int nevents = MAXEVENTS;
48 int eventset = PAPI_NULL;
49 int events[MAXEVENTS];
50 int quiet;
51 char event_names[MAXEVENTS][256] = {
52 "PAPI_BR_NTK", // not taken
53 "PAPI_BR_PRC", // predicted correctly
54 "PAPI_BR_INS", // total branches
55 "PAPI_BR_MSP", // branches mispredicted
56 };
57
58 /* Set quiet variable */
59 quiet = tests_quiet( argc, argv );
60
61 /* Parse command line args */
62 if ( argc > 1 ) {
63 if ( !strcmp( argv[1], "TESTS_QUIET" ) ) {
64
65 }
66 }
67
68 events[0] = PAPI_BR_NTK; // not taken
69 events[1] = PAPI_BR_PRC; // predicted correctly
70 events[2] = PAPI_BR_INS; // total branches
71 events[3] = PAPI_BR_MSP; // branches mispredicted
72
73 /* Why were these disabled?
74 events[3]=PAPI_BR_CN;
75 events[4]=PAPI_BR_UCN;
76 events[5]=PAPI_BR_TKN; */
77
78
79 /* Clear out the results to zero */
80 for ( i = 0; i < MAXEVENTS; i++ ) {
81 values[i] = 0;
82 }
83
84 if ( !quiet ) {
85 printf( "\nAccuracy check of branch presets.\n" );
86 printf( "Comparing a measurement with separate measurements.\n\n" );
87 }
88
89 /* Initialize library */
91 if (retval != PAPI_VER_CURRENT ) {
92 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
93 }
94
95 /* Create Eventset */
96 retval = PAPI_create_eventset( &eventset );
97 if ( retval ) {
98 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
99 }
100
101#ifdef MPX
103 if ( retval ) {
104 test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval );
105 }
106
107 retval = PAPI_set_multiplex( eventset );
108 if ( retval ) {
109 test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
110 }
111#endif
112
113 nevents = 0;
114
115 /* Add as many of the 4 events that exist on this machine */
116 for ( i = 0; i < MAXEVENTS; i++ ) {
117 if ( PAPI_query_event( events[i] ) != PAPI_OK )
118 continue;
119 if ( PAPI_add_event( eventset, events[i] ) == PAPI_OK ) {
120 events[nevents] = events[i];
121 nevents++;
122 }
123 }
124
125 /* If none of the events can be added, skip this test */
126 if ( nevents < 1 ) {
127 test_skip( __FILE__, __LINE__, "Not enough events left...", 0 );
128 }
129
130 /* Find a reasonable number of iterations (each
131 * event active 20 times) during the measurement
132 */
133
134 /* Target: 10000 usec/multiplex, 20 repeats */
135 t2 = (long long)(10000 * 20) * nevents;
136
137 if ( t2 > 30e6 ) {
138 test_skip( __FILE__, __LINE__, "This test takes too much time",
139 retval );
140 }
141
142 /* Measure one run */
144 y = do_flops3( x, iters, 1 );
145 t1 = PAPI_get_real_usec( ) - t1;
146
147 if ( t2 > t1 ) /* Scale up execution time to match t2 */
148 iters = iters * ( int ) ( t2 / t1 );
149 else if ( t1 > 30e6 ) /* Make sure execution time is < 30s per repeated test */
150 test_skip( __FILE__, __LINE__, "This test takes too much time",
151 retval );
152
153 x = 1.0;
154
155 /**********************************/
156 /* First run: Grouped Measurement */
157 /**********************************/
158 if ( !quiet ) {
159 printf( "\nFirst run: Together.\n" );
160 }
161
163
164 retval = PAPI_start( eventset );
165 if (retval) test_fail( __FILE__, __LINE__, "PAPI_start", retval );
166
167 y = do_flops3( x, iters, 1 );
168
169 retval = PAPI_stop( eventset, values );
170 if (retval) test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
171
173
174 if ( !quiet ) {
175 printf( "\tOperations= %.1f Mflop", y * 1e-6 );
176 printf( "\t(%g Mflop/s)\n\n", ( y / ( double ) ( t2 - t1 ) ) );
177 printf( "PAPI grouped measurement:\n" );
178
179 for ( j = 0; j < nevents; j++ ) {
180 PAPI_get_event_info( events[j], &info );
181 printf( "%20s = ", info.short_descr );
182 printf( LLDFMT, values[j] );
183 printf( "\n" );
184 }
185 printf( "\n" );
186 }
187
188 /* Remove all the events, start again */
189 retval = PAPI_remove_events( eventset, events, nevents );
190 if (retval) test_fail( __FILE__, __LINE__, "PAPI_remove_events", retval );
191
192 retval = PAPI_destroy_eventset( &eventset );
193 if (retval) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
194
195 /* Recreate eventset */
196 eventset = PAPI_NULL;
197 retval = PAPI_create_eventset( &eventset );
198 if (retval) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
199
200 /* Run events one by one */
201 for ( i = 0; i < nevents; i++ ) {
202
203 /* Clear out old event */
204 retval = PAPI_cleanup_eventset( eventset );
205 if (retval) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
206 /* Add the event */
207 retval = PAPI_add_event( eventset, events[i] );
208 if (retval) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
209
210 x = 1.0;
211
212 if ( !quiet ) {
213 printf( "\nReference measurement %d (of %d):\n", i + 1, nevents );
214 }
215
217
218 retval = PAPI_start( eventset );
219 if (retval) test_fail( __FILE__, __LINE__, "PAPI_start", retval );
220
221 y = do_flops3( x, iters, 1 );
222
223 retval = PAPI_stop( eventset, &refvalues[i] );
224 if (retval) test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
225
227
228
229 if ( !quiet ) {
230 printf( "\tOperations= %.1f Mflop", y * 1e-6 );
231 printf( "\t(%g Mflop/s)\n\n", ( y / ( double ) ( t2 - t1 ) ) );
232 PAPI_get_event_info( events[i], &info );
233 printf( "PAPI results:\n%20s = ", info.short_descr );
234 printf( LLDFMT, refvalues[i] );
235 printf( "\n" );
236 }
237 }
238
239 if ( !quiet ) {
240 printf( "\n" );
241 }
242
243 /* Validate the results */
244
245 if ( !quiet ) {
246 printf( "\n\nRelative accuracy:\n" );
247 printf( "\tEvent\t\tGroup\t\tIndividual\tSpread\n");
248 }
249
250 for ( j = 0; j < nevents; j++ ) {
251 spread[j] = abs( ( int ) ( refvalues[j] - values[j] ) );
252 if ( values[j] )
253 spread[j] /= ( double ) values[j];
254 if ( !quiet ) {
255 printf( "\t%02d: ",j);
256 printf( "%s",event_names[j]);
257 printf( "\t%10lld", values[j] );
258 printf( "\t%10lld", refvalues[j] );
259 printf("\t%10.3g\n", spread[j] );
260 }
261
262 /* Make sure that NaN get counted as errors */
263 if ( spread[j] > MPX_TOLERANCE ) {
264
265 /* Neglect inprecise results with low counts */
266 if ( refvalues[j] < MINCOUNTS ) {
267 }
268 else {
269 errors++;
270 if (!quiet) {
271 printf("\tError: Spread > %lf\n",MPX_TOLERANCE);
272 }
273 }
274 }
275 }
276 if ( !quiet ) {
277 printf( "\n\n" );
278 }
279
280 if ( errors ) {
281 test_fail( __FILE__, __LINE__, "Values outside threshold", i );
282 }
283
284 test_pass( __FILE__ );
285
286 return 0;
287}
static const char * event_names[2]
Definition: Gamum.c:27
int i
static struct timeval t1 t2
Definition: benchSANVML.c:117
#define MAXEVENTS
Definition: branches.c:33
#define MINCOUNTS
Definition: branches.c:34
#define MPX_TOLERANCE
Definition: branches.c:35
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Get the event's name and description info.
get real time counter value in microseconds
initialize the PAPI library.
Initialize multiplex support in the PAPI library.
Query if PAPI event exists.
Remove an array of hardware event codes from a PAPI event set.
Convert a standard event set to a multiplexed event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
volatile double t1
double do_flops3(double x, int iters, int quiet)
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_BR_NTK
Definition: f90papi.h:288
#define PAPI_BR_MSP
Definition: f90papi.h:337
#define PAPI_BR_PRC
Definition: f90papi.h:371
#define PAPI_BR_INS
Definition: f90papi.h:300
char events[MAX_EVENTS][BUFSIZ]
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
#define LLDFMT
Definition: papi_test.h:104
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
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int quiet
Definition: rapl_overflow.c:19
int
Definition: sde_internal.h:89
long long int long long
Definition: sde_internal.h:85
char short_descr[PAPI_MIN_STR_LEN]
Definition: papi.h:961
volatile double y
volatile double x
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: