已开启
[Huawei][AscendNPU IR] feat: support CustomOp & CustomMacroOp in TileAndBindSubBlock Pass for sub-block 1:2 tiling #1293
sunteng创建于 6月29日
[Huawei][AscendNPU IR] feat: support CustomOp & CustomMacroOp in TileAndBindSubBlock Pass for sub-block 1:2 tiling #1293
已开启
合并受阻
6月29日 关联了issue:[社区任务]: customOp功能泛化-CV切分
ascend-robot
6月29日 评论:
6月29日 评论:
libing-pipeline创建中,请等待……


bishengir/test/Integration/HIVM/CustomOpTileAndBind/kernels_impl/add_custom_probe.py
已过期
@@ -0,0 +26,4 @@
26+import torch
27+try:
28+ import torch_npu # noqa: F401
29+except Exception as e: # pragma: no cover
30+ print(f"[warn] torch_npu import failed: {e}", file=sys.stderr)
【openlibing.ci】识别到代码检查告警抑制注释,匹配工具:flake8,请Committer检视其合理性。


sunteng
7月22日 评论:
7月22日 评论:
fixed
bishengir/test/Integration/HIVM/CustomOpTileAndBind/kernels_impl/mm_custom_probe.py
已过期
@@ -0,0 +24,4 @@
24+import torch
25+try:
26+ import torch_npu # noqa: F401
27+except Exception as e: # pragma: no cover
28+ print(f"[warn] torch_npu import failed: {e}", file=sys.stderr)
【openlibing.ci】识别到代码检查告警抑制注释,匹配工具:flake8,请Committer检视其合理性。


sunteng
7月22日 评论:
7月22日 评论:
fixed
此处折叠了917条消息 查看更多
sunteng
5 天前 评论:
5 天前 评论:
npuir-smoke


5 天前 添加了label:NPUIR-DT-RUNNING
5 天前 删除了label:NPUIR-DT-RUNNING
5 天前 添加了label:NPUIR-DT-SUCC
AtlasAccount
5 天前 评论:
5 天前 评论:
流水线 pipeline_npuir-smoke#3032 [ commitID:fb2fcf5a ] 已完成
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Compile | ✅ COMPLETED | >>> |
| 开发者测试 | CVOps | ✅ COMPLETED | >>> |
| TritonOps | ✅ COMPLETED | >>> | |
| TritonOps_Reduction | ✅ COMPLETED | >>> | |
| TritonOps_Feature_test | ✅ COMPLETED | >>> | |
| DSA_NSA_MLA | ✅ COMPLETED | >>> | |
| Mojo | ✅ COMPLETED | >>> | |
| Verl | ✅ COMPLETED | >>> | |
| LigerKernel | ✅ COMPLETED | >>> | |
| Sglang | ✅ COMPLETED | >>> | |
| Vllm | ✅ COMPLETED | >>> | |
| 流水线 | pipeline_npuir-smoke | ✅ COMPLETED | >>> |
- npuir-smoke : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


