1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
///
/// @file cpu_info.cpp
/// @brief Detect the CPUs' cache sizes
///
/// Copyright (C) 2025 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///
#include <CpuInfo.hpp>
#include <iostream>
#include <string>
using namespace primesieve;
int main()
{
const CpuInfo cpu;
std::string error = cpu.getError();
if (!error.empty())
{
std::cerr << "Error: " << error << std::endl;
return 1;
}
if (!cpu.hasLogicalCpuCores() &&
cpu.logicalCpuCores() > 0)
{
std::cerr << "Invalid logical CPU cores: " << cpu.logicalCpuCores() << std::endl;
return 1;
}
if (!cpu.hasL1Cache() &&
cpu.l1CacheBytes() > 0)
{
std::cerr << "Invalid L1 cache size: " << cpu.l1CacheBytes() << std::endl;
return 1;
}
if (!cpu.hasL2Cache() &&
cpu.l2CacheBytes() > 0)
{
std::cerr << "Invalid L2 cache size: " << cpu.l2CacheBytes() << std::endl;
return 1;
}
if (!cpu.hasL3Cache() &&
cpu.l3CacheBytes() > 0)
{
std::cerr << "Invalid L3 cache size: " << cpu.l3CacheBytes() << std::endl;
return 1;
}
if (!cpu.hasL1Sharing() &&
cpu.l1Sharing() > 0)
{
std::cerr << "Invalid L1 cache sharing: " << cpu.l1Sharing() << std::endl;
return 1;
}
if (!cpu.hasL2Sharing() &&
cpu.l2Sharing() > 0)
{
std::cerr << "Invalid L2 cache sharing: " << cpu.l2Sharing() << std::endl;
return 1;
}
if (!cpu.hasL3Sharing() &&
cpu.l3Sharing() > 0)
{
std::cerr << "Invalid L3 cache sharing: " << cpu.l3Sharing() << std::endl;
return 1;
}
if (cpu.hasCpuName())
std::cout << cpu.cpuName() << std::endl;
std::cout << "L1 cache size: " << (cpu.l1CacheBytes() >> 10) << " KiB" << std::endl;
std::cout << "L2 cache size: " << (cpu.l2CacheBytes() >> 10) << " KiB" << std::endl;
std::cout << "L3 cache size: " << (cpu.l3CacheBytes() >> 10) << " KiB" << std::endl;
return 0;
}
|