Pull Request已成功合入, 合并人@CANN-robot
(感谢 szhexin 的贡献)以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入
| Module List | Reviewers | Committers |
|---|---|---|
| matmul | N/A | crystalhu, fanqirui, zhang-wu, chaotang233, tangweiwei2 |
| */*/op_host/op_api/*.h | N/A | wangyongguang, tang-lei01 |


🔵 source code change are detected, tasks labels is removed in this pull request!


流水线任务触发成功,任务链接 [0e080b17b31446cd96f0ef828857df35]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| anti_virus | ✅ SUCCESS | >>>>> | |
| Check_Pr | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| API_Check | ⚠️ WARNING | >>>>> | |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| Smoke_A900 | ✅ SUCCESS | >>>>> | >>>>> |
[2026-01-28 11:45:42] CI执行结束


代码结构与可维护性: 循环变量类型与比较类型不匹配。在 for 循环中,变量 i 的类型为 size_t,而 tensor0Shape.GetDimNum() 的返回值类型未明确给出,但通常也应为 size_t 或 uint64_t 等无符号类型。然而,在循环体内,使用 i 作为参数调用 tensor0Shape.GetDim(i) 和 OP_LOGE 的格式化参数 %ld。%ld 是用于格式化 long int 类型的,而 size_t 在 64 位系统上通常是 unsigned long 或 unsigned long long,直接使用 %ld 可能导致格式化错误或数据截断。虽然代码逻辑上可能不会出错,但这种类型不匹配会影响代码的可移植性和健壮性。
问题类型: 代码结构与可维护性
文件路径: matmul/batch_mat_mul_v3/op_host/op_api/aclnn_einsum.cpp
行号: 102
问题代码:
for (size_t i = 0; i < tensor0Shape.GetDimNum(); i++) {
if (tensor0Shape.GetDim(i) == DIM_ZERO) {
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "tensor0 shape dim%ld [0] should not be zero", i);
return ACLNN_ERR_PARAM_INVALID;
}
}
修改建议:
建议将循环变量 i 的类型改为与 GetDimNum() 返回值一致的类型,或者使用更通用的类型如 int64_t(如果维度数量不会超过其范围),并相应地调整格式化字符串。例如,如果 GetDimNum() 返回 int64_t,则改为:for (int64_t i = 0; i < tensor0Shape.GetDimNum(); ++i)。如果坚持使用 size_t,则应将格式化字符串中的 %ld 改为 %zu(适用于 size_t)。
此评论由代码审查工具自动生成


代码规范/静态函数声明: 函数UpdateX2NewShape从非静态函数改为静态函数。该函数仅在InferShapeForBatchMatMul函数中被调用,且位于同一个namespace Ops::NN内。改为静态函数可以限制其链接范围,避免命名污染,符合内部辅助函数的定义规范。
问题类型: 代码规范/静态函数声明
文件路径: matmul/common/op_host/matmul_common_infershape.cpp
行号: 321
问题代码:
static ge::graphStatus UpdateX2NewShape(
const gert::InferShapeContext* context, Shape& new_shape, bool& reshape_flag, bool trans_x1, bool trans_x2,
const bool is_packed)
修改建议:
保持static修饰符,这是正确的封装做法。
此评论由代码审查工具自动生成


代码规范/静态函数声明: 函数InitializeRange从非静态函数改为静态函数。该函数在InferShapeRangeBatchMatMul::InferShapeRange和InferRangeBias中被调用,用于初始化形状范围向量。由于这些调用都发生在同一个cpp文件内,将其改为静态函数是合理的,可以避免与其他文件中的同名函数冲突。
问题类型: 代码规范/静态函数声明
文件路径: matmul/common/op_host/matmul_common_infershape.cpp
行号: 427
问题代码:
static bool InitializeRange(
size_t num, const std::vector<std::pair<int64_t, int64_t>>& range,
std::vector<std::pair<int64_t, int64_t>>& new_range)
修改建议:
保持static修饰符,确保函数作用域仅限于当前文件。
此评论由代码审查工具自动生成


代码规范/静态函数声明: 函数GetBatchIntersection从非静态函数改为静态函数。该函数在InferShapeRangeBatchMatMul::InferShapeRange和InferRangeBias中被调用,用于计算批次维度的交集。由于这些调用都在同一个cpp文件内,改为静态函数是合适的。
问题类型: 代码规范/静态函数声明
文件路径: matmul/common/op_host/matmul_common_infershape.cpp
行号: 455
问题代码:
static bool GetBatchIntersection(
const char* op_name, std::pair<int64_t, int64_t>& a, std::pair<int64_t, int64_t>& b,
std::pair<int64_t, int64_t>& out)
修改建议:
保持static修饰符,这是正确的封装做法。
此评论由代码审查工具自动生成


代码规范/静态函数声明: 函数GetKNIntersection从非静态函数改为静态函数。该函数在InferShapeRangeBatchMatMul::InferShapeRange中被调用,用于计算K/N维度的交集。由于调用发生在同一个cpp文件内,改为静态函数是合理的。
问题类型: 代码规范/静态函数声明
文件路径: matmul/common/op_host/matmul_common_infershape.cpp
行号: 488
问题代码:
static bool GetKNIntersection(
const char* op_name, const std::pair<int64_t, int64_t>& a, const std::pair<int64_t, int64_t>& b,
std::pair<int64_t, int64_t>& out)
修改建议:
保持static修饰符,确保函数作用域仅限于当前文件。
此评论由代码审查工具自动生成


代码规范/静态函数声明: 函数ExpendOneDimRange从非静态函数改为静态函数。该函数在InferShapeRangeBatchMatMul::InferShapeRange中被调用,用于扩展一维输入的形状范围。由于调用发生在同一个cpp文件内,改为静态函数是合适的。
问题类型: 代码规范/静态函数声明
文件路径: matmul/common/op_host/matmul_common_infershape.cpp
行号: 505
问题代码:
static void ExpendOneDimRange(
size_t num_dim_x1, size_t num_dim_x2, std::vector<std::pair<int64_t, int64_t>>& shape_range_x1,
std::vector<std::pair<int64_t, int64_t>>& shape_range_x2)
修改建议:
保持static修饰符,这是正确的封装做法。注意函数名'Expend'可能存在拼写错误,应为'Expand',但这不是本次PR的改动内容。
此评论由代码审查工具自动生成


代码规范/静态函数声明: 函数ReduceOneDimRange从非静态函数改为静态函数。该函数在InferShapeRangeBatchMatMul::SetOutput中被调用,用于还原一维输入的形状范围。由于调用发生在同一个cpp文件内,改为静态函数是合理的。
问题类型: 代码规范/静态函数声明
文件路径: matmul/common/op_host/matmul_common_infershape.cpp
行号: 521
问题代码:
static void ReduceOneDimRange(
size_t num_dim_x1, size_t num_dim_x2, size_t& num_dim_out,
std::vector<std::pair<int64_t, int64_t>>& shape_range_out)
修改建议:
保持static修饰符,确保函数作用域仅限于当前文件。
此评论由代码审查工具自动生成


代码规范/静态函数声明: 函数InferRangeBias从非静态函数改为静态函数。该函数在InferShapeRangeBatchMatMul::InferShapeRange中被调用,用于推断偏置的形状范围。由于调用发生在同一个cpp文件内,改为静态函数是合适的。
问题类型: 代码规范/静态函数声明
文件路径: matmul/common/op_host/matmul_common_infershape.cpp
行号: 537
问题代码:
static bool InferRangeBias(
const char* op_name, std::vector<std::pair<int64_t, int64_t>>& new_shape_range_out, size_t idx_n,
const gert::Range<gert::Shape>* bias_shape_range,
const std::vector<std::pair<int64_t, int64_t>>& new_shape_range_x2)
修改建议:
保持static修饰符,这是正确的封装做法。
此评论由代码审查工具自动生成


问题/功能描述
本次PR主要包含三方面改进:一是修复Einsum算子实现中潜在的整数类型不匹配和字符运算溢出问题,提升代码健壮性;二是对MatMul算子的形状推断相关代码进行重构,将多个辅助函数的作用域限制为文件内部,以增强封装性并减少符号污染;三是扩展MatMul算子的工具函数,新增核心信息创建函数,并修复了部分工具类成员函数的常量性修饰,以提升代码的可维护性和安全性。
修改方案描述
具体修改包括:1. 将Einsum算子中循环索引变量类型从uint64_t改为size_t以匹配维度获取函数,并加固方程归一化函数中的字符映射逻辑,通过显式类型转换防止溢出。2. 将MatMul形状推断文件中的8个内部辅助函数链接属性修改为static,限制其仅在当前编译单元内可见。3. 新增CreateMatmulOpInfo函数以集中创建算子信息结构体,并将SocMatMulRuleBase::GetInputCase等成员函数标记为const,明确其只读语义。所有修改均不涉及功能逻辑变更,属于代码优化和安全性增强。


/lgtm


The following label is not ready.
approved: Please wait for committers to review the code.


The following label is not ready.
approved: Please wait for committers to review the code.


/approve


Review Guide
This Pull-Request Passes Review.
Committers who wrote a comment of /approve are: chenqi317, tang-lei01.
Reviewers who wrote a comment of /lgtm are: fanqirui, chenqi317, tang-lei01.


描述
关联的Issue
测试
文档更新
类型标签