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

Go to the source code of this file.

Macros

#define NUM_RUNS   100
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ NUM_RUNS

#define NUM_RUNS   100

Definition at line 18 of file papi_l2_dcr.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file papi_l2_dcr.c.

20  {
21 
22  int i;
23  int eventset=PAPI_NULL;
24  int num_runs=NUM_RUNS;
25  long long high,low,average,expected;
26  long long count,total;
27 
28  int retval;
29  int l1_size,l2_size,l1_linesize,l2_linesize,l2_entries;
30  int arraysize;
31  int quiet,errors=0;
32 
33  double error;
34  double *array;
35  double aSumm = 0.0;
36 
37  quiet=tests_quiet(argc,argv);
38 
39  if (!quiet) {
40  printf("Testing the PAPI_L2_DCR event\n");
41  }
42 
43  /* Init the PAPI library */
45  if (retval != PAPI_VER_CURRENT) {
46  test_fail(__FILE__,__LINE__,"PAPI_library_init",retval);
47  }
48 
49  retval=PAPI_create_eventset(&eventset);
50  if (retval!=PAPI_OK) {
51  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
52  }
53 
54  retval=PAPI_add_named_event(eventset,"PAPI_L2_DCR");
55  if (retval!=PAPI_OK) {
56  test_skip( __FILE__, __LINE__, "adding PAPI_L2_DCR", retval );
57  }
58 
59  l1_size=get_cachesize(L1D_CACHE);
60  l1_linesize=get_linesize(L1D_CACHE);
61  l2_size=get_cachesize(L2_CACHE);
62  l2_linesize=get_linesize(L2_CACHE);
63  l2_entries=get_entries(L2_CACHE);
64 
65  if (!quiet) {
66  printf("\tDetected %dk L1 DCache, %dB linesize\n",
67  l1_size/1024,l1_linesize);
68  printf("\tDetected %dk L2 DCache, %dB linesize, %d entries\n",
69  l2_size/1024,l2_linesize,l2_entries);
70  }
71 
72  arraysize=l2_size/sizeof(double);
73 
74  if (!quiet) {
75  printf("\tAllocating %zu bytes of memory (%d doubles)\n",
76  arraysize*sizeof(double),arraysize);
77  }
78 
79  array=calloc(arraysize,sizeof(double));
80  if (array==NULL) {
81  test_fail(__FILE__,__LINE__,"Can't allocate memory",0);
82  }
83 
84  /******************/
85  /* Testing Writes */
86  /******************/
87 
88  if (!quiet) {
89  printf("\nWrite Test: Initializing an array of %d doubles:\n",
90  arraysize);
91  }
92 
93  high=0; low=0; total=0;
94 
95  for(i=0;i<num_runs;i++) {
96 
97  PAPI_reset(eventset);
98  PAPI_start(eventset);
99 
100  cache_write_test(array,arraysize);
101 
102  retval=PAPI_stop(eventset,&count);
103 
104  if (retval!=PAPI_OK) {
105  test_fail( __FILE__, __LINE__,
106  "reading PAPI_L2_DCR", retval );
107  }
108 
109  if (count>high) high=count;
110  if ((low==0) || (count<low)) low=count;
111  total+=count;
112  }
113 
114  average=(total/num_runs);
115 
116  expected=(arraysize/(l1_linesize/sizeof(double)))/10;
117 
118  if (!quiet) {
119  printf("\tShould be low, as we only measure reads:\n\n");
120  }
121 
122  if (!quiet) {
123  printf("\tMeasured average of: %lld\n",average);
124  }
125 
126  if (average>expected) {
127  if (!quiet) printf("Instruction count bigger than expected\n");
128  errors++;
129  }
130 
131  if (!quiet) printf("\n");
132 
133  /******************/
134  /* Testing Reads */
135  /******************/
136 
137  if (!quiet) {
138  printf("\nRead Test: Summing an array of %d doubles:\n",
139  arraysize);
140  }
141 
142  high=0; low=0; total=0;
143 
144  for(i=0;i<num_runs;i++) {
145 
146  PAPI_reset(eventset);
147  PAPI_start(eventset);
148 
149  aSumm+=cache_read_test(array,arraysize);
150 
151  retval=PAPI_stop(eventset,&count);
152 
153  if (retval!=PAPI_OK) {
154  test_fail( __FILE__, __LINE__,
155  "reading PAPI_L2_DCR", retval );
156  }
157 
158  if (count>high) high=count;
159  if ((low==0) || (count<low)) low=count;
160  total+=count;
161  }
162 
163  average=(total/num_runs);
164 
165  expected=arraysize/(l1_linesize/sizeof(double));
166 
167  if (!quiet) {
168  printf("\tShould be roughly "
169  "arraysize/L1_linesize/double_size (%d/%d/%zu): "
170  "%lld\n\n",
171  arraysize,l1_linesize,sizeof(double),
172  expected);
173  }
174 
175  error=display_error(average,high,low,expected,quiet);
176 
177  if ((error > 1.0) || (error<-1.0)) {
178  if (!quiet) printf("Instruction count off by more than 1%%\n");
179  errors++;
180  }
181 
182  if (!quiet) {
183  printf("\n");
184  }
185 
186  /* FIXME: Warn, as we fail on broadwell and more recent */
187  if (errors) {
188  test_warn( __FILE__, __LINE__, "Error too high", 1 );
189  }
190 
191  test_pass(__FILE__);
192 
193  return 0;
194 }
#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 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 PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
int cache_write_test(double *array, int size)
Definition: cache_testcode.c:6
#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
#define NUM_RUNS
Definition: papi_l2_dcr.c:18
int PAPI_start(int EventSet)
Definition: papi.c:2096
long long get_entries(int type)
Definition: cache_helper.c:94
static long count
int i
Definition: fileop.c:140
double cache_read_test(double *array, int size)
Here is the call graph for this function: