PAPI 7.1.0.0
Loading...
Searching...
No Matches
tenth.c
Go to the documentation of this file.
1/*
2* File: tenth.c
3* Mods: Maynard Johnson
4* maynardj@us.ibm.com
5*/
6
7#include <stdio.h>
8#include <stdlib.h>
9
10#include "papi.h"
11#include "papi_test.h"
12
13#include "do_loops.h"
14
15#define ITERS 100
16
17/* This file performs the following test: start, stop and timer functionality for
18 PAPI_L1_TCM derived event
19
20 - They are counted in the default counting domain and default
21 granularity, depending on the platform. Usually this is
22 the user domain (PAPI_DOM_USER) and thread context (PAPI_GRN_THR).
23 - Get us.
24 - Start counters
25 - Do flops
26 - Stop and read counters
27 - Get us.
28*/
29
30
31#if defined(sun) && defined(sparc)
32#define CACHE_LEVEL "PAPI_L2_TCM"
33#define EVT1 PAPI_L2_TCM
34#define EVT2 PAPI_L2_TCA
35#define EVT3 PAPI_L2_TCH
36#define EVT1_STR "PAPI_L2_TCM"
37#define EVT2_STR "PAPI_L2_TCA"
38#define EVT3_STR "PAPI_L2_TCH"
39#define MASK1 MASK_L2_TCM
40#define MASK2 MASK_L2_TCA
41#define MASK3 MASK_L2_TCH
42#else
43#if defined(__powerpc__)
44#define CACHE_LEVEL "PAPI_L1_DCA"
45#define EVT1 PAPI_L1_DCA
46#define EVT2 PAPI_L1_DCW
47#define EVT3 PAPI_L1_DCR
48#define EVT1_STR "PAPI_L1_DCA"
49#define EVT2_STR "PAPI_L1_DCW"
50#define EVT3_STR "PAPI_L1_DCR"
51#define MASK1 MASK_L1_DCA
52#define MASK2 MASK_L1_DCW
53#define MASK3 MASK_L1_DCR
54#else
55#define CACHE_LEVEL "PAPI_L1_TCM"
56#define EVT1 PAPI_L1_TCM
57#define EVT2 PAPI_L1_ICM
58#define EVT3 PAPI_L1_DCM
59#define EVT1_STR "PAPI_L1_TCM"
60#define EVT2_STR "PAPI_L1_ICM"
61#define EVT3_STR "PAPI_L1_DCM"
62#define MASK1 MASK_L1_TCM
63#define MASK2 MASK_L1_ICM
64#define MASK3 MASK_L1_DCM
65#endif
66#endif
67
68
69int
70main( int argc, char **argv )
71{
72 int retval, num_tests = 30, tmp;
73 int EventSet1 = PAPI_NULL;
74 int EventSet2 = PAPI_NULL;
75 int EventSet3 = PAPI_NULL;
76 int mask1 = MASK1;
77 int mask2 = MASK2;
78 int mask3 = MASK3;
79 int num_events1;
80 int num_events2;
81 int num_events3;
82 long long **values;
83 int i, j;
84 long long min[3];
85 long long max[3];
86 long long sum[3];
87 int quiet;
88
89 /* Set TESTS_QUIET variable */
90 quiet = tests_quiet( argc, argv );
91
93 if ( retval != PAPI_VER_CURRENT ) {
94 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
95 }
96
97 /* Make sure that required resources are available */
98 /* Skip (don't fail!) if they are not */
100 if ( retval != PAPI_OK ) {
101 test_skip( __FILE__, __LINE__, EVT1_STR, retval );
102 }
103
105 if ( retval != PAPI_OK ) {
106 test_skip( __FILE__, __LINE__, EVT2_STR, retval );
107 }
108
110 if ( retval != PAPI_OK ) {
111 test_skip( __FILE__, __LINE__, EVT3_STR, retval );
112 }
113
115 EventSet2 = add_test_events( &num_events2, &mask2, 1 );
116 EventSet3 = add_test_events( &num_events3, &mask3, 1 );
117
119
120 /* Warm me up */
122 do_misses( 1, 1024 * 1024 * 4 );
123
124 for ( i = 0; i < 10; i++ ) {
126 if ( retval != PAPI_OK )
127 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
128
130 do_misses( 1, 1024 * 1024 * 4 );
131
132 retval = PAPI_stop( EventSet1, values[( i * 3 ) + 0] );
133 if ( retval != PAPI_OK )
134 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
135
137 if ( retval != PAPI_OK )
138 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
139
141 do_misses( 1, 1024 * 1024 * 4 );
142
143 retval = PAPI_stop( EventSet2, values[( i * 3 ) + 1] );
144 if ( retval != PAPI_OK )
145 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
146
147 retval = PAPI_start( EventSet3 );
148 if ( retval != PAPI_OK )
149 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
150
152 do_misses( 1, 1024 * 1024 * 4 );
153
154 retval = PAPI_stop( EventSet3, values[( i * 3 ) + 2] );
155 if ( retval != PAPI_OK )
156 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
157 }
158
160 remove_test_events( &EventSet2, mask2 );
161 remove_test_events( &EventSet3, mask3 );
162
163 for ( j = 0; j < 3; j++ ) {
164 min[j] = 65535;
165 max[j] = sum[j] = 0;
166 }
167 for ( i = 0; i < 10; i++ ) {
168 for ( j = 0; j < 3; j++ ) {
169 if ( min[j] > values[( i * 3 ) + j][0] )
170 min[j] = values[( i * 3 ) + j][0];
171 if ( max[j] < values[( i * 3 ) + j][0] )
172 max[j] = values[( i * 3 ) + j][0];
173 sum[j] += values[( i * 3 ) + j][0];
174 }
175 }
176
177 if ( !quiet ) {
178 printf( "Test case 10: start, stop for derived event %s.\n",
179 CACHE_LEVEL );
180 printf( "--------------------------------------------------------\n" );
181 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
182 printf( "Default domain is: %d (%s)\n", tmp,
184 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
185 printf( "Default granularity is: %d (%s)\n", tmp,
187 printf( "Using %d iterations of c += a*b\n", ITERS );
188 printf( "Repeated 10 times\n" );
189 printf
190 ( "-------------------------------------------------------------------------\n" );
191/*
192 for (i=0;i<10;i++) {
193 printf("Test type : %12s%13s%13s\n", "1", "2", "3");
194 printf(TAB3, EVT1_STR, values[(i*3)+0][0], (long long)0, (long long)0);
195 printf(TAB3, EVT2_STR, (long long)0, values[(i*3)+1][0], (long long)0);
196 printf(TAB3, EVT3_STR, (long long)0, (long long)0, values[(i*3)+2][0]);
197 printf
198 ("-------------------------------------------------------------------------\n");
199 }
200*/
201 printf( "Test type : %12s%13s%13s\n", "min", "max", "sum" );
202 printf( TAB3, EVT1_STR, min[0], max[0], sum[0] );
203 printf( TAB3, EVT2_STR, min[1], max[1], sum[1] );
204 printf( TAB3, EVT3_STR, min[2], max[2], sum[2] );
205 printf
206 ( "-------------------------------------------------------------------------\n" );
207 printf( "Verification:\n" );
208#if defined(sun) && defined(sparc)
209 printf( TAB1, "Sum 1 approximately equals sum 2 - sum 3 or",
210 ( sum[1] - sum[2] ) );
211#else
212 printf( TAB1, "Sum 1 approximately equals sum 2 + sum 3 or",
213 ( sum[1] + sum[2] ) );
214#endif
215 }
216
217 {
218 long long tmin, tmax;
219
220#if defined(sun) && defined(sparc)
221 tmax = ( long long ) ( sum[1] - sum[2] );
222#else
223 tmax = ( long long ) ( sum[1] + sum[2] );
224#endif
225
226 if (!quiet) {
227 printf( "percent error: %f\n",
228 (( float ) abs( ( int ) ( tmax - sum[0] ) ) /
229 (float) sum[0] ) * 100.0 );
230 }
231 tmin = ( long long ) ( ( double ) tmax * 0.8 );
232 tmax = ( long long ) ( ( double ) tmax * 1.2 );
233 if ( sum[0] > tmax || sum[0] < tmin ) {
234 test_fail( __FILE__, __LINE__, CACHE_LEVEL, 1 );
235 }
236 }
237
238 test_pass( __FILE__ );
239
240 return 0;
241}
double tmp
int i
Get PAPI library or event set options.
initialize the PAPI library.
Query if PAPI event exists.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define min(x, y)
Definition: darwin-common.h:4
void do_l1misses(int n)
Definition: do_loops.c:220
void do_misses(int n, int bytes)
Definition: do_loops.c:120
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_DEFGRN
Definition: f90papi.h:26
#define PAPI_DEFDOM
Definition: f90papi.h:188
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
int add_test_events(int *number, int *mask, int allow_derived)
Definition: test_utils.c:152
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define TAB3
Definition: papi_test.h:100
#define TAB1
Definition: papi_test.h:98
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
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 remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
int EventSet2
Definition: rapl_overflow.c:17
long long int long long
Definition: sde_internal.h:85
#define EVT2_STR
Definition: tenth.c:60
#define MASK3
Definition: tenth.c:64
#define EVT3_STR
Definition: tenth.c:61
#define ITERS
Definition: tenth.c:15
#define MASK2
Definition: tenth.c:63
#define EVT2
Definition: tenth.c:57
#define EVT1_STR
Definition: tenth.c:59
#define EVT1
Definition: tenth.c:56
#define EVT3
Definition: tenth.c:58
#define MASK1
Definition: tenth.c:62
#define CACHE_LEVEL
Definition: tenth.c:55
int EventSet1
Definition: zero_fork.c:47
int num_events1
Definition: zero_fork.c:49
int mask1
Definition: zero_fork.c:48
int num_tests
Definition: zero_fork.c:53
int retval
Definition: zero_fork.c:53