seams-core v2.14.0
libyodaLib, the C++ engine of d-SEAMS
Loading...
Searching...
No Matches
seams::cpu Namespace Reference

Classes

struct  Features

Functions

Features detectFeatures ()
const Features & features ()
void allowSimdKernels (bool allow)
bool simdKernelsAllowed ()

Function Documentation

◆ allowSimdKernels()

void seams::cpu::allowSimdKernels ( bool allow)

◆ detectFeatures()

Features seams::cpu::detectFeatures ( )
inline

Definition at line 41 of file cpu_features.hpp.

41 {
42 Features out;
43#if defined(SEAMS_HOST_X86)
44 unsigned a = 0, b = 0, c = 0, d = 0;
45 unsigned xlo = 0;
46#if defined(_MSC_VER)
47 int regs[4] = {};
48 __cpuidex(regs, 1, 0);
49 a = static_cast<unsigned>(regs[0]);
50 b = static_cast<unsigned>(regs[1]);
51 c = static_cast<unsigned>(regs[2]);
52 d = static_cast<unsigned>(regs[3]);
53#else
54 if (!__get_cpuid(1, &a, &b, &c, &d)) {
55 return out;
56 }
57#endif
58 const bool osxsave = (c & (1u << 27)) != 0;
59 const bool avx = (c & (1u << 28)) != 0;
60 const bool fma = (c & (1u << 12)) != 0;
61 if (!osxsave || !avx) {
62 return out;
63 }
64#if defined(_MSC_VER)
65 xlo = static_cast<unsigned>(_xgetbv(0));
66#else
67 unsigned xhi = 0;
68 __asm__ volatile("xgetbv" : "=a"(xlo), "=d"(xhi) : "c"(0));
69 (void)xhi;
70#endif
71 // The OS saves the YMM state (bits 1, 2) and the ZMM state (bits 5-7).
72 const bool ymm = (xlo & 0x6u) == 0x6u;
73 const bool zmm = ymm && (xlo & 0xe0u) == 0xe0u;
74#if defined(_MSC_VER)
75 __cpuidex(regs, 7, 0);
76 a = static_cast<unsigned>(regs[0]);
77 b = static_cast<unsigned>(regs[1]);
78 c = static_cast<unsigned>(regs[2]);
79 d = static_cast<unsigned>(regs[3]);
80#else
81 if (!__get_cpuid_count(7, 0, &a, &b, &c, &d)) {
82 return out;
83 }
84#endif
85 out.fma = ymm && fma;
86 out.avx2 = ymm && (b & (1u << 5)) != 0;
87 out.avx512f = zmm && (b & (1u << 16)) != 0;
88 out.avx512dq = out.avx512f && (b & (1u << 17)) != 0;
89 out.avx512vnni = out.avx512f && (c & (1u << 11)) != 0;
90 // AMX-TILE and AMX-INT8, and the OS saves TILECFG and TILEDATA
91 // (bits 17, 18). Linux still has to grant TILEDATA per process.
92 out.amxInt8 = (d & (3u << 24)) == (3u << 24) && (xlo & 0x60000u) == 0x60000u;
93#endif
94 return out;
95}

◆ features()

const Features & seams::cpu::features ( )
inline

Definition at line 97 of file cpu_features.hpp.

97 {
98 static const Features cached = detectFeatures();
99 return cached;
100}
Features detectFeatures()

◆ simdKernelsAllowed()

bool seams::cpu::simdKernelsAllowed ( )