已合并
增加mesw算子空指针校验 #9580
wuyufei创建于 8月31日
增加mesw算子空指针校验 #9580
已合并
共 3 个文件变更+33-3
| @@ -44,8 +44,12 @@ ge::graphStatus InferShapeForMatmulEmuSplitWeight(gert::InferShapeContext* conte | |||
| 44 | wLowShape->GetDimNum() != kMinDimNum, | 44 | wLowShape->GetDimNum() != kMinDimNum, |
| 45 | CUBE_INNER_ERR_REPORT(op_name, "all inputs must be 2D"), return ge::GRAPH_FAILED); | 45 | CUBE_INNER_ERR_REPORT(op_name, "all inputs must be 2D"), return ge::GRAPH_FAILED); |
| 46 | 46 | ||
| 47 | - bool transX = *(attrs->GetAttrPointer<bool>(kAttrTransXIdx)); | 47 | + auto transXPtr = attrs->GetAttrPointer<bool>(kAttrTransXIdx); |
| 48 | - bool transW = *(attrs->GetAttrPointer<bool>(kAttrTransWIdx)); | 48 | + auto transWPtr = attrs->GetAttrPointer<bool>(kAttrTransWIdx); |
| 49 | + OP_CHECK_IF(transXPtr == nullptr || transWPtr == nullptr, | ||
| 50 | + CUBE_INNER_ERR_REPORT(op_name, "transX or transW attr is null"), return ge::GRAPH_FAILED); | ||
| 51 | + bool transX = *transXPtr; | ||
| 52 | + bool transW = *transWPtr; | ||
| 49 | 53 | ||
| 50 | int64_t M = transX ? xShape->GetDim(1) : xShape->GetDim(0); | 54 | int64_t M = transX ? xShape->GetDim(1) : xShape->GetDim(0); |
| 51 | int64_t K = transX ? xShape->GetDim(0) : xShape->GetDim(1); | 55 | int64_t K = transX ? xShape->GetDim(0) : xShape->GetDim(1); |
| @@ -82,7 +82,10 @@ ge::graphStatus MatmulEmuSplitWeightTiling::ExtractAttrs() | |||
| 82 | const int32_t* yDtypePtr = attrs->GetAttrPointer<int32_t>(INDEX_ATTR_Y_DTYPE); | 82 | const int32_t* yDtypePtr = attrs->GetAttrPointer<int32_t>(INDEX_ATTR_Y_DTYPE); |
| 83 | yDtype_ = (yDtypePtr != nullptr) ? *yDtypePtr : Y_DTYPE_FP32; | 83 | yDtype_ = (yDtypePtr != nullptr) ? *yDtypePtr : Y_DTYPE_FP32; |
| 84 | 84 | ||
| 85 | - scale_ = *(attrs->GetAttrPointer<float>(INDEX_ATTR_W_LOW_SCALE)); | 85 | + const float* scalePtr = attrs->GetAttrPointer<float>(INDEX_ATTR_W_LOW_SCALE); |
| 86 | + OP_TILING_CHECK(scalePtr == nullptr, CUBE_INNER_ERR_REPORT(context_->GetNodeName(), "wLowScale attr is null"), | ||
| 87 | + return ge::GRAPH_FAILED); | ||
| 88 | + scale_ = *scalePtr; | ||
| 86 | 89 | ||
| 87 | const bool* transXPtr = attrs->GetAttrPointer<bool>(INDEX_ATTR_TRANS_X); | 90 | const bool* transXPtr = attrs->GetAttrPointer<bool>(INDEX_ATTR_TRANS_X); |
| 88 | transX_ = (transXPtr != nullptr) ? *transXPtr : false; | 91 | transX_ = (transXPtr != nullptr) ? *transXPtr : false; |
| @@ -187,10 +190,30 @@ ge::graphStatus MatmulEmuSplitWeightTiling::ValidateAttrs() const | |||
| 187 | return ge::GRAPH_SUCCESS; | 190 | return ge::GRAPH_SUCCESS; |
| 188 | } | 191 | } |
| 189 | 192 | ||
| 193 | +// ====== Input null-check ====== | ||
| 194 | + | ||
| 195 | +ge::graphStatus MatmulEmuSplitWeightTiling::ValidateInputsNotNull() | ||
林 | |||
| 196 | +{ | ||
| 197 | + auto attrs = context_->GetAttrs(); | ||
| 198 | + OPS_CHECK_NULL_WITH_CONTEXT(context_, attrs); | ||
| 199 | + OPS_CHECK_NULL_WITH_CONTEXT(context_, context_->GetInputDesc(INDEX_X)); | ||
| 200 | + OPS_CHECK_NULL_WITH_CONTEXT(context_, context_->GetInputShape(INDEX_X)); | ||
| 201 | + OPS_CHECK_NULL_WITH_CONTEXT(context_, context_->GetInputDesc(INDEX_W_HIGH)); | ||
| 202 | + OPS_CHECK_NULL_WITH_CONTEXT(context_, context_->GetInputShape(INDEX_W_HIGH)); | ||
| 203 | + OPS_CHECK_NULL_WITH_CONTEXT(context_, context_->GetInputDesc(INDEX_W_LOW)); | ||
| 204 | + OPS_CHECK_NULL_WITH_CONTEXT(context_, context_->GetInputShape(INDEX_W_LOW)); | ||
| 205 | + OPS_CHECK_NULL_WITH_CONTEXT(context_, context_->GetOutputDesc(INDEX_Y)); | ||
| 206 | + OPS_CHECK_NULL_WITH_CONTEXT(context_, context_->GetOutputShape(INDEX_Y)); | ||
| 207 | + return ge::GRAPH_SUCCESS; | ||
| 208 | +} | ||
| 209 | + | ||
| 190 | // ====== GetShapeAttrsInfo: orchestrates extract + validate phases ====== | 210 | // ====== GetShapeAttrsInfo: orchestrates extract + validate phases ====== |
| 191 | 211 | ||
| 192 | ge::graphStatus MatmulEmuSplitWeightTiling::GetShapeAttrsInfo() | 212 | ge::graphStatus MatmulEmuSplitWeightTiling::GetShapeAttrsInfo() |
| 193 | { | 213 | { |
| 214 | + if (ValidateInputsNotNull() != ge::GRAPH_SUCCESS) { | ||
| 215 | + return ge::GRAPH_FAILED; | ||
| 216 | + } | ||
| 194 | if (ExtractAttrs() != ge::GRAPH_SUCCESS) { | 217 | if (ExtractAttrs() != ge::GRAPH_SUCCESS) { |
| 195 | return ge::GRAPH_FAILED; | 218 | return ge::GRAPH_FAILED; |
| 196 | } | 219 | } |
| @@ -32,6 +32,9 @@ protected: | |||
| 32 | ge::graphStatus PostTiling() override; | 32 | ge::graphStatus PostTiling() override; |
| 33 | 33 | ||
| 34 | private: | 34 | private: |
| 35 | + // Input null-check | ||
| 36 | + ge::graphStatus ValidateInputsNotNull(); | ||
| 37 | + | ||
| 35 | // Extract phases | 38 | // Extract phases |
| 36 | void ExtractDtype(); | 39 | void ExtractDtype(); |
| 37 | void ExtractFormat(); | 40 | void ExtractFormat(); |
PR 描述的测试字段是空的,本次新增的三处校验(infershape 的 transX/transW 判空、tiling 的 scale 判空、ValidateInputsNotNull 整条链)都没有用例验证。建议至少补一个属性指针为 null 时走报错分支的 UT 用例,否则这些校验逻辑本身没有回归保护,后续改动容易把判空条件改丢。