Gromacs  2025-dev-20240913-b871546
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions
gmx::anonymous_namespace{cpuinfo.cpp} Namespace Reference

Classes

struct  ApicInfo
 internal structure to return os logical cpu id together with APIC info for it More...
 
struct  ApicIdLayout
 The layout of the bits in the APIC ID. More...
 

Functions

void trimString (std::string *s)
 Remove initial and trailing whitespace from string. More...
 
int executeX86CpuID (unsigned int gmx_unused level, unsigned int gmx_unused ecxval, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
 execute x86 cpuid instructions with custom level and extended level More...
 
CpuInfo::Vendor detectX86Vendor ()
 Detect x86 vendors by using the cpuid assembly instructions. More...
 
bool detectProcCpuInfoSecondAvx512FMA (const std::string &brand, int model)
 Detect second AVX-512 FMA from the processor name. More...
 
void setFeatureFromBit (std::set< CpuInfo::Feature > *featureSet, CpuInfo::Feature feature, unsigned int registerValue, unsigned char bit)
 Simple utility function to set/clear feature in a set. More...
 
void detectX86Features (std::string *brand, int *family, int *model, int *stepping, std::set< CpuInfo::Feature > *features)
 Process x86 cpuinfo features that are common to Intel and AMD CPUs. More...
 
std::vector< ApicInfodetectX86ApicInfo (bool gmx_unused haveX2Apic)
 Return a vector with x86 APIC info for all processing units. More...
 
ApicIdLayout detectX2ApicIdLayout ()
 Detect the APIC ID layout for x2APIC.
 
ApicIdLayout detectAmdApicIdLayout (unsigned int maxExtLevel)
 Detect the APIC ID layout for standard APIC or xAPIC on AMD. More...
 
std::vector
< CpuInfo::LogicalProcessor
detectX86LogicalProcessors ()
 Try to detect basic CPU topology information using x86 cpuid. More...
 
std::map< std::string,
std::string > 
parseProcCpuInfo ()
 Parse /proc/cpuinfo into a simple string map. More...
 
CpuInfo::Vendor detectProcCpuInfoVendor (const std::map< std::string, std::string > &cpuInfo)
 Try to detect vendor from /proc/cpuinfo. More...
 
void detectProcCpuInfoIbm (const std::map< std::string, std::string > &cpuInfo, std::string *brand, std::set< CpuInfo::Feature > *features)
 Detect IBM processor name and features from /proc/cpuinfo. More...
 
void detectProcCpuInfoArm (const std::map< std::string, std::string > &cpuInfo, std::string *brand, int *family, int *model, int *stepping, std::set< CpuInfo::Feature > *features)
 Detect ARM processor name and features from /proc/cpuinfo. More...
 
void detectProcCpuInfo (CpuInfo::Vendor *vendor, std::string *brand, int *family, int *model, int *stepping, std::set< CpuInfo::Feature > *features)
 Try to detect vendor, cpu and features from /proc/cpuinfo. More...
 

Function Documentation

ApicIdLayout gmx::anonymous_namespace{cpuinfo.cpp}::detectAmdApicIdLayout ( unsigned int  maxExtLevel)

Detect the APIC ID layout for standard APIC or xAPIC on AMD.

Parameters
[in]maxExtLevelThe largest CPUID extended function input value supported by the processor implementation
void gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfo ( CpuInfo::Vendor *  vendor,
std::string *  brand,
int *  family,
int *  model,
int *  stepping,
std::set< CpuInfo::Feature > *  features 
)

Try to detect vendor, cpu and features from /proc/cpuinfo.

Parameters
[out]vendorDetected hardware vendor
[out]brandString where to write the brand string
[out]familyMajor version of processor
[out]modelMiddle version of processor
[out]steppingMinor version of processor
[out]featuresFeature set where supported features are inserted

This routine reads the /proc/cpuinfo file into a map and calls subroutines that attempt to parse by matching keys and values to known strings. It is much more fragile than our x86 detection, but it does not depend on specific system calls, intrinsics or assembly instructions.

void gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfoArm ( const std::map< std::string, std::string > &  cpuInfo,
std::string *  brand,
int *  family,
int *  model,
int *  stepping,
std::set< CpuInfo::Feature > *  features 
)

Detect ARM processor name and features from /proc/cpuinfo.

Parameters
cpuInfoMap returned from parseProcCpuinfo()
[out]brandString where to write the brand string
[out]familyMajor version of processor
[out]modelMiddle version of processor
[out]steppingMinor version of processor
[out]featuresFeature set where supported features are inserted

This routine tries to match a few common labels in /proc/cpuinfo to see if we can find the processor name and features. It is likely fragile.

void gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfoIbm ( const std::map< std::string, std::string > &  cpuInfo,
std::string *  brand,
std::set< CpuInfo::Feature > *  features 
)

Detect IBM processor name and features from /proc/cpuinfo.

Parameters
cpuInfoMap returned from parseProcCpuinfo()
[out]brandString where to write the brand string
[out]featuresFeature set where supported features are inserted

This routine tries to match a few common labels in /proc/cpuinfo to see if we can find the processor name and features. It is likely fragile.

bool gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfoSecondAvx512FMA ( const std::string &  brand,
int  model 
)

Detect second AVX-512 FMA from the processor name.

Should only be called for processors already determined to support AVX-512.

Parameters
[in]brandx86 processor name
[in]modelx86 model
Returns
True if second FMA present
CpuInfo::Vendor gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfoVendor ( const std::map< std::string, std::string > &  cpuInfo)

Try to detect vendor from /proc/cpuinfo.

Parameters
cpuInfoMap returned from parseProcCpuinfo()

This routine tries to match a few common labels in /proc/cpuinfo to see if they begin with the name of a standard vendor. If the file cannot be read or if no match is found, we return gmx::CpuInfo::Vendor::Unknown.

std::vector<ApicInfo> gmx::anonymous_namespace{cpuinfo.cpp}::detectX86ApicInfo ( bool gmx_unused  haveX2Apic)

Return a vector with x86 APIC info for all processing units.

Parameters
haveX2ApicTrue if the processors supports x2APIC, otherwise vanilla APIC.
Returns
A new vector with os-provided logical cpu id and corresponding hardware APIC id.
void gmx::anonymous_namespace{cpuinfo.cpp}::detectX86Features ( std::string *  brand,
int *  family,
int *  model,
int *  stepping,
std::set< CpuInfo::Feature > *  features 
)

Process x86 cpuinfo features that are common to Intel and AMD CPUs.

Parameters
[out]brandString where to write the x86 brand string
[out]familyMajor version of processor
[out]modelMiddle version of processor
[out]steppingMinor version of processor
[out]featuresFeature set where supported features are inserted
std::vector<CpuInfo::LogicalProcessor> gmx::anonymous_namespace{cpuinfo.cpp}::detectX86LogicalProcessors ( )

Try to detect basic CPU topology information using x86 cpuid.

If x2APIC support is present, this is our first choice, otherwise we attempt to use old vanilla APIC.

Returns
A new vector of entries with package, core, processing unit information for each logical processor.
CpuInfo::Vendor gmx::anonymous_namespace{cpuinfo.cpp}::detectX86Vendor ( )

Detect x86 vendors by using the cpuid assembly instructions.

If support for the cpuid instruction is present, we check for Intel, AMD or Hygon vendors

Returns
gmx::CpuInfo::Vendor::Intel, gmx::CpuInfo::Vendor::Amd, gmx::CpuInfl::Vendor::Hygon, . If neither Intel, Amd nor Hygon can be identified, or if the code fails to execute, gmx::CpuInfo::Vendor::Unknown is returned.
int gmx::anonymous_namespace{cpuinfo.cpp}::executeX86CpuID ( unsigned int gmx_unused  level,
unsigned int gmx_unused  ecxval,
unsigned int *  eax,
unsigned int *  ebx,
unsigned int *  ecx,
unsigned int *  edx 
)

execute x86 cpuid instructions with custom level and extended level

Parameters
levelThe main cpuid level (input argument for eax register)
ecxvalExtended level (input argument for ecx register)
eaxOutput in eax register
ebxOutput in ebx register
ecxOutput in ecx register
edxOutput in edx register
Returns
0 on success, or non-zero if the instruction could not execute.
std::map<std::string, std::string> gmx::anonymous_namespace{cpuinfo.cpp}::parseProcCpuInfo ( )

Parse /proc/cpuinfo into a simple string map.

This routine will read the contents of /proc/cpuinfo, and for each line that is not empty we will assign the (trimmed) string to the right of the colon as a key, and the left-hand side as the value in the map. For multi-processor systems where lines are repeated the latter lines will overwrite the first occurrence.

Returns
New map with the contents. If the file is not available, the returned map will be empty.
void gmx::anonymous_namespace{cpuinfo.cpp}::setFeatureFromBit ( std::set< CpuInfo::Feature > *  featureSet,
CpuInfo::Feature  feature,
unsigned int  registerValue,
unsigned char  bit 
)

Simple utility function to set/clear feature in a set.

Parameters
featureSetPointer to the feature set to update
featureThe specific feature to set/clear
registerValueRegister value (returned from cpuid)
bitBit to check in registerValue. The feature will be added to the featureSet if this bit is set.
Note
Nothing is done if the bit is not set. In particular, this will not erase anything if the feature already exists in the set.
void gmx::anonymous_namespace{cpuinfo.cpp}::trimString ( std::string *  s)

Remove initial and trailing whitespace from string.

Parameters
sPointer to string where whitespace will be removed