Gromacs  2024.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
gmx::anonymous_namespace{hardwaretopology.cpp} Namespace Reference

Functions

void translateCpuInfoLogicalProcessorsToMachine (const std::vector< CpuInfo::LogicalProcessor > &logicalProcessors, HardwareTopology::Machine *machine)
 Utlility function to renumber and translate low-level APIC info to topology. More...
 
HardwareTopology::SupportLevel parseCpuInfo (HardwareTopology::Machine *machine)
 Initialize machine data from basic information in cpuinfo. More...
 
int detectLogicalProcessorCount ()
 Try to detect the number of logical processors. More...
 
std::vector< int > parseCpuString (const std::string &cpuString)
 Parse cpu list (integers) from string separated by commas and ranges. More...
 
HardwareTopology::SupportLevel parseSysFsCpuTopology (HardwareTopology::Machine *machine, const std::string &root="", const std::vector< int > &allowedCpus={})
 Attempt to read basic topology from Linux sysfs interface. More...
 
std::string findCgroupPath (const std::vector< std::string > &mountPoints, const std::vector< std::string > &subGroups, const std::string &root)
 Find the active cgroup path for the current process. More...
 
float parseCgroup1CpuLimit (const std::vector< std::string > &mountPoints, const std::string &root="")
 Parse cpu limits from cgroup version 1 file system on Linux. More...
 
float parseCgroup2CpuLimit (const std::vector< std::string > &mountPoints, const std::string &root="")
 Parse cpu limits from cgroup version 2 file system on Linux. More...
 
float detectCpuLimit (const std::string &root="")
 
int setMaxThreads (float cpuLimit, int topologyCpus, int systemCpus)
 

Function Documentation

int gmx::anonymous_namespace{hardwaretopology.cpp}::detectLogicalProcessorCount ( )

Try to detect the number of logical processors.

Returns
The number of hardware processing units, or 0 if it fails.
std::string gmx::anonymous_namespace{hardwaretopology.cpp}::findCgroupPath ( const std::vector< std::string > &  mountPoints,
const std::vector< std::string > &  subGroups,
const std::string &  root 
)

Find the active cgroup path for the current process.

Parameters
mountPointsList of potential mount points
subGroupsList of potential subgroup paths
rootOptional mock root for creating topologies from saved data. If provided, all paths will be relative to this mock root.

This routine will attempt to detect the path to the cgroup that's active for the present process by searching for our own process id in the cgroups.procs file in each combination of mountPoint and subGroup.

Returns
Path to the active cgroup directory, or empty string if none found.
float gmx::anonymous_namespace{hardwaretopology.cpp}::parseCgroup1CpuLimit ( const std::vector< std::string > &  mountPoints,
const std::string &  root = "" 
)

Parse cpu limits from cgroup version 1 file system on Linux.

Parameters
mountPointsTop-level mount point for cgroups1
rootOptional mock root for creating topologies from saved data. If provided, all paths will be relative to this mock root.
Returns
Allowed CPU limit. Note that this is often larger than 1, meaning the limit is larger than 1 thread.
float gmx::anonymous_namespace{hardwaretopology.cpp}::parseCgroup2CpuLimit ( const std::vector< std::string > &  mountPoints,
const std::string &  root = "" 
)

Parse cpu limits from cgroup version 2 file system on Linux.

Parameters
mountPointsTop-level mount point for cgroups2
rootOptional mock root for creating topologies from saved data. If provided, all paths will be relative to this mock root.
Returns
Allowed CPU limit. Note that this is often larger than 1, meaning the limit is larger than 1 thread.
HardwareTopology::SupportLevel gmx::anonymous_namespace{hardwaretopology.cpp}::parseCpuInfo ( HardwareTopology::Machine *  machine)

Initialize machine data from basic information in cpuinfo.

Parameters
machineMachine tree structure where information will be assigned if the cpuinfo object contains topology information.
Returns
SupportLevel::Basic if topology information was found.
std::vector<int> gmx::anonymous_namespace{hardwaretopology.cpp}::parseCpuString ( const std::string &  cpuString)

Parse cpu list (integers) from string separated by commas and ranges.

Parameters
cpuStringString with integers in the standard linux cpulist format, i.e. integers and integer ranges (specified with dashes) separated by commas like "0,3-5,7,8,10-15". If the string is ill-formed, or If any integer is negative or the indices are not strictly increasing, we return an empty vector.
Returns
vector containing the integers specified, with ranges expanded to all entries.
HardwareTopology::SupportLevel gmx::anonymous_namespace{hardwaretopology.cpp}::parseSysFsCpuTopology ( HardwareTopology::Machine *  machine,
const std::string &  root = "",
const std::vector< int > &  allowedCpus = {} 
)

Attempt to read basic topology from Linux sysfs interface.

Parameters
machinePointer to machine structure in topology to be populated
rootOptional path to (mock) file system root. If this is provided, all file system access will be relative to this path instead. This allows us to create mock topologies based on saved data.
allowedCpusWhen creating mock topologies by setting the root parameter, we will not attempt to check if we can run on processors based on cpuset affinity masks, but you should use this parameter to provide a vector of logical (OS) processor indices on which we are allowed to run.

This is a poor man's version of the much fancier topology detection available from hwloc, but given the compilcations of modern hardware we are critically dependent on being able to understand at least how many sockets/cores/threads we have, even when Gromacs is compiled without hwloc support.

Returns
SupportLevel::Basic if topology information was found.
void gmx::anonymous_namespace{hardwaretopology.cpp}::translateCpuInfoLogicalProcessorsToMachine ( const std::vector< CpuInfo::LogicalProcessor > &  logicalProcessors,
HardwareTopology::Machine *  machine 
)

Utlility function to renumber and translate low-level APIC info to topology.

Parameters
logicalProcessorsLogical processor information according to the CpuInfo structure. Note that the indices refer to low-level hardware, so they will be renumbered to only consider logical cores/processing units we use.
machineHardware topology machine structure where result is written.