Merged
【PR】:RunGraphWithStreamAsync support empty outputs #3306
tang-haojieAdd on Jun 1
【PR】:RunGraphWithStreamAsync support empty outputs #3306
Merged
tang-haojieAdd on Jun 1
tang-haojie
tang-haojieCollaborators
Jun 1

Pull Request

描述

背景
RunGraphWithStreamAsync 静态图执行时,若用户未注册 external allocator 且 outputs 为空,当前实现会失败。需要支持内置 allocator 自动分配输出内存。
修改逻辑

  1. ModelManager 新增内置 allocator 管理
    • 添加 model_built_allocator_ 成员(std::map<uint32_t, ScalableAllocatorManager>)
    • 实现 GetOutputAllocator() 方法:优先返回 external allocator,否则创建/复用内置 allocator
    • 使用 map_mutex_ 保证并发安全,try_emplace 避免拷贝
  2. MallocOutputsMemory 重构
    • 签名变更:移除 AllocatorPtr 参数,改为内部调用 GetOutputAllocator()
    • 提取 EnsureTensorInfo() 方法消除两个重载的重复代码
    • 提取 CreateHbmManager() 函数减少 lambda 嵌套
  3. 接口调整
    • CopyGeOutputsMemToUserOutputs() 移除 stream 参数(简化后不再需要)
    • MallocOutputsMemory() 和 GetOutputAllocator() 改为 public(供 JIT 调用)
  4. 防御性检查
    • SetNetOutputTensorInfo() 添加 compute_graph 空指针检查
    • gert::Tensor 版本补回 ret_tensor_size.size() == outputs.size() 校验
  5. 测试适配
    • UT/ST 新增 builtin allocator 场景测试
    • 修复 test_run_graph_with_stream 等用例:使用 CreateGraphWithConstOutput() 构建完整图,修正错误码期望值
      影响范围
  • 静态图 RunGraphWithStreamAsync 执行路径
  • JIT 执行器输出内存分配
  • 无 external allocator 场景的兼容性提升

变更类型

请选择本次引入的变更类型:

关联的Issue

如何测试

描述测试此变更的步骤和前提条件:
1.
2.

核对清单

其他信息

在此添加任何其他关于本次 PR 的说明。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for tang-haojie's contribution.)
tang-haojietang-haojieCollaborators
Jun 1 Added label: enhancement
tang-haojietang-haojieCollaborators
Jun 1 Created pull request, commit d8fd49a2
CANN-robotCANN-robotCollaborators
Jun 1 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jun 1 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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-cann/ge ✅ yuht9, stevenaw0, wangxiaotian995 (3/2) ✅ wangxiaotian995 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
tang-haojietang-haojieCollaborators
Jun 2 Pre merge succeeded (commit_id: ab52e04911b2b62e382d67664b5e36468e632afa)
127 messages are collapsed here。 See more
yuht9
yuht9Collaborators
Jun 3 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Jun 3 Added label: lgtm
wangxiaotian995
wangxiaotian995Collaborators
Jun 3 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Jun 3 Added label: approved
CANN-robotCANN-robotCollaborators
Jun 3 Merged pull request