已合并
按照cleancode规范消除池化类算子的告警 #2877
小王!创建于 3月18日
按照cleancode规范消除池化类算子的告警 #2877
已合并
小王!创建于 3月18日
从已删除 :remove-compile-warnning-9.0.0合入到cann/ops-nn9.0.0
共 17 个文件变更+29-30
@@ -70,7 +70,6 @@ uint64_t AdaptiveMaxPool3DTilingSimt::GetTilingKey() const
70 }else {70 }else {
71 return GET_TPL_TILING_KEY(TPL_MODE_2, TPL_INT64_UINT64, TPL_MULTI_MODE_0, TPL_DATA_FORMAT_MODE_0);71 return GET_TPL_TILING_KEY(TPL_MODE_2, TPL_INT64_UINT64, TPL_MULTI_MODE_0, TPL_DATA_FORMAT_MODE_0);
72 }72 }
73-
74}73}
75 74 
76ge::graphStatus AdaptiveMaxPool3DTilingSimt::PostTiling()75ge::graphStatus AdaptiveMaxPool3DTilingSimt::PostTiling()
@@ -173,7 +173,7 @@ ge::graphStatus AdaptivePool3dBaseTiling::GetPlatformInfo()
173{173{
174 auto platformPtr = context_->GetPlatformInfo();174 auto platformPtr = context_->GetPlatformInfo();
175 if (platformPtr == nullptr) {175 if (platformPtr == nullptr) {
176- auto compileInfoPtr = reinterpret_cast<const AdaptivePool3dCompileInfo*>(context_->GetCompileInfo());176+ auto compileInfoPtr = static_cast<const AdaptivePool3dCompileInfo*>(context_->GetCompileInfo());
177 OP_CHECK_IF(177 OP_CHECK_IF(
178 compileInfoPtr == nullptr, OP_LOGE(context_->GetNodeName(), "compile info is null"),178 compileInfoPtr == nullptr, OP_LOGE(context_->GetNodeName(), "compile info is null"),
179 return ge::GRAPH_FAILED);179 return ge::GRAPH_FAILED);
@@ -28,9 +28,9 @@
28#include "util/math_util.h"28#include "util/math_util.h"
29#include "op_host/tiling_util.h"29#include "op_host/tiling_util.h"
30 30 
31-using namespace std;
32 31 
33namespace optiling {32namespace optiling {
33+using namespace std;
34using Ops::NN::Optiling::TilingBaseClass;34using Ops::NN::Optiling::TilingBaseClass;
35constexpr int64_t MAX_INT32 = 2147483647;35constexpr int64_t MAX_INT32 = 2147483647;
36constexpr uint64_t MAX_UINT32 = 4294967295;36constexpr uint64_t MAX_UINT32 = 4294967295;
Mpooling/avg_pool_v2_grad/op_host/arch35/avg_pool_v2_grad_tiling_base.cpp+1-2文件内容审核中,请稍后刷新重试
Mpooling/avg_pool_v2_grad/op_host/arch35/avg_pool_v2_grad_tiling_common.h+1-1文件内容审核中,请稍后刷新重试
@@ -94,16 +94,17 @@ ge::graphStatus InferShape4AvgPoolV2Grad(gert::InferShapeContext* context)
94 94 
95 auto padding_mode = attrs->GetAttrPointer<char>(ATTR_PADDING_MODE_POS);95 auto padding_mode = attrs->GetAttrPointer<char>(ATTR_PADDING_MODE_POS);
96 OP_CHECK_NULL_WITH_CONTEXT(context, padding_mode);96 OP_CHECK_NULL_WITH_CONTEXT(context, padding_mode);
97- OP_CHECK_IF(97+ OP_CHECK_IF(strcmp(padding_mode, "SAME") != 0 && strcmp(padding_mode, "VALID") != 0 &&
CANN-robot
CANN-robotCANN-robot3月18日
逻辑运算与副作用: 第97-100行的逻辑表达式存在逻辑错误。原始代码使用 '&&' 连接三个 strcmp 不等于0的条件,这意味着只有当 padding_mode 同时不等于 "SAME"、"VALID" 和 "CALCULATED" 时才会进入错误处理分支。然而,一个字符串不可能同时不等于这三个值,因为 padding_mode 只能是其中一个值。正确的逻辑应该是:如果 padding_mode 不是这三个有效值中的任何一个,就报错。但当前的逻辑表达式实际上永远为假,导致校验失效。
问题类型: 逻辑运算与副作用
文件路径: pooling/avg_pool_v2_grad/op_host/avg_pool_v2_grad_infershape.cpp
行号: 97
问题代码:
OP_CHECK_IF(strcmp(padding_mode, "SAME") != 0 && strcmp(padding_mode, "VALID") != 0 &&
        strcmp(padding_mode, "CALCULATED") != 0, OP_LOGE(context->GetNodeName(),
                "attr padding_mode(%s) only support SAME, VALID and CALCULATED", padding_mode),
        return GRAPH_FAILED);
修改建议:
将逻辑运算符 '&&' 改为 '||'。正确的逻辑是:如果 padding_mode 不等于 "SAME" 且不等于 "VALID" 且不等于 "CALCULATED",则报错。修改为:OP_CHECK_IF(strcmp(padding_mode, "SAME") != 0 || strcmp(padding_mode, "VALID") != 0 || strcmp(padding_mode, "CALCULATED") != 0, ...)。或者更清晰地写为:if (strcmp(padding_mode, "SAME") != 0 && strcmp(padding_mode, "VALID") != 0 && strcmp(padding_mode, "CALCULATED") != 0) { 报错 }。
---
此评论由代码审查工具自动生成
likedislike
98- !strcmp(padding_mode, "SAME") && !strcmp(padding_mode, "VALID") && !strcmp(padding_mode, "CALCULATED"),98+ strcmp(padding_mode, "CALCULATED") != 0, OP_LOGE(context->GetNodeName(),
99- OP_LOGE(context->GetNodeName(),"attr padding_mode(%s) only support SAME、 VALID and CALCULATED", padding_mode), return GRAPH_FAILED);99+ "attr padding_mode(%s) only support SAME, VALID and CALCULATED", padding_mode),
100+ return GRAPH_FAILED);
100 101 
101 auto ksize = attrs->GetAttrPointer<gert::ContinuousVector>(ATTR_KERNEL_POS);102 auto ksize = attrs->GetAttrPointer<gert::ContinuousVector>(ATTR_KERNEL_POS);
102 OP_CHECK_NULL_WITH_CONTEXT(context, ksize);103 OP_CHECK_NULL_WITH_CONTEXT(context, ksize);
103 OP_CHECK_IF(104 OP_CHECK_IF(
104 ksize->GetSize() != ATTR_LIST_SHAPE_SIZE,105 ksize->GetSize() != ATTR_LIST_SHAPE_SIZE,
105 OP_LOGE(context->GetNodeName(), "Length of ksize %lu must be 4!", ksize->GetSize()), return GRAPH_FAILED);106 OP_LOGE(context->GetNodeName(), "Length of ksize %lu must be 4!", ksize->GetSize()), return GRAPH_FAILED);
106- auto ksize_data = reinterpret_cast<const int64_t*>(ksize->GetData());107+ auto ksize_data = static_cast<const int64_t*>(ksize->GetData());
107 108 
108 if (dataFormatStr == "NCHW") {109 if (dataFormatStr == "NCHW") {
109 OP_CHECK_IF(ksize_data[IDX_ZERO] != ONE,110 OP_CHECK_IF(ksize_data[IDX_ZERO] != ONE,
@@ -126,7 +127,7 @@ ge::graphStatus InferShape4AvgPoolV2Grad(gert::InferShapeContext* context)
126 OP_CHECK_IF(127 OP_CHECK_IF(
127 strides->GetSize() != ATTR_LIST_SHAPE_SIZE,128 strides->GetSize() != ATTR_LIST_SHAPE_SIZE,
128 OP_LOGE(context->GetNodeName(), "Length of strides %lu must be 4!", strides->GetSize()), return GRAPH_FAILED);129 OP_LOGE(context->GetNodeName(), "Length of strides %lu must be 4!", strides->GetSize()), return GRAPH_FAILED);
129- auto strides_data = reinterpret_cast<const int64_t*>(strides->GetData());130+ auto strides_data = static_cast<const int64_t*>(strides->GetData());
130 131 
131 if (dataFormatStr == "NCHW") {132 if (dataFormatStr == "NCHW") {
132 OP_CHECK_IF(strides_data[IDX_ZERO] != ONE,133 OP_CHECK_IF(strides_data[IDX_ZERO] != ONE,
@@ -20,9 +20,8 @@
20#include "../../../pool_grad_common/op_host/arch35/max_pool_grad_with_argmax_tiling_common.h"20#include "../../../pool_grad_common/op_host/arch35/max_pool_grad_with_argmax_tiling_common.h"
21#include "../../../pool_grad_common/op_kernel/arch35/max_pool_grad_with_argmax_struct_common.h"21#include "../../../pool_grad_common/op_kernel/arch35/max_pool_grad_with_argmax_struct_common.h"
22 22 
23-using namespace std;
24- 
25namespace optiling {23namespace optiling {
24+using namespace std;
26 25 
27BEGIN_TILING_DATA_DEF(MaxPoolGradWithArgmaxV3TilingData)26BEGIN_TILING_DATA_DEF(MaxPoolGradWithArgmaxV3TilingData)
28TILING_DATA_FIELD_DEF(uint64_t, nc);27TILING_DATA_FIELD_DEF(uint64_t, nc);
@@ -46,7 +46,7 @@ ge::graphStatus MaxPoolWithArgmaxV3BaseTiling::GetPlatformInfo()
46{46{
47 auto platformPtr = context_->GetPlatformInfo();47 auto platformPtr = context_->GetPlatformInfo();
48 if (platformPtr == nullptr) {48 if (platformPtr == nullptr) {
49- auto compileInfoPtr = reinterpret_cast<const MaxPoolWithArgmaxV3CompileInfo*>(context_->GetCompileInfo());49+ auto compileInfoPtr = static_cast<const MaxPoolWithArgmaxV3CompileInfo*>(context_->GetCompileInfo());
50 OP_CHECK_IF(50 OP_CHECK_IF(
51 compileInfoPtr == nullptr, CUBE_INNER_ERR_REPORT(context_, "compile info is null"),51 compileInfoPtr == nullptr, CUBE_INNER_ERR_REPORT(context_, "compile info is null"),
52 return ge::GRAPH_FAILED);52 return ge::GRAPH_FAILED);
@@ -446,7 +446,7 @@ ge::graphStatus GetAvgPool3DPlatformInfo(gert::TilingContext* context, uint64_t&
446{446{
447 auto platformPtr = context->GetPlatformInfo();447 auto platformPtr = context->GetPlatformInfo();
448 if (platformPtr == nullptr) {448 if (platformPtr == nullptr) {
449- auto compileInfoPtr = reinterpret_cast<const optiling::avgPool3DTilingCompileInfo::CubeCompileInfo *>(context->GetCompileInfo());449+ auto compileInfoPtr = static_cast<const optiling::avgPool3DTilingCompileInfo::CubeCompileInfo *>(context->GetCompileInfo());
450 OP_TILING_CHECK(compileInfoPtr == nullptr, CUBE_INNER_ERR_REPORT(context, "compile info is null"),450 OP_TILING_CHECK(compileInfoPtr == nullptr, CUBE_INNER_ERR_REPORT(context, "compile info is null"),
451 return ge::GRAPH_FAILED);451 return ge::GRAPH_FAILED);
452 coreNum = compileInfoPtr->core_num;452 coreNum = compileInfoPtr->core_num;
@@ -102,7 +102,7 @@ public:
102 const char *op_type = context->GetNodeType();102 const char *op_type = context->GetNodeType();
103 fe::PlatFormInfos *platformInfoPtr = context->GetPlatformInfo();103 fe::PlatFormInfos *platformInfoPtr = context->GetPlatformInfo();
104 if (platformInfoPtr == nullptr) {104 if (platformInfoPtr == nullptr) {
105- auto compileInfoPtr = reinterpret_cast<const Ops::NN::Optiling::CompileInfoCommon *>(context->GetCompileInfo());105+ auto compileInfoPtr = static_cast<const Ops::NN::Optiling::CompileInfoCommon *>(context->GetCompileInfo());
106 OPS_ERR_IF(compileInfoPtr == nullptr, OPS_REPORT_VECTOR_INNER_ERR(op_type, "compileInfoPtr is null."),106 OPS_ERR_IF(compileInfoPtr == nullptr, OPS_REPORT_VECTOR_INNER_ERR(op_type, "compileInfoPtr is null."),
107 return ge::GRAPH_FAILED);107 return ge::GRAPH_FAILED);
108 soc_version = compileInfoPtr->socVersion;108 soc_version = compileInfoPtr->socVersion;
@@ -138,7 +138,7 @@ public:
138 const char *op_type = context->GetNodeType();138 const char *op_type = context->GetNodeType();
139 auto platformInfoPtr = context->GetPlatformInfo();139 auto platformInfoPtr = context->GetPlatformInfo();
140 if (platformInfoPtr == nullptr) {140 if (platformInfoPtr == nullptr) {
141- auto compileInfoPtr = reinterpret_cast<const Ops::NN::Optiling::CompileInfoCommon *>(context->GetCompileInfo());141+ auto compileInfoPtr = static_cast<const Ops::NN::Optiling::CompileInfoCommon *>(context->GetCompileInfo());
142 OPS_ERR_IF(compileInfoPtr == nullptr, OPS_REPORT_VECTOR_INNER_ERR(op_type, "compileInfoPtr is null."),142 OPS_ERR_IF(compileInfoPtr == nullptr, OPS_REPORT_VECTOR_INNER_ERR(op_type, "compileInfoPtr is null."),
143 return ge::GRAPH_FAILED);143 return ge::GRAPH_FAILED);
144 soc_version = compileInfoPtr->socVersion;144 soc_version = compileInfoPtr->socVersion;
Mpooling/pool_grad_common/op_host/arch35/util.h+3-3文件内容审核中,请稍后刷新重试