Pull Request已成功合入, 合并人@CANN-robot
(感谢 liuchuangdev 的贡献)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 |
|---|---|---|
| pooling | ✅ 黄迪, 章武 (2/2) | ✅ 黄迪 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
liuchuangdev, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


流水线任务触发成功
任务链接 [b22719dcd3ee4201abcb0d82abec78f5][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer-chs-nn | ✅ SUCCESS | >>>>> | |
| UT_Test_ophost | ❌ FAILED | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |


流水线任务触发成功
任务链接 [0bd4a571dffe43ac84aa568215ff9764][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_style | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ⚠️ WARNING | >>>>> | >>>>> |
| SCA | ❌ FAILED |


变更摘要
此 PR 对 MaxPool3DGradWithArgmax 算子在 arch35 上的 SIMD 内核进行了性能优化。核心思路包括:将多层循环的 DataCopy 合并为整块 D×H×W 平面单次搬运;删除 helpBuf_ 辅助缓冲区,改为寄存器直接生成索引;引入 DivMagic/PrecomputeDiv 快速除法替代 MicroAPI::Div;在全载模板 fullLoadMultipleLineProcessVF2 中对 highBlockIdx 循环进行两两合并;同时对 FilterMask3D 和 IndexConvNcdhwFastDiv 等函数签名与实现做了适配性改造。
主要改动
-
DataCopy 平面化优化: 在
max_pool3d_grad_with_argmax_simd_full_load.h的CopyIn中,将原先基于LoopMode按 d/h 维度分次搬运的DataCopyPad改为单次搬运整块highAxisActual_ × dhwPlaneBytes平面,新增dhwPlaneAligned_成员将 D×H×W 对齐到MAX_DATA_NUM_IN_ONE_BLOCK,消除多层 DataCopy 调度开销。 -
移除
helpBuf_辅助缓冲区: 从MaxPool3DGradWithArgmaxNCDHWKernel和MaxPool3DGradWithArgmaxNCDHWFullLoadKernel中删除TBuf<QuePosition::VECCALC> helpBuf_成员及其初始化,所有fullLoad*函数不再接收helpAddr参数;索引生成改用GenInitial3DIndicesFast、GenInitial4DIndicesFast等寄存器直接计算方式,不再通过 UB 预计算表 +DataCopy读取。 -
快速除法替代
MicroAPI::Div: 新增DivMagic结构体和PrecomputeDiv/FastDivInt32工具函数,在max_pool3d_grad_with_argmax_simd.h中新增GenInitial*IndicesFast、Gen3DIndexOneFast、Gen4DIndexOneFast、Gen3DHighIndexOneFast等系列函数,使用GetUintDivMagicAndShift+FastDivImpl进行坐标索引的快速整数除法;IndexConvNcNcdhwFullLoad中的high维输出索引计算同步改用快速除法。 -
循环合并减少开销: 在
fullLoadMultipleLineProcessVF2中将原先 4 个独立的for highBlockIdx主循环两两合并为 2 个、4 个尾部循环两两合并为 2 个,并将highArgmaxOffset/highOutputOffset的计算外提到循环外部通过步进累加实现;非全载模板multipleLineProcessVF2同步应用相同合并策略。 -
FilterMask3D与索引函数签名改造:FilterMask3D的掩码生成从串行gtMask逐维比较-取交改为并行生成hMask/wMask/dMask后一次性MaskAnd;IndexConvNcdhwFastDiv参数从int32_t的dIndexReg/hIndexReg/wIndexReg改为uint32_t的dTmpReg/hTmpReg/wTmpReg,移除了curDIndex/curHIndex/curWIndex偏移减法,改用baseOffset统一偏移。


compile


流水线任务触发成功
任务链接 [904c3cf0f31540a98efbd94034746ca3][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer-chs-nn | ✅ SUCCESS | >>>>> | |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-07-02 12:23:12] CI执行结束


流水线任务触发成功
任务链接 [7fc6112fd1564779bdc4c9f63892f0b8][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_style | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ⚠️ WARNING | >>>>> | >>>>> |
| SCA | ✅ SUCCESS | >>>>> |
[2026-07-02 12:18:32] CI执行结束


代码审查
Closing Summary
已逐一审查了全部 5 个变更文件:
| 文件 | 审查结果 |
|---|---|
max_pool3d_grad_with_argmax_simd_tiling.cpp |
1 个 P3 发现(KSIZE_STRIDE_RATIO_THRESHOLD 未使用) |
max_pool3d_grad_with_argmax_simd.h |
无问题(快速除法工具函数、FilterMask3D 语义修正均正确) |
max_pool3d_grad_with_argmax_simd_full_load.h |
1 个 P3 发现(indexIncReg 参数未使用) |
max_pool3d_grad_with_argmax_simd_impl.h |
无问题(非全载模板同步优化正确) |
test_max_pool3d_grad_with_argmax_tiling.cpp |
1 个 P3 发现(dlog_setlevel 被注释) |
发现统计: P0: 0, P1: 0, P2: 0, P3: 3
整体风险评估:低。
此 diff 是一个性能优化变更,主要涉及:(1) DataCopy 从 LoopMode 改为单次 DataCopyPad 整块搬运;(2) 移除 helpBuf_ 辅助缓冲区并用寄存器直接生成索引;(3) 引入快速整数除法 (FastDivInt32/PrecomputeDiv) 替代 MicroAPI::Div;(4) 循环合并减少开销;(5) 条件化 isCheckRange 在无膨胀时跳过范围检查。
核心逻辑(FilterMask3D 边界检查语义、DataCopyPad 对齐计算、快速除法等效性)经审查均为正确。没有发现正确性、安全性或可靠性方面的 P0–P2 级别问题。三个 P3 发现均为代码清洁度问题,不影响功能。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


🟡 Medium Priority
在 multipleLineProcessVF2 函数第 741 行:
dArgmaxActual 和 hArgmaxActual 均为 uint16_t 类型。根据 C++ 整型提升规则,uint16_t * uint16_t 会在 int(32 位有符号)域中计算,最大值 65535 × 65535 ≈ 4.29×10⁹ 超过 INT32_MAX(2.14×10⁹),触发有符号整数溢出(UB)。溢出后的错误值随后才提升为 int64_t 与 wArgmaxAligned 相乘。
highStride 被用于 GenInitial4DIndicesFast 和 Gen4DIndexOneFast 的索引生成(第 833-844 行调用),错误的高维步长将导致梯度累加到错误的输出位置,产生精度错误。
虽然当前 UB 容量(256KB)限制了 dArgmaxActual * hArgmaxActual * sizeof(T2) 的实际取值,使该溢出在现有硬件上不易触发,但这属于项目规范明确禁止的"乘法链转换滞后"模式(32 位中间乘法后赋给 64 位),且若未来 UB 容量增大或 T2 为更小类型时将成为真实 bug。
建议:在乘法链首显式转换为 int64_t,使整个乘法在 64 位域中完成:
| 741
| - int64_t highStride = dArgmaxActual * hArgmaxActual * wArgmaxAligned; |
|
741 | + int64_t highStride = static_cast<int64_t>(dArgmaxActual) * hArgmaxActual * wArgmaxAligned; |


/lgtm
/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
优化 MaxPool3DGradWithArgmax 算子在 arch35 上的 SIMD 内核性能,主要改动如下:
1. DataCopy 优化
dhwPlaneAligned_成员,将 D×H×W 平面对齐到MAX_DATA_NUM_IN_ONE_BLOCK,使单次 DataCopy 可行2. 移除 helpBuf_ 辅助缓冲区
TBuf<QuePosition::VECCALC> helpBuf_及所有 fullLoad 函数的helpAddr参数GenInitial3DIndicesFast、GenInitial4DIndicesFast等),消除 DataCopy 开销3. 快速除法优化
PrecomputeDiv/DivMagic快速整数除法替代MicroAPI::DivGetUintDivMagicAndShift+FastDivImpl替代MicroAPI::Div4. 循环合并
fullLoadMultipleLineProcessVF2:将 4 个for highBlockIdx循环两两合并为 2 个,4 个尾部循环两两合并为 2 个,减少循环开销和重复 offset 计算multipleLineProcessVF2同步应用循环合并优化涉及文件
max_pool3d_grad_with_argmax_simd.h:新增 fast div 工具函数max_pool3d_grad_with_argmax_simd_full_load.h:全载模板核心优化max_pool3d_grad_with_argmax_simd_impl.h:非全载模板同步优化max_pool3d_grad_with_argmax_simd_tiling.cpp:tiling 参数适配关联的Issue
#3739
测试
主线性能用例测试、门槛用例回归、冒烟测试
文档更新
无
类型标签