Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
hardware_topology.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef REALM_TOPOLOGY_H
19#define REALM_TOPOLOGY_H
20
21#include "realm/realm_config.h"
22#include <stddef.h>
23#include <memory>
24#include <set>
25#include <map>
26#include <vector>
27
28namespace Realm {
29
39
40 public:
45 typedef int ProcID;
46
51 struct Proc {
53 int domain;
54 std::set<ProcID> kernel_proc_ids;
55 std::set<ProcID>
57 std::set<ProcID>
59 std::set<ProcID>
61 };
62
67 struct MemoryInfo {
68 size_t bytes;
69 int domain;
70 };
71
77
82
89 HardwareTopology(const std::vector<Proc> &logical_cores,
90 const std::vector<MemoryInfo> &memories, const size_t host_memory);
91
96
98
103
108 size_t system_memory(void) const;
109
114 unsigned num_logical_cores(void) const;
115
120 unsigned num_physical_cores(void) const;
121
126 unsigned num_numa_domains(void) const;
127
132 void get_logical_cores(std::set<ProcID> &cores) const;
133
139 bool has_processor(ProcID proc_id) const;
140
146 bool numa_domain_has_processors(int domain_id) const;
147
153 const std::set<ProcID> &get_processors_by_domain(int domain_id) const;
154
160 const std::set<ProcID> &get_processors_share_alu(ProcID proc_id) const;
161
167 const std::set<ProcID> &get_processors_share_fpu(ProcID proc_id) const;
168
174 const std::set<ProcID> &get_processors_share_ldst(ProcID proc_id) const;
175
182 const std::set<ProcID> &get_kernel_processor_ids(ProcID proc_id) const;
183
188 std::vector<ProcID> distribute_processors_across_domains(void) const;
189
196 friend std::ostream &operator<<(std::ostream &os, const HardwareTopology &topo);
197
198 private:
199 size_t sys_memory_size{0};
200 unsigned physical_cores{0};
201
202 typedef std::map<ProcID, Proc> ProcMap;
203
208 struct DomainInfo {
209 size_t memory_size;
210 std::set<ProcID> logical_cores;
211 };
212
213 typedef std::map<int, DomainInfo> DomainMap;
214
215 ProcMap all_procs;
216 DomainMap by_domain;
217 };
218
219}; /* namespace Realm*/
220
221#endif /* REALM_TOPOLOGY_H */
Represents the topology of the host processor cores and memory.
Definition hardware_topology.h:38
void remove_hyperthreads(void)
Removes hyperthreads from the topology.
int ProcID
A unique integer identifier for a processor.
Definition hardware_topology.h:45
size_t system_memory(void) const
Returns the size of system memory in bytes.
const std::set< ProcID > & get_processors_share_alu(ProcID proc_id) const
Gets processors sharing an ALU with a specified processor.
HardwareTopology & operator=(const HardwareTopology &rhs)=default
std::vector< ProcID > distribute_processors_across_domains(void) const
Distributes processors across NUMA domains.
const std::set< ProcID > & get_processors_by_domain(int domain_id) const
Gets the processors in a specific NUMA domain.
HardwareTopology(void)
Constructs an empty HardwareTopology instance.
bool numa_domain_has_processors(int domain_id) const
Checks if a NUMA domain exists in the topology and has processors.
friend std::ostream & operator<<(std::ostream &os, const HardwareTopology &topo)
Outputs the topology information to a stream.
HardwareTopology(const std::vector< Proc > &logical_cores, const std::vector< MemoryInfo > &memories, const size_t host_memory)
Constructs a HardwareTopology instance.
static HardwareTopology create_topology(void)
Creates a topology instance based on the system's hardware.
bool has_processor(ProcID proc_id) const
Checks if a processor exists in the topology.
const std::set< ProcID > & get_kernel_processor_ids(ProcID proc_id) const
Gets kernel processor IDs (usually assigned by OS) associated with a specified processor.
~HardwareTopology(void)
Destructor for HardwareTopology.
unsigned num_logical_cores(void) const
Returns the number of logical cores.
unsigned num_numa_domains(void) const
Returns the number of NUMA domains.
unsigned num_physical_cores(void) const
Returns the number of physical cores.
const std::set< ProcID > & get_processors_share_ldst(ProcID proc_id) const
Gets processors sharing LD/ST with a specified processor.
void get_logical_cores(std::set< ProcID > &cores) const
Retrieves the set of logical core IDs.
const std::set< ProcID > & get_processors_share_fpu(ProcID proc_id) const
Gets processors sharing an FPU with a specified processor.
Definition activemsg.h:38
Represents memory information for a NUMA domain.
Definition hardware_topology.h:67
int domain
NUMA domain associated with the memory.
Definition hardware_topology.h:69
size_t bytes
Size of memory in bytes.
Definition hardware_topology.h:68
Represents a processor core with sharing relationships.
Definition hardware_topology.h:51
int domain
NUMA domain the processor belongs to.
Definition hardware_topology.h:53
std::set< ProcID > shares_alu
Set of processors sharing an ALU with this processor.
Definition hardware_topology.h:56
std::set< ProcID > shares_fpu
Set of processors sharing an FPU with this processor.
Definition hardware_topology.h:58
std::set< ProcID > kernel_proc_ids
Set of kernel processor IDs (may be empty).
Definition hardware_topology.h:54
ProcID id
Unique processor identifier.
Definition hardware_topology.h:52
std::set< ProcID > shares_ldst
Set of processors sharing LD/ST paths with this processor.
Definition hardware_topology.h:60