已合并
refactor: 将MemoryNoReuseScope和OpMemoryType改为枚举类 #4352
refactor: 将MemoryNoReuseScope和OpMemoryType改为枚举类 #4352
已合并
tangqunzhang创建于 8月12日
tangqunzhang成员
8月12日

Pull Request

描述

将compiler/graph/build/memory/memory_block.h中的MemoryNoReuseScope和OpMemoryType两个普通enum改为enum class,避免命名空间污染,提升类型安全。

同步更新所有引用处加OpMemoryType::或MemoryNoReuseScope::前缀,MarkZeroCopyBlockAttr参数类型从bool改为OpMemoryType。

变更类型

关联的Issue

如何测试

  1. 编译ge_compiler和UT
  2. 运行block_mem_assigner_unittest、mem_assigner_unittest等单元测试

核对清单

其他信息

涉及12个文件,127 insertions, 113 deletions。

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

变更摘要

此 PR 将 compiler/graph/build/memory/memory_block.h 中的 MemoryNoReuseScope 和 OpMemoryType 两个普通 enum 重构为 enum class,以避免命名空间污染并提升类型安全性。同步更新了所有引用处(共 12 个文件),为枚举值添加 OpMemoryType:: 或 MemoryNoReuseScope:: 前缀,并将 MarkZeroCopyBlockAttr 的参数类型从 bool 改为 OpMemoryType。由于 enum class 禁止隐式整数转换,测试代码中部分原本利用隐式转换将枚举值传给 uint64_t 形参的写法也做了相应适配。

主要改动

  • 枚举定义重构:memory_block.h 中 enum MemoryNoReuseScope 和 enum OpMemoryType 改为 enum class MemoryNoReuseScope 和 enum class OpMemoryType,同时 NodeTypeIndex 的 mem_type_ 默认值从 kOutput 改为 OpMemoryType::kOutput。

  • 业务代码全局适配:block_mem_assigner.cc、block_mem_zero_copy.cc、block_type_list.cc、atomic_clean_checker.cc、dynamic_batch_mem_assigner.cc、graph_mem_assigner.cc、memory_block.cc 中所有 kOutput、kWorkspace、kOutputDesc、kInput 均加 OpMemoryType:: 前缀,kSessionNoReuse 加 MemoryNoReuseScope:: 前缀并辅以 static_cast<MemoryNoReuseScope> 显式转换。

  • MarkZeroCopyBlockAttr 签名变更:block_mem_zero_copy.h 和 block_mem_zero_copy.cc 中该函数第四个参数从 bool mem_type 改为 OpMemoryType mem_type,内部比较从 mem_type == kOutput 改为 mem_type == OpMemoryType::kOutput。

  • GetMemType 静态方法中的 switch-case 适配:memory_block.h 中 NodeTypeIndex::GetMemType 的 case 标签从 kOutput/kWorkspace/kOutputDesc/kInput 分别改为 OpMemoryType::kOutput 等。

  • 测试代码适配:block_mem_assigner_unittest.cc 和 mem_assigner_unittest.cc 中,原来利用普通枚举隐式转换将 OpMemoryType 变量传给 MemoryBlock 构造函数(期望 uint64_t)的写法改为直接声明 uint64_t 类型变量并赋 RT_MEMORY_HBM;枚举值输出时添加 static_cast<int> 转换;所有比较和构造中的枚举值均加上作用域前缀。

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

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

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

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 ✅ kobemini, stevenaw0, 张德鹏, xchu42, lining23666 (5/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
此处折叠了57条消息 查看更多
黄桂军
黄桂军成员
8月12日 评论:

/lgtm

likedislike
张德鹏成员
8月12日 评论:

/approve

likedislike
CANN-robot
CANN-robot成员
8月12日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
hunger517

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