G5 仿真参数分层管理设计
日期: 2026-04-13 范围:
perfmodel/evaluation/g5/(Rust) + 芯片/拓扑 YAML + 前端类型
背景
G5 仿真引擎共 56 个参数,当前散布在 7 个 Rust 文件中:17 个 const(含 9 处重复定义)、37 个 Config 结构体字段(通过 impl Default 硬编码)、2 个 MultiChipSim 实例字段。
问题
NO_DEP定义 4 次,PSN_MASK定义 2 次,DEFAULT_THREADS_PER_CDMA定义 4 次- 芯片微架构参数(
DATAPATH_BYTES、threads_per_cdma)硬编码为 const,换芯片需改代码 - 7 个
impl Default块中的值无法从配置文件覆盖 - 缺乏参数分类,协议常量和可配置参数混在一起
设计原则
按"谁决定这个值"分层,不同层用不同机制管理。
参数分类
L0 — 协议常量(编译期固定,Rust const)
PAXI RC 协议规范中的固定定义,永远不变,不可配置。
| 参数 | 值 | 含义 |
|---|---|---|
NO_DEP | u32::MAX | 无依赖哨兵值 |
PSN_BITS | 12 | PSN 位宽 |
PSN_MASK | 0xFFF | 12-bit PSN 掩码(从 PSN_BITS 推导) |
PSN_HALF | 0x800 | PSN 空间中点(从 PSN_BITS 推导) |
VC_BANK0~3 | 0~3 | 虚拟通道编号 |
VC_MUL | 4 | 组播虚拟通道编号 |
VC_COUNT | 5 | 虚拟通道总数 |
VC_ORDER | [0,1,2,3,4] | VC 轮询顺序 |
L1 — 芯片硬件参数(芯片 YAML paxi 段)
同一芯片型号固定、不同芯片可能不同的参数。跟着芯片配置走。
PAXI Core(4 个): w_ost_limit, r_ost_limit, mps, max_payload
RC Link TX(10 个): type1_ost, header_overhead, pkt_ovhd, credit_size, credit_uf_limit, max_retry, retry_timeout_ns, overcredit_limit, datapath_bytes, vc_weights
RC Link RX(7 个): merge_depth, poll_groups, poll_cycle_ns, credit_return_delay_ns, credit_size, pkt_ovhd, cnp_interval_ns
DCQCN(6 个): g, byte_threshold, timer_interval_ns, min_rate_bytes_per_ns, fast_recovery_stages, additive_increase_factor
链路级(2 个): initial_credit, ack_wire_bytes
CDMA(1 个): threads_per_cdma(已存在于 dma_engines.cdma.threads_per_cdma,直接复用)
L2 — 拓扑参数(拓扑 YAML switches 段扩展)
Switch 参数随交换机型号变化,已有 port_count 和 forwarding_latency_ns,需补全。
补全字段(8 个): port_bandwidth_gbps, buffer_capacity_bytes, alpha, ecn_kmin, ecn_kmax, islip_iterations, frame_size_bytes, priority_count
C2C Link(3 个): bandwidth_gbps, base_latency_ns, mtu_bytes —— 其中 bandwidth_gbps 和 latency 已在 link_types.c2c 中存在,mtu_bytes 新增。
方案:扩展现有 YAML(方案 A)
芯片 YAML 新增 paxi 段
在 configs/chips/SG2262.yaml 中 d2d 段之后新增:
paxi:
core:
w_ost_limit: 256
r_ost_limit: 256
mps: 4096
max_payload: 1344
tx:
type1_ost: 512
header_overhead: 50
pkt_ovhd: 50
credit_size: 256
credit_uf_limit: 1
max_retry: 15
retry_timeout_ns: 50000
overcredit_limit: 512
datapath_bytes: 64
vc_weights: [1, 1, 1, 1, 256]
rx:
merge_depth: 64
poll_groups: 4
poll_cycle_ns: 4.0
credit_return_delay_ns: 1.0
credit_size: 256
pkt_ovhd: 50
cnp_interval_ns: 50000
dcqcn:
g: 0.00390625
byte_threshold: 153600
timer_interval_ns: 55000
min_rate_bytes_per_ns: 1.0
fast_recovery_stages: 5
additive_increase_factor: 200.0
initial_credit: 1024
ack_wire_bytes: 50
拓扑 YAML switches 段补全
现有 clos-2tier-4chip.yaml 的 switches 段扩展:
switches:
- id: s0
type: tor
port_count: 32
forwarding_latency_ns: 150
port_bandwidth_gbps: 400
buffer_capacity_bytes: 16777216
alpha: 2.0
ecn_kmin: 0.5
ecn_kmax: 0.8
islip_iterations: 2
frame_size_bytes: 1406
priority_count: 4
协议常量集中
新建 src/protocol.rs:
/// PAXI RC 协议规范常量(不可配置)
pub const NO_DEP: u32 = u32::MAX;
pub const PSN_BITS: u32 = 12;
pub const PSN_MASK: u16 = (1 << PSN_BITS) - 1;
pub const PSN_HALF: u16 = 1 << (PSN_BITS - 1);
pub const VC_BANK0: u32 = 0;
pub const VC_BANK1: u32 = 1;
pub const VC_BANK2: u32 = 2;
pub const VC_BANK3: u32 = 3;
pub const VC_MUL: u32 = 4;
pub const VC_COUNT: usize = 5;
pub const VC_ORDER: [u32; 5] = [VC_BANK0, VC_BANK1, VC_BANK2, VC_BANK3, VC_MUL];
数据流
芯片 YAML (paxi 段)
→ Python ChipSpecImpl 加载
→ PyO3: input::parse_chip_spec() 解析 → ChipSpec.paxi: PaxiFullConfig
→ MultiChipSim::create_paxis() 用 chip.paxi 构建 PAXIBridge
→ collective::expand() 从 chip.cdma.threads_per_cdma 获取线程数
拓扑 YAML (switches 段)
→ Python TopologySpec 加载
→ PyO3: input::extract_routing_data() 解析 → ExtractedRoutingData.switch_configs (完整参数)
→ MultiChipSim 用完整 SwitchConfig 构建 SwitchModel
变更清单
Rust 端
| 文件 | 改动 |
|---|---|
src/protocol.rs | 新建,集中 L0 协议常量 |
src/lib.rs | 注册 mod protocol |
src/input.rs | ChipSpec 新增 paxi: PaxiFullConfig(必填);parse_chip_spec 解析 paxi 段,缺失即报错;switch 解析补全字段 |
src/tier6/paxi.rs | 删除 impl Default for PAXIConfig,构造函数改为必须传入完整 config |
src/tier6/paxi_core.rs | 删除 impl Default for PaxiCoreConfig |
src/tier6/rc_link_tx.rs | 删除 impl Default for RcLinkTxConfig + impl Default for DcqcnConfig;删除 const PSN_MASK/PSN_HALF/DATAPATH_BYTES/VC_*/VC_WEIGHTS,改用 protocol::* + config 字段 |
src/tier6/rc_link_rx.rs | 删除 impl Default for RcLinkRxConfig;删除 const PSN_MASK/CNP_INTERVAL_NS,改用 protocol::* + config 字段 |
src/tier6/switch.rs | 删除 impl Default for SwitchConfig;switch_configs 解析接收全部字段 |
src/tier6/c2c_link.rs | 删除 impl Default for C2CLinkConfig |
src/collective/allreduce.rs | 删除 NO_DEP + DEFAULT_THREADS_PER_CDMA,改用 protocol::NO_DEP + 参数传入 |
src/collective/allgather.rs | 同上 |
src/collective/reducescatter.rs | 同上 |
src/collective/alltoall.rs | 同上 |
src/collective/expand.rs | expand_collectives 签名新增 threads_per_cdma: u32 参数 |
src/top/multi_chip.rs | create_paxis 用 chip.paxi 构建;init_components 传递 threads_per_cdma |
YAML 配置
| 文件 | 改动 |
|---|---|
configs/chips/SG2262.yaml | 新增 paxi 段(30 个字段) |
configs/chips/_template.yaml | 新增 paxi 段定义 + 每个字段的详细注释说明 |
configs/topologies/_template.yaml | switches 段补全 8 个字段说明 |
configs/topologies/clos-2tier-4chip.yaml | switches 各项补全参数 |
前端
| 文件 | 改动 |
|---|---|
frontend/src/types/math_model.ts | ChipPreset 接口新增 paxi?: PaxiConfig 类型定义 |
注: 前端 ChipPresetEditor.tsx 是递归渲染所有字段,新增 YAML 段后自动展示,无需改渲染逻辑。
后端 Python
| 文件 | 改动 |
|---|---|
services/schemas.py | validate_chip_config 中 CHIP_REQUIRED_PATHS 新增 paxi 段必填字段校验 |
兼容性
paxi段在芯片 YAML 中为必填。缺失时 Rust 侧parse_chip_spec()直接报错,拒绝启动仿真。所有芯片 YAML 必须包含完整paxi段。- Switch 补全字段也是必填的。拓扑中有
switches段时,每个 switch 必须包含全部字段,缺失即报错。 - 无
switches段的拓扑(全连接无 switch)不受影响。
测试验证
cargo check --tests编译通过- 现有 Rust 单元测试全部通过(测试中构造 Config 改为显式写全字段)
- SG2262.yaml 加载验证:Python 端加载新 YAML 无报错
- 前端 ChipPresetEditor 能正确显示和编辑 paxi 段字段