nfx-cpu 0.1.3
Cross-platform C++ CPU feature detection and system identification library
Loading...
Searching...
No Matches
CoreTopology.h File Reference

CPU core topology detection. More...

#include <cstdint>
#include "nfx/detail/cpu/CoreTopology.inl"
Include dependency graph for CoreTopology.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

uint32_t nfx::cpu::physicalCoreCount () noexcept
 Gets the number of physical CPU cores.
uint32_t nfx::cpu::logicalCoreCount () noexcept
 Gets the number of logical processors (threads).
bool nfx::cpu::hasHyperThreading () noexcept
 Detects if Hyper-Threading (or SMT) is enabled.
float nfx::cpu::hyperThreadingRatio () noexcept
 Gets the Hyper-Threading ratio (logical cores / physical cores).

Detailed Description

CPU core topology detection.

Runtime detection of physical cores, logical processors, and hyper-threading using CPUID and OS APIs with static caching for zero overhead

Definition in file CoreTopology.h.

Function Documentation

◆ hasHyperThreading()

bool nfx::cpu::hasHyperThreading ( )
inlinenodiscardnoexcept

Detects if Hyper-Threading (or SMT) is enabled.

Compares logical processor count to physical core count. If logical > physical, hyper-threading is enabled. Result is cached via static initialization for zero runtime overhead.

Returns
true if HT/SMT is enabled, false otherwise
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ hyperThreadingRatio()

float nfx::cpu::hyperThreadingRatio ( )
inlinenodiscardnoexcept

Gets the Hyper-Threading ratio (logical cores / physical cores).

Calculates the ratio of logical processors to physical cores. For traditional HT: 2.0 (2 threads per core) For hybrid architectures: varies (e.g., 1.43 for 6P+8E cores = 20/14) For no HT: 1.0 (1 thread per core) Result is cached via static initialization for zero runtime overhead.

Returns
Hyper-Threading ratio as floating point value
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ logicalCoreCount()

uint32_t nfx::cpu::logicalCoreCount ( )
inlinenodiscardnoexcept

Gets the number of logical processors (threads).

Queries the operating system to retrieve the total number of logical processors. This includes both physical cores and hyper-threaded logical cores. Result is cached via static initialization for zero runtime overhead.

Returns
Number of logical processors
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Uses std::thread::hardware_concurrency() which returns logical processors

◆ physicalCoreCount()

uint32_t nfx::cpu::physicalCoreCount ( )
inlinenodiscardnoexcept

Gets the number of physical CPU cores.

Queries the operating system to retrieve the actual number of physical cores. This excludes logical processors created by Hyper-Threading/SMT. Result is cached via static initialization for zero runtime overhead.

Returns
Number of physical CPU cores
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Uses std::thread::hardware_concurrency() on platforms without native core detection