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