Merged
DropOutV3 perf improve by unroll philox & fix nan/inf input precision error #5682
贾剑勇Add on Sep 15
DropOutV3 perf improve by unroll philox & fix nan/inf input precision error #5682
Merged
贾剑勇Add on Sep 15
贾剑勇
贾剑勇Collaborators
Sep 15

描述

DropOutV3 perf improve by unroll philox & fix nan/inf input precision error

关联的Issue

https://gitcode.com/cann/ops-math/issues/3186

测试

精度、性能、冒烟验证ok

文档更新

不涉及

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 贾剑勇's contribution.)
贾剑勇贾剑勇Collaborators
Sep 15 Created pull request, commit 7a714a9e
atomgit-bot
atomgit-bot
Sep 15 Comments:

变更摘要

该 PR 针对 DropOutV3 算子(random/drop_out_v3)做两方面改动:一是通过展开 Philox 随机数生成流水提升性能,二是修复输入含 nan/inf 时的精度错误。核心实现位于 drop_out_v3_simd_impl.h:ComputeContinuousSimd 将原来"逐 batch 生成随机数并 dropout"的单循环重构为多阶段流水(先映射并暂存 counter,再分 3 轮执行 Philox 变换 SpNetworkKernel<4>/<4>/<2>,最后统一计算 dropout),各阶段以 LocalMemBar 同步,尾 batch 单独处理;PhiloxCtrConvertAndDropout 新增 oneFloatReg 参数,mask 应用由 Select 改为先生成 mask 位寄存器再与缩放输入 Mul,避免 nan/inf 经 mask 传播。同时 Tiling 侧移除 transportMode 字段并简化 totalThreads 计算,kernel 调度改为按 vec == 1 选择实现,尾 mask 清零逻辑由首核 Fill<uint16_t> 改为末核逐字节 WriteGmByPassDCache。

主要改动

  • Philox 流水展开(性能优化):ComputeContinuousSimd 将随机数生成拆分为 counter 映射、3 轮 Philox 变换(SpNetworkKernel<4>/<4>/<2>)、dropout 计算三组循环,counter 经 ctrBufPtr 暂存并插入 LocalMemBar 同步,尾 batch 单独走 SpNetworkKernel<10> 逻辑。
  • 修复 nan/inf 输入精度错误:PhiloxCtrConvertAndDropout 增加 oneFloatReg 形参,输出改为 scaledInput 与 mask 位(Select 生成 1/0)相乘,且连续处理路径的分支阈值由 outputSize >= 524288 改为 outputSize > UINT32_MAX_VALUE。
  • Tiling 数据简化:drop_out_v3_tiling_data_arch35.h 删除 transportMode 字段;tiling 中 totalThreads 改为固定 AIC_CLUSTER_COUNT * MAX_THREADS_PER_AIC,UB 中 random float buffer 数量按 vec == NUM_2 取 2、否则取 1,并相应调整 perBlockBytes 与对齐校验。
  • 调度与尾 mask 清零调整:drop_out_v3.cpp 由按 transportMode 改为按 tilingData.vec == 1 分发到 DropOutV3Impl/DropOutV3SimdImpl;Process 中尾字节清零从 blockIdx_ == 0 的 Fill<uint16_t> 改为末核(usedCoreNum - 1)逐字节 WriteGmByPassDCache,并移除 SyncAll()。
  • 单测期望值更新:test_drop_out_v3_tiling.cpp 同步更新 tiling 数据期望串(移除 transportMode、更新 totalThreads)。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 15 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 15 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 15 Comments:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/ops-math ✅ xuejinghui, 汤平川 (2/2) ✅ 汤平川, xuejinghui (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

jia-jianyong, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Sep 15 Set yue-ma,zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding as approver
CANN-robotCANN-robotCollaborators
Sep 15 Set yue-ma,zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding as approver
贾剑勇
贾剑勇Collaborators
Sep 15 Comments:

compile

likedislike
贾剑勇贾剑勇Collaborators
Sep 15 Pre merge succeeded (commit_id: a9df8b2edb58935fbe3dd053ce86139408a8b278)
CANN-robot
CANN-robotCollaborators
Sep 15 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 15 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 15 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 15 Added label: ci-pipeline-passed
贾剑勇贾剑勇Collaborators
Sep 15 Modify description of pull request
xuejinghui
xuejinghuiCollaborators
Sep 15 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 15 Added label: approved
TangPC
TangPCCollaborators
Sep 15 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 15 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 15 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 15 Merged pull request