Skip to content

Update: 去除 HBG replay 重复的全包 FNV checksum 扫描 - #2494

Open
nalinaly wants to merge 1 commit into
hw-native-sys:feat/kernel-mode-integration-testfrom
nalinaly:feat/hbg-replay-checksum-20260930
Open

nalinaly wants to merge 1 commit into
hw-native-sys:feat/kernel-mode-integration-testfrom
nalinaly:feat/hbg-replay-checksum-20260930

Conversation

@nalinaly

Copy link
Copy Markdown
Contributor

问题与修改

HBG 的 graph packet 已在 Host 构建和提交时完成完整校验,但 AICPU 每次 replay 仍逐字节计算整个 packet 的 FNV checksum,开销随 graph image 大小增长。

本 PR 将两类检查分开:

  • 新增 validate_graph_packet_framing,保留 version / reserved、长度、溢出、对齐、region 顺序、目标范围与容量等结构检查。
  • validate_graph_packet 继续在 framing 后执行完整 checksum;Host 构建和提交仍调用完整校验。
  • AICPU replay 对 CANN 持有的不可变副本只做 framing,随后仍执行 trusted callable / device / generation / binary / 地址容量检查和 image 语义校验。注册表自身的 checksum 保留。
  • 更新 CPU 用例和两份 HBG 契约文档。

契约变化:设备 replay 不再承诺通过 checksum 检出任意 payload bit flip,依赖 Host 完整验证和 CANN 对不可变副本的复制及生命周期保证。 这不是取消全部 packet 校验。copy、heap zero、flush、callable bind、调度和算术保持原样。

性能结果

A3、CANN 9.2.0-beta.2,单卡 TP1、128K/B4、出 5 验 6、NZ2、atomic_add=0、确定性 level 1。正式权重下第 2 层 CSA 输出直接接第 3 层 HCA 输入,使用实际服务 custom-op 入口并确认没有 Native fallback。同一个手动 NPUGraph 重放 CSA→HCA;固定 metadata 和合成历史,每次在计时外恢复同一 cache/state 初态。

编译和 warmup 后,关闭 profiler/DFX,采 10 次 NPU Event,单位 μs:

配置 min mean max
保留 replay checksum 222261.15 224361.40 225649.26
去除 replay checksum 205985.11 207478.31 209156.75

联合重放 mean 减少 16883.09 μs(7.52%)。A/B 均包含PR #2493 中的 HBG 采集修复,唯一实验变量是本 PR 的 replay checksum;该采集修复不是本补丁的代码依赖。

另采 3 个 profiling step,采集 PyTorch/CANN trace 与对应泳道。去除 checksum 后,CSA / HCA 完整 AICPU span 均值分别约 139044.68 / 69611.91 μs;核内任务首尾区间分别约 540.18 / 339.08 μs。主要差距仍在核内任务之外,尚未量化 copy / zero / flush / bind 各自占比,不能将它们归因为 checksum,也不能将此结果外推为整模型或 Native/TMR 对比收益。

正确性与验证范围

  • graph packet / slot / restore CPU 测试 56 项通过。完整 validator 继续检测首/中/末字节损坏;新增 replay 不重复 hash 的用例;非法 reserved 字段仍触发恢复拒绝且不能暴露旧成功结果。
  • A2/A3 onboard 运行时构建通过,A3 联合 replay / profiling 正常结束。
  • A/B 各自 graph / eager,以及优化后对优化前的 12 项输出、Top-K、cache/state 零容差比较全部通过,浮点 max_abs=0、整数 mismatches=0,保护区检查通过。
  • 未做 A5 真机、整模型 token / DSpark、16 卡验证。本次 HCA history 不跨 C128 压缩边界,不将其计作跨边界写入验证。

本 PR 只包含 checksum 优化一个提交,以 feat/kernel-mode-integration-test 为基线;不包含采集修复、PTO-ISA pin 更新或其他调度修改。

提交前检查:改动 C++ 文件通过 clang-format 21.1.0;headers、English-only、retired names、kernel wire isolation 及 git diff --check 通过。

将 graph packet 的格式检查与全包 FNV 完整性检查拆开。Host 构建和
提交模板时仍执行完整检查;AICPU 对 CANN 持有的不可变副本只执行
framing 检查,再保留原有的 callable、设备、版本、generation、目标
地址/容量及镜像语义检查,不再在每次 replay 上逐字节扫描整个 payload。

明确收窄契约:设备 replay 不再承诺通过 checksum 检出任意 payload
bit flip,依赖 Host 验证及 CANN 的复制、生命周期保证。注册表自身的
校验没有移除,copy/zero/flush/bind 路径也保持不变,便于独立衡量收益。

测试保留 full validator 的首/中/末字节损坏检测,新增 replay 不重复
hash 的验证;旧的退休后拒绝测试改用无效 reserved 字段,继续验证拒绝
发生前不写目标、不能暴露上次成功结果。同步两份 HBG 契约文档。

验证:a2a3 的 graph packet/slot/restore 共 56 项 CPU 测试通过。
A3、CANN 9.2 的 128K/B4 单卡 CSA→HCA,在 warmup 后关闭采集,
各测 10 次 NPU Event:均值 224361.40→207478.31 us,减少 7.52%。
前后版本均包含 HBG 采集修复,另外各采三步 PyTorch 与对应泳道;
12 项输出、Top-K、cache/state 的 graph/eager 及前后版本零容差
比较均通过,保护区正常。该结果不是整模型或 Native/TMR 对比收益;
A5 真机、整模型 token/DSpark 和 16 卡不在本次验证范围。

Signed-off-by: nalinaly <nalinaly@163.com>
@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: e5ad98d9-7454-4bc2-ad66-463b00c6b283

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant