跳到主要内容

G5 仿真参数分层管理设计

日期: 2026-04-13 范围: perfmodel/evaluation/g5/ (Rust) + 芯片/拓扑 YAML + 前端类型

背景

G5 仿真引擎共 56 个参数,当前散布在 7 个 Rust 文件中:17 个 const(含 9 处重复定义)、37 个 Config 结构体字段(通过 impl Default 硬编码)、2 个 MultiChipSim 实例字段。

问题

  1. NO_DEP 定义 4 次,PSN_MASK 定义 2 次,DEFAULT_THREADS_PER_CDMA 定义 4 次
  2. 芯片微架构参数(DATAPATH_BYTESthreads_per_cdma)硬编码为 const,换芯片需改代码
  3. 7 个 impl Default 块中的值无法从配置文件覆盖
  4. 缺乏参数分类,协议常量和可配置参数混在一起

设计原则

按"谁决定这个值"分层,不同层用不同机制管理。

参数分类

L0 — 协议常量(编译期固定,Rust const)

PAXI RC 协议规范中的固定定义,永远不变,不可配置。

参数含义
NO_DEPu32::MAX无依赖哨兵值
PSN_BITS12PSN 位宽
PSN_MASK0xFFF12-bit PSN 掩码(从 PSN_BITS 推导)
PSN_HALF0x800PSN 空间中点(从 PSN_BITS 推导)
VC_BANK0~30~3虚拟通道编号
VC_MUL4组播虚拟通道编号
VC_COUNT5虚拟通道总数
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_countforwarding_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.yamld2d 段之后新增:

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.yamlswitches 段扩展:

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.rsChipSpec 新增 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.rsexpand_collectives 签名新增 threads_per_cdma: u32 参数
src/top/multi_chip.rscreate_paxischip.paxi 构建;init_components 传递 threads_per_cdma

YAML 配置

文件改动
configs/chips/SG2262.yaml新增 paxi 段(30 个字段)
configs/chips/_template.yaml新增 paxi 段定义 + 每个字段的详细注释说明
configs/topologies/_template.yamlswitches 段补全 8 个字段说明
configs/topologies/clos-2tier-4chip.yamlswitches 各项补全参数

前端

文件改动
frontend/src/types/math_model.tsChipPreset 接口新增 paxi?: PaxiConfig 类型定义

注: 前端 ChipPresetEditor.tsx 是递归渲染所有字段,新增 YAML 段后自动展示,无需改渲染逻辑。

后端 Python

文件改动
services/schemas.pyvalidate_chip_config 中 CHIP_REQUIRED_PATHS 新增 paxi 段必填字段校验

兼容性

  • paxi 段在芯片 YAML 中为必填。缺失时 Rust 侧 parse_chip_spec() 直接报错,拒绝启动仿真。所有芯片 YAML 必须包含完整 paxi 段。
  • Switch 补全字段也是必填的。拓扑中有 switches 段时,每个 switch 必须包含全部字段,缺失即报错。
  • switches 段的拓扑(全连接无 switch)不受影响。

测试验证

  1. cargo check --tests 编译通过
  2. 现有 Rust 单元测试全部通过(测试中构造 Config 改为显式写全字段)
  3. SG2262.yaml 加载验证:Python 端加载新 YAML 无报错
  4. 前端 ChipPresetEditor 能正确显示和编辑 paxi 段字段