已合并
add gatherV2 simd small inner template #7349
z30075199创建于 7月10日
add gatherV2 simd small inner template #7349
已合并
z30075199创建于 7月10日
z30075199成员
7月10日

描述

gatherV2算子新增simd小尾轴模板

关联的Issue

https://gitcode.com/cann/ops-transformer/issues/3721

测试

文档更新

类型标签

  • Bug修复
  • 新特性
  • 性能优化
  • 文档更新
  • 其他,请描述:

AI/Agent生成声明

  • AI辅助编写
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 z30075199 的贡献)
Zz30075199成员
7月10日 创建了 pull request,commit 424f9a7f
atomgit-bot
atomgit-bot
7月10日 评论:

变更摘要

此 PR 主要为 gatherV2 算子新增了 PCIe 场景的 SIMD 内核支持,并在 embedding 算子中简化了 GatherV2 的调用路径。核心思路是:当检测到输入/输出张量地址落在 PCIe 地址空间(0x40000000000 ~ 0x80000000000)时,路由到新增的 Gatherv2SimdPcieGatherv2SimdTwoDimPcie 内核;同时,tiling 数据结构补充了 gatherSizedtypeSize 字段,以支持 PCIe 内核的 buffer 计算。Embedding 侧则移除了不再需要的 NoContiguousEmbedding 内核分支,统一收敛到 GatherV2/GatherV2WithImplMode

主要改动

  • 新增 PCIe SIMD 内核 Gatherv2SimdPcie: 在 gather_v2_simd_pcie.h 中实现了模板类 Gatherv2SimdPcie,基于 double-buffer (BUFFER_NUM_SIMD_PCIE = 2) 的 VecIn/VecOut 流水线,支持按列不拆分 (NoSplitColProcess) 和按列拆分 (SplitColProcess) 两种处理模式,并内嵌 indices 的按需分块加载 (GetIndex) 和最近三次 xIndex 缓存去重。

  • 新增 PCIE SIMD Two-Dim 内核 Gatherv2SimdTwoDimPcie: 在 gather_v2_simd_two_dim_pcie.h 中实现了模板类 Gatherv2SimdTwoDimPcie,针对 gatherSize 维度多核切分场景,提供与 Gatherv2SimdPcie 类似的双模式处理和 indices 分块加载逻辑,使用独立的 tiling 结构 GatherV2TilingDataSimtTwoDim

  • 内核调度新增 PCIe 地址判断: 在 gather_v2_apt.cpp 中,对 SIMT_TWO_DIM_*TILING_KEY_X_* 两类 tiling key,运行时根据 addrX/addrIndices/addrAxis/addrY 是否落入 PCIe 地址范围,动态选择 PCIe 内核 (Gatherv2SimdPcie / Gatherv2SimdTwoDimPcie) 或原有内核;同时将原本由 #if 预编译分发的 SIMD_TILING_KEYSIMD_TILING_KEY_TWO_DIM 等分支改为 #elif 运行时路由。

  • Tiling 数据结构扩展: 在 gather_v2_tiling.hGatherV2TilingDataSimtTwoDim 中新增 gatherSizedtypeSize 两个字段;在 gather_v2_tiling.cppCalcCoreElement() 中追加了 set_dtypeSize 调用,在 SimtTwoDimTiling() 中追加了 set_gatherSizeset_dtypeSize 调用,以向 PCIe 内核传递必要的 tiling 参数。

  • Embedding 算子简化 GatherV2 调用路径: 在 aclnn_embedding.cpp 中移除了 IsUseNoContiguous/CalNoContiguous 分支和 CheckEmbeddingKernel/l0op::Embedding 降级路径,统一走 Contiguous 转换后调用 GatherV2WithImplMode(高性能模式)或 GatherV2,减少分支复杂度。

likedislike
atomgit-bot
atomgit-bot
7月10日 评论:

代码审查

Now I have completed my thorough analysis of all six changed files. Let me provide the closing summary.


审查总结

各文件审查结果

文件 审查结论
index/embedding/op_api/aclnn_embedding.cpp 发现 1 个问题:移除了 IsUseNoContiguous 路径和 CheckEmbeddingKernel/Embedding 回退,可能导致功能回归 (P2)
index/gather_v2/op_host/arch35/gather_v2_tiling.cpp 无问题。改动为在 CalcCoreElement 中补充了缺失的 set_dtypeSize(修复了 bug),在 SimtTwoDimTiling 中正确设置了新增的 gatherSizedtypeSize 字段,其余为缩进格式调整
index/gather_v2/op_host/arch35/gather_v2_tiling.h 无问题。新增字段 gatherSizedtypeSize 正确追加在 GatherV2TilingDataSimtTwoDim 末尾,符合 TilingKey 规则
index/gather_v2/op_kernel/arch35/gather_v2_simd_pcie.h 发现 3 个问题needCoreNum_ 类型收窄 (P3)、dcacheSize 计算与 tiling 不一致 (P2)、kernel 重新计算 tiling 参数忽略 host 下发值 (P2)
index/gather_v2/op_kernel/arch35/gather_v2_simd_two_dim_pcie.h gather_v2_simd_pcie.h 共享同样的 tiling 参数重新计算问题 (P2);无其他独立问题
index/gather_v2/op_kernel/gather_v2_apt.cpp 无问题。PCIe 地址范围检查和路由逻辑正确,addrX/addrY/addrIndices/addrAxis 计算模式与框架一致

