已合并
【feat】: Support PCIe Through #4394
kantao1创建于 8月14日
【feat】: Support PCIe Through #4394
已合并
kantao1创建于 8月14日
kantao1成员
8月14日

Pull Request

接口评审时间:2026/08/06(周四)

描述

PCIE Through 是 Ascend NPU 硬件能力,允许 device 端算子通过 PCIE 总线直接访问 host 内存。当前单算子场景可用,但在模型编译场景下,编译期无法确定输入 tensor 的真实的地址范围,导致 tiling 阶段无法选择正确 kernel。

本特性通过编译期能力识别 + TilingContext 注入 + 执行期上下文扩展(动态 shape),解决此问题。

核心设计

编译阶段(lowering)

  • BuildTilingPcieThroughInputDefaultOpImplSpaceRegistryV2 查询算子是否支持 PCIe Through,同时通过 IsPcieThroughEnabled 检查运行环境(option 开关、芯片能力、设备连接类型),两者均满足时将 pcie_through_flag 初始值设为 true
  • IsPcieThroughEnabled 结果通过 thread_local static 缓存,每个线程仅计算一次
  • BuildTilingCommonInputsinput_addrs 可用时,通过 BuildRefTensor 将输入从 StorageShape 升级为包含设备地址的 Tensor,使运行时能通过 GetInputTensor(i)->GetAddr() 获取实际输入地址

运行时(executor)

  • UpdatePcieThroughFlag 读取 pcie_through_flag,为 false 时直接跳过;为 true 时通过 IsAnyInputInPcieRange 遍历输入地址,检查是否落在 PCIe 地址范围内
  • 若存在 PCIe 地址 → flag 保持 true;否则改为 false
  • GetPcieThroughFlag() 接口供 Tiling 函数和缓存键计算使用

关键修复

  • fwk_data_idx 恢复后向计算(input_num - kFwkDataOffset),修复 symbol tiling 路径中前向计算导致的 702 行 ASSERT 失败
  • GetPcieThroughFlag 改为后向 GetInputNum() - 1,与 pcie_through_flag 作为最后一个输入的布局一致
  • TilingForAtomic 补充 BuildTilingPcieThroughInput 调用,保证输入布局一致性
  • BuildGeneralTilingCacheKey 简化为直接读 GetPcieThroughFlag(),消除运行时查 space_registry 的版本不一致问题

变更类型

关联的Issue

如何测试

  1. 编译 UT:make -C cmake-build-gcov ut_fast_runtime2_test ut_exe_graph ut_register -j$(nproc)
  2. 运行 PCIe Through 相关 UT:--gtest_filter='*PcieThrough*'
  3. 运行 TilingContextBuilder UT:--gtest_filter='TilingContextBuilderUT.*'
  4. 在 PCIe 直通环境上执行模型推理,验证 pcie_through 算子正确识别地址并优化搬运

核对清单

其他信息

涉及文件

仓库 文件 改动说明
ge runtime/v2/graph_builder/bg_tiling.cc 新增 IsPcieThroughEnabledBuildTilingPcieThroughInputBuildTilingCommonInputs 支持 BuildRefTensor;TilingForAtomic 补充 pcie through 输入
ge runtime/v2/kernel/common_kernel_impl/tiling.cc 新增 IsAnyInputInPcieRangeUpdatePcieThroughFlagfwk_data_idx 恢复后向计算;BuildGeneralTilingCacheKey 简化
ge runtime/v2/kernel/common_kernel_impl/tiling.h 新增 kPcieThroughFlag 枚举项
metadef inc/external/exe_graph/runtime/tiling_context.h GetPcieThroughFlag 改为后向计算
ge tests/ 新增 PCIe Through 相关 UT/ST 用例
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 kantao1 的贡献)
Kkantao1成员
8月14日 添加了label:enhancement
Kkantao1成员
8月14日 创建了 pull request,commit 436984cb
atomgit-bot
atomgit-bot
8月14日 评论:

变更摘要

该 PR 旨在为 tiling 流程新增“PCIe 直通(PCIe Through)”支持:通过在算子属性、全局配置、tiling 上下文固定输入和执行期判定等环节传递并校验 pcie through 标志,使得仅当平台支持且算子输入地址落在 host-device 地址范围内时,才真正启用 PCIe 直通。改动主要涉及属性定义与配置项、图管理阶段标记、tiling 上下文构建器的输入扩展,以及 RT2/Runtime v2 执行路径中的标志解析与更新。

主要改动

  • 新增属性与全局配置项: 在 ge_attr_define 中新增 ATTR_NAME_PCIE_THROUGHATTR_NAME_PCIE_THROUGH_FLAG 属性,并在 ge_common_api_types.h 中新增配置项 OPTION_EXEC_DISABLE_PCIE_THROUGHge.exec.disable_pcie_through),同时将其加入 option_supportion_checker 的全局选项校验集合。

  • 图管理阶段标记算子: 新增 GraphManager::ProcessPcieThrough,遍历计算图节点,通过 OpImpl::IsSupportPcieThrough() 判断算子是否支持 PCIE 直通,并为其设置 ATTR_NAME_PCIE_THROUGHATTR_NAME_PCIE_THROUGH_FLAG 属性;该步骤在 PreRunOptimizeSubGraph 中先于 ProcessNullableOutput 执行。

  • 扩展 tiling 上下文固定输入: TilingContextBuilderDeviceTilingContextBuilder 新增 SetPcieThroughFlag 方法及 pcie_through_flag_ 成员,在原有确定性标志之后追加第 m + 5 个固定输入用于传递直通标志;同时 op_tiling_py.cckTilingCtxFixedInputSize 调整为 6,新增 kPcieThroughOffset 并解析 compile info 中的 pcie_through_flag

  • RT2 路径中的直通判定: 在 op_tiling_rt2.cc 新增 IsPcieThroughEnabledDeterminePcieThroughFromInputs,通过 aclrtHostGetDevicePointerAddrRange 判断算子输入地址是否位于 host-device 地址范围,并在 RtParseAndTiling 中据此更新 tiling 上下文对应固定输入的值。

  • Runtime v2 执行路径联动: bg_tiling.cc 新增 BuildTilingPcieThroughInput,将直通标志作为 tiling 输入追加到各类 tiling 构建路径;tiling.cc 新增 UpdatePcieThroughFlag,在执行 TilingProc / CacheableTilingProc 前重新校验实际标志,并将其纳入 BuildGeneralTilingCacheKey 的缓存键计算。

likedislike
不准确?
atomgit-bot
atomgit-bot
8月14日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
8月14日 添加了label:cann-cla/yes
此处折叠了183条消息 查看更多
yangyongqiang
yangyongqiang成员
14 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
14 天前 添加了label:lgtm
CANN-robotCANN-robot成员
14 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
14 天前 添加了label:ci-pipeline-passed
CANN-robotCANN-robot成员
14 天前 合入了pull request