Gromacs  2020.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions
cpuinfo.cpp File Reference
#include "gmxpre.h"
#include "cpuinfo.h"
#include "config.h"
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include "gromacs/utility/basedefinitions.h"
#include "architecture.h"
+ Include dependency graph for cpuinfo.cpp:

Description

Implements gmx::CpuInfo.

We need to be able to compile this file in stand-alone mode to use basic CPU feature detection to set the SIMD acceleration and similar things in CMake, while we still want to use more features that enable topology detection when config.h is present.

We solve this by skipping the advanced stuff when the preprocessor macro GMX_CPUINFO_STANDALONE is defined. In this case you likely also need to define GMX_X86_GCC_INLINE_ASM if you are on x86; without inline assembly support it is not possible to perform the actual detection on Linux/Mac. Since these macros are specific to this file, they do not use the GMX prefix.

The remaining defines (GMX_NATIVE_WINDOWS,HAVE_UNISTD_H,HAVE_SCHED_H, HAVE_SYSCONF, HAVE_SCHED_AFFINITY) are only used to determine the topology on 86, and for this we rely on including config.h.

Author
Erik Lindahl erik..nosp@m.lind.nosp@m.ahl@g.nosp@m.mail.nosp@m..com

Classes

struct  gmx::anonymous_namespace{cpuinfo.cpp}::ApicIdLayout
 The layout of the bits in the APIC ID. More...
 

Functions

void gmx::anonymous_namespace{cpuinfo.cpp}::trimString (std::string *s)
 Remove initial and trailing whitespace from string. More...
 
int gmx::anonymous_namespace{cpuinfo.cpp}::executeX86CpuID (unsigned int level, unsigned int 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 gmx::anonymous_namespace{cpuinfo.cpp}::detectX86Vendor ()
 Detect x86 vendors by using the cpuid assembly instructions. More...
 
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. More...
 
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. More...
 
std::vector< unsigned int > gmx::anonymous_namespace{cpuinfo.cpp}::detectX86ApicIDs (bool haveX2Apic)
 Return a vector with x86 APIC IDs for all threads. More...
 
void gmx::anonymous_namespace{cpuinfo.cpp}::renumberIndex (std::vector< unsigned int > *v)
 Utility to renumber indices extracted from APIC IDs. More...
 
ApicIdLayout gmx::anonymous_namespace{cpuinfo.cpp}::detectX2ApicIdLayout ()
 Detect the APIC ID layout for x2APIC.
 
ApicIdLayout gmx::anonymous_namespace{cpuinfo.cpp}::detectAmdApicIdLayout (unsigned int maxExtLevel)
 Detect the APIC ID layout for standard APIC or xAPIC on AMD. More...
 
std::vector
< CpuInfo::LogicalProcessor > 
gmx::anonymous_namespace{cpuinfo.cpp}::detectX86LogicalProcessors ()
 Try to detect basic CPU topology information using x86 cpuid. More...
 
std::map< std::string,
std::string > 
gmx::anonymous_namespace{cpuinfo.cpp}::parseProcCpuInfo ()
 Parse /proc/cpuinfo into a simple string map. More...
 
CpuInfo::Vendor gmx::anonymous_namespace{cpuinfo.cpp}::detectProcCpuInfoVendor (const std::map< std::string, std::string > &cpuInfo)
 Try to detect vendor from /proc/cpuinfo. More...
 
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. More...
 
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. More...
 
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. More...
 
bool gmx::cpuIsX86Nehalem (const CpuInfo &cpuInfo)
 Return true if the CPU is an Intel x86 Nehalem. More...