Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
numa_topology.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
12#pragma once
13
14#include <cstddef>
15#include <vector>
16
17namespace kcenon::thread
18{
19
25{
26 int node_id{-1};
27 std::vector<int> cpu_ids;
28 std::size_t memory_size_bytes{0};
29};
30
68{
69public:
73 numa_topology() = default;
74
83 [[nodiscard]] static auto detect() -> numa_topology;
84
90 [[nodiscard]] auto get_node_for_cpu(int cpu_id) const -> int;
91
102 [[nodiscard]] auto get_distance(int node1, int node2) const -> int;
103
110 [[nodiscard]] auto is_same_node(int cpu1, int cpu2) const -> bool;
111
116 [[nodiscard]] auto is_numa_available() const -> bool;
117
122 [[nodiscard]] auto node_count() const -> std::size_t;
123
128 [[nodiscard]] auto cpu_count() const -> std::size_t;
129
134 [[nodiscard]] auto get_nodes() const -> const std::vector<numa_node>&;
135
141 [[nodiscard]] auto get_cpus_for_node(int node_id) const -> std::vector<int>;
142
143private:
145 std::vector<int> cpu_to_node_;
146 std::vector<std::vector<int>> distances_;
147 std::size_t total_cpus_{0};
148
152 static auto detect_linux() -> numa_topology;
153
158 static auto create_fallback() -> numa_topology;
159};
160
161} // namespace kcenon::thread
NUMA (Non-Uniform Memory Access) topology information.
std::size_t total_cpus_
Total CPU count.
numa_topology()=default
Default constructor - creates an empty topology.
auto get_nodes() const -> const std::vector< numa_node > &
Get all NUMA nodes.
static auto detect() -> numa_topology
Detect and return the system's NUMA topology.
auto get_cpus_for_node(int node_id) const -> std::vector< int >
Get CPUs belonging to a specific node.
auto get_distance(int node1, int node2) const -> int
Get the distance between two NUMA nodes.
auto get_node_for_cpu(int cpu_id) const -> int
Get the NUMA node for a given CPU.
std::vector< std::vector< int > > distances_
Inter-node distances.
std::vector< numa_node > nodes_
All NUMA nodes.
auto is_numa_available() const -> bool
Check if NUMA is available on this system.
static auto detect_linux() -> numa_topology
Detect topology on Linux using sysfs.
std::vector< int > cpu_to_node_
CPU ID -> NUMA node mapping.
auto cpu_count() const -> std::size_t
Get the total number of CPUs.
static auto create_fallback() -> numa_topology
Create fallback single-node topology.
auto node_count() const -> std::size_t
Get the number of NUMA nodes.
auto is_same_node(int cpu1, int cpu2) const -> bool
Check if two CPUs are on the same NUMA node.
Core threading foundation of the thread system library.
Definition thread_impl.h:17
STL namespace.
Information about a single NUMA node.
std::vector< int > cpu_ids
CPUs belonging to this node.
std::size_t memory_size_bytes
Total memory on this node.
int node_id
NUMA node identifier.