Pull Request已成功合入, 合并人@CANN-robot
(感谢 z30075199 的贡献)变更摘要
此 PR 主要为 gatherV2 算子新增了 PCIe 场景的 SIMD 内核支持,并在 embedding 算子中简化了 GatherV2 的调用路径。核心思路是:当检测到输入/输出张量地址落在 PCIe 地址空间(0x40000000000 ~ 0x80000000000)时,路由到新增的 Gatherv2SimdPcie 或 Gatherv2SimdTwoDimPcie 内核;同时,tiling 数据结构补充了 gatherSize 和 dtypeSize 字段,以支持 PCIe 内核的 buffer 计算。Embedding 侧则移除了不再需要的 NoContiguous 和 Embedding 内核分支,统一收敛到 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_KEY、SIMD_TILING_KEY_TWO_DIM等分支改为#elif运行时路由。 -
Tiling 数据结构扩展: 在
gather_v2_tiling.h的GatherV2TilingDataSimtTwoDim中新增gatherSize和dtypeSize两个字段;在gather_v2_tiling.cpp的CalcCoreElement()中追加了set_dtypeSize调用,在SimtTwoDimTiling()中追加了set_gatherSize和set_dtypeSize调用,以向 PCIe 内核传递必要的 tiling 参数。 -
Embedding 算子简化 GatherV2 调用路径: 在
aclnn_embedding.cpp中移除了IsUseNoContiguous/CalNoContiguous分支和CheckEmbeddingKernel/l0op::Embedding降级路径,统一走Contiguous转换后调用GatherV2WithImplMode(高性能模式)或GatherV2,减少分支复杂度。


代码审查
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 中正确设置了新增的 gatherSize 和 dtypeSize 字段,其余为缩进格式调整 |
index/gather_v2/op_host/arch35/gather_v2_tiling.h |
无问题。新增字段 gatherSize 和 dtypeSize 正确追加在 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 |
💬 仅评论


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
z30075199, thanks for your pull request. All authors of the commits have signed the CLA. 👍


🟡 Medium Priority
在 gather_v2_simd_pcie.h 的 Init() 函数中,kernel 在设备侧重新计算了 UB 可用空间 maxElement_(第 87-88 行,第 100-106 行):
而 host 端的 CalcSimdTiling()(gather_v2_tiling.cpp 第 420 行)计算 maxElement 时使用的是 (ubSize_ - INDICES_SIZE) / ubBlockSize * ubBlockSize / improveDtypeSize_ / BUFFER_NUM ——不减去 DCACHE。
这导致两个不一致:
- Kernel 侧计算出的
maxElement_比 tiling 侧计算出的tilingData_->maxElement小 128KB(经过除法的折算),kernel 忽略了 tiling 下发的maxElement值。 - 如果 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,不存在此问题。


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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 | >>>>> |


/approve


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


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


描述
gatherV2算子新增simd小尾轴模板
关联的Issue
https://gitcode.com/cann/ops-transformer/issues/3721
测试
文档更新
类型标签
AI/Agent生成声明