已合并
【PR】: codegen infershape remove unused symbol #1688
chengyutao3创建于 16 天前
【PR】: codegen infershape remove unused symbol #1688
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 chengyutao3 的贡献)16 天前 添加了label:enhancement
16 天前 创建了 pull request,commit 83380fda
atomgit-bot
16 天前 评论:
16 天前 评论:
变更摘要
此 PR 对 codegen_infershape.cpp 中的 InfershapeGen::GenInferShapeFunc 方法进行了优化:在生成推断形状函数时,新增了未使用符号的过滤逻辑,仅输出在形状维度表达式中实际被引用的符号定义,避免生成冗余的 auto 变量声明。
主要改动
- 新增
#include <set>头文件:为后续使用std::set<std::string>收集已使用符号名称提供支持。 - 新增符号使用分析逻辑:在生成
common_get_input_str之前,遍历symbol_shape_str中所有形状维度表达式,通过整词边界匹配(检查前后字符是否为字母数字)从shape_info中筛选出被实际引用的符号,存入used_symbols集合。 - 符号声明输出过滤:在遍历
shape_info生成auto变量声明时,增加used_symbols.count(it.first) == 0判断,跳过未被任何形状表达式引用的符号,从而精简生成的代码。


atomgit-bot
16 天前 评论:
16 天前 评论:
16 天前 添加了label:cann-cla/yes
此处折叠了63条消息 查看更多
chengyutao3
5 天前 评论:
5 天前 评论:
/check-pr


CANN-robot
5 天前 评论:
5 天前 评论:
The following label is not ready.
approved: Please wait for committers to review the code.


5 天前 添加了label:approved
5 天前 合入了pull request
Pull Request
描述
优化
InferShape代码生成逻辑:在生成符号变量声明前,先扫描所有 shape 表达式,仅对实际被引用的符号生成auto xxx = ...声明,避免输出未使用的变量代码。具体实现:
shape_info中的符号名,收集被引用的符号到used_symbols集合。变更类型
关联的Issue
如何测试
描述测试此变更的步骤和前提条件:
GenInferShapeFunc生成。.cpp文件中InferShape函数,确认不包含未被 shape 表达式引用的符号变量声明。核对清单
其他信息
仅修改
autofuse/codegen/codegen_infershape.cpp,新增 23 行,新增<set>头文件依赖。