已合并
perf: 优化stream间内存复用性能 #4569
tangqunzhang创建于 8月26日
perf: 优化stream间内存复用性能 #4569
已合并
tangqunzhang创建于 8月26日
tangqunzhang成员
8月26日

Pull Request

描述

优化 compiler/graph/build/memory/ 下 stream 间内存复用相关代码的性能,减少冗余计算和内存拷贝。

具体改动:

  1. block_mem_zero_copy.cc: SetReleaseBlockLifeEnd 中 out_stream_life_time_ 的 const auto 改为 const auto &,避免每次调用产生整个 map 的深拷贝
  2. block_mem_assigner.cc: GetDiffStreamEdgeLife 中将 GetStreamId(node_desc) 提到循环外,避免在 peer anchor 循环内重复调用
  3. block_mem_assigner.cc/h: AddInStreamEdge 中新增 InsertStreamInEdge(set&, ...) 重载,直接传入已查找的 in_edge_set 引用,消除 InsertStreamInEdge 内部的重复 map 查找

变更类型

关联的Issue

无

如何测试

  1. 编译 GE 项目确认无编译错误
  2. 运行内存复用相关 UT 确认无功能回归

核对清单

其他信息

性能改进点:

  • map 值拷贝消除:每次 SetReleaseBlockLifeEnd 调用避免一次堆分配+拷贝
  • 循环内冗余调用消除:GetStreamId 每个 peer anchor 少一次调用
  • 重复 map 查找消除:AddInStreamEdge 中每条跨流边少一次 O(log S) 查找
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 tangqunzhang 的贡献)
Ttangqunzhang成员
8月26日 创建了 pull request,commit 8ff57d23
atomgit-bot
atomgit-bot
8月26日 评论:

变更摘要

本 PR 主要聚焦于 compiler/graph/build/memory/ 目录下 stream 间内存复用相关代码的性能优化,属于不改变功能行为的重构。具体通过消除 map 值深拷贝、将循环内冗余调用上提、以及直接传入已查找的集合引用三类手段减少冗余计算与内存拷贝,涉及 block_mem_zero_copy.cc、block_mem_assigner.cc 及 block_mem_assigner.h。

主要改动

  • 避免 map 深拷贝:在 block_mem_zero_copy.cc 的 SetReleaseBlockLifeEnd 中,将 to_release->NodeTypeIndexList().back().out_stream_life_time_ 的绑定方式由 const auto 改为 const auto &,使每次调用不再产生整个 out_stream_life_time_ map 的堆分配与拷贝。

  • 消除循环内冗余调用:在 block_mem_assigner.cc 的 GetDiffStreamEdgeLife 中,将 GetStreamId(node_desc) 从 peer anchor 循环体内上提到循环外,使每个 peer anchor 少一次 GetStreamId 调用。

  • 消除重复 map 查找:block_mem_assigner.cc/h 中 InsertStreamInEdge 的签名改为直接接收已查找的 std::set<EdgeLife, CompareEdgeLife> &in_edge_set 引用,调用方 AddInStreamEdge 及 GetDiffStreamEdgeLife 传入预先通过 in_stream_edges_[dst_stream_id][src_stream_id] 查得的集合,省去函数内部对 in_stream_edges_ 的重复查找(每条跨流边少一次 O(log S) 查找)。

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

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

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

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
此处折叠了102条消息 查看更多
GengChao
GengChao成员
8月27日 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
8月27日 添加了label:lgtm
张德鹏成员
8月27日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
8月27日 添加了label:approved
CANN-robotCANN-robot成员
8月27日 合入了pull request