Go to the documentation of this file.00001
00002 #define EIGEN_INTERNAL_DEBUG_CACHE_QUERY
00003 #include <iostream>
00004 #include "../Eigen/Core"
00005
00006 using namespace Eigen;
00007 using namespace std;
00008
00009 #define DUMP_CPUID(CODE) {\
00010 int abcd[4]; \
00011 abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;\
00012 EIGEN_CPUID(abcd, CODE, 0); \
00013 std::cout << "The code " << CODE << " gives " \
00014 << (int*)(abcd[0]) << " " << (int*)(abcd[1]) << " " \
00015 << (int*)(abcd[2]) << " " << (int*)(abcd[3]) << " " << std::endl; \
00016 }
00017
00018 int main()
00019 {
00020 cout << "Eigen's L1 = " << internal::queryL1CacheSize() << endl;
00021 cout << "Eigen's L2/L3 = " << internal::queryTopLevelCacheSize() << endl;
00022 int l1, l2, l3;
00023 internal::queryCacheSizes(l1, l2, l3);
00024 cout << "Eigen's L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
00025
00026 #ifdef EIGEN_CPUID
00027
00028 int abcd[4];
00029 int string[8];
00030 char* string_char = (char*)(string);
00031
00032
00033 EIGEN_CPUID(abcd,0x0,0);
00034 string[0] = abcd[1];
00035 string[1] = abcd[3];
00036 string[2] = abcd[2];
00037 string[3] = 0;
00038 cout << endl;
00039 cout << "vendor id = " << string_char << endl;
00040 cout << endl;
00041 int max_funcs = abcd[0];
00042
00043 internal::queryCacheSizes_intel_codes(l1, l2, l3);
00044 cout << "Eigen's intel codes L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
00045 if(max_funcs>=4)
00046 {
00047 internal::queryCacheSizes_intel_direct(l1, l2, l3);
00048 cout << "Eigen's intel direct L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
00049 }
00050 internal::queryCacheSizes_amd(l1, l2, l3);
00051 cout << "Eigen's amd L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
00052 cout << endl;
00053
00054
00055 if(max_funcs>=4)
00056 {
00057 l1 = l2 = l3 = 0;
00058 int cache_id = 0;
00059 int cache_type = 0;
00060 do {
00061 abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
00062 EIGEN_CPUID(abcd,0x4,cache_id);
00063 cache_type = (abcd[0] & 0x0F) >> 0;
00064 int cache_level = (abcd[0] & 0xE0) >> 5;
00065 int ways = (abcd[1] & 0xFFC00000) >> 22;
00066 int partitions = (abcd[1] & 0x003FF000) >> 12;
00067 int line_size = (abcd[1] & 0x00000FFF) >> 0;
00068 int sets = (abcd[2]);
00069 int cache_size = (ways+1) * (partitions+1) * (line_size+1) * (sets+1);
00070
00071 cout << "cache[" << cache_id << "].type = " << cache_type << "\n";
00072 cout << "cache[" << cache_id << "].level = " << cache_level << "\n";
00073 cout << "cache[" << cache_id << "].ways = " << ways << "\n";
00074 cout << "cache[" << cache_id << "].partitions = " << partitions << "\n";
00075 cout << "cache[" << cache_id << "].line_size = " << line_size << "\n";
00076 cout << "cache[" << cache_id << "].sets = " << sets << "\n";
00077 cout << "cache[" << cache_id << "].size = " << cache_size << "\n";
00078
00079 cache_id++;
00080 } while(cache_type>0 && cache_id<16);
00081 }
00082
00083
00084 std::cout << endl <<"Raw dump:" << endl;
00085 for(int i=0; i<max_funcs; ++i)
00086 DUMP_CPUID(i);
00087
00088 DUMP_CPUID(0x80000000);
00089 DUMP_CPUID(0x80000001);
00090 DUMP_CPUID(0x80000002);
00091 DUMP_CPUID(0x80000003);
00092 DUMP_CPUID(0x80000004);
00093 DUMP_CPUID(0x80000005);
00094 DUMP_CPUID(0x80000006);
00095 DUMP_CPUID(0x80000007);
00096 DUMP_CPUID(0x80000008);
00097 #else
00098 cout << "EIGEN_CPUID is not defined" << endl;
00099 #endif
00100 return 0;
00101 }