CUDA 的护城河正在瓦解:Agent 在 NPU 和 GPU 上的优化能力对比
GPU 过去的优势来自硬件算力和 CUDA 生态。随着 Agent 优化 Infra 的能力提升,CUDA 生态的门槛正在降低。沿用 RSI-Infra Bench 的冻结裁判与长程迭代方式,我们为模型提供 Ascend 910C 工具链和 ascend-opt Skill。目前最强的 Agent(Gemini 4 Neon)已在 910C 上完成多类任务的迁移、修 bug 与手写 Ascend C 算子(全程 BF16/FP32,无降精度):
- 多模态与预训练:LLaVA-1.5-7B 10h 达
6.46×(MFU56.52%,达~91%实测上限;同题 GLM-5.45.99×/51.90%;300 步mix665k4.20×);NanoChat D242.18×(手写 10 个 Ascend C 核,达实测上限92.6%,接近 H200 的93.7%)。 - 非常规与自定义算子:3DGS 30K 步
203.5×(418 万个高斯球,PSNR27.51 dB);Flash-QSA 64K 稀疏算子与 Qwen3.8-Flash-Next 176.7B 推理(bs=8Decode3.41×,4K Prefill52.3×)。 - 多机 RL:64 卡 256K Agentic RL 端到端
2.82×(Rollout3.59×,7.80M tok 逐比特一致)。 - 跨硬件对比与开源:通过 MFU、MBU 和实测上限对比 H200 与 910C 的优化差距,分析轨迹差异并开源全部代码与 13 份 Trace 至 ResearchBoost-Agent (
ascend分支);ResearchBoost Agent 也已集成ascend-optSkill,NPU 用户可直接用于优化模型。
备注(Qwen3.8-Flash-Next 差距归因):Qwen3.8-Flash-Next(176.7B,360 GB 权重)上 910C 与 H200 的 MBU / MFU 差距,主要来自 910C 单卡 64 GB 显存墙迫使模型拆到 TP=8, EP=8(H200 单卡 141 GB 仅需 TP=4, EP=4),带来 96 次 8 卡串行 HCCL 同步、复制权重翻倍与小块切分开销(详见 §2.3 Gap 3)。
1. 模型在 910C 上的优化效果
在 CUDA 上,主流训练与推理框架已有长期适配,优化通常从能正常运行且较快的基线开始。在 Ascend 910C-64G(Ascend910_9382,376 TFLOPS/die BF16 Cube,48 AIV 核,192 KB UB/核,1,600 GB/s HBM,CANN 8.5.1)上,Agent 需要先后完成两类工作:先定位并修复静默回退和框架语义 bug,再做框架调优和手写 Ascend C 算子。
1.1先修 Bug,再优化:6 个任务实测结果
NPU 迁移中常见的数十倍退化或运行失败,多由不报错的静默回退与语义差异引起。
这类问题不抛异常,只表现为算子掉回 AiCPU 或未融合路径。借助 torch_npu.profiler、冻结参考输出和单测 A/B 隔离,Agent 在 6 个任务上自主定位并修复了这些回退和 bug,随后通过框架优化和手写 Ascend C 实现 2.18× 到 203.5× 加速。
| 任务 | 工作负载与硬件 | 修复的主要问题 | 实测加速比 | 真实权重 / 数据验证 |
|---|---|---|---|---|
| LLaVA-1.5-7B | 多模态 Stage-2 SFT 8×910C · 严格 BF16 |
HF 4D mask 静默禁用 NPU FA(慢 25×);FSDP 微批次缺 no_sync |
6.46× (Neon) 5.99× (GLM-5.4) |
同基线 10h 实测(18,769.6 ms):Neon 2,906.7 ms(56.52% MFU,R5)vs GLM-5.4 3,132.6 ms(51.90% MFU,R7),均 N1 PASS;mix665k 300 步 4.20×(Val PPL 2.3017 vs 2.3017) |
| NanoChat D24 | 1.384B (729.8M matmul) 8×910C · 严格 BF16 |
_foreach_copy_ 不增 _version;bf16 Pow 慢 4×;torchair 反向错误 |
2.18× (Neon) 1.76× (GLM-5.4) |
Neon 手写 10 个双缓冲 Ascend C 核,ClimbMix-400B 200 步配对 2.17×,N1 PASS |
| Faster-3DGS | Mip-NeRF 360 garden1×910C · 严格 FP32 |
Sort32 int32/64 回退 AiCPU(慢 139×);cumsum 回退 AiCPU(慢 185×) |
203.5×400² 97.2× |
30,000 步(138.8K → 4.18M 个高斯球)1h 43m,PSNR 27.512 dB(高于原论文 27.41 dB) |
| Flash-QSA & Qwen3.8-Flash-Next |
176.7B 真权重 MoE+GDN+QSA 8×910C TP=8, EP=8 |
bool.scatter_ 回退 AiCPU(慢 1,933×);64K 稠密 mask 超时;CANN 原生稀疏算子不支持 QSA 形状配置 |
3.41× (bs=8)52.3× (4K Pre) |
11 个手写 Ascend C 核;B=1 8K 96.4 tok/s / 64K 94.4 tok/s;bs=8 Decode 56.34 → 16.54 ms(483.8 tok/s),136/136 逐 token 一致 + 64K 捞针 |
| 256K Agentic RL | Qwen3.8-27B TIS+GRPO 64×910C · Docker 沙箱 |
共置 NPUGraph 卸载泄漏 +18.7 GiB/cycle;GDN 8×8 幂零精度误差;fla 48.1% 反向重算 |
2.82× (256K) Rollout 3.59× |
64 卡 7.80M tok 256K RL:0 MB 显存漂移,actor_train_vs_infer = 0.0 逐比特一致 |
Migration & Bug Fixes
Agent 在 910C(CANN 8.5.1)上定位并修复的典型问题
静默 AiCPU 回退最高造成 1,933× 退化·框架语义 bug 与 NPUGraph 卸载泄漏全部定位修复
展开细节收起
- 静默 AiCPU 回退:QSA Indexer 中
bool.scatter_回退 AiCPU 耗时 2,513.7 ms/层(改float32.scatter_降至 1.30 ms,1,933×);3DGS 中torch.sort(int32/int64)耗时 172–196 ms(改 FP32 硬件Sort32为 1.24 ms,139×);at::cumsum(int32)耗时 9.25 ms(改 48 核 Ascend C 前缀和为 0.05 ms,185×)。 - 框架语义 Bug:
torch._foreach_copy_在 NPU 上不递增Tensor._version,导致权重 cast 缓存第 4 步发散;torchair全图编译在 RoPE 反向产生maxdiff = 416;共置 RL 卸载NPUGraph每轮泄漏 18.7 GiB(用untyped_storage().resize_(0)清零至 0 MB 漂移)。 - CANN 8.5.1 实测环境:免升级宿主机驱动(
25.2.t5),经/proc/self/maps校验零回退。BF164096³Cube GEMM 实测 319.2 TF/s(84.9% 标称),256K GDN3.88×(N0 逐比特 0.0),3DGS 1K 墙钟 32.45 s,Qwen3.8-Flash-Next 4K Prefill 6,151 tok/s,Flash-QSA 64K Prefill 9.69 s(DecodeB=194.37 tok/s)。
1.23DGS:用非常规自定义算子检验模型写 Ascend C 的能力
3DGS 几乎不含标准矩阵乘,属于典型的非常规图形学算子(可微 Tile 光栅化、前缀和分桶、球谐投影、融合 SSIM),CANN 无现成实现,必须从零手写算子,适合直接检验模型写 Ascend C 算子的能力。
在 Mip-NeRF 360 garden(1297×840,4,346 个 16×16 tile,初始 138,766 高斯,严格 FP32)上,纯 PyTorch NPU 基线单步耗时 5,716.15 ms(17.67 GB 显存)。Neon 用 24 轮迭代从零手写整套 Ascend C++ 算子,把单步压到 28.10 ms(203.46×):
- 向量化 SoA SIMD 预处理(R20a/b):用硬件
Gather完成 AoS→SoA 转换,64 宽 FP32 SIMD 并行计算投影、协方差与 0–3 阶球谐,前向2.95 → 0.68 ms(4.32×),反向5.44 → 2.70 ms(2.01×)。 - 零散射连续 Binning(R21b):910C 上 64B 随机 MTE3 散射耗时约 10.5 ms,而
index_select随机 MTE2 gather + 连续 MTE3 突发可达 150+ GB/s(0.40 ms,快 26×);结合 48 核两趟前缀和(0.05 ms 取代 9.25 ms AiCPUcumsum)与 FP32 硬件Sort32,Binning 从11.03 → 4.76 ms。 - Tight-Conic AABB 剪枝 + 192 KB UB 光栅化(R16–R24b):每个 16×16 tile 常驻 192 KB UB,按
dx = √(2.004·ln(255·op)·c₀₀)收紧外接盒,在保持精确 FP32 一致的前提下于 iter 0 减少 27.0%、中后期减少 45%–60% 无效 tile-高斯对;配合STRIP_W=384消除PIPE_ALL的融合 SSIM 与 6 张量融合adam_step6(L2 驻留达 2,576 GB/s)。
单张 910C 上完成 30,000 步训练(最终 4,178,450 个高斯球)耗时 1 小时 43 分,测试集 PSNR 27.512 dB / SSIM 0.8685(SIGGRAPH'23 原论文为 27.41 dB / 0.868),418 万个高斯球渲染 11.92 FPS。
1.3Case Study & Tutorial:从零写出 Flash-QSA-Ascend(64K 稀疏注意力)
当 CANN 原生稀疏算子均不支持 QSA 的头数与分块规格时,Agent 在零联网环境下直接手写 1,021 行纯 Ascend C++,实现 cos_sim = 1.000000;其中自定义 indexer(1,347.1 GB/s,达 106% 实测 STREAM)与 64K Decode bs=8(FlashQSA-Cube 单层约 0.07 ms、纯 AIV 核 0.076 ms,受核启动与串行归约下限约束)均已接近 910C 硬件极限。
背景与卡点:Qwen3.8-Flash-Next 的 12 层 Query-Sparse Attention(QSA)在 64K 上下文下将 KV 历史压缩为 16,384 个 4-token 块,每个 Query 仅选 Top-512 块(≤ 2,048 tokens,占 64K 的 3.1%),8 卡 TP8 下的形状与分块参数为 Hq=3, Hkv=1, D=256, block_size=4, topk=512。在 H200 上,sglang 上游用几十行 Triton gather 接现成 FA3 varlen 即可运行;而在 910C 上,测试 CANN 全部 4 个原生稀疏算子(npu_nsa_select_attention_infer、mlp_sparse_flash_attention 等)均报错不支持该形状和 block_size=4;退回稠密 [B, 1, 64K, 64K] bool mask 则单次调用占用 4.0 GB,直接触发 AICORE_TIMEOUT (507014, >40 GiB)。
ascend 分支 docs/en/flashqsa_arch_en.svg):(A) 单 AIV 核 192 KB UB 静态 32B 对齐布局(总占 ~125 KB,3-Head 共享 K/V);(B) 64K 稀疏 Gather 跳过 96.9% HBM;(C) v1 频繁 PIPE_ALL 停顿 vs v3 单次批量 HardEvent::V_S 流水线;(D) 48 AIV 核 Split-K FlashDecoding + 3 核 Log-Sum-Exp 归约。| Flash-QSA 实测负载(Ascend 910C, BF16) | R4 稠密 FIA 基线 | Flash-QSA-Ascend | 收益 |
|---|---|---|---|
单层 64K Full Prefill (L=65,536) |
TIMEOUT (>40 GiB) | 212.7 ms (1.52 GiB) | 跑通 · 显存 >26×↓ |
单层 64K Decode B=1 / B=8 / B=16 / B=32 |
1.79 / — / 6.41 / 12.52 ms | 0.0394 / 0.076 (核) / 1.27 / 2.33 ms | 5.05× – 5.36× · B=8 接近硬件极限 |
自定义 indexer_relu_sum_mask 带宽 |
PyTorch Eager (1.07 GB 缓冲) | 1,347.1 GB/s | 7.5×–9.2× · 84.2% 标称 / 106% STREAM(达硬件极限) |
8 卡 48 层 360 GB 真权重 64K(L=65,536, B=1) |
Pre 15.72 s / Dec 131.5 ms | Pre 9.69 s / Dec 10.60 ms(94.37 tok/s) | Pre +1.62× / Dec 12.41× |
Tutorial:在 910C 上编写并接入一个 torch_npu Ascend C 算子(以 Flash-QSA 为例)
在 910C 上开发自定义算子,主要难点集中在构建链配置与 192 KB UB 同步。结合 Flash-QSA 的 3 个源文件(共 1,021 行),流程分为四步:
- 第 1 步 · 用
ascendc_library()一键接入 CANN 8.5 编译链:直接include(ascendc.cmake)+ascendc_library(... STATIC)自动编译__aicore__核并生成宿主机启动桩,再链接进SHARED动态库(CANN 8.5.1 需显式传-DCMAKE_BUILD_TYPE=Release,并过滤torch.utils.cmake_prefix_path首行杂输出)。 - 第 2 步 · 静态 32B 对齐 UB 编排,严守 ≤ 160 KB 水位:每个 AIV 核只有 192 KB Unified Buffer,避免动态队列碎片化。用单个
TBuf<VECCALC>配合 32B 对齐的UbAlloc静态切分:Flash-QSA 将Q/O FP32(12 KB) +K/V BF16(32 KB,TILE_BLK=8=32 tok) +K/V FP32(64 KB) + Online Softmax (17 KB) 全部压进 ~125 KB,零 HBM spill,并让Hq=3共享同一块 KV 实现 3× HBM 带宽复用。 - 第 3 步 · 消灭
PIPE_ALL,按负载分流 AIV vs Cube:交错发射 3 个头的Mul/Axpy隐藏向量流水延迟,整块 32 token 仅在归约后发一次HardEvent::V_S同步再标量读 UB;B*S < 24时自动走 48 核 Split-K + log-sum-exp reduce;而大SPrefill(或大批量 Decode 的 FlashQSA-Cube)用 UB 零拷贝 gather 喂给 376 TFLOPS Cube FIA。 - 第 4 步 ·
TORCH_LIBRARY(..., PrivateUse1)注册 +stream(true)刷队列 + 三层验证:在torch_bridge.cpp中通过c10_npu::getCurrentNPUStream().stream(true)同步刷新异步任务队列,注册到PrivateUse1后直接torch.ops.load_library(...)调用;先过 8 组 Golden FP32 单测(cos_sim = 1.000000),再接全模型 64K 大海捞针(L=65,493精确召回密钥NEBULA7941)。
查看 Flash-QSA-Ascend 核心模板代码(CMakeLists.txt + UbAlloc/零 PIPE_ALL 核 + Python 调用)
set(SOC_VERSION "Ascend910_9382" CACHE STRING "")
set(RUN_MODE "npu" CACHE STRING "")
include(${ASCEND_CANN_PACKAGE_PATH}/tools/tikcpp/ascendc_kernel_cmake/ascendc.cmake)
# 自动编译 __global__ __aicore__ 核并生成宿主机 launch 桩
ascendc_library(flashqsa_kernels STATIC flash_qsa_kernel.cpp)
add_library(flashqsa_cann SHARED torch_bridge.cpp)
target_link_libraries(flashqsa_cann PRIVATE flashqsa_kernels ${TORCH_LIBRARIES} torch_npu ascendcl)
template <typename T>
__aicore__ inline AscendC::LocalTensor<T> UbAlloc(
AscendC::TBuf<AscendC::TPosition::VECCALC>& buf, uint32_t n, uint32_t& off) {
auto t = buf.GetWithOffset<T>(n, off);
off += ((n * static_cast<uint32_t>(sizeof(T)) + 31u) / 32u) * 32u;
return t;
}
// 32-token tile 内全部 Hq=3 头做完 Mul + WholeReduceSum,仅发一次 HardEvent::V_S
AscendC::SetFlag<AscendC::HardEvent::V_S>(EVENT_ID0);
AscendC::WaitFlag<AscendC::HardEvent::V_S>(EVENT_ID0);
// 随后把 32 个 score + (m_old - m_new) 拼成 stride=40,一次向量 AscendC::Exp 搞定
# 编译(~15 秒产出 libflashqsa_cann.so)
source /usr/local/Ascend/ascend-toolkit/set_env.sh
cd ascendc_ext/flash_qsa && cmake -B build -S . -DCMAKE_BUILD_TYPE=Release && cmake --build build -j16
# Python 中直接调用并支持 NPUGraph 捕获
import torch, torch_npu
torch.ops.load_library("ascendc_ext/flash_qsa/build/libflashqsa_cann.so")
out = torch.ops.flashqsa_cann.sparse_attn_fwd(q, k, v, top_blocks, q_pos, 4, scale)
2. 模型在 H200 和 910C 上的 MFU / MBU 与峰值对比
只看加速比会把“修复 NPU 基线回退”和“逼近硬件极限”混在一起。要对比 Agent 在 GPU 和 NPU 上的真实优化能力,需要剥离芯片规格差异,统一按 MFU(算力受限)、MBU(访存受限) 以及 相对单卡实测上限的占比(SOL%) 衡量。
2.1双平台单卡实测硬件上限
我们在 1×H200(143 GB,700 W TDP,Torch 2.9.1 + CUDA 12.8)与 1×Ascend 910C(64 GB 单 die,Ascend910_9382,CANN 8.5.1)上分别测量单卡实际可达的算力与带宽上限:
| 单卡微基准项 | H200 实测(占纸面峰值) | 910C 单 die 实测(占纸面峰值) | 硬件实测比 |
|---|---|---|---|
BF16 稠密 GEMM (4096³ / 8192³) |
730.6 / 680.3 TF/s (73.8% / 68.8% of 989.5) | 319.2 / 294.8 TF/s (84.9% / 78.4% of 376) | 2.3× |
| BF16 GEMM(LLM/VLM 实际形状) | 615.1 – 677.4 TF/s (62.2%–68.5%) | 均 ~283 TF/s,前向峰值 321 TF/s (75.3%) | ~2.3× |
| HBM STREAM Copy / Triad | 4,292 / 4,371 GB/s (89.4% / 91.1% of 4,800) | 1,269.5 / 1,194.1 GB/s (79.3% / 74.6% of 1,600) | 3.4×–3.7× |
| BF16 算存比拐点 (Ridge Point) | 标称 206 · 实测 ~158 FLOP/B | 标称 235 · 实测 242–252 FLOP/B | 910C 更偏带宽敏感 |
| FP32 非矩阵乘矢量峰值 | 51.1 TF/s GEMM / 45.2 FMA (of 67.0) | 11.06 TF/s (48 AIV 核,Ridge 8.71 FLOP/B) | 6.06× (标称) |
2.2MFU、MBU 与 3DGS 峰值对照(统一用 Gemini 4 Neon)
按各自物理 Roofline 归一化,在标准密集训练(NanoChat 严格 BF16)上,Neon 在 910C 上已经做到 92.6%,几乎追平 H200 的 93.7%;但在超稀疏多卡推理和纯 FP32 3DGS 上,受 64 GB 显存墙(需 TP=8, EP=8)与硬件规格差异影响,落差依然明显。
为避免 nanochat 原生 estimate_flops() 重复计入因果掩码外注意力导致的口径偏差,下表对 NanoChat 同时给出纯矩阵乘 Strict MFU(仅 6·N_matmul)与统一含精确因果滑窗注意力 MFU(w=512);对 Qwen3.8-Flash-Next 推理按实测 STREAM 带宽同时报告标称 MBU 与 STREAM MBU。
| 代表任务 | 主指标 | H200 (GPU · Neon 10h) | Ascend 910C (NPU · Neon 10h) | 物理 Roofline / 峰值对照 |
|---|---|---|---|---|
| NanoChat D24 严格 BF16 预训练 |
MFU | 2 卡 · 1.172× (1.2248→1.0448 s)Strict: 47.36% → 55.52%统一含 attn: 50.19% → 58.84% |
8 卡 · 2.176× (7,448→3,422 ms)Strict: 20.49% → 44.60%统一含 attn: 21.72% → 47.27% |
GPU 93.7% vs NPU 92.6% 几乎持平;裸 MFU 差 11 pp 主要源于 910C 算存比更高与闭源 Cube/FA 下限 |
| LLaVA-1.5-7B 多模态 BF16 SFT |
MFU | 2 卡 · 3.12×20.2% → 63.0% |
8 卡 10h 实测: Neon 8.7% → 56.52% (6.46×)GLM-5.4 8.7% → 51.90% (5.99×) |
GPU ~95% vs NPU ~91% SOL% 8 卡 ZeRO-2 / FSDP 通信下,Neon 已接近 H200 饱和度(GLM-5.4 达 ~84%,配合完整 Skill 达 59.25%) |
Qwen3.8-Flash-Nextbs=8, 8K/1024 |
Decode MBU Prefill MFU |
4 卡 TP=4, EP=4(sglang):MBU 23.4% → 41.9% (R28 50.1%)STREAM 46.0% (R28 55.0%) · Pre 12.5% |
8 卡 TP=8, EP=8(11 核 Ascend C):MBU 6.62% → 22.25% (3.41×)STREAM 28.1% · Pre 4.40% |
STREAM MBU 差 1.6–1.9×,主因是 64 GB 显存墙迫使 TP=8, EP=8:MoE 算子本身已达 79% STREAM,96 次 HCCL + 核气泡占去 37% |
| 3DGS (FP32) 全规模 30K 步 |
FP32 矢量 & 带宽峰值 |
1 卡 truck (2.03M G, 979×546):307.5 → 72.7 s (4.23×)FP32 16.4% · 带宽 ~39% |
1 卡 garden (4.18M G, 1297×840):单步 28.10 ms ( 203.5×),30K 1h 43mFP32 3.88% (光栅化 5.3%–6.5%) |
910C 光栅化 AI 高达 40–60 FLOP/B,属 Vector-Pipe 算力受限(非带宽);芯片 FP32 峰值本身差 6.06× |
TP=8, EP=8,每步 16.54 ms 中物理纯 HBM 下限仅 4.64 ms,96 次 HCCL 与 ~1,200 个发射气泡合计占去 37%。2.3轨迹分析:模型在 GPU 和 NPU 上优化行为的差异,以及还差在哪?
对比 H200(NanoChat 25 轮、Qwen3.8-Flash-Next 28 轮、3DGS)与 910C(13 份完整 Trace)的逐轮优化轨迹,Agent 在两类硬件上的差距主要来自以下四类系统与硬件因素:
Gap 1 · 中层 DSL 成熟度与模型先验 中层 DSL 工具链与模型先验仍弱于 CUDA/Triton,突破框架上限往往要手写 Ascend C++ NanoChat 10h 实证:纯 PyTorch 的 GLM-5.4 止步 36.08%,手写 10 核 Ascend C 的 Neon 达 44.60% (+8.52 pp) 展开细节收起
在 H200 上,PyTorch → torch.compile → Triton → CUTLASS/CUDA 生态非常成熟,且大模型在预训练阶段见过海量 Triton 与 torch.compile 代码,中等能力模型也能依靠几十行 Triton 拿到大部分融合收益。
在 910C 上,虽然社区已经有 TileLang-Ascend 和 Triton-Ascend 等中层 DSL,但目前两方面仍有差距:一是默认集群环境常未预装且在复杂反向图/非规则访存上的生态覆盖度不及 CUDA Triton(例如当前环境中 torchair 在反向图上存在 RoPE 梯度错误,编译核带宽约 0.62–1.27 TB/s);二是主流模型对 TileLang-Ascend / Triton-Ascend 的预训练语料极少,在缺乏对应 Skill 时很难稳定写出高效核。因此本次实测中要突破框架上限,Agent 往往需要直接手写 Ascend C++,手动管理 192 KB UB 分配、32B 对齐和 HardEvent 同步。这放大了模型之间的差距——Neon 写出了 10 个双缓冲核(NanoChat +8.52 pp MFU,Flash-QSA 1,021 行),而停留在框架层的 GLM-5.4 止步 36.08% MFU。后续随着 TileLang-Ascend 等 DSL 成熟并配齐对应 Skill,这一差距有望进一步缩小。
Gap 2 · 算子库开放度
闭源基础库边界:H200 支持 SM90 CUTLASS EVT 融合进 GEMM Epilogue,910C 只能核外拼接
NanoChat G1 R25:Neon 在 H200 用 CUTLASS EVT 消除中间张量 y2,每步少搬 19.3 GB HBM3e
展开细节收起
在 H200 NanoChat BF16 第 25 轮,Neon 利用无权重 RMSNorm 的线性性,通过 SM90 CUTLASS EVT 将 o_proj + residual + rstd 规约以及 c_fc + relu² 的 scale-fold 融合进 GEMM epilogue,完全消除了前反向里的中间激活 y2,将 MFU 推至 58.84%(93.7% SOL%)。
在 910C 上,24 核 Cube MatMulV2 与 FIA 为闭源算子,不支持自定义 epilogue,融合通信算子 MC2 在当前环境亦不可用(EZ1001)。即使 Neon 写出 10 个 80%–90% 带宽利用率的 AIV 融合核,仍无法消除这约 638 GB 的 HBM 读写(约 473 ms 物理下限)。
Gap 3 · 多卡物理硬件限制
Qwen3.8-Flash-Next 的 STREAM MBU(28% vs 46%)与 Prefill MFU(4.4% vs 12.5%)差距的五项硬件原因
910C MoE 算子已达 79% STREAM,差距主因是 64 GB 显存墙迫使 TP=8, EP=8、HCCS 互联、小矩阵算存比与 Cube/Vector 分离
展开细节收起
拆解 Qwen3.8-Flash-Next 176.7B 在 8×910C 与 4×H200 上的耗时后,STREAM MBU(28.1% vs 46.0%–55.0%)与 Prefill MFU(4.4% vs 12.5%)的差距主要由 5 项物理硬件差异决定:
- 64 GB 显存墙迫使
TP=8, EP=8(相对 H200TP=4, EP=4卡数翻倍):360 GB 权重在 H200(141 GB)上 4 卡可装下,在 910C(64 GB)上需要 8 卡。卡数翻倍后,总带宽分母翻倍,但 96 次串行all_reduce与约 1,200 次核发射的固定延迟并未减半,同时复制态权重(96 层 Hyper-Connections、QSA KV 头)读写量翻倍。 - 卡间互联延迟(HCCS vs NVLink 4.0):8×910C 每 token 串行执行 96 次 8 卡 HCCL
all_reduce,耗时 3.2–3.5 ms(单次约 35 µs);4×H200 卡数减半且具备全互联 NVLink(900 GB/s/卡)与 NVLS 硬件多播,同步延迟明显更低。 - 高算存比拐点叠加细粒度 MoE 切分:910C 实测 BF16 算存比拐点为 242–252 FLOP/B(H200 约 158),需要更大的单核矩阵块才能打满算力。Qwen3.8-Flash-Next 为 512 专家选 10(
moe_intermediate_size=640),Prefill 即使以chunk=2048 × bs=8 = 16,384token 输入,单专家平均M_e也仅约 320;TP8/EP8 切分后shared_expert维度仅80、GDN 仅 2 K-head/卡,小矩阵填充损耗明显高于 H200。 - Cube / Vector 物理分离与片上搬运:H200 的 Tensor Core 与 CUDA Core 共享 SM 寄存器与 L1/SMEM;910C 的 24 个 AIC(Cube)与 48 个 AIV(Vector)物理分离,中间结果需经 L2/HBM 往返搬入 192 KB UB。在 36 层 GDN + 96 层 HC + 12 层 QSA 这类高频小 GEMM 与逐元素交替的结构上,AIC↔AIV 数据往返直接拉低 Prefill MFU。
- 显存余量限制 Prefill chunk 大小(
2048vs H2008192):8×910C 载入权重后仅余约 14.5 GiB,Prefill 只能设为chunk=2048(H200 为8192),单次分组 GEMM 规模缩小为 1/4。
Gap 4 · 诊断开销与硬件定位 静默回退排查开销与 FP32 矢量峰值差异(6.06×) NPU 前期轮次有相当比例用于排查 AiCPU 回退与语义差异;3DGS 上 910C FP32 矢量峰值仅 11.06 TF/s vs H200 67 TF/s 展开细节收起
诊断与工具链开销:GPU 上 nsys/ncu 可直接定位 warp stall 与 bank conflict;NPU 上高频出现不报错的静默回退(bool.scatter_、int32 sort/cumsum、4D mask)及粗粒度 AICORE_TIMEOUT,Agent 需要消耗更多前期轮次定位问题。
FP32 硬件规格差异:3DGS 在 910C 上经 R22 去原子实验证实为 Vector-Pipe FP32 算力受限(AI 40–60 FLOP/B,远高于 8.71 拐点)。910C 48 AIV 核的 FP32 峰值仅 11.06 TF/s,而 H200 为 67.0 TF/s(差 6.06×),这决定了两者的绝对耗时差距。
3. RBA 已集成 910C 专属 Skill:让更多模型都能完成昇腾编译与深度优化
将 910C 真机验证的构建链、UB 同步规范与回退排错经验整理成按需加载的参考卡后,不同模型都能快速上手昇腾算子编译与系统调优,而不必从零试错。
我们在 ResearchBoost Agent 中加入了面向昇腾 910C 的渐进式技能包 skills/ascend-opt/(已合入 PR #17),其中核心入口 ascend-910c-playbook 包含 1 份 34 行路由总纲(SKILL.md)和 6 张按需读取的参考卡;启动时仅加载 1 行 metadata,Agent 先 Profile 定位热点再只读取对应卡片,避免过多占用上下文:
| 参考卡 | 触发场景 | 核心真机经验 |
|---|---|---|
01-ascendc-build-and-bridge |
手写自定义 Ascend C 核 | CANN 8.5 ascendc_library() 最小 CMake 模板、TORCH_LIBRARY(PrivateUse1) 与 stream(true) 刷队列 |
02-ub-tiling-and-sync |
设计 UB 分块与 Split-K | 192 KB UB 32B 对齐 UbAlloc、消灭 PIPE_ALL 改单次批量 HardEvent::V_S、48 核 Split-K、AIV vs Cube 分流 |
03-aicpu-fallbacks-and-cann-pitfalls |
10×–1000× 异常慢或数值错 | bool.scatter_ / int32 sort / cumsum AiCPU 回退清单、_foreach_copy_ _version 与 torchair 反向问题修复 |
04-npugraph-and-comm |
Decode 发射瓶颈与多卡同步 | 48L NPUGraph/ACLGraph(含 HCCL 捕获)、resize_(0) 清卸载泄漏、HCCL_OP_EXPANSION_MODE=AIV |
05-training-fsdp-and-varlen-fa |
VLM/LLM 多卡训练 | 修 HF 4D mask 静默禁用 FA、TND 变长打包、FSDP no_sync 与跨卡 token 均衡 |
06-verification-and-mfu |
诚实效率核算与防作弊验证 | 剔除查表 embedding 的精确 MFU、Golden FP32 校验、RL Token-Forcing 与 64K 捞针 |
3.1多模型实证:以 GLM-5.4 在 4 条赛道上的 10h 真机表现为例
以 GLM-5.4 为例:在未提供 Skill 时,它在 NanoChat 第 5 轮因环境中找不到旧资料假设的编译配置而放弃了自定义 Ascend C 算子;接入 ascend-opt Skill 后,GLM-5.4 在 20 分钟内就一次编通自定义 Ascend C .so,并在严格隔离的 4 个 10 小时 /goal 任务上全部完成真机验证(LLaVA 达 5.99× / 51.90% MFU,配合完整 Skill 进一步达 6.84× / 59.25% MFU):
| 赛道(10h 隔离实测) | GLM-5.4 实测结果 | 加速比 | 硬件利用率与校验 |
|---|---|---|---|
| LLaVA-1.5-7B 8×910C · 严格 BF16 |
18,770 → 3,132.6 ms(Judge 3,145.2 ms,43.82 GiB);配合完整 Skill 达 2,744.1 ms(零重算,54.89 GiB) |
5.99× 6.84×(+Skill) |
51.90% MFU(同题 Neon 6.46× / 56.52%);+Skill 达 59.25% MFU(设备忙碌率 99.4%),均 N1 PASS |
| NanoChat D24 8×910C · 严格 BF16 |
7,448 → 4,230.4 ms(247.9K tok/s,38.15 GB,双次复现差 0.03 ms) |
1.76× | 36.08% Strict MFU(统一 38.24%,纯 PyTorch / torchair 方案,N1 PASS) |
| Faster-3DGS 1×910C · 严格 FP32 Ascend C |
手写 13 个 Ascend C 核(6 核 binning + 前反向光栅化 + 融合 Adam);400×400 429.9 → 15.43 ms,1297×840 116.3 ms |
27.8× | 9/9 项精确校验全过(FP32 cos=1.000000,radii_diff=0),3.5K 步 PSNR 30.45 dB |
| Flash-QSA 64K 1–8×910C · 纯 AIV Ascend C |
手写 "mode 21" 流水线核:64K 注意力阶段 716.0 → 324.4 ms;64K Decode 核 B=8/16/32 压至 0.076 / 0.103 / 0.190 ms |
2.20× | 纯 AIV 注意力达 427.2 GB/s(33.5% STREAM),72/72 PASS(min cos=0.999991),64K 大海捞针召回 |
注:在 LLaVA-1.5-7B 上,GLM-5.4 在 10h 内连做 20 轮优化(LPT 跨卡均衡、去全量重算、_NpuLinear 消除 180 MB 权重拷贝、_FlatViews 消除 405 MB 梯度拼接、侧流通信与异步 H2D 预取),把 8×910C 设备忙碌率推到 99.4%、59.25% 诚实 MFU,几乎追平 2×H200 的 63.0% MFU;在 3DGS 与 Flash-QSA 上也均独立完成了纯手写 Ascend C 算子并全部通过真机数值校验。
3.2NPU 用户现在就能用 RBA 优化自己的模型
拉取 ResearchBoost-Agent 的 ascend 分支中的 skills/ascend-opt/ 即可直接接入你的 Coding Agent,参考 traces/01–13 搭建冻结裁判闭环:
# 1. 克隆完整源码、Ascend C 算子、Skill 包与 13 份逐轮 Trace
git clone --branch ascend --single-branch \
https://github.com/DAGroup-PKU/ResearchBoost-Agent.git RBA-Ascend
# 2. 将渐进式 Skill 挂入你的 Agent 工作区(启动时仅加载 1 行 metadata)
cp -r RBA-Ascend/skills/ascend-opt /path/to/your-project/.claude/skills/
# 3. 固定 reference/ 与冻结 judge,启动 RBA 闭环(profile → 改动 → 校验精度与速度)
CUDA's Moat Is Eroding: Benchmarking Agentic Infra Optimization on NPU vs. GPU
GPU dominance has long rested on two pillars: silicon performance and the CUDA ecosystem. As coding agents get stronger at systems and kernel optimization, the CUDA ecosystem barrier is rapidly shrinking. Following the frozen-judge, long-horizon iteration setup of RSI-Infra Bench, we equip models with Ascend 910C toolchains and the progressive ascend-opt skill. Our strongest agent (Gemini 4 Neon) already handles migration, silent-fallback bug fixes, and custom Ascend C kernel authoring end to end under a strict BF16/FP32 floor (zero quantization downgrade):
- Multimodal & Pretraining: LLaVA-1.5-7B
6.46×(MFU56.52%,~91%of empirical ceiling; GLM-5.45.99×/51.90%; 300-stepmix665k4.20×); NanoChat D242.18×(10 hand-written Ascend C kernels, reaching92.6%of empirical physical ceiling, closely matching H200's93.7%). - Non-Standard & Custom Kernels: Full-scale 30K-iter 3DGS
203.5×(4.18M Gaussians, PSNR27.51 dB); Flash-QSA 64K sparse attention & Qwen3.8-Flash-Next 176.7B serving (bs=8decode3.41×, 4K prefill52.3×). - Multi-Node RL: 64-NPU full-256K Agentic RL
2.82×end-to-end (3.59×rollout, bitwise-exact across 7.80M tokens). - Cross-Hardware Analysis & Open Release: We compare H200 vs. 910C on the same tasks via MFU, STREAM MBU, and empirical ceilings, analyze trace-level gaps, and open-source all code and 13 traces in ResearchBoost-Agent (
ascendbranch). ResearchBoost-Agent also ships theascend-optskill so NPU users can optimize their own models directly.
Note on Qwen3.8-Flash-Next gap: The MBU / MFU gap between 910C and H200 on Qwen3.8-Flash-Next (176.7B, 360 GB weights) stems primarily from the 64 GB per-card HBM memory wall forcing TP=8, EP=8 on 910C (vs. TP=4, EP=4 on 141 GB H200), adding 96 sequential 8-card HCCL all-reduces, doubled replicated weights, and finer sharding overhead (see §2.3 Gap 3).
1. Optimization Results on Ascend 910C
On CUDA, mainstream training and inference frameworks already start from years of hand-tuned fast paths. On Ascend 910C-64G (Ascend910_9382, 376 TFLOPS/die BF16 Cube, 48 AIV cores, 192 KB UB/core, 1,600 GB/s HBM, CANN 8.5.1), an agent has to execute two distinct steps: first locate and fix silent fallbacks and framework semantic bugs, then apply framework tuning and hand-written Ascend C kernels.
1.1Bug Fixes First, Then End-to-End Speedups
Many 10×–1000× slowdowns during NPU migration come from silent fallbacks and subtle semantic differences that raise no errors.
These regressions silently route ops to AiCPU or unfused math paths. Using torch_npu.profiler, frozen reference outputs, and isolated A/B tests, the agent diagnosed and fixed these issues across all 6 tracks before delivering 2.18× to 203.5× end-to-end speedups.
| Task | Workload & Hardware | Key Migration Bugs / Fallbacks Fixed | Speedup | Real-Weight / Dataset Verification |
|---|---|---|---|---|
| LLaVA-1.5-7B | Multimodal Stage-2 SFT 8×910C · Strict BF16 |
HF 4D mask silently disabled NPU FA (25× slower); missing FSDP micro-batch no_sync |
6.46× (Neon) 5.99× (GLM-5.4) |
10h head-to-head (18,769.6 ms ref): Neon 2,906.7 ms (56.52% MFU, R5) vs. GLM-5.4 3,132.6 ms (51.90% MFU, R7), both N1 PASS; mix665k 300-step 4.20× (Val PPL 2.3017 vs 2.3017) |
| NanoChat D24 | 1.384B (729.8M matmul) 8×910C · Strict BF16 |
_foreach_copy_ skips _version bump; bf16 Pow 4× slower; torchair bwd mismatch |
2.18× (Neon) 1.76× (GLM-5.4) |
10 double-buffered Ascend C kernels; ClimbMix-400B 200-step paired 2.17×, N1 PASS |
| Faster-3DGS | Mip-NeRF 360 garden1×910C · Strict FP32 |
Sort32 int32/64 AiCPU fallback (139×); cumsum AiCPU fallback (185×) |
203.5×400² 97.2× |
30,000 iters (138.8K → 4.18M Gaussians) in 1h 43m, PSNR 27.512 dB (vs. paper 27.41 dB) |
| Flash-QSA & Qwen3.8-Flash-Next |
176.7B MoE+GDN+QSA (360 GB) 8×910C TP=8, EP=8 |
bool.scatter_ AiCPU fallback (1,933×); 64K dense mask timeout; CANN sparse ops unsupported for QSA shape |
3.41× (bs=8)52.3× (4K Pre) |
11 custom Ascend C kernels; B=1 8K 96.4 tok/s / 64K 94.4 tok/s; bs=8 decode 56.34 → 16.54 ms (483.8 tok/s), 136/136 exact greedy + 64K Needle |
| 256K Agentic RL | Qwen3.8-27B TIS+GRPO 64×910C · Docker Sandbox |
Colocated NPUGraph offload leak (+18.7 GiB/cycle); GDN 8×8 nilpotent cancellation; fla 48.1% bwd recompute |
2.82× (256K) Rollout 3.59× |
64-NPU 7.80M tok live 256K RL: 0 MB HBM drift, actor_train_vs_infer = 0.0 bitwise exact |
Migration & Bug Fixes
Representative Bugs & Fallbacks Diagnosed on 910C (CANN 8.5.1)
Silent AiCPU fallbacks up to 1,933×·Framework semantic bugs & NPUGraph offload leaks resolved
DetailsClose
- Silent AiCPU Fallbacks:
bool.scatter_in QSA Indexer took 2,513.7 ms/layer on AiCPU (fixed viafloat32.scatter_→ 1.30 ms, 1,933×);torch.sort(int32/int64)in 3DGS took 172–196 ms (FP32 hardwareSort32→ 1.24 ms, 139×);at::cumsum(int32)took 9.25 ms (48-core Ascend C prefix sum → 0.05 ms, 185×). - Framework Semantic Bugs:
torch._foreach_copy_on NPU does not incrementTensor._version, causing stale bf16 weight caches to diverge at step 4; full-graphtorchairproduces RoPE backward errors (maxdiff = 416); colocated RLNPUGraphoffload leaked 18.7 GiB/cycle (eliminated to 0 MB drift viauntyped_storage().resize_(0)). - CANN 8.5.1 Verification: Validated user-space without upgrading host driver (
25.2.t5), confirmed zero fallback via/proc/self/maps. Empirical BF164096³Cube GEMM hits 319.2 TF/s (84.9% spec), 256K GDN3.88×(N0 exact 0.0), 3DGS 1K wall 32.45 s, Qwen3.8-Flash-Next 4K prefill 6,151 tok/s, Flash-QSA 64K prefill 9.69 s (B=1decode 94.37 tok/s).
1.23DGS on 910C: Testing Non-Standard Custom Kernel Authoring
3DGS contains almost no standard GEMMs; its core consists of non-standard graphics operators (differentiable tile rasterization, prefix-sum binning, spherical harmonics, fused SSIM) with no built-in CANN implementation, directly testing an agent's ability to author custom Ascend C kernels.
On Mip-NeRF 360 garden (1297×840, 4,346 16×16 tiles, 138,766 initial Gaussians, strict FP32), the pure PyTorch NPU baseline took 5,716.15 ms/iter (17.67 GB HBM). Across 24 rounds (R1–R24b), Neon wrote the full Ascend C++ pipeline from scratch and brought iteration latency down to 28.10 ms (203.46×):
- Vectorized SoA SIMD Preprocess (R20a/b): Hardware
GatherAoS→SoA + 64-wide FP32 SIMD for projection, covariance, and degree 0–3 SH (2.95 → 0.68 msfwd,5.44 → 2.70 msbwd). - Zero-Scatter Contiguous Binning (R21b): Replaced ~10.5 ms 64B random MTE3 scatters with 48-core 2-pass Ascend C prefix sum (0.05 ms vs. 9.25 ms AiCPU
cumsum), hardware FP32Sort32, and contiguousindex_selectgather (0.40 ms, 150+ GB/s), cutting binning11.03 → 4.76 ms. - Tight-Conic AABB Pruning & 192 KB UB Rasterization (R16–R24b): Kept 16×16 tiles resident in UB, pruned 27.0% (iter 0) to 45%–60% (mid/late training) dead tile-Gaussian pairs with exact FP32 parity, fused
STRIP_W=384zero-PIPE_ALLSSIM, and fused 6-tensoradam_step6(2,576 GB/s L2-resident).
Full 30,000-iter training on 1×910C (growing to 4,178,450 Gaussians) finished in 1h 43m with held-out Test PSNR 27.512 dB / SSIM 0.8685 (SIGGRAPH'23 paper: 27.41 dB / 0.868), rendering 4.18M Gaussians at 11.92 FPS.
1.3Case Study & Tutorial: Building Flash-QSA-Ascend (64K Sparse Attention)
When all built-in CANN sparse attention ops failed on QSA's head/block configuration, the agent authored 1,021 lines of pure Ascend C++ offline, hitting cos_sim = 1.000000 — with both the custom indexer (1,347.1 GB/s, 106% of empirical STREAM) and 64K Decode bs=8 (FlashQSA-Cube ~0.07 ms/layer; pure-AIV kernel 0.076 ms, bounded by launch and serial reduction floors) operating near Ascend 910C hardware limits.
Problem: Qwen3.8-Flash-Next's 12 Query-Sparse Attention (QSA) layers compress 64K KV history into 16,384 4-token blocks and select Top-512 blocks (≤ 2,048 tokens, 3.1% of 64K) with TP=8 shape Hq=3, Hkv=1, D=256, block_size=4, topk=512. On H200, upstream sglang assembles this via a short Triton gather + FA3 varlen. On 910C, all 4 native CANN sparse ops (npu_nsa_select_attention_infer, mlp_sparse_flash_attention, etc.) error out on this shape and block_size=4, while a dense [B, 1, 64K, 64K] boolean mask takes 4.0 GB/call and triggers AICORE_TIMEOUT (507014, >40 GiB).
ascend branch docs/en/flashqsa_arch_en.svg): (A) 32B-aligned static 192 KB UB arena (~125 KB used, 3-head KV reuse); (B) 64K sparse gather skipping 96.9% HBM; (C) v1 PIPE_ALL stalls vs. v3 single batched HardEvent::V_S; (D) 48-core Split-K FlashDecoding + 3-core log-sum-exp reduce.| Flash-QSA Benchmark (Ascend 910C, BF16) | R4 Dense FIA Base | Flash-QSA-Ascend | Gain |
|---|---|---|---|
Single-Layer 64K Full Prefill (L=65,536) |
TIMEOUT (>40 GiB) | 212.7 ms (1.52 GiB) | Unblocked · >26× HBM↓ |
Single-Layer 64K Decode B=1 / 8 / 16 / 32 |
1.79 / — / 6.41 / 12.52 ms | 0.0394 / 0.076 (kern) / 1.27 / 2.33 ms | 5.05× – 5.36× · B=8 near hardware limit |
Custom indexer_relu_sum_mask BW |
PyTorch Eager (1.07 GB buf) | 1,347.1 GB/s | 7.5×–9.2× · 84.2% spec / 106% STREAM (at limit) |
8-NPU 48L 360 GB Real-Weight 64K (L=65,536, B=1) |
Pre 15.72 s / Dec 131.5 ms | Pre 9.69 s / Dec 10.60 ms (94.37 tok/s) | Pre +1.62× / Dec 12.41× |
Tutorial: Writing & Registering a Custom torch_npu Ascend C Op on 910C
The main hurdles for custom 910C operators are build-chain setup and 192 KB UB synchronization. Distilled from Flash-QSA's 3 source files (1,021 LOC):
- Step 1 · Build with
ascendc_library()on CANN 8.5: Includeascendc.cmake, compile__aicore__kernels withascendc_library(... STATIC), and link into aSHAREDlibrary (pass-DCMAKE_BUILD_TYPE=Releaseon CANN 8.5.1 and strip stray stdout lines fromtorch.utils.cmake_prefix_path). - Step 2 · Static 32B-aligned UB arena (≤ 160 KB of 192 KB): Slice a single
TBuf<VECCALC>viaUbAlloc. Flash-QSA packsQ/O FP32(12 KB) +K/V BF16(32 KB, 32 tokens) +K/V FP32(64 KB) + online softmax (17 KB) into ~125 KB with zero HBM spill and 3× GQA KV reuse. - Step 3 · Eliminate
PIPE_ALL& route AIV vs. Cube: Interleave 3-headMul/Axpy, issue one batchedHardEvent::V_Sper 32-token tile before scalar reads, use 48-core Split-K forB*S < 24, and dispatch large-Sprefill or compacted gather (FlashQSA-Cube) to 376-TFLOPS Cube FIA. - Step 4 · Register on
PrivateUse1withstream(true): Callc10_npu::getCurrentNPUStream().stream(true)to flushtorch_npu's async queue, allocate outputs viaat::empty, register withTORCH_LIBRARY(..., PrivateUse1), verify against FP32 golden references (cos_sim = 1.000000), then validate 64K Needle recall (NEBULA7941).
View Flash-QSA-Ascend core template (CMakeLists.txt + UbAlloc / zero-PIPE_ALL + Python call)
set(SOC_VERSION "Ascend910_9382" CACHE STRING "")
set(RUN_MODE "npu" CACHE STRING "")
include(${ASCEND_CANN_PACKAGE_PATH}/tools/tikcpp/ascendc_kernel_cmake/ascendc.cmake)
# Compiles __global__ __aicore__ kernels and auto-generates host launch stubs
ascendc_library(flashqsa_kernels STATIC flash_qsa_kernel.cpp)
add_library(flashqsa_cann SHARED torch_bridge.cpp)
target_link_libraries(flashqsa_cann PRIVATE flashqsa_kernels ${TORCH_LIBRARIES} torch_npu ascendcl)
template <typename T>
__aicore__ inline AscendC::LocalTensor<T> UbAlloc(
AscendC::TBuf<AscendC::TPosition::VECCALC>& buf, uint32_t n, uint32_t& off) {
auto t = buf.GetWithOffset<T>(n, off);
off += ((n * static_cast<uint32_t>(sizeof(T)) + 31u) / 32u) * 32u;
return t;
}
// Single V_S sync after Mul + WholeReduceSum across all Hq=3 heads and 32 tokens
AscendC::SetFlag<AscendC::HardEvent::V_S>(EVENT_ID0);
AscendC::WaitFlag<AscendC::HardEvent::V_S>(EVENT_ID0);
source /usr/local/Ascend/ascend-toolkit/set_env.sh
cd ascendc_ext/flash_qsa && cmake -B build -S . -DCMAKE_BUILD_TYPE=Release && cmake --build build -j16
import torch, torch_npu
torch.ops.load_library("ascendc_ext/flash_qsa/build/libflashqsa_cann.so")
out = torch.ops.flashqsa_cann.sparse_attn_fwd(q, k, v, top_blocks, q_pos, 4, scale)
2. H200 vs. 910C: MFU, MBU & Empirical Peak Comparison
Raw speedup mixes fixing NPU baseline fallbacks with approaching hardware ceilings. To measure agent optimization capability cleanly across platforms, we normalize by MFU (compute-bound), MBU (memory-bound), and % of empirical single-chip ceiling (SOL%).
2.1Empirical Single-Chip Ceilings
We measured single-chip compute and memory ceilings on 1×H200 (143 GB, 700 W TDP, Torch 2.9.1 + CUDA 12.8) and 1×Ascend 910C (64 GB die, Ascend910_9382, CANN 8.5.1):
| Microbenchmark | H200 Measured (% of Spec) | 910C Die Measured (% of Spec) | Ratio |
|---|---|---|---|
BF16 Dense GEMM (4096³ / 8192³) |
730.6 / 680.3 TF/s (73.8% / 68.8% of 989.5) | 319.2 / 294.8 TF/s (84.9% / 78.4% of 376) | 2.3× |
| BF16 GEMM (Real LLM/VLM Shapes) | 615.1 – 677.4 TF/s (62.2%–68.5%) | ~283 TF/s avg (321 TF/s fwd peak) | ~2.3× |
| HBM STREAM Copy / Triad | 4,292 / 4,371 GB/s (89.4% / 91.1% of 4,800) | 1,269.5 / 1,194.1 GB/s (79.3% / 74.6% of 1,600) | 3.4×–3.7× |
| BF16 Ridge Point | 206 spec · ~158 empirical FLOP/B | 235 spec · 242–252 empirical FLOP/B | 910C more BW-sensitive |
| FP32 Non-TC Vector Peak | 51.1 TF/s GEMM / 45.2 FMA (of 67.0) | 11.06 TF/s (48 AIV cores, Ridge 8.71) | 6.06× (spec) |
2.2Same-Task MFU, MBU & 3DGS Peak Comparison (Gemini 4 Neon, 10h)
Normalized to each chip's empirical roofline, Neon on 910C reaches 92.6% on strict-BF16 NanoChat — nearly matching H200's 93.7%. On ultra-sparse multi-card serving and FP32 3DGS, gaps remain, driven primarily by the 64 GB memory wall (TP=8, EP=8) and silicon specs.
To eliminate discrepancies in nanochat's built-in estimate_flops(), we report both Strict Matmul MFU (6·N_matmul only) and Unified MFU (adding exact causal sliding-window attention, w=512). For Qwen3.8-Flash-Next decode, we report both datasheet MBU and empirical STREAM MBU.
| Task | Metric | H200 (GPU · Neon 10h) | Ascend 910C (NPU · Neon 10h) | Empirical Ceiling Takeaway |
|---|---|---|---|---|
| NanoChat D24 Strict BF16 Pretraining |
MFU | 2×H200 · 1.172× (1.2248→1.0448 s)Strict: 47.36% → 55.52%Unified: 50.19% → 58.84% |
8×910C · 2.176× (7,448→3,422 ms)Strict: 20.49% → 44.60%Unified: 21.72% → 47.27% |
GPU 93.7% vs. NPU 92.6% SOL% Virtually tied; the 11 pp raw MFU gap reflects 910C's higher ridge point & closed Cube/FA floors |
| LLaVA-1.5-7B Multimodal BF16 SFT |
MFU | 2×H200 · 3.12×20.2% → 63.0% |
8×910C 10h: Neon 8.7% → 56.52% (6.46×)GLM-5.4 8.7% → 51.90% (5.99×) |
GPU ~95% vs. NPU ~91% SOL% Under 8-card ZeRO-2 / FSDP comm, Neon closely approaches H200 saturation (GLM-5.4 reaches ~84%, and 59.25% with full skills) |
Qwen3.8-Flash-Nextbs=8, 8K/1024 |
Decode MBU Prefill MFU |
4×H200 TP=4, EP=4 (sglang):MBU 23.4% → 41.9% (R28 50.1%)STREAM 46.0% (R28 55.0%) · Pre 12.5% |
8×910C TP=8, EP=8 (11 Ascend C):MBU 6.62% → 22.25% (3.41×)STREAM 28.1% · Pre 4.40% |
1.6–1.9× STREAM MBU gap, driven primarily by the 64 GB memory wall forcing TP=8, EP=8: MoE ops hit 79% STREAM, while 96× HCCL + launch bubbles take 37% |
| 3DGS (FP32) Full-Scale 30K Iters |
FP32 & BW Peak | 1×H200 truck (2.03M G, 979×546):307.5 → 72.7 s (4.23×)FP32 16.4% · BW ~39% |
1×910C garden (4.18M G, 1297×840):28.10 ms/iter ( 203.5×), 30K 1h 43mFP32 3.88% (raster 5.3%–6.5%) |
910C rasterization has AI 40–60 FLOP/B (Vector-Pipe compute-bound); silicon FP32 peak itself differs by 6.06× |
TP=8, EP=8 forced by 64 GB HBM) — pure HBM floor is 4.64 ms, while 96× HCCL + ~1,200 dispatch bubbles consume 37% of the 16.54 ms step.2.3Trace Analysis: Behavioral Differences & Remaining Gaps
Comparing round-by-round traces on H200 (25 rounds NanoChat, 28 rounds Qwen3.8-Flash-Next, 3DGS) and 910C (13 traces) attributes the remaining gaps to four concrete system and hardware factors:
Gap 1 · Mid-Level DSL Maturity & Priors Mid-level DSL tooling and model priors still lag CUDA/Triton; breaking the framework ceiling often requires Ascend C++ 10h NanoChat: pure-PyTorch GLM-5.4 plateaus at 36.08%; Neon's 10 Ascend C kernels reach 44.60% (+8.52 pp) DetailsClose
On H200, PyTorch → torch.compile → Triton → CUTLASS/CUDA is mature and heavily represented in model pretraining data, letting even mid-tier models capture most fusion gains with short Triton kernels.
On 910C, while community DSLs such as TileLang-Ascend and Triton-Ascend exist, two gaps remain today: (1) they are often absent from default cluster images with narrower coverage on complex backward graphs and irregular memory access (while torchair hits RoPE backward errors and 0.62–1.27 TB/s compiled bandwidth); (2) frontier LLMs have far fewer pretraining priors on TileLang-Ascend / Triton-Ascend. Breaking the framework ceiling therefore required hand-written Ascend C++, widening the gap between Neon (+8.52 pp MFU on NanoChat) and GLM-5.4. As TileLang-Ascend matures and gains dedicated skills, this gap should narrow further.
Gap 2 · Library Openness
Closed-source GEMM boundaries: H200 allows SM90 CUTLASS EVT epilogues; 910C fuses outside the Cube
NanoChat R25 on H200: CUTLASS EVT eliminates intermediate tensor y2, saving 19.3 GB/step HBM3e
DetailsClose
In H200 NanoChat BF16 Round 25, Neon wrote an SM90 CUTLASS EVT epilogue fusing o_proj + residual + rstd and c_fc + relu² scale-folding directly into the GEMM, eliminating intermediate activation y2 and reaching 58.84% MFU (93.7% SOL%).
On 910C, Cube MatMulV2 and FIA are closed-source without custom epilogue hooks, and fused-comm MC2 is unsupported on this stack (EZ1001). Even with 10 AIV kernels running at 80%–90% STREAM bandwidth, ~638 GB/step of unavoidable HBM traffic (~473 ms floor) remains outside the Cube.
Gap 3 · Multi-Card Physical Hardware Limits
Five physical hardware causes behind Qwen3.8-Flash-Next's MBU (28% vs 46%) and Prefill MFU (4.4% vs 12.5%) gap
910C MoE GEMMs already reach 79% STREAM; the gap is driven by the 64 GB memory wall forcing TP=8, EP=8, HCCS latency, ridge point, and Cube/Vector split
DetailsClose
Breaking down Qwen3.8-Flash-Next 176.7B across 8×910C vs. 4×H200 shows five physical hardware constraints dominate the remaining gap:
- 64 GB memory wall forcing
TP=8, EP=8(vs. H200TP=4, EP=4): 360 GB weights fit on 4×H200 (141 GB each) but require 8×910C (64 GB each). Doubling card count doubles the aggregate bandwidth denominator and replicated weight traffic (96 Hyper-Connections, QSA KV heads) without halving fixed sync/launch latencies. - Interconnect latency (HCCS vs. NVLink 4.0): 8×910C executes 96 sequential 8-card HCCL
all_reducecalls per token, taking 3.2–3.5 ms (~35 µs each), whereas 4×H200 has half the ranks on full-mesh 900 GB/s NVLink with NVLS hardware multicast. - High ridge point (242–252 FLOP/B) × fine-grained MoE sharding: 512 experts (
moe_intermediate_size=640) sharded across 8 cards leaveshared_expertdim 80 and 2 GDN K-heads/card, increasing small-GEMM tiling waste on 910C Cube cores. - Physical Cube/Vector separation: Unlike H200 SMs sharing registers/SMEM between Tensor and CUDA cores, 910C's 24 AIC and 48 AIV cores route intermediates through L2/HBM and 192 KB UB, penalizing interleaved GDN+HC+QSA layers.
- Memory headroom caps prefill chunk (
2048vs. H2008192): With ~14.5 GiB free HBM on 8×910C, prefill is capped atchunk=2048, reducing grouped-GEMM batch size by 4×.
Gap 4 · Triage Overhead & FP32 Spec Silent-fallback triage overhead and the 6.06× silicon FP32 vector peak gap Early NPU rounds spend more time diagnosing silent fallbacks; 3DGS FP32 vector peak is 11.06 TF/s on 910C vs. 67 TF/s on H200 DetailsClose
Triage overhead: GPU nsys/ncu pinpoints warp stalls and bank conflicts directly; on NPU, silent fallbacks (bool.scatter_, int32 sort/cumsum, 4D masks) and coarse AICORE_TIMEOUT errors consume extra early rounds.
FP32 silicon positioning: Round 22 confirmed 3DGS rasterization on 910C is Vector-Pipe FP32 compute-bound (AI 40–60 FLOP/B vs. 8.71 ridge point). The 6.06× FP32 peak difference (11.06 vs. 67.0 TF/s) sets the absolute wall-clock gap.
3. Ascend 910C Skills in ResearchBoost-Agent: Bringing NPU Compilation & Optimization to Any Model
Distilling hardware-verified build chains, UB synchronization rules, and fallback workarounds into on-demand reference cards lets different coding models compile custom Ascend C kernels and run deep NPU optimizations without trial-and-error from scratch.
We integrated the progressive-disclosure skills/ascend-opt/ package into ResearchBoost-Agent (PR #17). Its primary entry point, ascend-910c-playbook, pairs a 34-line router (SKILL.md) with 6 focused cards loaded strictly on demand after profiling — keeping startup context to a single metadata line (~560 tokens across all 14 Ascend skills combined):
| Reference Card | Read When | Hardware-Verified Content |
|---|---|---|
01-ascendc-build-and-bridge |
Writing custom Ascend C | CANN 8.5 ascendc_library() minimal CMake, TORCH_LIBRARY(PrivateUse1), stream(true) queue flush |
02-ub-tiling-and-sync |
UB tiling & Split-K | 192 KB UB 32B UbAlloc, zero-PIPE_ALL batched HardEvent::V_S, 48-core Split-K, AIV vs. Cube routing |
03-aicpu-fallbacks-and-cann-pitfalls |
10×–1000× slowdown / mismatch | AiCPU fallback table (bool.scatter_, int32 sort, cumsum), _foreach_copy_ _version, torchair bwd fixes |
04-npugraph-and-comm |
Decode launch / comm overhead | 48L NPUGraph/ACLGraph with HCCL inside, resize_(0) offload leak fix, HCCL_OP_EXPANSION_MODE=AIV |
05-training-fsdp-and-varlen-fa |
Multi-card VLM/LLM training | Bypassing HF 4D masks via TND varlen FA, FSDP no_sync & token load balancing |
06-verification-and-mfu |
Honest MFU/MBU & parity | Lookup-excluded MFU, STREAM MBU, Golden FP32 parity, RL Token-Forcing & 64K Needle checks |
3.1Example Across Models: GLM-5.4 Silicon-Verified on All 4 Tracks (10h Each)
Taking GLM-5.4 as a concrete example: without skills, it abandoned custom Ascend C in NanoChat Round 5 when legacy build configs failed. Once equipped with ascend-opt, GLM-5.4 compiled its first custom Ascend C .so in 20 minutes and completed silicon-verified 10-hour /goal campaigns across all 4 isolated tracks (reaching 5.99× / 51.90% MFU on LLaVA head-to-head and 6.84× / 59.25% MFU with full skill guidance):
| Track (10h Isolated) | GLM-5.4 Silicon-Verified Result | Speedup | Utilization & Parity |
|---|---|---|---|
| LLaVA-1.5-7B 8×910C · Strict BF16 |
18,770 → 3,132.6 ms (Judge 3,145.2 ms, 43.82 GiB); with full skill: 2,744.1 ms (zero recompute, 54.89 GiB) |
5.99× 6.84× (+Skill) |
51.90% MFU (vs. Neon 6.46× / 56.52%); +Skill hits 59.25% MFU (99.4% device busy), both N1 PASS |
| NanoChat D24 8×910C · Strict BF16 |
7,448 → 4,230.4 ms (247.9K tok/s, 38.15 GB, 0.03 ms repeatability) |
1.76× | 36.08% Strict MFU (38.24% Unified, pure PyTorch/torchair, N1 PASS) |
| Faster-3DGS 1×910C · FP32 Ascend C |
13 custom Ascend C kernels (6 binning + fwd/bwd raster + fused Adam); 400×400 429.9 → 15.43 ms, 1297×840 116.3 ms |
27.8× | 9/9 checks PASS (FP32 cos=1.000000, radii_diff=0), 3.5K PSNR 30.45 dB |
| Flash-QSA 64K 1–8×910C · Pure-AIV Ascend C |
Custom "mode 21" pipeline: 64K attn 716.0 → 324.4 ms; 64K decode kernel B=8/16/32 at 0.076 / 0.103 / 0.190 ms |
2.20× | 427.2 GB/s (33.5% STREAM) pure-AIV attn, 72/72 PASS (min cos=0.999991), 64K Needle recalled |
Note: On LLaVA-1.5-7B, 20 rounds of optimization by GLM-5.4 (LPT balancing, removing activation checkpointing, _NpuLinear eliminating 180 MB weight copies, _FlatViews eliminating 405 MB grad concat, side-stream comm & async H2D) drove 8×910C device utilization to 99.4% and 59.25% honest BF16 MFU — approaching 2×H200's 63.0% MFU. On 3DGS and Flash-QSA, GLM-5.4 also authored and verified complete custom Ascend C libraries on silicon.
3.2Quick Start for NPU Users
Pull skills/ascend-opt/ from the ascend branch of ResearchBoost-Agent into your coding agent workspace and pair it with a frozen judge:
# 1. Clone code, custom Ascend C kernels, progressive skills, and all 13 traces
git clone --branch ascend --single-branch \
https://github.com/DAGroup-PKU/ResearchBoost-Agent.git RBA-Ascend
# 2. Install the progressive skill into your agent workspace
cp -r RBA-Ascend/skills/ascend-opt /path/to/your-project/.claude/skills/
# 3. Freeze reference/ and bench/, then run the RBA loop (profile → edit → verify)