SC-卸载配置生成器
二进制:
extracted/libtpu-0.0.40-cp314-cp314-manylinux_2_31_x86_64/libtpu/libtpu.so(构建 ID89edbbe81c5b328a958fe628a9f2207d,构建libtpu_lts_20260413_b_RC00;.textVMA == 文件偏移0xe63c000)。 状态: 重新实现级 · 证据等级: 已确认(字节锚定) - 模板化构建器签名、主体管道、每颜色发射 lambda 和三个*OffloadConfig结构族与 IDA 反编译进行了交叉检查;下面标记为 [LOW] 的两个剩余子布局 · 第 XIII 部分 — On-Pod Collectives & Barriers / SparseCore-offload Collectives · 返回索引
摘要
当 SparseCore 卸载基底门保持时(请参阅 On-Pod 集体 — 剖面图 §5),嵌入类集合 不会 降低到 HLO ReplicaGroup 设备列表。相反,模板化构建器构建一个 CollectiveIciStrategyConfig 原型 - 物理 X/Y/Z 环上的单向 (UNIDIR) 环的按颜色集 - 并将其嵌入到三个字节相同的后端配置消息之一中:AllGatherOffloadConfig、AllReduceOffloadConfig 或 ReduceScatterOffloadConfig。本页记录了构建器算法和承载其输出的 OffloadConfig 结构体系列。
构建器是 xla::tpu::sparse_core::collective::(anonymous)::ConstructConfigForCollectiveUniDirNDGroups<OffloadConfig, HloXxx>,实例化 3 次(每个操作系列一次)。它是密集 TensorCore StrategyND::BuildStrategy 的 **SparseCore 模拟:相同的芯片环面范围、相同的 K/2K 扭曲几何形状,但发出每个颜色环的原型,而不是 HLO 副本组列表。平面与分层相分离由 HierarchicalKind 参数控制,记录在其自己的页面上; SparseCore 核心选择和卸载门在其他地方有记录。该页面拥有三件事:
ConstructConfigForCollectiveUniDirNDGroups<*>构建器算法(主体管道 + 修复HierarchicalKind的三个公共 ND 包装器),- 三个
*OffloadConfig结构布局(sizeof 0x48,字节相同)以及它们携带的CollectiveIciStrategyConfig原型嵌套, - 每颜色环结构 —
GetDimensionRings每轴属性如何提供每颜色PerColorIciStrategyConfig/IciStrategyRingConfig发射。
二进制文件中观察到的构建器合约:
- 构建器是单个模板化函数
@0x133c82c0(AllGather) /@0x133c2dc0(AllReduce) /@0x133cd800(ReduceScatter),来源offload_collective_config.cc。这三者都具有完全相同的损坏签名;仅原型类型和 Hlo 指令类型不同。 - 输出是
CollectiveConfigInfo<OffloadConfig>— 填充的*OffloadConfig原型及其策略维度元数据 — 由sret作为absl::StatusOr<...>返回。 - 每轴环组由
GetDimensionRings生产,它读取相同的芯片环面范围([chip_cfg+0x58]=X、+0x5c=Y、+0x60=Z)作为密集拾取器和成本模型 - 因此 SparseCoreIciStrategyRingDim环形调光索引与密集StrategyND环形调光相同的硬件几何形状。 - AllGather和ReduceScatter固定平(它们的包装器硬连线
HierarchicalKind == 0x100); 只有 AllReduce 可以采用分层多阶段路径,并且仅当编译标志为engage+true并且调用者的可选重写不会强制扁平时。
概览
| 方面 | 值(字节锚定) |
|---|---|
| 模板化构建器 | ConstructConfigForCollectiveUniDirNDGroups<OffloadConfig, HloXxx> |
| 实例化 | 全部聚集 @0x133c82c0、全部减少 @0x133c2dc0、减少分散 @0x133cd800 |
| 源TU | offload_collective_config.cc(字符串@0x133c82c0体,线1616) |
| 返回 | absl::StatusOr<CollectiveConfigInfo<OffloadConfig>> (sret) |
| 公共 ND 包装器 | …AllGatherUniDirND @0x133c76c0、…AllReduceUniDirND @0x133c2c80、…ReduceScatterUniDirND @0x133ccbe0 |
| 每轴环形源 | GetDimensionRings @0x133df520(X/Y/Z范围+0x58/+0x5c/+0x60 + LDPC megacore) |
| 扭桥 | TryCreateTwistedTorusTopologyInfo @0x133e1980(由 cmp $3 网格暗淡计数选通) |
| 每个颜色附加器 | 拉姆达 @0x133e0a80 (AG) / 0x133ddae0 (AR) / 0x133e0c00 (RS) |
| OffloadConfig 结构 | AllGather/AllReduce/ReduceScatter OffloadConfig — 字节相同,sizeof 0x48 |
| 携带原型巢 | CollectiveIciStrategyConfig → PerColorIciStrategyConfig[] → IciStrategyRingConfig[] |
1. 模板化构建器条目 + ABI
构建器是一个具有三个实例化的模板化函数。安腾损坏的签名(从反编译的符号)解码为:
// xla::tpu::sparse_core::collective::(anonymous namespace)::
template <class OffloadConfig, class HloXxx>
absl::StatusOr<CollectiveConfigInfo<OffloadConfig>>
ConstructConfigForCollectiveUniDirNDGroups(
const jellyfish::Target& target, // [+0] chip-config carrier
const DeviceAssignment& device_assign, // replica → device map
const HloXxx* hlo, // AllGather/AllReduce/ReduceScatter inst
bool arg0, // leading bool (see §1.1)
bool arg1, //
jellyfish::HierarchicalKind hier, // flat-vs-hierarchical discriminant
std::optional<bool> opt0,
std::optional<bool> opt1,
std::optional<int> tensor_split); // tensor_split_factor override
```text
这三个实例仅在 `OffloadConfig`/`HloXxx` 中有所不同:
| 实例化 | VA | `OffloadConfig` | `HloXxx` |
|---------------|----|-----------------|----------|
| AllGather | `0x133c82c0` | `AllGatherOffloadConfig` | `HloAllGatherInstruction` |
| AllReduce | `0x133c2dc0` | `AllReduceOffloadConfig` | `HloAllReduceInstruction` |
| ReduceScatter | `0x133cd800` | `ReduceScatterOffloadConfig` | `HloReduceScatterInstruction` |
> 从 AllGather 实例化中读取的损坏符号是 `…StatusOrINS2_20CollectiveConfigInfoIT_EEEERKNS5_6TargetERKNS_16DeviceAssignmentEPKT0_bbNS3_16HierarchicalKindENSt3__u8optionalIbEESQ_NSP_IiEE` — 即 `(Target const&, DeviceAssignment const&, T0 const*, bool, bool, HierarchicalKind, optional<bool>, optional<bool>, optional<int>) → StatusOr<CollectiveConfigInfo<T>>`。 `bbNS3_16HierarchicalKind…` 片段确认了两个 `bool`,然后是 `HierarchicalKind`,然后是三个 `optional`。所有三个实例都携带相同的片段,仅交换了消息/Hlo 类型。
### 1.1 三个公共ND包装器——谁设置了`HierarchicalKind`
选项生成不直接调用模板化构建器;三个公共包装器执行此操作,每个包装器都为其操作系列修复 `HierarchicalKind`:
| 包装 | VA | `HierarchicalKind` 通过 | 相行为 |
|---------|----|--------------------------|-----------------|
| `ConstructConfigForAllGatherUniDirND` | `0x133c76c0` | 硬连线 `0x100` | 始终平坦(单相) |
| `ConstructConfigForReduceScatterUniDirND` | `0x133ccbe0` | 硬连线 `0x100` | 始终平坦(单相) |
| `ConstructConfigForAllReduceUniDirND` | `0x133c2c80` | 呼叫者 `optional<bool>` | 平面 *或* 分层 |
AllGather 和ReduceScatter 包装器传递接合但错误的判别式`0x100`,构建器将其读取为“显式平坦”。 AllReduce 包装器是唯一能够达到分层多阶段路径的包装器。其前导 `bool` 参数计算为
```text
arg0 = (!ShouldEnableSparseCoreHierarchicalAllReduce(target_comp_env)) @0x133c2c80
&& ((~caller_optional_hier) & 0x101 != 0)即“使用平坦路径” - true 除非编译标志为engage+true 并且调用者的可选覆盖不会强制平坦。
在 AllReduce 包装器反编译 (
…AllReduceUniDirND…_0x133c2c80.c) 中,ShouldEnableSparseCoreHierarchicalAllReduce出现在第 18/35 行,并与第 41 行的0x101掩码组合 — 与上面的反转匹配。 AG/RS(0x100)的扁针为engenged+false判别式;完整的枚举解码位于 分层种类。
2.构建器主体管道
在 AllGather 实例化 @0x133c82c0 上追踪(AllReduce/ReduceScatter 主体在结构上相同,仅原型类型和(对于 AllReduce)可到达的分层分支不同)。行号位于该函数的反编译 C 中。
ConstructConfigForCollectiveUniDirNDGroups<AllGatherOffloadConfig, HloAllGatherInstruction>:
[a] CheckInputOutputNumberOfElementIsBelowLimit(hlo) @line 529 (0x133dcc00)
└─ size gate; on failure return an error Status
[b] construct empty AllGatherOffloadConfig proto (ctor @0x1d6ee220; sizeof 0x48)
[c] GetPhysicalDeviceGroups(hlo, device_assign, megacore) @line 552 (0x133b6b80)
└─ the replica device groups, with a megacore-aware byte read from the Hlo
[d] ExtractNDPlaneInfo(target, device_assign, hlo, …) @line 571 (0x133bb940)
└─ NDPlaneInfo: per-axis ring-dim / extent descriptor
└─ RetCheck "IsNDPlaneSpanAcrossEntireDimension" @line 595
(the ND-plane must span the entire torus dimension, else bail)
[e] read chip torus extents from (target +0x3b8): @lines 567-569
v613 = *(int*)(v17 + 88); // 0x58 = X extent
v615 = *(int*)(v17 + 92); // 0x5c = Y extent
addr = *(int*)(v17 + 96); // 0x60 = Z extent
[f] per plane-dim: push tuple<IciStrategyRingDim, long, long> onto a deque
└─ ring-dim slot = 2 - (NDPlaneInfo[+0xa0] & 1) (mesh-vs-torus / megacore parity)
└─ tuple stride 0x18 : {ringDim @+0, lo @+8, hi @+0x10}
[g] HierarchicalKind dispatch (mask & 0x101, see §3):
(HierarchicalKind & 0x101) == 0x100 → FLAT : one GetDimensionRings per axis
inserted directly into the flat_map
else → HIER : walk the deque, each queued ring
dim processed as a phase
[h] GetDimensionRings(target, ringDim, devcount, …, megacore_aware) @line 3104 (0x133df520)
└─ per-axis ring partitioner → RingConfigAttributes (0x18-byte POD)
[i] accumulate into flat_map<IciStrategyRingDim, RingConfigAttributes> (operator[] @0x133ddc60)
[j] TWIST gate: count how many of the 3 mesh dims == K (one operand) or == 2K (other)
└─ if all 3 (cmp $3) → TryCreateTwistedTorusTopologyInfo(min,max,K,2K) @line 936 (0x133e1980)
VLOG "Skipping twisted torus strategy because its strided."
[k] per-color emission: lambda(long) @0x133e0a80
└─ index/create the color's PerColorIciStrategyConfig and Add() an IciStrategyRingConfig
└─ CopyRuntimeConfigToProtoLiteral<AllGatherOffloadConfig> @lines 2641/3366 (0x133dd260)
[l] return CollectiveConfigInfo<AllGatherOffloadConfig>(config, strategy_dimension)
```text
> 管道中的每个被调用者都位于 `…AllGatherIn_dfa0bc1bcac2597e_0x133c82c0.c` 中引用的行:`CheckInputOutputNumberOfElementIsBelowLimit` (529)、`GetPhysicalDeviceGroups` (552)、`ExtractNDPlaneInfo` (571)、`IsNDPlaneSpanAcrossEntireDimension` (595)、 `TryCreateTwistedTorusTopologyInfo` (936)、`GetDimensionRings` (3104)、`CopyRuntimeConfigToProtoLiteral` (2641、3366) 以及 `v17 + 88/92/96` (567-569) 的芯片范围。第 3206 行的 `MakeErrorStream` 调用引用源 `offload_collective_config.cc:1616`,固定 TU 名称。
### 2.1 `GetDimensionRings` — 每轴环形分区器
`GetDimensionRings @0x133df520` 是每轴工作器,可将一个 `IciStrategyRingDim` 加上设备计数转换为 `RingConfigAttributes` POD。 (它是它自己的外联函数 - `xla::tpu::sparse_core::collective::(anonymous namespace)::GetDimensionRings(Target const&, IciStrategyRingDim, int, bool, bool)` - `call`,来自 `@line 3104` 站点的构建器主体,而不是内联。)
```text
RingConfigAttributes GetDimensionRings(
const Target& target,
IciStrategyRingDim ring_dim, // 1..7
int devcount,
bool /*r8*/,
bool megacore_aware): // r9
1. validate ring_dim ∈ [1..7] (jump table)
RetCheck "dim_x || dim_y || dim_z" (offload_collective_config.cc:417)
2. select chip torus extent by ring_dim:
X → [chip_cfg +0x58] Y → [+0x5c] Z → [+0x60]
(set the mesh-vs-torus flag per switch arm)
3. LDPC = LogicalDevicesPerChip(target) (0x1d615b00)
megacore = megacore_aware && (LDPC >= 2) (setge)
4. divide extent by devcount → ring length / segment counts
5. emit RingConfigAttributes {flag, lo, hi} (0x18-byte POD)X/Y/Z 芯片范围偏移 +0x58/+0x5c/+0x60 与密集拾取器、成本模型和扭曲几何读取的相同偏移 — 这是 概述 §1.3 中指出的共享几何不变量。
RingConfigAttributes 值是一个 24 字节 (0x18) POD,逐字复制到 flat_map 中,然后复制到按颜色环中。它的三个字段 {flag/int, lo, hi} 可以追溯到双端元组对应({ringDim, lo, hi}),但不单独命名为环长度/段计数/邻居步幅语义 - 参见第 6 节中的 [LOW]。
3. HierarchicalKind 调度(扁平与多阶段)
构建器在 HierarchicalKind 上调度,这是一个 xla::jellyfish::AutoOr<bool> 打包的 16 位值(位 0 = 包含的布尔值,位 8 = “参与”位,掩码 0x101 = 每个消费者应用的判别式)。完整的枚举解码位于 分层种类;这里只是 builder 如何使用它。
v75 = (HierarchicalKind value) & 0x101; @line 3032 (the mask)
FLAT path when (HierarchicalKind & 0x101) == 0x100 → one GetDimensionRings call per axis,
inserted directly into the flat_map
HIER path otherwise → the queued-deque multi-phase walk
guard: if ((~hier_word & 0x101) == 0) { … } @lines 3204, 3262
└─ MakeErrorStream("offload_collective_config.cc", 1616, …) @line 3206
```text
当值位和参与位都被设置时,`(~hier_word & 0x101) == 0` 测试准确地为真——即“分层”判别式 `0x101`。该分支到达多阶段双端队列遍历和关联的验证错误路径。平坦路径 (`== 0x100`) 是 AllGather/ReduceScatter 硬连线,因此在此构建中只有 AllReduce 评估分层分支。
> 第 3032 行的 `& 0x101` 掩码和第 3204/3262 行的 `(~v & 0x101) == 0` 判别式在 AllGather 构建器反编译中以字节精确的方式存在; `0x100` 平坦比较站点 (`(_DWORD)v615 == 256`) 位于第 3102 行和第 3525 行。该机制(每轴平坦单环与排队多相行走)已得到确认;分层 AllReduce 发射的*内容*(`IciStrategyRingType`/邻居中芯片内和芯片间相位环如何不同)未完全扩展 - 参见 [LOW] §6。
---
## 4. 三个`*OffloadConfig`结构布局
这三个后端配置消息 — `AllGatherOffloadConfig`、`AllReduceOffloadConfig`、`ReduceScatterOffloadConfig` — 在内存布局(从同一字段集生成原始)`sizeof = 0x48`(72 字节)中**字节相同**。只有 vtable / typeinfo 指针不同。
| 偏移 | 字段 | 原型字段(#,类型) |
|--------|-------|-----------------------|
| `+0x00` | vptr | AG vtbl `0x21ce1ce0` / AR `0x21ce1ca0` / RS `0x21ce1c60` (`+0x10`) |
| `+0x08` | `InternalMetadata`(Arena ptr \| 标记位) | —(proto2 内部) |
| `+0x10` | `hasbits` (int32) | bit0=`physical_core_indices`,bit1=`ici_strategy_config`,bit2=`constant_propagation_config`,bit3=`use_single_sparse_core`,bit5=`use_n_dimension_strategy` |
| `+0x18` | `RepeatedField<int32>` 标志 \|竞技场标签 | `physical_core_indices` 堆位(低位) |
| `+0x1c` | int32 `current_size` | `physical_core_indices` 元素计数 |
| `+0x20` | `Rep*`(`int32[]` 在 `Rep+0x8`) | `physical_core_indices` 数据 |
| `+0x28` | int32 序列化大小缓存 | (`physical_core_indices`缓存字节长度) |
| `+0x30` | `message*` `ici_strategy_config` | 2、`CollectiveIciStrategyConfig` |
| `+0x38` | `message*` `constant_propagation_config` | 3、`CollectiveOffloadConstantPropagationConfig` |
| `+0x40` | `bool` `use_single_sparse_core` | 1,可选布尔值 |
| `+0x44` | int32 标量 | `tensor_split_factor` / `use_n_dimension_strategy`(低字节区域) |
重复的 `physical_core_indices` 是 `+0x18..+0x20` 处的标准 proto2 `RepeatedField<int32>`(堆位 `+0x18`、`current_size` `+0x1c`、`Rep*` `+0x20` 与 `int32[]` 位于 `Rep+0x8`);作者/读者(`AddCollectivePhysicalCoreIndicesHelper` / `GetPhysicalCoreIndices`)和 `_InternalSerialize` 见证人都同意这些偏移量 - 请参阅 **[物理核心放置](physical-core-placement.md)** §1。 `bool` 标量 `use_single_sparse_core`(字段 1)和 `use_n_dimension_strategy`(字段 6)位于 `+0x40` / 低字节区域;构建器从 `optional<int>` 参数中读取 `tensor_split_factor` 并填充 `physical_core_indices`。
原始字段模式(从 `.rodata` 中的序列化 `FileDescriptorProto` 读取):
```protobuf
// byte-identical for AllGather / AllReduce / ReduceScatter OffloadConfig
message {AllGather|AllReduce|ReduceScatter}OffloadConfig {
bool use_single_sparse_core = 1;
CollectiveIciStrategyConfig ici_strategy_config = 2;
CollectiveOffloadConstantPropagationConfig constant_propagation_config = 3;
repeated int32 physical_core_indices = 4;
int32 tensor_split_factor = 5;
bool use_n_dimension_strategy = 6;
}三个向量
@0x1d6ee220(AG) /0x1d6ed860(AR) /0x1d6eebe0(RS) 以及匹配的Clear/ByteSizeLong三元组,将相同的0x48字节范围归零;三个原型符号 (AllGather/AllReduce/ReduceScatterOffloadConfig) 存在于整个构建器反编译过程以及CopyRuntimeConfigToProtoLiteral<…>和CollectiveConfigInfo<…>实例化中。 vtable/typeinfo 基数和字段偏移量是字节锚定的。
4.1 外包装和成本模型探针
这三个 *OffloadConfig 消息并不独立 — 每个消息都是 CollectiveOffloadConfig oneof (GetIciStrategyAndConstantConfig @0x133d2c20) over {all_reduce | all_gather | reduce_scatter | ragged_all_to_all | all_to_all}_offload_config(字段 1)的一个臂。这是 SparseCore 卸载 成本 路径探测的消息:GetCollectiveOffloadConfig @0x133e1740 准确读取此构建器发出的 CollectiveIciStrategyConfig,并对 SparseCore 环操作点而不是密集 TensorCore 操作点进行充电(请参阅 概述 §1.2 和成本页面)。
5. 每色环结构(原型巢)
构建器的输出环累积到 OffloadConfig 的 ici_strategy_config 子树中。该巢是 SparseCore 对应于密集的 StrategyND 每色环时间表:
{AllGather|AllReduce|ReduceScatter}OffloadConfig (sizeof 0x48)
└─ ici_strategy_config : CollectiveIciStrategyConfig (field 2)
└─ color_strategies[] : PerColorIciStrategyConfig ([+0x18 repeated, +0x20 size])
└─ phase_rings[] : IciStrategyRingConfig ([+0x18 repeated, +0x20 size])
```text
```protobuf
message CollectiveIciStrategyConfig {
repeated PerColorIciStrategyConfig color_strategies = 1;
}
message PerColorIciStrategyConfig {
repeated IciStrategyRingConfig phase_rings = 1;
}
message IciStrategyRingConfig { // 13 scalars; hasbits @[+0x10] = 0x1 .. 0x1000
IciStrategyRingType ring_type;
IciStrategyRingNeighbor ring_neighbor;
int32 core_count;
IciStrategyRingDim ring_dim;
int32 ring_neighbor_table_offset;
int32 barrier_id;
bool across_cores_on_chip;
bool has_reordering_map;
IciStrategyRingDim explicit_strategy_ring_dim;
int32 core_count_adjustment;
bool partner_transfers_outside_the_ring;
int32 id_info_offset;
int32 group_info_table_offset;
}5.1 每颜色附加器 lambda
每个颜色的发射是一个 lambda — @0x133e0a80 表示 AllGather,0x133ddae0 表示 AllReduce,0x133e0c00 表示 ReduceScatter。它采用颜色索引(long),索引或创建该颜色的 PerColorIciStrategyConfig,并且 Add() 是一个新的 IciStrategyRingConfig,其字段从累积的 RingConfigAttributes 中复制:
lambda(long color):
1. RepeatedPtrFieldBase::Add → PerColorIciStrategyConfig[color] (proto2 repeated)
2. RepeatedPtrFieldBase::Add → IciStrategyRingConfig (a new phase ring)
3. fill ring_type / ring_dim / core_count / … from RingConfigAttributes
```text
> 在 AllGather 每颜色 lambda (`…_adac2b005e1e2b0d_0x133e0a80.c`) 中,主体按顺序显示 `RepeatedPtrFieldBase` → `PerColorIciStrategyConfig`(第 38 行),然后是 `RepeatedPtrFieldBase` → `IciStrategyRingConfig`(第 67 行),索引为`color`(第 78 行)— 与上面的索引颜色/添加环序列完全相同。 13 标量 `IciStrategyRingConfig` 字段 *set* 和 has-bit 计数是字节精确的;消息中每个标量的每字段字节偏移量并未单独固定 — 请参阅 [LOW] §6。
### 5.2 环枚举
每个颜色环参考的三个枚举是从 `.rodata` 中的原始 `NameOfDenseEnum` 表中读取的:
| `IciStrategyRingDim` | 值 | | `IciStrategyRingType` | | `IciStrategyRingNeighbor` |
|----------------------|-----|-|-----------------------|-|---------------------------|
| `ICI_RING_DIM_INVALID` | 0 | | `ICI_RING_TYPE_INVALID_RING_TYPE` | | `ICI_RING_NEIGHBOR_INVALID` |
| `ICI_RING_DIM_X_TORUS` | 1 | | `ICI_RING_TYPE_BIDIR` | | `ICI_RING_NEIGHBOR_EXPLICIT` |
| `ICI_RING_DIM_X_MESH` | 2 | | `ICI_RING_TYPE_UNIDIR_CW` | | `ICI_RING_NEIGHBOR_IMPLICIT` |
| `ICI_RING_DIM_Y_TORUS` | 3 | | `ICI_RING_TYPE_UNIDIR_CCW` | | |
| `ICI_RING_DIM_Y_MESH` | 4 | | `ICI_RING_TYPE_UNIDIR_ALL_TO_ALL_CW` | | |
| `ICI_RING_DIM_Z_TORUS` | 5 | | `ICI_RING_TYPE_UNIDIR_ALL_TO_ALL_CCW` | | |
| `ICI_RING_DIM_Z_MESH` | 6 | | | | |
| `ICI_RING_DIM_D2D` | 7 | | | | |
环形尺寸 1/3/5 是 `*_TORUS` 轴,2/4/6 是 `*_MESH` 轴; torus-vs-mesh 是 `GetDimensionRings` 从芯片范围开始每个轴设置的环绕模式。 `ConstructConfigForCollectiveUniDirNDGroups` 发出 UNIDIR 环型集(`ICI_RING_TYPE_UNIDIR_CW` / `_CCW`),与其名称一致; `ICI_RING_DIM_D2D` 值 (7) 是模具到模具环的尺寸。
---
## 6. SC 卸载构建器与密集 `StrategyND` — 结构并行
构建者故意是密集 `StrategyND::BuildStrategy` (**[SelectND策略](strategy-nd-picker.md)**) 的 SparseCore 镜像。两者在相同的圆环上产生相同的环几何形状,但输出形式不同:
| 方面 | 密集 `StrategyND` (TensorCore) | SC卸载构建器(本页) |
|--------|---------------------------------|--------------------------------|
| 生成器 | `TwistedTorusND::BuildStrategy` / 阶段副本组 | `ConstructConfigForCollectiveUniDirNDGroups<*>` |
| 输出 | HLO `ReplicaGroup` 设备列表 | `CollectiveIciStrategyConfig` 原型(每色 UNIDIR 环) |
| 每调光环形源 | `ComputeColorDimensions` + 环位置表 | `GetDimensionRings`(X/Y/Z 范围 + LDPC)→ `RingConfigAttributes` |
| 枚举 | 隐式 X/Y/Z 环面 | `IciStrategyRingDim` `{X,Y,Z}_{TORUS,MESH}` + `D2D`(8 值) |
| 扭转门 | 网状调光 `2·a == dim` 计数 | 计数 3 个网格变暗 `== K`/`== 2K` (`cmp $3`) → `TryCreateTwistedTorusTopologyInfo` |
| 分相 | 巨核 `LogicalDevicesPerChip` 2m / 2m+1 | `HierarchicalKind` `AutoOr<bool>` bit0/bit8(扁平与多重) |
| 消费者 | XLA集体调度器 | SparseCore 发射器 + `GetCollectiveOffloadConfig`(成本) |
扭曲门是通往 SparseCore 扭曲环路路径的桥梁:当所有三个网格尺寸都与 K/2K 几何形状匹配时,构建器调用 `TryCreateTwistedTorusTopologyInfo @0x133e1980`(AllGather 主体中的 `@0x133c9560`,AllReduce 中的 `@0x133c45db`) - **[扭曲环面](../twist/overview.md)** 下记录的相同扭曲子系统。
---
## 7. 验证说明
> 对照 `libtpu.so` v0.0.40 的 IDA 反编译进行交叉检查:
>
> - **模板化签名** - 所有三个实例化的损坏符号都带有 `…bbNS3_16HierarchicalKindENSt3__u8optionalIbEESQ_NSP_IiEE` = `(…, bool, bool, HierarchicalKind, optional<bool>, optional<bool>, optional<int>) → StatusOr<CollectiveConfigInfo<T>>` - 准确。
> - **主体管道** — `CheckInputOutputNumberOfElementIsBelowLimit`(第 529 行)、`GetPhysicalDeviceGroups` (552)、`ExtractNDPlaneInfo` + `IsNDPlaneSpanAcrossEntireDimension` RetCheck (571/595),芯片范围 `v17 + 88/92/96` = `0x58/0x5c/0x60` (567-569)、`TryCreateTwistedTorusTopologyInfo` (936)、`GetDimensionRings` (3104)、`CopyRuntimeConfigToProtoLiteral` (2641/3366) — 全部按顺序出现。
> - **HierarchicalKind 调度** — `& 0x101` 在第 3032 行; `(~v & 0x101) == 0`,第 3204/3262 行; `0x100` (`== 256`) 公寓位于 3102/3525 — 准确。
> - **AllReduce 包装器** — `ShouldEnableSparseCoreHierarchicalAllReduce`(第 18/35 行)与 `0x101`(第 41 行)相结合; AG/RS 包装器 (`0x133c76c0`/`0x133ccbe0`) 硬线 `0x100` — 准确。
> - **OffloadConfig 结构** — 通过 ctors `0x1d6ee220`/`0x1d6ed860`/`0x1d6eebe0` 的三个字节相同的 `sizeof 0x48` 消息; `_InternalSerialize`见证者(`@0x1d6ee760`,AG)在`+0x18`(堆位)/`+0x1c`(大小)/`+0x20`(`Rep*`)处引脚`physical_core_indices` `RepeatedField<int32>`,具有序列化大小的缓存`+0x28`、`ici_strategy_config` msg ptr `+0x30`、`constant_propagation_config` msg ptr `+0x38`、`use_single_sparse_core` bool `+0x40` 和 `<6>` int32 标量`+0x44`;携带的 `CollectiveIciStrategyConfig` → `PerColorIciStrategyConfig` → `IciStrategyRingConfig` 巢 — 已确认(与 [物理核心放置](physical-core-placement.md) §1 上的 `AddCollectivePhysicalCoreIndicesHelper` 写入器和 `GetPhysicalCoreIndices` 读取器匹配)。
> - **每颜色附加器** — lambda `@0x133e0a80` 添加 `PerColorIciStrategyConfig`(第 38 行),然后添加 `IciStrategyRingConfig`(第 67 行),由 `color`(第 78 行)键入 — 准确。
> - **来源 TU** — `MakeErrorStream` 调用(第 3206 行)引用 `offload_collective_config.cc:1616`,固定翻译单元(原始工作笔记的 `_builder.cc` 后缀被更正为二进制确认的名称)。
>
> **[低]** 两个残差由*结构*确认,但不是由每字段数字解码确认:
>
> - `[+0x18..0x50]` 内 13 个 `IciStrategyRingConfig` 标量中每一个的精确每字段字节偏移:字段 *set* 和 13 个 has 位 (`0x1..0x1000`) 是字节精确的,但哪个字节保存 `ring_type` 与 `core_count` 对比`barrier_id`等没有单独固定。
> - 三个 `RingConfigAttributes` 字段(`{flag/int, lo, hi}`,flat_map 值):证明 `0x18` 字节 POD 逐字复制到每个环中,但这三个字段的语义(环长度 vs 段计数 vs 邻居步长)仅跟踪到双端元组对应关系,而不单独命名。
> - 分层(非 `0x100`)AllReduce 多阶段分支 - AllReduce 构建器 `@0x133c2dc0` 的内部分支,从 AllReduce 反编译行 3142 处的 `(~v & 0x101) == 0` 判别式到达(其 `MakeErrorStream` 引用`offload_collective_config.cc:1616`(第 3144 行):确认了双端队列迭代器和每相附加,但芯片内与芯片间相位环的不同之处(它们的 `IciStrategyRingType` / 邻居)并未扩展 - 只有 AllReduce 到达它,并且在观察到的包装器中默认情况下该标志处于关闭状态。
---
## 交叉引用
### SparseCore 卸载基板
- [On-Pod 集体 — 剖面图](overview.md) — 基板分离和 SC 卸载门 (§5)
- [分层种类](hierarchical-kind.md) — 该构建器调度的 `AutoOr<bool>` 扁平与分层阶段分割
- [SC 核心选择(卸载)](sc-core-selection-offload.md) — `SparseCoreConfig.offload` 运算类型分类和核心选择
### 密集对应
- [SelectND策略](strategy-nd-picker.md) — 该构建器镜像的密集 `StrategyND` 选择器
- [ReduceScatter](reduce-scatter.md) — 密集全归约分解的归约分散阶段
### 同级子系统
- [扭曲环面](../twist/overview.md) — `cmp $3` K/2K 门桥的扭转几何形状
- [屏障](../barrier/overview.md) — `barrier_id` / SFLAG 绑定环配置引用
- [返回索引](../index.md)