Gael Guennebaud | 931027f | 2010-06-26 23:15:06 +0200 | [diff] [blame^] | 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 = " << 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 | |
| 28 | ei_queryCacheSizes_intel(l1, l2, l3); |
| 29 | cout << "Eigen's intel L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl; |
| 30 | ei_queryCacheSizes_amd(l1, l2, l3); |
| 31 | cout << "Eigen's amd L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl; |
| 32 | |
| 33 | int abcd[4]; |
| 34 | int string[8]; |
| 35 | char* string_char = (char*)(string); |
| 36 | |
| 37 | // vendor ID |
| 38 | EIGEN_CPUID(abcd,0x0,0); |
| 39 | string[0] = abcd[1]; |
| 40 | string[1] = abcd[3]; |
| 41 | string[2] = abcd[2]; |
| 42 | string[3] = 0; |
| 43 | cout << "vendor id = " << string_char << endl; |
| 44 | |
| 45 | // dump Intel direct method |
| 46 | { |
| 47 | l1 = l2 = l3 = 0; |
| 48 | int cache_id = 0; |
| 49 | int cache_type = 0; |
| 50 | do { |
| 51 | abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0; |
| 52 | EIGEN_CPUID(abcd,0x4,cache_id); |
| 53 | cache_type = (abcd[0] & 0x0F) >> 0; |
| 54 | int cache_level = (abcd[0] & 0xE0) >> 5; // A[7:5] |
| 55 | int ways = (abcd[1] & 0xFFC00000) >> 22; // B[31:22] |
| 56 | int partitions = (abcd[1] & 0x003FF000) >> 12; // B[21:12] |
| 57 | int line_size = (abcd[1] & 0x00000FFF) >> 0; // B[11:0] |
| 58 | int sets = (abcd[2]); // C[31:0] |
| 59 | int cache_size = (ways+1) * (partitions+1) * (line_size+1) * (sets+1); |
| 60 | |
| 61 | cout << "cache[" << cache_id << "].type = " << cache_type << "\n"; |
| 62 | cout << "cache[" << cache_id << "].level = " << cache_level << "\n"; |
| 63 | cout << "cache[" << cache_id << "].ways = " << ways << "\n"; |
| 64 | cout << "cache[" << cache_id << "].partitions = " << partitions << "\n"; |
| 65 | cout << "cache[" << cache_id << "].line_size = " << line_size << "\n"; |
| 66 | cout << "cache[" << cache_id << "].sets = " << sets << "\n"; |
| 67 | cout << "cache[" << cache_id << "].size = " << cache_size << "\n"; |
| 68 | |
| 69 | cache_id++; |
| 70 | } while(cache_type>0); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | // dump everything |
| 75 | std::cout << endl <<"Raw dump:" << endl; |
| 76 | DUMP_CPUID(0x0); |
| 77 | DUMP_CPUID(0x1); |
| 78 | DUMP_CPUID(0x2); |
| 79 | DUMP_CPUID(0x3); |
| 80 | DUMP_CPUID(0x4); |
| 81 | DUMP_CPUID(0x5); |
| 82 | DUMP_CPUID(0x6); |
| 83 | DUMP_CPUID(0x80000000); |
| 84 | DUMP_CPUID(0x80000001); |
| 85 | DUMP_CPUID(0x80000002); |
| 86 | DUMP_CPUID(0x80000003); |
| 87 | DUMP_CPUID(0x80000004); |
| 88 | DUMP_CPUID(0x80000005); |
| 89 | DUMP_CPUID(0x80000006); |
| 90 | DUMP_CPUID(0x80000007); |
| 91 | DUMP_CPUID(0x80000008); |
| 92 | #else |
| 93 | cout << "EIGEN_CPUID is not defined" << endl; |
| 94 | #endif |
| 95 | return 0; |
| 96 | } |
| 97 | #if 0 |
| 98 | #define FOO(CODE) { \ |
| 99 | EIGEN_CPUID(abcd, CODE); \ |
| 100 | std::cout << "The code " << CODE << " gives " \ |
| 101 | << (int*)(abcd[0]) << " " << (int*)(abcd[1]) << " " \ |
| 102 | << (int*)(abcd[2]) << " " << (int*)(abcd[3]) << " " << std::endl; \ |
| 103 | } |
| 104 | |
| 105 | |
| 106 | int abcd[5]; |
| 107 | abcd[4] = 0; |
| 108 | // for (int a = 0; a < 5; a++) { |
| 109 | // cpuid(abcd,a); |
| 110 | // std::cout << "The code " << a << " gives " |
| 111 | // << abcd[0] << " " << abcd[1] << " " |
| 112 | // << abcd[2] << " " << abcd[3] << " " << abcd[4] << std::endl; |
| 113 | // } |
| 114 | |
| 115 | FOO(0x1); std::cerr << (char*)abcd << "\n"; |
| 116 | FOO(0x2); |
| 117 | FOO(0x2); |
| 118 | FOO(0x2); |
| 119 | FOO(0x3); std::cerr << (char*)abcd << "\n"; |
| 120 | FOO(0x80000002); std::cerr << (char*)abcd << "\n"; |
| 121 | FOO(0x80000003); std::cerr << (char*)abcd << "\n"; |
| 122 | FOO(0x80000004); std::cerr << (char*)abcd << "\n"; |
| 123 | FOO(0x80000005); std::cerr << (char*)abcd << "\n"; |
| 124 | FOO(0x80000006); std::cerr << (char*)(abcd) << "\n"; |
| 125 | std::cerr << "L2 : " << (abcd[2] >> 16) << "KB\n"; |
| 126 | // FOO(0x80000019); std::cerr << (char*)(abcd) << "\n"; |
| 127 | FOO(0x8000001A); std::cerr << (char*)(abcd) << "\n"; |
| 128 | |
| 129 | #endif |