blob: d2e75048a29f2b5b93d4630d8830008a1794140e [file] [log] [blame]
Gael Guennebaud931027f2010-06-26 23:15:06 +02001
2#define EIGEN_INTERNAL_DEBUG_CACHE_QUERY
3#include <iostream>
4#include "../Eigen/Core"
5
6using namespace Eigen;
7using 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
18int main()
19{
20 cout << "Eigen's L1 = " << ei_queryL1CacheSize() << endl;
21 cout << "Eigen's L2/L3 = " << ei_queryTopLevelCacheSize() << endl;
22 int l1, l2, l3;
23 ei_queryCacheSizes(l1, l2, l3);
24 cout << "Eigen's L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
25
26 #ifdef EIGEN_CPUID
27
Gael Guennebaud931027f2010-06-26 23:15:06 +020028 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;
Gael Guennebaud5e7bd962010-06-26 23:37:42 +020038 cout << endl;
Gael Guennebaud931027f2010-06-26 23:15:06 +020039 cout << "vendor id = " << string_char << endl;
Gael Guennebaud5e7bd962010-06-26 23:37:42 +020040 cout << endl;
Gael Guennebaudf0964522010-06-27 00:17:38 +020041 int max_funcs = abcd[0];
Gael Guennebaud931027f2010-06-26 23:15:06 +020042
Gael Guennebaudf0964522010-06-27 00:17:38 +020043 ei_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 ei_queryCacheSizes_intel_direct(l1, l2, l3);
48 cout << "Eigen's intel direct L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
49 }
50 ei_queryCacheSizes_amd(l1, l2, l3);
51 cout << "Eigen's amd L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
52 cout << endl;
53
Gael Guennebaud931027f2010-06-26 23:15:06 +020054 // dump Intel direct method
Gael Guennebaudf0964522010-06-27 00:17:38 +020055 if(max_funcs>=4)
Gael Guennebaud931027f2010-06-26 23:15:06 +020056 {
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++;
Gael Guennebaudf0964522010-06-27 00:17:38 +020080 } while(cache_type>0 && cache_id<16);
Gael Guennebaud5e7bd962010-06-26 23:37:42 +020081 }
Gael Guennebaud931027f2010-06-26 23:15:06 +020082
83 // dump everything
84 std::cout << endl <<"Raw dump:" << endl;
Gael Guennebaudf0964522010-06-27 00:17:38 +020085 for(int i=0; i<max_funcs; ++i)
86 DUMP_CPUID(i);
87
Gael Guennebaud931027f2010-06-26 23:15:06 +020088 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}