PAPI  5.7.0.0
papi_l2_dca.c File Reference
Include dependency graph for papi_l2_dca.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 29 of file papi_l2_dca.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 31 of file papi_l2_dca.c.

31  {
32 
33  int i;
34  int eventset=PAPI_NULL;
35  int num_runs=NUM_RUNS;
36  long long high,low,average,expected;
37  long long count,total;
38 
39  int retval;
40  int l1_size,l2_size,l1_linesize,l2_linesize,l2_entries;
41  int arraysize;
42  int quiet,errors=0;
43 
44  double error;
45  double *array;
46  double aSumm = 0.0;
47 
48  quiet=tests_quiet(argc,argv);
49 
50  if (!quiet) {
51  printf("Testing the PAPI_L2_DCA event\n");
52  }
53 
54  /* Init the PAPI library */
56  if (retval != PAPI_VER_CURRENT) {
57  test_fail(__FILE__,__LINE__,"PAPI_library_init",retval);
58  }
59 
60  retval=PAPI_create_eventset(&eventset);
61  if (retval!=PAPI_OK) {
62  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
63  }
64 
65  retval=PAPI_add_named_event(eventset,"PAPI_L2_DCA");
66  if (retval!=PAPI_OK) {
67  test_skip( __FILE__, __LINE__, "adding PAPI_L2_DCA", retval );
68  }
69 
70  l1_size=get_cachesize(L1D_CACHE);
71  l1_linesize=get_linesize(L1D_CACHE);
72  l2_size=get_cachesize(L2_CACHE);
73  l2_linesize=get_linesize(L2_CACHE);
74  l2_entries=get_entries(L2_CACHE);
75 
76  if ((l2_size==0) || (l2_linesize==0)) {
77  if (!quiet) {
78  printf("Unable to determine size of L2 cache!\n");
79  }
80  test_skip( __FILE__, __LINE__, "adding PAPI_L2_DCA", retval );
81  }
82 
83  if (!quiet) {
84  printf("\tDetected %dk L1 DCache, %dB linesize\n",
85  l1_size/1024,l1_linesize);
86  printf("\tDetected %dk L2 DCache, %dB linesize, %d entries\n",
87  l2_size/1024,l2_linesize,l2_entries);
88  }
89 
90  arraysize=l2_size/sizeof(double);
91 
92  if (!quiet) {
93  printf("\tAllocating %zu bytes of memory (%d doubles)\n",
94  arraysize*sizeof(double),arraysize);
95  }
96 
97  array=calloc(arraysize,sizeof(double));
98  if (array==NULL) {
99  test_fail(__FILE__,__LINE__,"Can't allocate memory",0);
100  }
101 
102  /******************/
103  /* Testing Writes */
104  /******************/
105 
106  if (!quiet) {
107  printf("\nWrite Test: Initializing an array of %d doubles:\n",
108  arraysize);
109  }
110 
111  high=0; low=0; total=0;
112 
113  for(i=0;i<num_runs;i++) {
114 
115  PAPI_reset(eventset);
116  PAPI_start(eventset);
117 
118  cache_write_test(array,arraysize);
119 
120  retval=PAPI_stop(eventset,&count);
121 
122  if (retval!=PAPI_OK) {
123  test_fail( __FILE__, __LINE__,
124  "reading PAPI_L2_DCA", retval );
125  }
126 
127  if (count>high) high=count;
128  if ((low==0) || (count<low)) low=count;
129  total+=count;
130  }
131 
132  average=(total/num_runs);
133 
134  expected=arraysize/(l2_linesize/sizeof(double));
135 
136  if (!quiet) {
137  printf("\tShould be roughly "
138  "arraysize/L2_linesize/double_size (%d/%d/%zu): "
139  "%lld\n\n",
140  arraysize,l2_linesize,sizeof(double),
141  expected);
142  }
143 
144  error=display_error(average,high,low,expected,quiet);
145 
146  if ((error > 1.0) || (error<-1.0)) {
147  if (!quiet) printf("Instruction count off by more than 1%%\n");
148  errors++;
149  }
150 
151  if (!quiet) printf("\n");
152 
153  /******************/
154  /* Testing Reads */
155  /******************/
156 
157  if (!quiet) {
158  printf("\nRead Test: Summing an array of %d doubles:\n",
159  arraysize);
160  }
161 
162  high=0; low=0; total=0;
163 
164  for(i=0;i<num_runs;i++) {
165 
166  PAPI_reset(eventset);
167  PAPI_start(eventset);
168 
169  aSumm+=cache_read_test(array,arraysize);
170 
171  retval=PAPI_stop(eventset,&count);
172 
173  if (retval!=PAPI_OK) {
174  test_fail( __FILE__, __LINE__,
175  "reading PAPI_L2_DCA", retval );
176  }
177 
178  if (count>high) high=count;
179  if ((low==0) || (count<low)) low=count;
180  total+=count;
181  }
182 
183  average=(total/num_runs);
184 
185  expected=arraysize/(l2_linesize/sizeof(double));
186 
187  if (!quiet) {
188  printf("\tShould be roughly "
189  "arraysize/L2_linesize/double_size (%d/%d/%zu): "
190  "%lld\n\n",
191  arraysize,l2_linesize,sizeof(double),
192  expected);
193  }
194 
195  error=display_error(average,high,low,expected,quiet);
196 
197  if ((error > 1.0) || (error<-1.0)) {
198  if (!quiet) printf("Instruction count off by more than 1%%\n");
199  errors++;
200  }
201 
202  if (!quiet) {
203  printf("\n");
204  }
205 
206  /* Warn for now, as we get errors we can't easily */
207  /* explain on haswell and more recent Intel chips */
208  if (errors) {
209  test_warn( __FILE__, __LINE__, "Error too high", 1 );
210  }
211 
212  test_pass(__FILE__);
213 
214  return 0;
215 }
#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
#define NUM_RUNS
Definition: papi_l2_dca.c:29
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
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: