Pull Request已成功合入, 合并人@CANN-robot
(感谢 qianzehong 的贡献)Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| math/mul | ✅ 周奇龙, 宋凯 (2/2) | ✅ 周奇龙, 宋凯 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
qianzehong, thanks for your pull request. All authors of the commits have signed the CLA. 👍


950 上板端到端验证(自定义编译 aclnnMul 实跑)
用 build.sh --pkg --soc=ascend950 --ops=mul 编出含本改动的自定义 vendor 包(libcust_opapi.so 导出 aclnnMulGetWorkspaceSize),--extract 到独立路径并经 ASCEND_CUSTOM_OPP_PATH 让 torch_npu 的 torch.mul 解析到改动后的 aclnnMul(未改系统内置 opp)。开 INFO 日志跑 2 个命中 case + 1 个对照 case:
| Case | 输入 | MulPreferContiguous | Mul tiling | 正确性 |
|---|---|---|---|---|
| 89418(命中) | self[381,4800,1] × other[1,4800,1] s[312000,65,1] off64 |
✅ 触发 → 转连续 | inputAllContiguous 0→1 |
correct=True |
| 89424(命中) | self[381,688,1] × other[1,688,1] s[22704,33,1] off32 |
✅ 触发 → 转连续 | inputAllContiguous 0→1 |
correct=True |
| 89399(对照) | self[381,32,1] s[4128,129,1] off128 × other[1,32,1] s[1056,33,1] |
❌ 不触发(payload=32 太小) | inputAllContiguous:0(保持非连续) |
correct=True |
关键日志(节选):
>>>BEGIN 89418_FLAG
[INFO] aclnn_mul.cpp:523 [MulPreferContiguous] aclnnMul_5: sparse-broadcast operand detected, route to Contiguous + Mul instead of non-contiguous kernel.
[INFO] aclnnMul_5_Contiguous ... x: [381, 4800, 1]
[INFO] aclnnMul_5_Contiguous ... x: [1, 4800, 1] strides[312000,65,1] off64
[INFO] [OPS_MATH_CUSTOM][Mul] DoTiling coreNum:56 inputAllContiguous:1
>>>END 89418_FLAG correct=True
>>>BEGIN 89399_keep
[INFO] [OPS_MATH_CUSTOM][Mul] DoTiling coreNum:56 inputAllContiguous:0 ← 对照组保持非连续,未误触发
>>>END 89399_keep correct=True
OPS_MATH_CUSTOM tiling tag + aclnn_mul.cpp:523 行号确认跑的是本 PR 代码。结论:两个非连续 Mul kernel 劣化 case 正确改走「转连续 + l0op::Mul」,对照组保持非连续不误触发,全部数值正确——与离线基准(89418 4.4x / 89424 1.7x)一致。
设备:Ascend950PR,CANN 9.1.0,torch 2.8 + torch_npu 2.8.0.post4。


compile


描述
非连续 Mul kernel 在「外层广播 + 内层稀疏 gather」的输入上严重劣化(典型来自 RoPE cos/sin 表的
[1, N, 1]视图,stride 含 +1 对齐 padding,最内连续块仅 1 个元素,且被外层广播重复读 K 次)。基于 Ascend950 上板基准(lm eager 网络的 mul 非连续 case,npu.Event 设备侧计时,三轮稳定):
[1,4800,1]strides[312000,65,1][1,688,1]strides[22704,33,1]而转置大张量(
[80,381,640]等 0.36~0.52)、大张量带 padding 切片、纯 stride-0 广播等场景非连续 kernel 仍更优,因此只在命中退化模式时回退。改动
在
aclnnMulGetWorkspaceSize中新增MulPreferContiguous(self, other)判定:任一输入同时满足MulBroadcastFactor >= 8(被重复读 K 次)MulViewNumel >= 256MulInnerContiguousRun < 32(无可向量化连续块)时,把两个非连续门(
isSupportNonContiguous与 normal 分支的IsMulSupportNonContiguous条件)置假,走原有的l0op::Contiguous+l0op::Mul路径。阈值均为具名constexpr,便于回归微调。关联的Issue
#1965
测试
-fsyntax-only -Wall -Wextra编译零错误零告警。文档更新
无需更新文档
类型标签