← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
system_topology.h
Go to the documentation of this file.
1/*
2 * system_topology.h - System hardware topology discovery for distributed training
3 *
4 * Probes CPU, memory, NUMA, PCIe, and network configuration to provide
5 * recommendations for optimal distributed training setup.
6 */
7
8#ifndef SYSTEM_TOPOLOGY_H
9#define SYSTEM_TOPOLOGY_H
10
11#include <stdint.h>
12#include <stdbool.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18// ═══════════════════════════════════════════════════════════════════════════════
19// Constants
20// ═══════════════════════════════════════════════════════════════════════════════
21
22#define MAX_NUMA_NODES 8
23#define MAX_CPUS 256
24#define MAX_CACHE_LEVELS 4
25#define MAX_NICS 8
26#define MAX_PCIE_DEVICES 32
27#define MAX_MEMORY_SLOTS 16
28#define MAX_STR_LEN 256
29
30// ═══════════════════════════════════════════════════════════════════════════════
31// CPU Information
32// ═══════════════════════════════════════════════════════════════════════════════
33
34typedef struct {
35 char model_name[MAX_STR_LEN];
36 char vendor[64];
37 int family;
38 int model;
40
46
49
50 // SIMD capabilities
52 bool has_avx;
57 bool has_avx512_bf16; // AVX-512 BF16 instructions
58 bool has_amx; // Intel AMX (any variant)
59 bool has_amx_tile; // AMX tile operations
60 bool has_amx_int8; // AMX INT8 matrix multiply
61 bool has_amx_bf16; // AMX BF16 matrix multiply
62 bool has_vnni; // Vector Neural Network Instructions
63
64 // PCIe lanes (from CPU)
67} CPUInfo;
68
69// ═══════════════════════════════════════════════════════════════════════════════
70// Cache Information
71// ═══════════════════════════════════════════════════════════════════════════════
72
73typedef struct {
74 int level; // L1, L2, L3
75 char type[16]; // "Data", "Instruction", "Unified"
79 int shared_by_cores; // How many cores share this cache
80} CacheInfo;
81
82typedef struct {
85 int l3_total_kb; // Total L3 across all sockets
87
88// ═══════════════════════════════════════════════════════════════════════════════
89// NUMA Information
90// ═══════════════════════════════════════════════════════════════════════════════
91
92typedef struct {
96 int cpu_list[MAX_CPUS];
98} NUMANode;
99
100typedef struct {
103 // Inter-node distances (for NUMA-aware allocation)
106
107// ═══════════════════════════════════════════════════════════════════════════════
108// Memory Information
109// ═══════════════════════════════════════════════════════════════════════════════
110
111typedef struct {
113 char locator[64]; // "DIMM_A1", "P1-DIMMA1", etc.
115 uint64_t size_mb;
117 char type[32]; // "DDR4", "DDR5"
118 int rank;
120} MemorySlot;
121
122typedef struct {
123 uint64_t total_mb;
124 uint64_t available_mb;
125 uint64_t cached_mb;
126
127 // DIMM configuration (requires dmidecode/root)
131
132 // Channel configuration
135 char channel_config[64]; // "Dual-channel", "Quad-channel", etc.
136
137 // Theoretical bandwidth
139 float measured_bandwidth_gbs; // From actual benchmark
140 int estimated_channels; // Inferred from measured bandwidth
141
142 // Benchmark details (for transparency)
143 int bw_test_numa_node; // Which NUMA node was tested
144 int bw_test_num_threads; // How many threads used
145
146 // Memory type detected
147 char memory_type[32];
149} MemoryInfo;
150
151// ═══════════════════════════════════════════════════════════════════════════════
152// PCIe Information
153// ═══════════════════════════════════════════════════════════════════════════════
154
155typedef struct {
156 char slot_id[32];
157 char device_name[MAX_STR_LEN];
158 char vendor[64];
160 int bus;
163
164 int link_width; // x1, x4, x8, x16
165 int link_width_max; // Maximum supported
166 int link_speed; // PCIe generation (3, 4, 5, 6)
168
169 float bandwidth_gbs; // Current bandwidth
170 float bandwidth_max_gbs; // Maximum possible
171
172 bool is_gpu;
173 bool is_nic;
175} PCIeDevice;
176
188
189// ═══════════════════════════════════════════════════════════════════════════════
190// Network Information
191// ═══════════════════════════════════════════════════════════════════════════════
192
193typedef struct {
194 char name[32]; // eth0, enp3s0, ib0
195 char driver[64];
196 char pci_address[32];
197
198 uint64_t speed_mbps; // Link speed in Mbps
199 bool is_up;
201
202 // Capabilities
203 bool supports_rdma; // RoCE or InfiniBand
207
208 char mac_address[24];
209 int mtu;
210
211 // PCIe info for this NIC
216
217typedef struct {
220
221 // Best interface for distributed training
226
227// ═══════════════════════════════════════════════════════════════════════════════
228// OpenMP / Affinity Information
229// ═══════════════════════════════════════════════════════════════════════════════
230
231typedef struct {
233 char omp_proc_bind[32]; // "close", "spread", "master", etc.
234 char omp_places[64]; // "cores", "threads", "sockets"
236
237 // Current process affinity
238 int affinity_cpus[MAX_CPUS];
241
242// ═══════════════════════════════════════════════════════════════════════════════
243// Complete System Topology
244// ═══════════════════════════════════════════════════════════════════════════════
245
260
261// ═══════════════════════════════════════════════════════════════════════════════
262// Recommendations
263// ═══════════════════════════════════════════════════════════════════════════════
264
271
279
280#define MAX_RECOMMENDATIONS 32
281
282typedef struct {
285 char title[128];
286 char description[512];
287 char action[256];
289
294
295// ═══════════════════════════════════════════════════════════════════════════════
296// API Functions
297// ═══════════════════════════════════════════════════════════════════════════════
298
299// Main discovery function
301
302// Individual discovery functions
310
311// Generate recommendations
313 RecommendationList *recs);
314
315// Display functions
316void topology_print_summary(const SystemTopology *topo);
317void topology_print_cpu(const CPUInfo *cpu);
318void topology_print_cache(const CacheTopology *cache, int logical_cores);
319void topology_print_numa(const NUMATopology *numa, int sockets);
320void topology_print_memory(const MemoryInfo *mem);
321void topology_print_pcie(const PCIeTopology *pcie);
325
326// Distributed training info
328
329// Utility
332 uint64_t model_size_mb);
333
334#ifdef __cplusplus
335}
336#endif
337
338#endif // SYSTEM_TOPOLOGY_H
int logical_cores
bool has_avx512bw
int pcie_generation
bool has_avx512_bf16
float max_freq_mhz
int cores_per_socket
bool has_amx_int8
int physical_cores
bool has_amx_bf16
int pcie_lanes_total
bool has_avx512f
int threads_per_core
bool has_avx512vl
float base_freq_mhz
bool has_sse4_2
bool has_amx_tile
int ways_of_associativity
float measured_bandwidth_gbs
uint64_t total_mb
float theoretical_bandwidth_gbs
uint64_t available_mb
uint64_t cached_mb
uint64_t size_mb
uint64_t memory_free_mb
uint64_t memory_total_mb
float bandwidth_max_gbs
RecommendationPriority priority
RecommendationCategory category
CacheTopology cache
NUMATopology numa
PCIeTopology pcie
NetworkTopology network
AffinityInfo affinity
void topology_print_memory(const MemoryInfo *mem)
int topology_discover_memory(MemoryInfo *mem)
int topology_discover_pcie(PCIeTopology *pcie)
int topology_discover(SystemTopology *topo)
#define MAX_RECOMMENDATIONS
int topology_discover_cpu(CPUInfo *cpu)
void topology_print_network(const NetworkTopology *net)
void topology_print_pcie(const PCIeTopology *pcie)
void topology_print_distributed_potential(const SystemTopology *topo)
void topology_print_numa(const NUMATopology *numa, int sockets)
#define MAX_STR_LEN
#define MAX_CACHE_LEVELS
#define MAX_NUMA_NODES
void topology_print_cpu(const CPUInfo *cpu)
#define MAX_MEMORY_SLOTS
int topology_discover_cache(CacheTopology *cache)
#define MAX_CPUS
int topology_discover_network(NetworkTopology *net)
RecommendationPriority
@ REC_PRIORITY_MEDIUM
@ REC_PRIORITY_CRITICAL
@ REC_PRIORITY_HIGH
@ REC_PRIORITY_LOW
void topology_print_affinity(const AffinityInfo *aff)
float topology_estimate_network_training_time(const NetworkTopology *net, uint64_t model_size_mb)
#define MAX_NICS
RecommendationCategory
@ REC_CATEGORY_AFFINITY
@ REC_CATEGORY_CPU
@ REC_CATEGORY_MEMORY
@ REC_CATEGORY_NETWORK
@ REC_CATEGORY_PCIE
int topology_generate_recommendations(const SystemTopology *topo, RecommendationList *recs)
void topology_print_recommendations(const RecommendationList *recs)
void topology_print_summary(const SystemTopology *topo)
float topology_estimate_memory_bandwidth(const MemoryInfo *mem)
#define MAX_PCIE_DEVICES
int topology_discover_affinity(AffinityInfo *aff)
void topology_print_cache(const CacheTopology *cache, int logical_cores)
int topology_discover_numa(NUMATopology *numa)