Detection#

#include <hpk/detection.hpp>

This header declares functions for detecting system properties at runtime.

Note that these functions respect the process’s CPU affinity. For example, if the application myapp is run with the following command:

taskset --cpu-list 0 myapp

then, in that application, detectCpus(), detectCores(), etc. will return 1, as only a single cpu is available to the process.

See Also:
Example source file: ncpu.cpp
Linux man pages: taskset(1), sched_getaffinity(2)

FUNCTIONS

Architecture hpk::detectArchitecture()#

Returns the instruction set architecture available to the current process.

int hpk::detectCpus()#

Returns the number of CPUs (i.e., hardware threads) available to the current process.

int hpk::detectCores()#

Returns the number of cores available to the current process.

int hpk::detectDies()#

Returns the number of dies available to the current process.

int hpk::detectPackages()#

Returns the number of packages available to the current process.

CacheInfo hpk::detectDataCache(int cacheLevel)#

Returns information describing the hardware data cache at the specified level for the CPU running the current process.


CLASS

struct CacheInfo#

Provides processor cache information.

Public Members

unsigned int size#

Total size of the cache in KiB.

int sharedCpus#

Number of CPUs sharing the cache.

unsigned int lineSize#

Size of each cache line in bytes.

unsigned int sets#

Number of sets (cache lines per way)

unsigned int ways#

Associativity (cache lines per set)

std::string toString(const CacheInfo &info)#

Returns a string description of a CacheInfo.

inline std::ostream &operator<<(std::ostream &os, const CacheInfo &info)#

Overload for ostream’s << operator for a CacheInfo.