Fixes #256
描述 Description
本 PR 让满足安全切分条件的
hivm.hir.custom和hivm.hir.custom_macro参与TileAndBindSubBlock的 sub-block 1:2切分。切分后,CustomOp、CustomMacroOp 及其下游 Store 使用一致的 tile 范围,使 Vector/AIV 计算能够在两个 sub-block 上并行执行。
两个算子共享
HIVM_CustomOp基类和HIVMStructuredOpInterface。本实现将维度分析和 slice bubble-up 抽象为 Custom-like 通用逻辑;对于 CustomMacroOp 的同步语义,以及当前尚无安全锚点的 leaf 场景,保持保守限制。本次补充修复以下两个由 Softmax CustomOp E2E 验证发现的问题:
no_side_effectCustomOp 在 bufferization 后仍会写入声明的 DPSoutput,不能被 canonicalization 或 DCE 当作无写入操作删除。
根据
iterator_types和indexing_map标记 reduction 维,确保TileAndBindSubBlock 只切分 parallel 维。
核心改动
1. Custom-like 维度分析
新增统一的 Custom-like 维度分析逻辑,处理
CustomOp和CustomMacroOp:iterator_types和indexing_map时,不建立输入、输出和结果之间的可切分维度关系,并保守回退。
expression 建立输入、输出和结果之间的维度关系。
不变。
iterator_types和各 operand/result 的 indexing map 显式标记reduction 维。
范围,只对 parallel 维执行 1:2 切分。
2. Slice bubble-up
新增
CustomOpBubbleUpStrategy,根据结果tensor.extract_slice计算 Custom-like 算子的 tile-local 输入和输出:iterator_types和indexing_map;任一属性缺失时保守回退。
构造的 slice。
operandSegmentSizes。3. Reduction 轴切分规则
对于包含 reduction iterator 的 CustomOp:
Softmax 覆盖两种典型布局:
4. no_side_effect 和 DPS output 语义
no_side_effect表示 CustomOp 没有未声明的隐藏副作用,不表示其声明的 DPS output 是只读的。tensor CustomOp 完成 bufferization 后不再依赖 SSA result 保持存活。如果丢失 output write effect,canonicalization 或 DCE 可能删除CustomOp library call,导致 Store 读取未初始化的 output buffer。
本实现对 CustomOp 和 CustomMacroOp 保留保守的 resource-levelRead/Write effect,从而保证:
no_side_effectCustomOp 的声明输出仍被视为有效写入。设备端 A/B 验证表明,移除该 effect 后 Softmax CustomOp 会被删除,baseline 输出全部为 0;恢复后精度与性能测试均通过。
5. 保守回退条件
当前仅对能够证明安全的场景执行切分。以下情况会保守回退,保持Custom-like 算子全量执行,并在需要时通过 sub-block 保护避免重复
执行:
sync_event_slots或sync_related_args。iterator_types或 indexing map 缺失、不完整。expression。
这些限制用于保证当前 1:2 切分的执行安全。后续只有在明确 per-sub-block buffer ownership、事件同步和更一般的 indexing semantics 后,才会进一步放宽。
6. Leaf Custom-like 行为
当前不支持没有 Store/Copy 等下游切分锚点的 leafCustomOp/CustomMacroOp 切分。
此类算子保持全量执行;如果不能证明重复执行安全,则限制在sub-block 0 执行。
7. MIX kernel 符号和 sub-block 执行
或 DCE 阶段错误删除。
operand 正确传递。
sub-block 范围。
测试验证 Testing
1. 主仓 LIT:CustomOp 切分结构
主要测试文件:
CustomOp 覆盖:
iterator_types/indexing_map的保守回退。transpose map 和 too-small shape 等保守回退场景。
CustomMacroOp 覆盖:
sync_event_slots场景的全量执行与 sub-block 0 保护。#0、#1结果。执行命令:
结果:
2. 主仓 LIT:memory effect 和 bufferization
新增或扩展:
验证:
no_side_effectmemref CustomOp 不会被 canonicalization 删除。3. 主仓完整回归
执行:
LIT_OPTS="--timeout=30 -j 4" \ ninja -C build check-bishengir LIT_OPTS="--timeout=30 -j 4" \ ninja -C build check-mlir结果:
端到端精度与性能测试
端到端测试按照社区规范放置在 AscendNPU-IR-DT仓库。
请填写 AscendNPU-IR-DT PR 链接37e32605测试设备和编译后端:
Ascend910_9382c220hivmcAscend950PR_9579c310hivmc-a5950 环境使用源码构建的
bishengir-compile,并使用与 CANN 9.1.0 配套的hivmc-a5完成设备二进制编译。1. 通用 CustomOp 精度
通过 Triton-Ascend
al.custom构造真实 Mix Cube/Vector 链路:覆盖 7 条 E2E 精度用例:
覆盖 identity、broadcast、parallel/reduction、多输出,以及
f16、bf16、f32。2. Softmax CustomOp 精度
新增基于数值稳定实现的 Softmax CustomOp:
覆盖以下 shape 和 reduction 轴:
64x64128x64256x64128x12864x12864x256128x128同时比较 baseline、tiled 和 PyTorch Reference,并验证沿 reduction轴的概率和接近 1。
上述用例已分别在 Ascend 910B2 和 Ascend 950PR 上通过。
3. 简化 Flash Attention
测试流程为:
编译后的 Mix kernel 包含:
最终
PV在 kernel 外执行,用于验证 Softmax 输出进入 Attention后续计算后的最终精度,不额外引入与本 PR 无关的CustomOp-to-Cube 切分规则。该用例已分别在 Ascend 910B2 和 Ascend 950PR 上通过。
4. 性能测试
比较同一个 Mix kernel 的两种编译配置:
计时范围:
测试方法:
0.98x;1.05x。Ascend 910B2
128x64256x64128x12864x12864x256128x128性能收益范围为
1.994x–1.997x,几何平均约为1.996x。Ascend 950PR
128x64256x64128x12864x12864x256128x128性能收益范围为
1.997x–1.998x,几何平均约为1.998x。两种设备上的 reduce-first 和 reduce-last 用例均获得接近 2 倍的性能收益,表明 TileAndBindSubBlock 保持 reduction 维完整并切分parallel 维后,两个 Vector sub-block 能够有效并行执行。
5. DT 测试结果
精度测试命令:
每种设备覆盖:
精度测试结果:
性能测试命令:
性能测试结果:
测试职责边界
CustomMacroOp 当前没有 Triton 前端接口,因此设备端 E2E 不覆盖
CustomMacroOp;其切分结构、同步限制和回退行为由主仓 LIT 验证。
测试环境说明
Ascend 950PR 测试期间,
npu-smi在测试前后均显示Health: Alarm。设备无其他运行进程,温度保持在 58–59℃,各组计时标准差接近 0,性能结果稳定。该设备健康状态作为测试环境限制记录。类型 Category
Checklist