PAPI  5.7.0.0
papi_l2_dcm.c File Reference
Include dependency graph for papi_l2_dcm.c:

Go to the source code of this file.

Macros

#define ALLOWED_ERROR   5.0
 
#define NUM_RUNS   100
 
#define ITERATIONS   1000000
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ ALLOWED_ERROR

#define ALLOWED_ERROR   5.0

Definition at line 28 of file papi_l2_dcm.c.

◆ ITERATIONS

#define ITERATIONS   1000000

Definition at line 32 of file papi_l2_dcm.c.

◆ NUM_RUNS

#define NUM_RUNS   100

Definition at line 30 of file papi_l2_dcm.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file papi_l2_dcm.c.

34  {
35 
36  int i;
37  int eventset=PAPI_NULL;
38  int num_runs=NUM_RUNS;
39  long long high,low,average,expected;
40  long long count,total;
41 
42  int retval;
43  int l1_size,l2_size,l1_linesize,l2_linesize,l2_entries;
44  int arraysize;
45  int quiet,errors=0;
46 
47  double error;
48  double *array;
49  double aSumm = 0.0;
50 
51  quiet=tests_quiet(argc,argv);
52 
53  if (!quiet) {
54  printf("Testing the PAPI_L2_DCM event\n");
55  }
56 
57  /* Init the PAPI library */
59  if (retval != PAPI_VER_CURRENT) {
60  test_fail(__FILE__,__LINE__,"PAPI_library_init",retval);
61  }
62 
63  retval=PAPI_create_eventset(&eventset);
64  if (retval!=PAPI_OK) {
65  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
66  }
67 
68  retval=PAPI_add_named_event(eventset,"PAPI_L2_DCM");
69  if (retval!=PAPI_OK) {
70  test_skip( __FILE__, __LINE__, "adding PAPI_L2_DCM", retval );
71  }
72 
73  l1_size=get_cachesize(L1D_CACHE);
74  l1_linesize=get_linesize(L1D_CACHE);
75  l2_size=get_cachesize(L2_CACHE);
76  l2_linesize=get_linesize(L2_CACHE);
77  l2_entries=get_entries(L2_CACHE);
78 
79  if (!quiet) {
80  printf("\tDetected %dk L1 DCache, %dB linesize\n",
81  l1_size/1024,l1_linesize);
82  printf("\tDetected %dk L2 DCache, %dB linesize, %d entries\n",
83  l2_size/1024,l2_linesize,l2_entries);
84  }
85 
86  arraysize=(l2_size/sizeof(double))*8;
87 
88  if (arraysize==0) {
89  if (!quiet) printf("Could not detect cache size\n");
90  test_skip(__FILE__,__LINE__,"Could not detect cache size",0);
91  }
92 
93  if (!quiet) {
94  printf("\tAllocating %zu bytes of memory (%d doubles)\n",
95  arraysize*sizeof(double),arraysize);
96  }
97 
98  array=calloc(arraysize,sizeof(double));
99  if (array==NULL) {
100  test_fail(__FILE__,__LINE__,"Can't allocate memory",0);
101  }
102 
103  /******************/
104  /* Testing Writes */
105  /******************/
106 
107  if (!quiet) {
108  printf("\nWrite Test: Writing an array of %d doubles %d random times:\n",
109  arraysize,ITERATIONS);
110  printf("\tPrefetch and shared nature of L2s make this hard.\n");
111  printf("\tExpected 7/8 of accesses to be miss.\n");
112  }
113 
114  high=0; low=0; total=0;
115 
116  for(i=0;i<num_runs;i++) {
117 
118  PAPI_reset(eventset);
119  PAPI_start(eventset);
120 
122 
123  retval=PAPI_stop(eventset,&count);
124 
125  if (retval!=PAPI_OK) {
126  test_fail( __FILE__, __LINE__,
127  "reading PAPI_L2_DCM", retval );
128  }
129 
130  if (count>high) high=count;
131  if ((low==0) || (count<low)) low=count;
132  total+=count;
133  }
134 
135  average=(total/num_runs);
136 
137  expected=(ITERATIONS*7)/8;
138 
139 // expected=arraysize/(l1_linesize);
140 
141  error=display_error(average,high,low,expected,quiet);
142 
143  if ((error > ALLOWED_ERROR) || (error<-ALLOWED_ERROR)) {
144  if (!quiet) {
145  printf("Instruction count off by more "
146  "than %.2lf%%\n",ALLOWED_ERROR);
147  }
148  errors++;
149  }
150 
151  if (!quiet) printf("\n");
152 
153  /******************/
154  /* Testing Reads */
155  /******************/
156 
157  if (!quiet) {
158  printf("\nRead Test: Summing %d random doubles from array "
159  "of size %d:\n",ITERATIONS,arraysize);
160  printf("\tExpected 7/8 of accesses to be miss.\n");
161  }
162 
163  high=0; low=0; total=0;
164 
165  for(i=0;i<num_runs;i++) {
166 
167  PAPI_reset(eventset);
168  PAPI_start(eventset);
169 
170  aSumm+=cache_random_read_test(array,arraysize,ITERATIONS);
171 
172  retval=PAPI_stop(eventset,&count);
173 
174  if (retval!=PAPI_OK) {
175  test_fail( __FILE__, __LINE__,
176  "reading PAPI_L2_DCM", retval );
177  }
178 
179  if (count>high) high=count;
180  if ((low==0) || (count<low)) low=count;
181  total+=count;
182  }
183 
184  average=(total/num_runs);
185 
186  expected=(ITERATIONS*7)/8;
187 
188 // expected=arraysize/(l1_linesize/sizeof(double));
189 
190  error=display_error(average,high,low,expected,quiet);
191 
192  if ((error > ALLOWED_ERROR) || (error<-ALLOWED_ERROR)) {
193  if (!quiet) {
194  printf("Instruction count off by more "
195  "than %.2lf%%\n",ALLOWED_ERROR);
196  }
197  errors++;
198  }
199 
200  if (!quiet) {
201  printf("\n");
202  }
203 
204  /* FIXME: Warn, as we fail on broadwell and more recent chips */
205  if (errors) {
206  test_warn( __FILE__, __LINE__, "Error too high", 1 );
207  }
208 
209 
210 
211  test_pass(__FILE__);
212 
213  return 0;
214 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
static int expected[NUM_THREADS]
int PAPI_reset(int EventSet)
Definition: papi.c:2459
double display_error(long long average, long long high, long long low, long long expected, int quiet)
Definition: display_error.c:7
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:524
#define NUM_RUNS
Definition: papi_l2_dcm.c:30
#define L2_CACHE
Definition: cache_helper.h:3
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
int cache_random_write_test(double *array, int size, int count)
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
double cache_random_read_test(double *array, int size, int count)
#define PAPI_NULL
Definition: fpapi.h:13
long long get_linesize(int type)
Definition: cache_helper.c:110
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
#define L1D_CACHE
Definition: cache_helper.h:2
long long get_cachesize(int type)
Definition: cache_helper.c:78
static int total
Definition: rapl_overflow.c:9
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_start(int EventSet)
Definition: papi.c:2096
long long get_entries(int type)
Definition: cache_helper.c:94
#define ALLOWED_ERROR
Definition: papi_l2_dcm.c:28
static long count
#define ITERATIONS
Definition: papi_l2_dcm.c:32
int i
Definition: fileop.c:140
Here is the call graph for this function: