alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
alpaka::onHost::internal::hwloc Namespace Reference

Implement functions required to set thread affinity and pin memory. More...

Functions

size_t getFreeGlobalMemBytes (uint32_t cpuDomainIdx)
 Return the number of free bytes in a CPU domain.
size_t getMemCapacityBytes (uint32_t cpuDomainIdx)
 Return the memory capacity of a CPU domain.
uint32_t getNumCores (uint32_t cpuDomainIdx)
 Return the number of cores in a CPU domain.
uint32_t getNumCpuDomains ()
 Get the number of alpaka host CPU domains.
std::optional< size_t > parseNodeMemInfoValueBytes (unsigned osNodeIndex, std::string_view key)
 Parse the OS NUMA information.
template<typename T>
void pinPointer (T *const ptr, size_t bytes, uint32_t cpuDomainIdx)
 Set the default NUMA memory node for a CPU-domain memory range.
void setThreadAffinity (uint32_t cpuDomainIdx)
 Set the affinity of the current thread to all cores of a CPU domain.

Variables

constexpr uint32_t allDomains = std::numeric_limits<uint32_t>::max()
 Constant to select all CPU domains.

Detailed Description

Implement functions required to set thread affinity and pin memory.

There is always a fallback implementation to be able to run without hwloc. In this case domain selection is not possible and all cores will be taken into account.

Domain model:

  • A CPU domain is the object used as an alpaka host device.
  • If hwloc Group objects with CPU sets are available, CPU domains are Groups.
  • Otherwise, CPU domains fall back to NUMA nodes with CPU sets.
  • NUMA nodes are memory targets attached to a CPU domain, not necessarily CPU devices themselves.

This avoids duplicating the same CPU cores as multiple alpaka devices on systems where DDR and HBM are modeled as separate NUMA nodes below the same Group.

Function Documentation

◆ getFreeGlobalMemBytes()

size_t alpaka::onHost::internal::hwloc::getFreeGlobalMemBytes ( uint32_t cpuDomainIdx)
inline

Return the number of free bytes in a CPU domain.

Linux-only implementation via /sys/devices/system/node/nodeX/meminfo. If the CPU domain has multiple attached NUMA memory nodes, e.g. DDR and HBM, the returned value is the sum of all attached memory nodes.

Parameters
cpuDomainIdxIndex of the cpu group.

Definition at line 504 of file utility.hpp.

◆ getMemCapacityBytes()

size_t alpaka::onHost::internal::hwloc::getMemCapacityBytes ( uint32_t cpuDomainIdx)
inline

Return the memory capacity of a CPU domain.

If the CPU domain has multiple attached NUMA memory nodes, e.g. DDR and HBM, the returned value is the sum of all attached memory nodes.

Parameters
cpuDomainIdxIndex of the cpu group.

Definition at line 474 of file utility.hpp.

◆ getNumCores()

uint32_t alpaka::onHost::internal::hwloc::getNumCores ( uint32_t cpuDomainIdx)
inline

Return the number of cores in a CPU domain.

Here "cores" means logical CPUs / processing units, so SMT siblings are counted too.

Parameters
cpuDomainIdxIndex of the cpu group.

Definition at line 442 of file utility.hpp.

◆ getNumCpuDomains()

uint32_t alpaka::onHost::internal::hwloc::getNumCpuDomains ( )
inline

Get the number of alpaka host CPU domains.

Definition at line 243 of file utility.hpp.

◆ parseNodeMemInfoValueBytes()

std::optional< size_t > alpaka::onHost::internal::hwloc::parseNodeMemInfoValueBytes ( unsigned osNodeIndex,
std::string_view key )
inline

Parse the OS NUMA information.

hwloc is not providing the available free memory in a NUMA domain. Therefore we fall back to check the NUMA node information in the OS directly.

Parameters
osNodeIndexThe index of the NUMA node in the OS.
keyThe key value you want to read out e.g. 'MemFree:' or 'HugePages_Total:'.

Definition at line 261 of file utility.hpp.

◆ pinPointer()

template<typename T>
void alpaka::onHost::internal::hwloc::pinPointer ( T *const ptr,
size_t bytes,
uint32_t cpuDomainIdx )
inline

Set the default NUMA memory node for a CPU-domain memory range.

Attention
This method should be called before the memory is touched, else it may have no effect. If a cpuDomainIdx contains more than one numa domain, the first numa domain will be used.
Parameters
ptrpointer address to pin, nullptr is valid input.
bytesthe number of bytes to pin starting from the ptr address.
cpuDomainIdxIndex of the cpu group.

Definition at line 410 of file utility.hpp.

◆ setThreadAffinity()

void alpaka::onHost::internal::hwloc::setThreadAffinity ( uint32_t cpuDomainIdx)
inline

Set the affinity of the current thread to all cores of a CPU domain.

Parameters
cpuDomainIdxLegacy name: CPU-domain index starting with zero, or 'allDomains' to use all cores.

Definition at line 301 of file utility.hpp.

Variable Documentation

◆ allDomains

uint32_t alpaka::onHost::internal::hwloc::allDomains = std::numeric_limits<uint32_t>::max()
constexpr

Constant to select all CPU domains.

Definition at line 40 of file utility.hpp.