Tensorium
Loading...
Searching...
No Matches
CPU_id.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cpuid.h>
4#include <cstring>
5#include <string>
6#include <iostream>
7
8inline std::string get_cpu_brand() {
9 char brand[0x40] = {0};
10 unsigned int regs[4] = {0};
11 for (int i = 0; i < 3; ++i) {
12 __cpuid(0x80000002 + i, regs[0], regs[1], regs[2], regs[3]);
13 std::memcpy(brand + i * 16, regs, sizeof(regs));
14 }
15 return std::string(brand);
16}
17
19 std::string brand = get_cpu_brand();
20
21 if (brand.find("Xeon Phi") != std::string::npos) return 256;
22 if (brand.find("Xeon") != std::string::npos) return 128;
23 if (brand.find("Ryzen") != std::string::npos) return 96;
24 if (brand.find("Apple") != std::string::npos) return 64;
25 if (brand.find("Core(TM)") != std::string::npos) return 128;
26 std::cout << "Unknown CPU brand. Defaulting to 64." << std::endl;
27 return 64;
28}
29
size_t detect_optimal_block_size()
Definition CPU_id.hpp:18
std::string get_cpu_brand()
Definition CPU_id.hpp:8