已合并
cleancode fix #3601
yangjinwen创建于 6月27日
cleancode fix #3601
已合并
yangjinwen创建于 6月27日
yangjinwen成员
6月27日

描述

CleanCode规范修改:重复代码块优化

关联的Issue

https://gitcode.com/cann/ops-math/issues/1944

测试

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 yangjinwen 的贡献)
Yyangjinwen成员
6月27日 创建了 pull request,commit 73c99b72
CANN-robotCANN-robot成员
6月27日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
6月27日 评论:

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
conversion/broadcast_to zhanw_coding, 宋恺 (2/2) zhanw_coding, 宋恺 (2/1)
conversion/transpose zhanw_coding, 宋恺 (2/2) zhanw_coding, 宋恺 (2/1)
math/expand zhanw_coding, 宋恺 (2/2) zhanw_coding, 宋恺 (2/1)
repo-cann/ops-math zhanw_coding, 宋恺 (2/2) zhanw_coding, 宋恺 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
atomgit-bot
atomgit-bot
6月27日 评论:

变更摘要

本次 PR 主要聚焦于 CleanCode 规范下的重复代码块优化,将多处重复出现的代码逻辑抽取为独立的辅助函数,以减少代码冗余。核心改动集中在两个层面:融合算子图层面提取张量描述解析逻辑,以及多核 tiling 参数下计算处理范围的统一封装。

主要改动

  • 抽取 ResolveSubgraphInputTensorDesc 辅助函数:在 permute_fusion_pass.cpp 中,将 GetInputsInfoInferShape 中重复的 TensorDesc 解析与 fallback 逻辑抽取为独立函数,统一了两处调用点。
  • 新增 ParseMultiCoreRange 辅助函数:在 transpose_base.h 中定义 ParseMultiCoreRange 内联函数,封装多核 tiling 参数下的处理范围计算逻辑(blkFactorblkTailFactorrealCoreNum),并在 transpose_big_dim.htranspose_cut_one_axis.htranspose_n_last.h 三处将原有内联代码替换为对该函数的调用。
  • 合并 GetLoopAddressOffsetImpl 统一实现:在 transpose_cut_two_axis.h 中,将 GetMainLoopAddressOffsetGetTailLoopAddressOffsetGetTailTailLoopAddressOffset 三者的共同循环地址偏移计算逻辑合并为单一的 GetLoopAddressOffsetImpl,通过 cutIndex1/cutIndex2 参数区分主循环与尾循环场景。
  • 简化 ProcessTail 中的重复表达式:在 transpose_cut_two_axis.hProcessTail 中,将 loopidx 的重复计算表达式提取为局部变量 tailLoopLocalIdx,并复用于两处 DecimalToMixedBase 调用。#### 变更摘要

本次 PR 对 CleanCode 规范中存在的重复代码块进行了优化重构,主要围绕两方面展开:一是将多处重复的张量描述解析逻辑抽取为独立的辅助函数 ResolveSubgraphInputTensorDesc;二是将多核分片参数下的处理范围计算逻辑封装为内联函数 ParseMultiCoreRange,供多个转换核使用。

主要改动

  • 抽取张量描述解析逻辑为独立函数:在 permute_fusion_pass.cpp 中新增 ResolveSubgraphInputTensorDesc 辅助函数,将 GetInputsInfoInferShape 中两处重复的 TensorDesc 获取与 shape fallback 逻辑统一收拢到该函数中。
  • 封装多核范围计算为内联函数:在 transpose_base.h 中定义 ParseMultiCoreRange,将多核 tiling 参数下的处理范围计算(blkFactor/blkTailFactor/realCoreNum 判断)封装为独立函数,并在 transpose_big_dim.htranspose_cut_one_axis.htranspose_n_last.h 中将原有内联代码替换为对该函数的调用。
  • 合并循环地址偏移计算为统一实现:在 transpose_cut_two_axis.h 中,将 GetMainLoopAddressOffsetGetTailLoopAddressOffsetGetTailTailLoopAddressOffset 三者共有的地址偏移计算逻辑合并为单一的 GetLoopAddressOffsetImpl,通过 cutIndex1cutIndex2 参数区分主循环、尾循环及尾尾循环场景。
  • 简化尾循环中的重复表达式:在 ProcessTail 中,将重复的 loopidx 计算表达式抽取为局部变量 tailLoopLocalIdx,并复用于两处 DecimalToMixedBase 调用。
likedislike
Yyangjinwen成员
6月27日 修改了pull request 的描述
此处折叠了83条消息 查看更多
zhanw_coding
zhanw_coding成员
6月30日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
6月30日 添加了label:approved
songkai111成员
6月30日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
6月30日 添加了label:lgtm
CANN-robotCANN-robot成员
6月30日 合入了pull request