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


compile


/approve


流水线任务触发成功
任务链接 [078b270410ba482a9adaea4b79d80931][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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 15:18:14] CI执行结束


流水线任务触发成功
任务链接 [125b836cc0334d4f9464bac9f36ec213][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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 15:13:48] CI执行结束


变更摘要
此 PR 主要围绕 AdaptiveAvgPool2dGrad 算子进行性能优化,涉及 host 端 tiling 策略、kernel 端计算流程以及 SIMT 内核的全方位改进。Host 端引入了基于成本模型的穷举搜索机制来寻找最优 tiling 参数,并新增了多种 SIMT 回退判定逻辑,将更多特定形状路由至 SIMT 内核执行。Kernel 端(small kernel)将 H 维度的索引计算从标量模式改为矢量化的 SIMD 批量计算,消除了 CalcOutputRangeFromInputIndex 标量函数,同时引入 highAxisLocalStride_ 对齐步长以提升访存效率。SIMT 内核则大幅扩展,新增了 6 个针对不同 resize 场景(H=1、小输出 W、H 上采样/下采样等)的特化变体,并通过分段预处理策略减少冗余计算。
主要改动
-
Host 端新增穷举搜索 tiling 策略: 在
SearchBestTiling中增加了ExhaustiveSearchBestTiling函数,对highAxisInner、hOutputInner、wOutputInner进行三维遍历搜索,通过EvalTilingCandidate成本模型(含AddCostPenalties惩罚项)评估每个候选配置,由TryRecordBetterTiling记录全局最优解;搜索失败时回退到ApplyCoarseFallback粗粒度策略。 -
Host 端新增 SIMT 回退判定: 在
IsCapable中增加了preferSimtInputAsGradY/preferSimtOutputAsGradY以及preferSimtUnfriendlyResize等多条件判断,当检测到强 resize 比例、小 W 尺寸或特定上下采样组合时返回false,使这些场景交由 SIMT 内核处理以获取更好性能。 -
Small Kernel 端 H 维度计算矢量化: 移除了标量函数
CalcOutputRangeFromInputIndex,换用MicroAPI对 H 维度的stH/edH/coverH进行批量(INDEX_VF_LEN)计算(与 W 维度对称);新增stHRegBuf_、edHRegBuf_、coverHRegBuf_和invCoverWRegBuf_缓冲区,并将invCoverH与invCoverW分拆相乘代替原来的1/(coverH*coverW)单次除法。 -
Small Kernel 端引入
highAxisLocalStride_对齐: 将 kernel 内部多处原本使用tiling_->highAxisInner的地址偏移计算改为使用CeilAlign对齐后的highAxisLocalStride_,提升 UB 内访存对齐度。 -
SIMT 内核新增 6 个特化变体及调度逻辑: 新增
AdaptiveAvgPool2dGradHInOne、AdaptiveAvgPool2dGradSmallOutWRow、AdaptiveAvgPool2dGradSmallOutWSegFast、AdaptiveAvgPool2dGradOutWSmall、AdaptiveAvgPool2dGradHExpandExactOutWSmallFast、AdaptiveAvgPool2dGradHReduceWExpandFast和AdaptiveAvgPool2dGradHExpandW2SmallFast等内核变体,Process方法根据输入形状(hIn==1、wOut为 2/3/4、H 上/下采样等条件)进行分支调度;同时SIMT_PARAMS_NUM从 32 增至 64,新增分段的 magic 参数与 segment 信息预处理。


代码审查
审查总结
本 diff 对 AdaptiveAvgPool2dGrad 算子进行了大规模性能优化,涉及 tiling 搜索策略重构、内核向量化计算重组、以及 SIMT 快速路径扩展。整体代码质量较高,核心逻辑(tiling 搜索、内核向量化、SIMT 分派)经过仔细审查,数学正确性和边界处理均未见实质缺陷。
各文件审查结果
| 文件 | 发现问题 |
|---|---|
adaptive_avg_pool2d_grad_nchw_small_kernel_tiling.cpp |
P2 ×1, P3 ×1 |
adaptive_avg_pool2d_grad_nchw_small_kernel_tiling.h |
无问题 |
adaptive_avg_pool2d_grad_nchw_small_kernel.h |
无问题 |
adaptive_avg_pool2d_grad_simt.h |
无问题 |
test_adaptive_avg_pool2d_grad_tiling.cpp |
无问题 |
按严重程度统计
- P0: 0 个
- P1: 0 个
- P2: 1 个(PrintSplitData 调试输出丢失)
- P3: 1 个(死代码变量 computeVl)
整体风险评估:低风险
两个已报告的问题均为代码质量/可维护性层面,不影响算子的计算正确性。建议在合入前恢复 PrintSplitData 的日志输出,以保持线上调试能力。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
⛔ 需要修改


🟡 Medium Priority
变更行 611–622:PrintSplitData() 原先通过 OP_LOGI 输出 splitData 中各字段的详细调试信息(包括 highAxisInner、hOutputInner、wOutputInner、totalBufferSize 等十余项关键数据)。新代码只计算了 highAxisPadding、highAxisValidRate、ubUseRate、coreUseRate 四个派生指标,但末尾的 OP_LOGI/OP_LOGD 调用被完全删除,这些计算结果未输出到任何地方。
影响:该函数在 DoOpTiling() (第 629 行) 被调用,是算子运行时唯一的调试/可观测性输出路径。移除后,当出现 UB 超限、core 使用率异常等问题时,开发者无法从日志中获取 split 数据的运行时快照,调试能力严重退化。
建议:恢复对 splitData 各字段的日志输出,并将新计算的 highAxisPadding / highAxisValidRate / ubUseRate / coreUseRate 也一并输出。例如在函数末尾添加:
OP_LOGI("AdaptiveAvgPool2dGradNCHW", "highAxisPadding=%ld validRate=%.2f ubUseRate=%.2f coreUseRate=%.2f", ...);
同时至少保留旧代码中总 bufferSize、usedCoreNum 等核心字段的输出。


/approve


The following users do not have permission to comment /lgtm or /approve on any module in this PR:
刘闯


/lgtm


The following users do not have permission to comment /lgtm or /approve on any module in this PR:
刘闯


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.


描述
一、SIMT 模板性能优化:针对 H 方向扩张、outW 较小、inH 为 1、小 W 行聚合等场景新增专用快路径。通过 W segment 合并计算、边界权重快速处理、行级复用和连续区间批量写回,减少逐点反查 gradY、重复窗口计算、重复累加和除法开销,提升特殊 shape 下的执行效率。
二、SIMD small kernel 模板性能优化:tiling 侧调整准入条件,将 SIMD 优化空间较小的极端 H/W 扩张或压缩场景转由 SIMT 处理;同时优化切分策略,综合评估 buffer 开销、block 数、core 利用率、highAxis padding 和尾块 VL 利用率,选择更优切分,减少 UB 转置和无效计算开销。
关联的Issue
https://gitcode.com/cann/ops-nn/issues/3743
测试
本地批跑500条性能用例均无功能性问题,优化后的性能单case均达标,二级冒烟和obp冒烟均无异常
文档更新
类型标签
AI/Agent生成声明