已合并
sc修改 #1062
szhexin创建于 1月28日
sc修改 #1062
已合并
szhexin创建于 1月28日
5 个文件变更+22-16
@@ -99,7 +99,7 @@ aclnnStatus CheckABCDxABCED2ABCE(const aclTensorList *tensors, const aclTensor *
99 return ACLNN_ERR_PARAM_INVALID;99 return ACLNN_ERR_PARAM_INVALID;
100 }100 }
101 101 
102- for (uint64_t i = 0; i < tensor0Shape.GetDimNum(); i++) {102+ for (size_t i = 0; i < tensor0Shape.GetDimNum(); i++) {
CANN-robot
CANN-robotCANN-robot1月28日

代码结构与可维护性: 循环变量类型与比较类型不匹配。在 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)。

此评论由代码审查工具自动生成

likedislike
103 if (tensor0Shape.GetDim(i) == DIM_ZERO) {103 if (tensor0Shape.GetDim(i) == DIM_ZERO) {
104 OP_LOGE(ACLNN_ERR_PARAM_INVALID, "tensor0 shape dim%ld [0] should not be zero", i);104 OP_LOGE(ACLNN_ERR_PARAM_INVALID, "tensor0 shape dim%ld [0] should not be zero", i);
105 return ACLNN_ERR_PARAM_INVALID;105 return ACLNN_ERR_PARAM_INVALID;
@@ -243,10 +243,10 @@ static void EquationUnification(std::string &equation) {
243 size_t indice = 0;243 size_t indice = 0;
244 for (auto &dim_shape : equation) {244 for (auto &dim_shape : equation) {
245 if (isalpha(dim_shape)) {245 if (isalpha(dim_shape)) {
246- if (normalize_map.find(dim_shape) == normalize_map.end()) {246+ if (normalize_map.find(dim_shape) == normalize_map.end()) {
247- normalize_map[dim_shape] = 'a' + indice;247+ normalize_map[dim_shape] = static_cast<char>(static_cast<unsigned char>('a') + indice);
248- indice++;248+ indice++;
249- }249+ }
250 dim_shape = normalize_map[dim_shape];250 dim_shape = normalize_map[dim_shape];
251 }251 }
252 }252 }
@@ -304,7 +304,8 @@ bool CheckIsUnknownDimNum(const gert::Shape& shape)
304 return shape.GetDimNum() == 1 && shape.GetDim(0) == UNKNOWN_DIM_NUM;304 return shape.GetDimNum() == 1 && shape.GetDim(0) == UNKNOWN_DIM_NUM;
305}305}
306 306 
307-bool CalculateTransX2Float(const gert::InferShapeContext* context, const Shape& shape_x2, bool trans_x1, bool trans_x2)307+static bool CalculateTransX2Float(
308+ const gert::InferShapeContext* context, const Shape& shape_x2, bool trans_x1, bool trans_x2)
308{309{
309 auto shape_x1 = context->GetInputShape(0);310 auto shape_x1 = context->GetInputShape(0);
310 auto x1_dim_num = shape_x1->GetDimNum();311 auto x1_dim_num = shape_x1->GetDimNum();
@@ -317,7 +318,7 @@ bool CalculateTransX2Float(const gert::InferShapeContext* context, const Shape&
317 return false;318 return false;
318}319}
319 320 
320-ge::graphStatus UpdateX2NewShape(321+static ge::graphStatus UpdateX2NewShape(
CANN-robot
CANN-robotCANN-robot1月28日

代码规范/静态函数声明: 函数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修饰符,这是正确的封装做法。

此评论由代码审查工具自动生成

likedislike
321 const gert::InferShapeContext* context, Shape& new_shape, bool& reshape_flag, bool trans_x1, bool trans_x2,322 const gert::InferShapeContext* context, Shape& new_shape, bool& reshape_flag, bool trans_x1, bool trans_x2,
322 const bool is_packed)323 const bool is_packed)
323{324{
@@ -423,7 +424,7 @@ ge::graphStatus InferShapeForBatchMatMul(
423constexpr int64_t INFINITE_RANGE = -1;424constexpr int64_t INFINITE_RANGE = -1;
424constexpr int64_t NORMALIZE_INFINITE_RANGE = std::numeric_limits<int64_t>::max();425constexpr int64_t NORMALIZE_INFINITE_RANGE = std::numeric_limits<int64_t>::max();
425static const std::pair<int64_t, int64_t> NORMALIZE_FULL_RANGE = {0, NORMALIZE_INFINITE_RANGE};426static const std::pair<int64_t, int64_t> NORMALIZE_FULL_RANGE = {0, NORMALIZE_INFINITE_RANGE};
426-bool InitializeRange(427+static bool InitializeRange(
CANN-robot
CANN-robotCANN-robot1月28日

代码规范/静态函数声明: 函数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修饰符,确保函数作用域仅限于当前文件。

此评论由代码审查工具自动生成

likedislike
427 size_t num, const std::vector<std::pair<int64_t, int64_t>>& range,428 size_t num, const std::vector<std::pair<int64_t, int64_t>>& range,
428 std::vector<std::pair<int64_t, int64_t>>& new_range)429 std::vector<std::pair<int64_t, int64_t>>& new_range)
429{430{
@@ -451,7 +452,7 @@ bool InitializeRange(
451 return true;452 return true;
452}453}
453 454 
454-bool GetBatchIntersection(455+static bool GetBatchIntersection(
CANN-robot
CANN-robotCANN-robot1月28日

代码规范/静态函数声明: 函数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修饰符,这是正确的封装做法。

此评论由代码审查工具自动生成

likedislike
455 const char* op_name, std::pair<int64_t, int64_t>& a, std::pair<int64_t, int64_t>& b,456 const char* op_name, std::pair<int64_t, int64_t>& a, std::pair<int64_t, int64_t>& b,
456 std::pair<int64_t, int64_t>& out)457 std::pair<int64_t, int64_t>& out)
457{458{
@@ -484,7 +485,7 @@ bool GetBatchIntersection(
484 return true;485 return true;
485}486}
486 487 
487-bool GetKNIntersection(488+static bool GetKNIntersection(
CANN-robot
CANN-robotCANN-robot1月28日

代码规范/静态函数声明: 函数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修饰符,确保函数作用域仅限于当前文件。

此评论由代码审查工具自动生成

likedislike
488 const char* op_name, const std::pair<int64_t, int64_t>& a, const std::pair<int64_t, int64_t>& b,489 const char* op_name, const std::pair<int64_t, int64_t>& a, const std::pair<int64_t, int64_t>& b,
489 std::pair<int64_t, int64_t>& out)490 std::pair<int64_t, int64_t>& out)
490{491{
@@ -501,7 +502,7 @@ bool GetKNIntersection(
501 return true;502 return true;
502}503}
503 504 
504-void ExpendOneDimRange(505+static void ExpendOneDimRange(
CANN-robotsxb154714
CANN-robotCANN-robot1月28日

代码规范/静态函数声明: 函数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的改动内容。

此评论由代码审查工具自动生成

likedislike
sxb154714sxb1547141月28日

拼接错误,需要整改

likedislike
505 size_t num_dim_x1, size_t num_dim_x2, std::vector<std::pair<int64_t, int64_t>>& shape_range_x1,506 size_t num_dim_x1, size_t num_dim_x2, std::vector<std::pair<int64_t, int64_t>>& shape_range_x1,
506 std::vector<std::pair<int64_t, int64_t>>& shape_range_x2)507 std::vector<std::pair<int64_t, int64_t>>& shape_range_x2)
507{508{
@@ -517,7 +518,7 @@ void ExpendOneDimRange(
517 }518 }
518}519}
519 520 
520-void ReduceOneDimRange(521+static void ReduceOneDimRange(
CANN-robot
CANN-robotCANN-robot1月28日

代码规范/静态函数声明: 函数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修饰符,确保函数作用域仅限于当前文件。

此评论由代码审查工具自动生成

likedislike
521 size_t num_dim_x1, size_t num_dim_x2, size_t& num_dim_out,522 size_t num_dim_x1, size_t num_dim_x2, size_t& num_dim_out,
522 std::vector<std::pair<int64_t, int64_t>>& shape_range_out)523 std::vector<std::pair<int64_t, int64_t>>& shape_range_out)
523{524{
@@ -533,7 +534,7 @@ void ReduceOneDimRange(
533 }534 }
534}535}
535 536 
536-bool InferRangeBias(537+static bool InferRangeBias(
CANN-robot
CANN-robotCANN-robot1月28日

代码规范/静态函数声明: 函数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修饰符,这是正确的封装做法。

此评论由代码审查工具自动生成

likedislike
537 const char* op_name, std::vector<std::pair<int64_t, int64_t>>& new_shape_range_out, size_t idx_n,538 const char* op_name, std::vector<std::pair<int64_t, int64_t>>& new_shape_range_out, size_t idx_n,
538 const gert::Range<gert::Shape>* bias_shape_range,539 const gert::Range<gert::Shape>* bias_shape_range,
539 const std::vector<std::pair<int64_t, int64_t>>& new_shape_range_x2)540 const std::vector<std::pair<int64_t, int64_t>>& new_shape_range_x2)
Mmatmul/common/op_host/op_api/matmul_util.h+6-1文件内容审核中,请稍后刷新重试
Mmatmul/mat_mul_v3/op_host/op_tiling/arch35/matmul_v3_basic_aswt_tiling.cpp+1-1文件内容审核中,请稍后刷新重试
@@ -41,7 +41,7 @@ protected:
41 41 
42private:42private:
43 void FullLoadPre();43 void FullLoadPre();
44- uint64_t GetAFullLoadBasicNL1();44+ uint64_t GetAFullLoadBasicNL1() const;
45 void CalcTailBasicBlockBL1Full();45 void CalcTailBasicBlockBL1Full();
46 void CalcTailBasicBlockAL1Full();46 void CalcTailBasicBlockAL1Full();
47 bool CheckBL1FullLoad();47 bool CheckBL1FullLoad();