已合并
perf: 缓存batch_all_memory_size引用消除重复查找 #4609
perf: 缓存batch_all_memory_size引用消除重复查找 #4609
已合并
tangqunzhang创建于 8月28日
tangqunzhang成员
8月28日

Pull Request

描述

优化 compiler/graph/build/memory/ 下连续节点生命期遍历和 batch 内存大小查找的性能。

具体改动:

  1. 递归改迭代:GetContinuousNodeLifeTimeBegin 和 SetContinuousNodeLifeTimeBegin 从递归改为迭代式(std::stack + std::unordered_set 防环),消除递归深度限制 kMaxDepthNum,不再需要兜底处理
  2. 简化函数签名:移除冗余的 org_node 和 depth 参数(调用方始终传相同值),SetContinuousNodeLifeTimeBegin 移除 depth 参数
  3. 消除重复属性查询:ATTR_NAME_NOPADDING_CONTINUOUS_INPUT 只获取一次,is_continuous 从循环中保存
  4. 缓存 batch_mem 引用:batch_all_memory_size[batch_label] 缓存为局部引用,消除循环内重复 operator[] 查找
  5. 新增 UT:NoPaddingContinuousCascadedLifeTimeBegin 验证级联连续输入场景下生命期传播正确性

变更类型

关联的Issue

无

如何测试

  1. 编译 GE 项目确认无编译错误
  2. 运行 UtestBlockMemAssigner.* 全部 68 个 UT
  3. 运行 ut_libge_multiparts_utest 全量 3065 个 UT
  4. 差分验证:递归版与迭代版在级联场景(BuildNoPaddingContinuousInCascadedGraph)上结果一致

核对清单

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 tangqunzhang 的贡献)
Ttangqunzhang成员
8月28日 创建了 pull request,commit c08e2aa4
atomgit-bot
atomgit-bot
8月28日 评论:

变更摘要

该 PR 对 compiler/graph/build/memory/block_mem_assigner.cc 中 BlockMemAssigner::GetOutAndWorkSpaceMem 函数做性能优化:通过将 batch_all_memory_size[batch_label] 的查找结果缓存为局部引用 batch_mem,消除函数内两处重复的 operator[] 容器查找;同时将遍历输出锚点指针的循环变量由按值拷贝改为常量引用,规避 shared_ptr 按值拷贝带来的原子引用计数开销。该改动为纯重构,不改变既有功能逻辑。

主要改动

  • 缓存 batch_mem 引用: 在函数入口处新增 auto &batch_mem = batch_all_memory_size[batch_label];,将后续两处 batch_all_memory_size[batch_label] 的重复 operator[] 查找替换为对 batch_mem 的直接使用(batch_mem.emplace_back(size) 与 batch_mem.insert(batch_mem.cend(), temp.cbegin(), temp.cend())),消除重复哈希查找开销。
  • 遍历改为常量引用: 将 for (auto out_anchor : n->GetAllOutDataAnchorsPtr()) 改为 for (const auto &out_anchor : ...),避免循环中对 shared_ptr 按值拷贝产生的原子引用计数增减开销。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月28日 评论:

🤖 本次改动均为数据 / 生成 / 二进制文件(如测试用例、锁文件、媒体资源),没有可审查的代码逻辑,已跳过 AI 代码审查。

likedislike
不准确?
CANN-robotCANN-robot成员
8月28日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
8月28日 评论:

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/ge ✅ Mexyy, kobemini, 张德鹏 (3/2) ✅ 张德鹏 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
此处折叠了243条消息 查看更多
夏国正成员
27 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
27 天前 添加了label:lgtm
张德鹏成员
26 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
26 天前 添加了label:approved
CANN-robotCANN-robot成员
26 天前 合入了pull request