问题统计

  • P2: 3 个(kernel 重新计算 tiling 参数 × 2 kernel 合并为 1 个、dcacheSize 不一致、Embedding 回退移除)
  • P3: 1 个(needCoreNum_ 类型收窄)
  • P0/P1: 0 个

总体风险评估

中等风险。改动引入的新 PCIe kernel 在功能上与已有 SIMD kernel 基本对应,事件同步模式继承自已有代码,核心逻辑路径没有明显的 correctness 缺陷。但存在三个值得关注的 P2 问题:PCIe kernel 在设备侧重新计算 tiling 参数而非使用 host 下发的值、UB 计算中的 dcacheSize 不一致、以及 embedding 接口中移除了备选执行路径。建议在合入前确认这些设计决策是有意为之,且不会在特定输入/平台组合下触发回归。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
CANN-robotCANN-robot成员
7月10日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月10日 评论:

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 /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
7月10日 将crystalhu,yangyang016,fanqirui,chenqi317,liubo75,tangweiwei2,gitcode-chenjiao,gcw_kUomxQ2l,Andy-lb设为评审人
CANN-robotCANN-robot成员
7月10日 将gitcode-chenjiao,gcw_kUomxQ2l,Andy-lb设为审查人
atomgit-bot
atomgit-bot7月10日进行代码检视1
index/gather_v2/op_kernel/arch35/gather_v2_simd_pcie.h
@@ -0,0 +103,4 @@
103+ if (blockFactor > 0) {
104+ needCoreNum_ = aivNum;
105+ }
106+ maxElement_ = ubAviable;
atomgit-bot
atomgit-bot7月10日评论:

🟡 Medium Priority

gather_v2_simd_pcie.hInit() 函数中,kernel 在设备侧重新计算了 UB 可用空间 maxElement_(第 87-88 行,第 100-106 行):

而 host 端的 CalcSimdTiling()(gather_v2_tiling.cpp 第 420 行)计算 maxElement 时使用的是 (ubSize_ - INDICES_SIZE) / ubBlockSize * ubBlockSize / improveDtypeSize_ / BUFFER_NUM ——不减去 DCACHE

这导致两个不一致:

  1. Kernel 侧计算出的 maxElement_ 比 tiling 侧计算出的 tilingData_->maxElement 小 128KB(经过除法的折算),kernel 忽略了 tiling 下发的 maxElement 值。
  2. 如果 host 端 ubSize_ 已经扣除了 DCACHE,则 kernel 侧重复扣除,导致 buffer 分配偏小,虽然不会越界但影响性能;如果 host 端未扣除,则 PCIe kernel 比已有的非 PCIe SIMD kernel 更保守。

同样的问题也存在于 gather_v2_simd_two_dim_pcie.h 第 75-81 行。已有的非 PCIe kernel(gather_v2_simd.h)直接使用 tilingData_->maxElement,不存在此问题。

likedislike
Zz30075199成员
7月10日 update merge request[project id: 7665709, iid: 7349, commit_id: b8937e87e59f92ca419d851e12289c618944e3c9] virtual merging success
此处折叠了11条事件消息 查看更多
Zz30075199成员
7月11日 解决了最后一个问题
z30075199成员
7月11日 评论:

compile

likedislike
Zz30075199成员
7月11日 update merge request[project id: 7665709, iid: 7349, commit_id: 29e171e462edafb349efbf6c7c477cea59f20204] virtual merging success
CANN-robotCANN-robot成员
7月11日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月11日 评论:

流水线任务触发成功
任务链接 [170015462d924793994d36ca2bbbc890][流水线指导]

任务名称状态日志下载链接
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-11 10:02:01]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
7月11日 评论:

流水线任务触发成功
任务链接 [b91ec07ebdd447859322acdac191e6ed][流水线指导]

任务名称状态日志下载链接
codecheck ❌ FAILED >>>>>
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 >>>>>
likedislike
CANN-robotCANN-robot成员
7月11日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月11日 添加了label:ci-pipeline-failed
Zz30075199成员
7月11日 修改了pull request 的描述
liulun0308成员
7月11日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
7月11日 添加了label:approved
chenqi317成员
7月11日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
7月11日 添加了label:lgtm
z30075199成员
7月11日 评论:

compile

likedislike
Zz30075199成员
7月11日 update merge request[project id: 7665709, iid: 7349, commit_id: 99b48cf34b211dc81afa7a298ac4df43e2ed3e04] virtual merging success
CANN-robotCANN-robot成员
7月11日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
7月11日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月11日 评论:

流水线任务触发成功
任务链接 [78c81b3402ba4a668c50b2307940c8ef][流水线指导]

任务名称状态日志下载链接
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-11 16:41:47]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
7月11日 评论:

流水线任务触发成功
任务链接 [12ebf910a39b42d1a722126527885285][流水线指导]

任务名称状态日志下载链接
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-11 16:36:30]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月11日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月11日 添加了label:ci-pipeline-passed
CANN-robotCANN-robot成员
7月11日 关闭了关联的issue
CANN-robotCANN-robot成员
7月11日 合入了pull request
CANN-robot
CANN-robot成员
7月11日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike