check_cache_queries.cpp File Reference
#include <iostream>
#include "../Eigen/Core"

Macros

#define EIGEN_INTERNAL_DEBUG_CACHE_QUERY
 
#define DUMP_CPUID(CODE)
 

Functions

int main ()
 

Macro Definition Documentation

◆ DUMP_CPUID

#define DUMP_CPUID (   CODE)
Value:
{ \
int abcd[4]; \
abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0; \
EIGEN_CPUID(abcd, CODE, 0); \
std::cout << "The code " << CODE << " gives " << (int*)(abcd[0]) << " " << (int*)(abcd[1]) << " " \
<< (int*)(abcd[2]) << " " << (int*)(abcd[3]) << " " << std::endl; \
}

◆ EIGEN_INTERNAL_DEBUG_CACHE_QUERY

#define EIGEN_INTERNAL_DEBUG_CACHE_QUERY

Function Documentation

◆ main()

int main ( )
18  {
19  cout << "Eigen's L1 = " << internal::queryL1CacheSize() << endl;
20  cout << "Eigen's L2/L3 = " << internal::queryTopLevelCacheSize() << endl;
21  int l1, l2, l3;
22  internal::queryCacheSizes(l1, l2, l3);
23  cout << "Eigen's L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
24 
25 #ifdef EIGEN_CPUID
26 
27  int abcd[4];
28  int string[8];
29  char* string_char = (char*)(string);
30 
31  // vendor ID
32  EIGEN_CPUID(abcd, 0x0, 0);
33  string[0] = abcd[1];
34  string[1] = abcd[3];
35  string[2] = abcd[2];
36  string[3] = 0;
37  cout << endl;
38  cout << "vendor id = " << string_char << endl;
39  cout << endl;
40  int max_funcs = abcd[0];
41 
42  internal::queryCacheSizes_intel_codes(l1, l2, l3);
43  cout << "Eigen's intel codes L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
44  if (max_funcs >= 4) {
45  internal::queryCacheSizes_intel_direct(l1, l2, l3);
46  cout << "Eigen's intel direct L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
47  }
48  internal::queryCacheSizes_amd(l1, l2, l3);
49  cout << "Eigen's amd L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
50  cout << endl;
51 
52  // dump Intel direct method
53  if (max_funcs >= 4) {
54  l1 = l2 = l3 = 0;
55  int cache_id = 0;
56  int cache_type = 0;
57  do {
58  abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
59  EIGEN_CPUID(abcd, 0x4, cache_id);
60  cache_type = (abcd[0] & 0x0F) >> 0;
61  int cache_level = (abcd[0] & 0xE0) >> 5; // A[7:5]
62  int ways = (abcd[1] & 0xFFC00000) >> 22; // B[31:22]
63  int partitions = (abcd[1] & 0x003FF000) >> 12; // B[21:12]
64  int line_size = (abcd[1] & 0x00000FFF) >> 0; // B[11:0]
65  int sets = (abcd[2]); // C[31:0]
66  int cache_size = (ways + 1) * (partitions + 1) * (line_size + 1) * (sets + 1);
67 
68  cout << "cache[" << cache_id << "].type = " << cache_type << "\n";
69  cout << "cache[" << cache_id << "].level = " << cache_level << "\n";
70  cout << "cache[" << cache_id << "].ways = " << ways << "\n";
71  cout << "cache[" << cache_id << "].partitions = " << partitions << "\n";
72  cout << "cache[" << cache_id << "].line_size = " << line_size << "\n";
73  cout << "cache[" << cache_id << "].sets = " << sets << "\n";
74  cout << "cache[" << cache_id << "].size = " << cache_size << "\n";
75 
76  cache_id++;
77  } while (cache_type > 0 && cache_id < 16);
78  }
79 
80  // dump everything
81  std::cout << endl << "Raw dump:" << endl;
82  for (int i = 0; i < max_funcs; ++i) DUMP_CPUID(i);
83 
84  DUMP_CPUID(0x80000000);
85  DUMP_CPUID(0x80000001);
86  DUMP_CPUID(0x80000002);
87  DUMP_CPUID(0x80000003);
88  DUMP_CPUID(0x80000004);
89  DUMP_CPUID(0x80000005);
90  DUMP_CPUID(0x80000006);
91  DUMP_CPUID(0x80000007);
92  DUMP_CPUID(0x80000008);
93 #else
94  cout << "EIGEN_CPUID is not defined" << endl;
95 #endif
96  return 0;
97 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define DUMP_CPUID(CODE)
Definition: check_cache_queries.cpp:9
void queryCacheSizes(int &l1, int &l2, int &l3)
Definition: Memory.h:1263
int queryTopLevelCacheSize()
Definition: Memory.h:1307
int queryL1CacheSize()
Definition: Memory.h:1299

References DUMP_CPUID, i, Eigen::internal::queryCacheSizes(), Eigen::internal::queryL1CacheSize(), and Eigen::internal::queryTopLevelCacheSize().