已合并
avg_pool_grad and max_pool_with_argmax errMsg fix #5775
zhaoxinmeng创建于 6月5日
avg_pool_grad and max_pool_with_argmax errMsg fix #5775
已合并
zhaoxinmeng创建于 6月5日
8 个文件变更+1559-229
@@ -63,7 +63,6 @@ static inline bool IsGreaterThanInt32Max(const AvgPoolV2GradInputInfo& inputData
63static ge::graphStatus GetPadInfo(gert::TilingContext* context,63static ge::graphStatus GetPadInfo(gert::TilingContext* context,
64 AvgPoolV2GradInputInfo& inputData, const AvgPoolGradCommon& commInfo)64 AvgPoolV2GradInputInfo& inputData, const AvgPoolGradCommon& commInfo)
65{65{
66- 
67 if (commInfo.padModeStr == "VALID") {66 if (commInfo.padModeStr == "VALID") {
68 inputData.pad = {0, 0, 0, 0}; // top, bottom, left, right67 inputData.pad = {0, 0, 0, 0}; // top, bottom, left, right
69 } else if (commInfo.padModeStr == "SAME") {68 } else if (commInfo.padModeStr == "SAME") {
@@ -79,7 +78,7 @@ static ge::graphStatus GetPadInfo(gert::TilingContext* context,
79 78 
80 inputData.pad = {topPad, bottomPad, leftPad, rightPad};79 inputData.pad = {topPad, bottomPad, leftPad, rightPad};
81 } else {80 } else {
82- VECTOR_INNER_ERR_REPORT_TILIING(context, "AvgPoolGrad: not support padmode %s", commInfo.padModeStr.c_str());81+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "padding", commInfo.padModeStr.c_str(), "SAME or VALID");
83 return ge::GRAPH_FAILED;82 return ge::GRAPH_FAILED;
84 }83 }
85 return ge::GRAPH_SUCCESS;84 return ge::GRAPH_SUCCESS;
@@ -91,10 +90,11 @@ static ge::graphStatus GetStrideInfo(gert::TilingContext* context, const gert::R
91 auto stride = runtimeAttrs->GetListInt(STRIDE_POS);90 auto stride = runtimeAttrs->GetListInt(STRIDE_POS);
92 OPS_CHECK_NULL_WITH_CONTEXT(context, stride);91 OPS_CHECK_NULL_WITH_CONTEXT(context, stride);
93 auto strideDim = stride->GetSize();92 auto strideDim = stride->GetSize();
94- OP_TILING_CHECK(strideDim != ONE_DIMS && strideDim != HW_DIMS && strideDim != NCHW_DIMS,93+ OP_TILING_CHECK(
95- VECTOR_INNER_ERR_REPORT_TILIING(context, "AvgPoolGrad: stride must have %d, %d, or %d elements ",94+ strideDim != ONE_DIMS && strideDim != HW_DIMS && strideDim != NCHW_DIMS,
96- ONE_DIMS, HW_DIMS, NCHW_DIMS),95+ OP_LOGE_FOR_INVALID_LISTSIZE(
97- return ge::GRAPH_FAILED);96+ context->GetNodeName(), "strides", std::to_string(strideDim).c_str(), "1, 2, or 4"),
97+ return ge::GRAPH_FAILED);
98 98 
99 int64_t hStride = ONE;99 int64_t hStride = ONE;
100 int64_t wStride = ONE;100 int64_t wStride = ONE;
@@ -109,11 +109,13 @@ static ge::graphStatus GetStrideInfo(gert::TilingContext* context, const gert::R
109 wStride = stride->GetData()[commInfo.wDim];109 wStride = stride->GetData()[commInfo.wDim];
110 }110 }
111 inputData.stride = {hStride, wStride};111 inputData.stride = {hStride, wStride};
112- OP_TILING_CHECK(hStride <= 0 || wStride <= 0,112+ OP_TILING_CHECK(
113- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),113+ hStride <= 0 || wStride <= 0,
114- "AvgPoolGrad: The stride of the H and W dimensions should be greater than 0, not support [%ld, %ld]",114+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
115- hStride, wStride),115+ context->GetNodeName(), "strides[h_dim, w_dim]",
116- return ge::GRAPH_FAILED);116+ ("[" + std::to_string(hStride) + ", " + std::to_string(wStride) + "]").c_str(),
117+ "h_dim and w_dim of strides should be greater than 0"),
118+ return ge::GRAPH_FAILED);
117 return ge::GRAPH_SUCCESS;119 return ge::GRAPH_SUCCESS;
118}120}
119 121 
@@ -125,8 +127,7 @@ static ge::graphStatus GetKernelKsizeInfo(gert::TilingContext* context, const ge
125 auto kSizeDim = kernelSize->GetSize();127 auto kSizeDim = kernelSize->GetSize();
126 OP_TILING_CHECK(128 OP_TILING_CHECK(
127 kSizeDim != ONE_DIMS && kSizeDim != HW_DIMS && kSizeDim != NCHW_DIMS,129 kSizeDim != ONE_DIMS && kSizeDim != HW_DIMS && kSizeDim != NCHW_DIMS,
128- VECTOR_INNER_ERR_REPORT_TILIING(context, "AvgPoolGrad: kernel_size must have %d, %d, or %d elements ",130+ OP_LOGE_FOR_INVALID_LISTSIZE(context->GetNodeName(), "ksize", std::to_string(kSizeDim).c_str(), "1, 2, or 4"),
129- ONE_DIMS, HW_DIMS, NCHW_DIMS),
130 return ge::GRAPH_FAILED);131 return ge::GRAPH_FAILED);
131 int64_t hKernelSize = 1;132 int64_t hKernelSize = 1;
132 int64_t wKernelSize = 1;133 int64_t wKernelSize = 1;
@@ -142,11 +143,13 @@ static ge::graphStatus GetKernelKsizeInfo(gert::TilingContext* context, const ge
142 }143 }
143 inputData.kernelSize = {hKernelSize, wKernelSize};144 inputData.kernelSize = {hKernelSize, wKernelSize};
144 145 
145- OP_TILING_CHECK(hKernelSize <= 0 || wKernelSize <= 0,146+ OP_TILING_CHECK(
146- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),147+ hKernelSize <= 0 || wKernelSize <= 0,
147- "AvgPoolGrad: The ksize of the H and W dimensions should be greater than 0, not support [%ld, %ld]",148+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
148- hKernelSize, wKernelSize),149+ context->GetNodeName(), "ksize[h_dim, w_dim]",
149- return ge::GRAPH_FAILED);150+ ("[" + std::to_string(hKernelSize) + ", " + std::to_string(wKernelSize) + "]").c_str(),
151+ "h_dim and w_dim of ksize should be greater than 0"),
152+ return ge::GRAPH_FAILED);
150 return ge::GRAPH_SUCCESS;153 return ge::GRAPH_SUCCESS;
151}154}
152 155 
@@ -154,28 +157,28 @@ static ge::graphStatus CheckShape(gert::TilingContext* context, gert::Shape& gra
154{157{
155 OP_TILING_CHECK(158 OP_TILING_CHECK(
156 gradShape.GetDimNum() != NCHW_DIMS && gradShape.GetDimNum() != CHW_DIMS,159 gradShape.GetDimNum() != NCHW_DIMS && gradShape.GetDimNum() != CHW_DIMS,
157- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(), "AvgPoolGrad: input shape dim = %zu, should be equal 3 or 4",160+ OP_LOGE_FOR_INVALID_SHAPEDIM(
158- gradShape.GetDimNum()),161+ context->GetNodeName(), "input_grad", std::to_string(gradShape.GetDimNum()).c_str(), "3 or 4"),
159 return ge::GRAPH_FAILED);162 return ge::GRAPH_FAILED);
160 OP_TILING_CHECK(163 OP_TILING_CHECK(
161 outputShape.GetDimNum() != NCHW_DIMS && outputShape.GetDimNum() != CHW_DIMS,164 outputShape.GetDimNum() != NCHW_DIMS && outputShape.GetDimNum() != CHW_DIMS,
162- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(), "AvgPoolGrad: output shape dim = %zu, should be equal 3 or 4",165+ OP_LOGE_FOR_INVALID_SHAPEDIM(
163- outputShape.GetDimNum()),166+ context->GetNodeName(), "out_grad", std::to_string(outputShape.GetDimNum()).c_str(), "3 or 4"),
164 return ge::GRAPH_FAILED);167 return ge::GRAPH_FAILED);
165 if (gradShape.GetShapeSize() == 0 && outputShape.GetShapeSize() == 0) {168 if (gradShape.GetShapeSize() == 0 && outputShape.GetShapeSize() == 0) {
166 return ge::GRAPH_SUCCESS;169 return ge::GRAPH_SUCCESS;
167 }170 }
168- OP_TILING_CHECK(gradShape.GetShapeSize() <= 0,171+ OP_TILING_CHECK(
169- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),172+ gradShape.GetShapeSize() <= 0,
170- "AvgPoolGrad: input shape size %ld less than zero failed",173+ OP_LOGE_FOR_INVALID_SHAPESIZE(
171- gradShape.GetShapeSize()),174+ context->GetNodeName(), "input_grad", std::to_string(gradShape.GetShapeSize()).c_str(), "greater than 0"),
172- return ge::GRAPH_FAILED);175+ return ge::GRAPH_FAILED);
173 176 
174- OP_TILING_CHECK(outputShape.GetShapeSize() <= 0,177+ OP_TILING_CHECK(
175- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),178+ outputShape.GetShapeSize() <= 0,
176- "AvgPoolGrad: output shape size %ld less than zero failed",179+ OP_LOGE_FOR_INVALID_SHAPESIZE(
177- outputShape.GetShapeSize()),180+ context->GetNodeName(), "out_grad", std::to_string(outputShape.GetShapeSize()).c_str(), "greater than 0"),
178- return ge::GRAPH_FAILED);181+ return ge::GRAPH_FAILED);
179 return ge::GRAPH_SUCCESS;182 return ge::GRAPH_SUCCESS;
180}183}
181 184 
@@ -191,9 +194,7 @@ ge::graphStatus GetFormat(gert::TilingContext* context, const gert::RuntimeAttrs
191 } else if (inputFormatStr == "NHWC") {194 } else if (inputFormatStr == "NHWC") {
192 inputData.inputFormat = ge::Format::FORMAT_NHWC;195 inputData.inputFormat = ge::Format::FORMAT_NHWC;
193 } else {196 } else {
194- VECTOR_INNER_ERR_REPORT_TILIING(context,197+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "data_format", inputFormatStr.c_str(), "NCHW or NHWC");
195- "AvgPoolGrad: only support NCHW、NHWC, not support format %s",
196- inputFormatStr.c_str());
197 return ge::GRAPH_FAILED;198 return ge::GRAPH_FAILED;
198 }199 }
199 return ge::GRAPH_SUCCESS;200 return ge::GRAPH_SUCCESS;
@@ -232,8 +233,8 @@ ge::graphStatus CalculateShapeInfo(gert::TilingContext* context, AvgPoolV2GradIn
232 }233 }
233 inputData.channels = shapeValue[commInfo.cDim];234 inputData.channels = shapeValue[commInfo.cDim];
234 } else {235 } else {
235- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),236+ OP_LOGE_FOR_INVALID_VALUE(
236- "AvgPoolGrad: only support NCHW and NHWC, not support format.");237+ context->GetNodeName(), "data_format", Ops::Base::ToString(inputData.inputFormat).c_str(), "NCHW or NHWC");
237 return ge::GRAPH_FAILED;238 return ge::GRAPH_FAILED;
238 }239 }
239 inputData.inputShape = {shapeValue[commInfo.hDim], shapeValue[commInfo.wDim]};240 inputData.inputShape = {shapeValue[commInfo.hDim], shapeValue[commInfo.wDim]};
@@ -248,25 +249,29 @@ ge::graphStatus CheckDimConsistency(gert::TilingContext* context, const int32_t*
248 auto outShape = EnsureNotScalar(outX->GetStorageShape());249 auto outShape = EnsureNotScalar(outX->GetStorageShape());
249 if (shapeDim == NCHW_DIMS) {250 if (shapeDim == NCHW_DIMS) {
250 OP_TILING_CHECK(251 OP_TILING_CHECK(
251- shapeValue[commInfo.nDim] != outShape.GetDim(commInfo.nDim),252+ shapeValue[commInfo.nDim] != outShape.GetDim(commInfo.nDim),
252- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),253+ OP_LOGE_FOR_INVALID_SHAPE(
253- "AvgPoolGrad: input n-dim shape value is %d, but output n-dim shape value is %ld, should be same ", shapeValue[commInfo.nDim], outShape.GetDim(commInfo.nDim)),254+ context->GetNodeName(), "output_grad[n_dim]", ("[" + std::to_string(outShape.GetDim(commInfo.nDim)) + "]").c_str(),
254- return ge::GRAPH_FAILED);255+ ("the same as orig_input_shape[n_dim] shape [" + std::to_string(shapeValue[commInfo.nDim]) + "]").c_str()),
256+ return ge::GRAPH_FAILED);
255 }257 }
256 OP_TILING_CHECK(258 OP_TILING_CHECK(
257 shapeValue[commInfo.cDim] != outShape.GetDim(commInfo.cDim),259 shapeValue[commInfo.cDim] != outShape.GetDim(commInfo.cDim),
258- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),260+ OP_LOGE_FOR_INVALID_SHAPE(
259- "AvgPoolGrad: input c-dim shape value is %d, but output c-dim shape value is %ld, should be same ", shapeValue[commInfo.cDim], outShape.GetDim(commInfo.cDim)),261+ context->GetNodeName(), "output_grad[c_dim]", ("[" + std::to_string(outShape.GetDim(commInfo.cDim)) + "]").c_str(),
262+ ("the same as orig_input_shape[c_dim] shape [" + std::to_string(shapeValue[commInfo.cDim]) + "]").c_str()),
260 return ge::GRAPH_FAILED);263 return ge::GRAPH_FAILED);
261 OP_TILING_CHECK(264 OP_TILING_CHECK(
262 shapeValue[commInfo.hDim] != outShape.GetDim(commInfo.hDim),265 shapeValue[commInfo.hDim] != outShape.GetDim(commInfo.hDim),
263- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),266+ OP_LOGE_FOR_INVALID_SHAPE(
264- "AvgPoolGrad: input h-dim shape value is %d, but output h-dim shape value is %ld, should be same ", shapeValue[commInfo.hDim], outShape.GetDim(commInfo.hDim)),267+ context->GetNodeName(), "output_grad[h_dim]", ("[" + std::to_string(outShape.GetDim(commInfo.hDim)) + "]").c_str(),
268+ ("the same as orig_input_shape[h_dim] shape [" + std::to_string(shapeValue[commInfo.hDim]) + "]").c_str()),
265 return ge::GRAPH_FAILED);269 return ge::GRAPH_FAILED);
266 OP_TILING_CHECK(270 OP_TILING_CHECK(
267 shapeValue[commInfo.wDim] != outShape.GetDim(commInfo.wDim),271 shapeValue[commInfo.wDim] != outShape.GetDim(commInfo.wDim),
268- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),272+ OP_LOGE_FOR_INVALID_SHAPE(
269- "AvgPoolGrad: input w-dim shape value is %d, but output w-dim shape value is %ld, should be same ", shapeValue[commInfo.wDim], outShape.GetDim(commInfo.wDim)),273+ context->GetNodeName(), "output_grad[w_dim]", ("[" + std::to_string(outShape.GetDim(commInfo.wDim)) + "]").c_str(),
274+ ("the same as orig_input_shape[w_dim] shape [" + std::to_string(shapeValue[commInfo.wDim]) + "]").c_str()),
270 return ge::GRAPH_FAILED);275 return ge::GRAPH_FAILED);
271 return ge::GRAPH_SUCCESS;276 return ge::GRAPH_SUCCESS;
272}277}
@@ -280,7 +285,8 @@ static ge::graphStatus GetShapeAndDtype(gert::TilingContext* context, const gert
280 auto shapeDim = inputShape0->GetStorageShape().GetDim(0);285 auto shapeDim = inputShape0->GetStorageShape().GetDim(0);
281 OP_TILING_CHECK(286 OP_TILING_CHECK(
282 shapeDim != NCHW_DIMS && shapeDim != CHW_DIMS,287 shapeDim != NCHW_DIMS && shapeDim != CHW_DIMS,
283- VECTOR_INNER_ERR_REPORT_TILIING(context, "inputShapeDim must be 3 or 4, shapeDim: %ld", shapeDim),288+ OP_LOGE_FOR_INVALID_SHAPESIZE(
289+ context->GetNodeName(), "orig_input_shape", std::to_string(shapeDim).c_str(), "3 or 4"),
284 return ge::GRAPH_FAILED);290 return ge::GRAPH_FAILED);
285 // input_grad291 // input_grad
286 auto inputShape1 = context->GetInputShape(INDEX_GRAD);292 auto inputShape1 = context->GetInputShape(INDEX_GRAD);
@@ -296,7 +302,9 @@ static ge::graphStatus GetShapeAndDtype(gert::TilingContext* context, const gert
296 302 
297 auto dtype = inputDesc->GetDataType();303 auto dtype = inputDesc->GetDataType();
298 if (IsInvalidType(dtype)) {304 if (IsInvalidType(dtype)) {
299- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(), "AvgPoolGrad: invalid dtype");305+ OP_LOGE_FOR_INVALID_DTYPE(
306+ context->GetNodeName(), "input_grad", Ops::Base::ToString(dtype).c_str(),
307+ "DT_FLOAT, DT_FLOAT16, or DT_BF16");
300 return ge::GRAPH_FAILED;308 return ge::GRAPH_FAILED;
301 }309 }
302 inputData.dtypeSize = ge::GetSizeByDataType(dtype);310 inputData.dtypeSize = ge::GetSizeByDataType(dtype);
@@ -305,9 +313,10 @@ static ge::graphStatus GetShapeAndDtype(gert::TilingContext* context, const gert
305 VECTOR_INNER_ERR_REPORT_TILIING(context, "inputData.dtypeSize must be greater than 0, dtypeSize: %ld", inputData.dtypeSize),313 VECTOR_INNER_ERR_REPORT_TILIING(context, "inputData.dtypeSize must be greater than 0, dtypeSize: %ld", inputData.dtypeSize),
306 return ge::GRAPH_FAILED);314 return ge::GRAPH_FAILED);
307 // 校验是否是3/4维315 // 校验是否是3/4维
308- OP_TILING_CHECK(CheckShape(context, gradShape, outShape) != ge::GRAPH_SUCCESS,316+ ge::graphStatus res = CheckShape(context, gradShape, outShape);
309- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(), "AvgPoolGrad: check shape failed"),317+ if (res != ge::GRAPH_SUCCESS) {
310- return ge::GRAPH_FAILED);318+ return res;
319+ }
311 // 值依赖转换320 // 值依赖转换
312 const gert::Tensor* shapeTensor = context->GetInputTensor(ORIG_INPUT_SHAPE_INDEX);321 const gert::Tensor* shapeTensor = context->GetInputTensor(ORIG_INPUT_SHAPE_INDEX);
313 OP_CHECK_NULL_WITH_CONTEXT(context, shapeTensor);322 OP_CHECK_NULL_WITH_CONTEXT(context, shapeTensor);
@@ -315,19 +324,22 @@ static ge::graphStatus GetShapeAndDtype(gert::TilingContext* context, const gert
315 if (shapeValue == nullptr) {324 if (shapeValue == nullptr) {
316 return ge::GRAPH_FAILED;325 return ge::GRAPH_FAILED;
317 }326 }
318- 327+ 
319 ge::graphStatus ret = GetFormat(context, runtimeAttrs, inputData);328 ge::graphStatus ret = GetFormat(context, runtimeAttrs, inputData);
320- OP_TILING_CHECK(ret != ge::GRAPH_SUCCESS,329+ if (ret != ge::GRAPH_SUCCESS) {
321- VECTOR_INNER_ERR_REPORT_TILIING(context, "AvgPoolGrad: get format failed"), return ret);330+ return ret;
331+ }
322 332 
323 ret = CalculateShapeInfo(context, inputData, commInfo, shapeValue);333 ret = CalculateShapeInfo(context, inputData, commInfo, shapeValue);
324- OP_TILING_CHECK(ret != ge::GRAPH_SUCCESS,334+ if (ret != ge::GRAPH_SUCCESS) {
325- VECTOR_INNER_ERR_REPORT_TILIING(context, "AvgPoolGrad: calculate shape info failed"), return ret);335+ return ret;
336+ }
326 337 
327 inputData.gradShape = {gradShape.GetDim(commInfo.hDim), gradShape.GetDim(commInfo.wDim)};338 inputData.gradShape = {gradShape.GetDim(commInfo.hDim), gradShape.GetDim(commInfo.wDim)};
328 ret = CheckDimConsistency(context, shapeValue, commInfo);339 ret = CheckDimConsistency(context, shapeValue, commInfo);
329- OP_TILING_CHECK(ret != ge::GRAPH_SUCCESS,340+ if (ret != ge::GRAPH_SUCCESS) {
330- VECTOR_INNER_ERR_REPORT_TILIING(context, "AvgPoolGrad: check dim consistency failed"), return ret);341+ return ret;
342+ }
331 343 
332 inputData.outShape = {outShape.GetDim(commInfo.hDim), outShape.GetDim(commInfo.wDim)};344 inputData.outShape = {outShape.GetDim(commInfo.hDim), outShape.GetDim(commInfo.wDim)};
333 return ge::GRAPH_SUCCESS;345 return ge::GRAPH_SUCCESS;
@@ -341,9 +353,9 @@ static ge::graphStatus GetAttrsInfo(gert::TilingContext* context, const gert::Ru
341 commInfo.padModeStr = padMode;353 commInfo.padModeStr = padMode;
342 OP_TILING_CHECK(354 OP_TILING_CHECK(
343 IsInvalidPaddingMode(commInfo.padModeStr),355 IsInvalidPaddingMode(commInfo.padModeStr),
344- VECTOR_INNER_ERR_REPORT_TILIING(context, "AvgPoolGrad: not support padmode %s", commInfo.padModeStr.c_str()),356+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "padding", commInfo.padModeStr.c_str(), "SAME or VALID"),
345 return ge::GRAPH_FAILED);357 return ge::GRAPH_FAILED);
346- 358+ 
347 // tensorflow 默认值对应 exclusive = true, 故countIncludePad为false , divisorOverride = 0, globalPooling = false, ceil_mode对AvgPoolV2Grad无影响359 // tensorflow 默认值对应 exclusive = true, 故countIncludePad为false , divisorOverride = 0, globalPooling = false, ceil_mode对AvgPoolV2Grad无影响
348 inputData.countIncludePad = false;360 inputData.countIncludePad = false;
349 inputData.divisorOverride = 0;361 inputData.divisorOverride = 0;
@@ -354,15 +366,19 @@ static ge::graphStatus GetAttrsInfo(gert::TilingContext* context, const gert::Ru
354 366 
355static ge::graphStatus CheckGradShapeForValid(gert::TilingContext* context, AvgPoolV2GradInputInfo& inputData)367static ge::graphStatus CheckGradShapeForValid(gert::TilingContext* context, AvgPoolV2GradInputInfo& inputData)
356{368{
357- int64_t expectedH = (inputData.inputShape[H_DIM] - inputData.kernelSize[H_DIM] + inputData.stride[H_DIM]) /369+ int64_t expectedH =
358- inputData.stride[H_DIM];370+ (inputData.inputShape[H_DIM] - inputData.kernelSize[H_DIM] + inputData.stride[H_DIM]) / inputData.stride[H_DIM];
359- int64_t expectedW = (inputData.inputShape[W_DIM] - inputData.kernelSize[W_DIM] + inputData.stride[W_DIM]) /371+ int64_t expectedW =
360- inputData.stride[W_DIM];372+ (inputData.inputShape[W_DIM] - inputData.kernelSize[W_DIM] + inputData.stride[W_DIM]) / inputData.stride[W_DIM];
361 if (inputData.gradShape[H_DIM] != expectedH || inputData.gradShape[W_DIM] != expectedW) {373 if (inputData.gradShape[H_DIM] != expectedH || inputData.gradShape[W_DIM] != expectedW) {
362- VECTOR_INNER_ERR_REPORT_TILIING(context,374+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(
363- "AvgPoolGrad: when padmode is VALID, the gradshape in h-dim and w-dim should be [%ld] [%ld], but got [%ld] [%ld]",375+ context->GetNodeName(), "input_grad[h_dim, w_dim]",
364- expectedH, expectedW, inputData.gradShape[H_DIM],376+ ("[" + std::to_string(inputData.gradShape[H_DIM]) + ", " + std::to_string(inputData.gradShape[W_DIM]) + "]")
365- inputData.gradShape[W_DIM]);377+ .c_str(),
378+ ("input_grad[h_dim, w_dim] does not match the expected shape calculated from other input shape, it "
379+ "should be [" +
380+ std::to_string(expectedH) + ", " + std::to_string(expectedW) + "]")
381+ .c_str());
366 return ge::GRAPH_FAILED;382 return ge::GRAPH_FAILED;
367 }383 }
368 return ge::GRAPH_SUCCESS;384 return ge::GRAPH_SUCCESS;
@@ -373,10 +389,14 @@ static ge::graphStatus CheckGradShapeForSame(gert::TilingContext* context, AvgPo
373 int64_t expectedH = (inputData.inputShape[H_DIM] + inputData.stride[H_DIM] - 1) / inputData.stride[H_DIM];389 int64_t expectedH = (inputData.inputShape[H_DIM] + inputData.stride[H_DIM] - 1) / inputData.stride[H_DIM];
374 int64_t expectedW = (inputData.inputShape[W_DIM] + inputData.stride[W_DIM] - 1) / inputData.stride[W_DIM];390 int64_t expectedW = (inputData.inputShape[W_DIM] + inputData.stride[W_DIM] - 1) / inputData.stride[W_DIM];
375 if (inputData.gradShape[H_DIM] != expectedH || inputData.gradShape[W_DIM] != expectedW) {391 if (inputData.gradShape[H_DIM] != expectedH || inputData.gradShape[W_DIM] != expectedW) {
376- VECTOR_INNER_ERR_REPORT_TILIING(context,392+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(
377- "AvgPoolGrad: when padmode is SAME, the gradshape in h-dim and w-dim should be [%ld] [%ld], but got [%ld] [%ld]",393+ context->GetNodeName(), "input_grad[h_dim, w_dim]",
378- expectedH, expectedW, inputData.gradShape[H_DIM],394+ ("[" + std::to_string(inputData.gradShape[H_DIM]) + ", " + std::to_string(inputData.gradShape[W_DIM]) + "]")
379- inputData.gradShape[W_DIM]);395+ .c_str(),
396+ ("input_grad[h_dim, w_dim] does not match the expected shape calculated from other input shape, it "
397+ "should be [" +
398+ std::to_string(expectedH) + ", " + std::to_string(expectedW) + "]")
399+ .c_str());
380 return ge::GRAPH_FAILED;400 return ge::GRAPH_FAILED;
381 }401 }
382 return ge::GRAPH_SUCCESS;402 return ge::GRAPH_SUCCESS;
@@ -390,9 +410,7 @@ static ge::graphStatus CheckGradShape(gert::TilingContext* context, AvgPoolV2Gra
390 } else if (commInfo.padModeStr == "SAME") {410 } else if (commInfo.padModeStr == "SAME") {
391 return CheckGradShapeForSame(context, inputData);411 return CheckGradShapeForSame(context, inputData);
392 }412 }
393- VECTOR_INNER_ERR_REPORT_TILIING(context,413+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "padding", commInfo.padModeStr.c_str(), "SAME or VALID");
394- "AvgPoolGrad: unsupported pad mode [%s], only VALID and SAME are supported",
395- commInfo.padModeStr.c_str());
396 return ge::GRAPH_FAILED;414 return ge::GRAPH_FAILED;
397}415}
398 416 
@@ -402,8 +420,7 @@ ge::graphStatus GetAvgPoolGradPlatformInfo(gert::TilingContext* context, uint64_
402 if (platformPtr == nullptr) {420 if (platformPtr == nullptr) {
403 auto compileInfoPtr = reinterpret_cast<const AvgPoolGradCompileInfo*>(context->GetCompileInfo());421 auto compileInfoPtr = reinterpret_cast<const AvgPoolGradCompileInfo*>(context->GetCompileInfo());
404 OP_TILING_CHECK(422 OP_TILING_CHECK(
405- compileInfoPtr == nullptr, CUBE_INNER_ERR_REPORT(context, "compile info is null"),423+ compileInfoPtr == nullptr, CUBE_INNER_ERR_REPORT(context, "compile info is null"), return ge::GRAPH_FAILED);
406- return ge::GRAPH_FAILED);
407 coreNum = compileInfoPtr->coreNum;424 coreNum = compileInfoPtr->coreNum;
408 ubSize = compileInfoPtr->ubSize;425 ubSize = compileInfoPtr->ubSize;
409 } else {426 } else {
@@ -415,40 +432,45 @@ ge::graphStatus GetAvgPoolGradPlatformInfo(gert::TilingContext* context, uint64_
415 ubSize = static_cast<int64_t>(ubSizePlatform);432 ubSize = static_cast<int64_t>(ubSizePlatform);
416 }433 }
417 434 
418- OP_TILING_CHECK(435+ OP_TILING_CHECK(coreNum == 0, CUBE_INNER_ERR_REPORT(context, "coreNum is 0"), return ge::GRAPH_FAILED);
419- coreNum == 0, CUBE_INNER_ERR_REPORT(context, "coreNum is 0"), return ge::GRAPH_FAILED);
420 return ge::GRAPH_SUCCESS;436 return ge::GRAPH_SUCCESS;
421}437}
422 438 
423-ge::graphStatus GetAvgPoolGradShapeAttrsInfo(gert::TilingContext *context, AvgPoolV2GradInputInfo& inputData)439+ge::graphStatus GetAvgPoolGradShapeAttrsInfo(gert::TilingContext* context, AvgPoolV2GradInputInfo& inputData)
424{440{
425 auto runtimeAttrs = context->GetAttrs();441 auto runtimeAttrs = context->GetAttrs();
426 AvgPoolGradCommon commInfo;442 AvgPoolGradCommon commInfo;
427 OPS_CHECK_NULL_WITH_CONTEXT(context, runtimeAttrs);443 OPS_CHECK_NULL_WITH_CONTEXT(context, runtimeAttrs);
428 444 
429- OP_TILING_CHECK(GetAttrsInfo(context, runtimeAttrs, inputData, commInfo) != ge::GRAPH_SUCCESS,445+ ge::graphStatus res = GetAttrsInfo(context, runtimeAttrs, inputData, commInfo);
430- VECTOR_INNER_ERR_REPORT_TILIING(context, "GetAttrsInfo fail."),446+ if (res != ge::GRAPH_SUCCESS) {
431- return ge::GRAPH_FAILED);447+ return res;
448+ }
432 449 
433- OP_TILING_CHECK(GetShapeAndDtype(context, runtimeAttrs, inputData, commInfo) != ge::GRAPH_SUCCESS,450+ res = GetShapeAndDtype(context, runtimeAttrs, inputData, commInfo);
434- VECTOR_INNER_ERR_REPORT_TILIING(context, "GetShapeAndDtype fail."),451+ if (res != ge::GRAPH_SUCCESS) {
435- return ge::GRAPH_FAILED);452+ return res;
453+ }
436 454 
437- OP_TILING_CHECK(GetKernelKsizeInfo(context, runtimeAttrs, inputData, commInfo) != ge::GRAPH_SUCCESS,455+ res = GetKernelKsizeInfo(context, runtimeAttrs, inputData, commInfo);
438- VECTOR_INNER_ERR_REPORT_TILIING(context, "GetKernelKsizeInfo fail."),456+ if (res != ge::GRAPH_SUCCESS) {
439- return ge::GRAPH_FAILED);457+ return res;
458+ }
440 459 
441- OP_TILING_CHECK(GetStrideInfo(context, runtimeAttrs, inputData, commInfo) != ge::GRAPH_SUCCESS,460+ res = GetStrideInfo(context, runtimeAttrs, inputData, commInfo);
442- VECTOR_INNER_ERR_REPORT_TILIING(context, "GetStrideInfo fail."),461+ if (res != ge::GRAPH_SUCCESS) {
443- return ge::GRAPH_FAILED);462+ return res;
463+ }
444 464 
445- OP_TILING_CHECK(GetPadInfo(context, inputData, commInfo) != ge::GRAPH_SUCCESS,465+ res = GetPadInfo(context, inputData, commInfo);
446- VECTOR_INNER_ERR_REPORT_TILIING(context, "GetPadInfo fail."),466+ if (res != ge::GRAPH_SUCCESS) {
447- return ge::GRAPH_FAILED);467+ return res;
468+ }
448 469 
449- OP_TILING_CHECK(CheckGradShape(context, inputData, commInfo) != ge::GRAPH_SUCCESS,470+ res = CheckGradShape(context, inputData, commInfo);
450- VECTOR_INNER_ERR_REPORT_TILIING(context, "CheckGradShape fail."),471+ if (res != ge::GRAPH_SUCCESS) {
451- return ge::GRAPH_FAILED);472+ return res;
473+ }
452 474 
453 if (IsGreaterThanInt32Max(inputData)) {475 if (IsGreaterThanInt32Max(inputData)) {
454 inputData.isInt32Meet = 0;476 inputData.isInt32Meet = 0;
@@ -69,48 +69,68 @@ ge::graphStatus CheckKernelAndStrides(gert::InferShapeContext* context, const st
69 auto attrs = context->GetAttrs();69 auto attrs = context->GetAttrs();
70 auto ksize = attrs->GetAttrPointer<gert::ContinuousVector>(ATTR_KERNEL_POS);70 auto ksize = attrs->GetAttrPointer<gert::ContinuousVector>(ATTR_KERNEL_POS);
71 OP_CHECK_NULL_WITH_CONTEXT(context, ksize);71 OP_CHECK_NULL_WITH_CONTEXT(context, ksize);
72- OP_CHECK_IF(72+ if (ksize->GetSize() != ATTR_LIST_SHAPE_SIZE) {
73- ksize->GetSize() != ATTR_LIST_SHAPE_SIZE,73+ OP_LOGE_FOR_INVALID_LISTSIZE(context->GetNodeName(), "ksize",
74- OP_LOGE(context->GetNodeName(), "Length of ksize %lu must be 4!", ksize->GetSize()), return GRAPH_FAILED);74+ std::to_string(ksize->GetSize()).c_str(), std::to_string(ATTR_LIST_SHAPE_SIZE).c_str());
75+ return GRAPH_FAILED;
76+ }
75 auto ksize_data = reinterpret_cast<const int64_t*>(ksize->GetData());77 auto ksize_data = reinterpret_cast<const int64_t*>(ksize->GetData());
76 78 
77 if (dataFormatStr == "NCHW") {79 if (dataFormatStr == "NCHW") {
78- OP_CHECK_IF(ksize_data[IDX_ZERO] != ONE,80+ if (ksize_data[IDX_ZERO] != ONE) {
79- OP_LOGE(context->GetNodeName(), "Pooling ksize[0] %ld must be 1.", ksize_data[IDX_ZERO]),81+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "ksize[0]",
80- return GRAPH_FAILED);82+ std::to_string(ksize_data[IDX_ZERO]).c_str(), "1");
81- OP_CHECK_IF(ksize_data[IDX_ONE] != ONE,83+ return GRAPH_FAILED;
82- OP_LOGE(context->GetNodeName(), "Pooling ksize[1] %ld must be 1.", ksize_data[IDX_ONE]),84+ }
83- return GRAPH_FAILED);85+ if (ksize_data[IDX_ONE] != ONE) {
86+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "ksize[1]",
87+ std::to_string(ksize_data[IDX_ONE]).c_str(), "1");
88+ return GRAPH_FAILED;
89+ }
84 } else if (dataFormatStr == "NHWC") {90 } else if (dataFormatStr == "NHWC") {
85- OP_CHECK_IF(ksize_data[IDX_ZERO] != ONE,91+ if (ksize_data[IDX_ZERO] != ONE) {
86- OP_LOGE(context->GetNodeName(), "Pooling ksize[0] %ld must be 1.", ksize_data[IDX_ZERO]),92+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "ksize[0]",
87- return GRAPH_FAILED);93+ std::to_string(ksize_data[IDX_ZERO]).c_str(), "1");
88- OP_CHECK_IF(ksize_data[IDX_THREE] != ONE,94+ return GRAPH_FAILED;
89- OP_LOGE(context->GetNodeName(), "Pooling ksize[3] %ld must be 1.", ksize_data[IDX_THREE]),95+ }
90- return GRAPH_FAILED);96+ if (ksize_data[IDX_THREE] != ONE) {
97+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "ksize[3]",
98+ std::to_string(ksize_data[IDX_THREE]).c_str(), "1");
99+ return GRAPH_FAILED;
100+ }
91 }101 }
92 102
93 auto strides = attrs->GetAttrPointer<gert::ContinuousVector>(ATTR_STRIDE_POS);103 auto strides = attrs->GetAttrPointer<gert::ContinuousVector>(ATTR_STRIDE_POS);
94 OP_CHECK_NULL_WITH_CONTEXT(context, strides);104 OP_CHECK_NULL_WITH_CONTEXT(context, strides);
95- OP_CHECK_IF(105+ if (strides->GetSize() != ATTR_LIST_SHAPE_SIZE) {
96- strides->GetSize() != ATTR_LIST_SHAPE_SIZE,106+ OP_LOGE_FOR_INVALID_LISTSIZE(context->GetNodeName(), "strides",
97- OP_LOGE(context->GetNodeName(), "Length of strides %lu must be 4!", strides->GetSize()), return GRAPH_FAILED);107+ std::to_string(strides->GetSize()).c_str(), std::to_string(ATTR_LIST_SHAPE_SIZE).c_str());
108+ return GRAPH_FAILED;
109+ }
98 auto strides_data = reinterpret_cast<const int64_t*>(strides->GetData());110 auto strides_data = reinterpret_cast<const int64_t*>(strides->GetData());
99 111 
100 if (dataFormatStr == "NCHW") {112 if (dataFormatStr == "NCHW") {
101- OP_CHECK_IF(strides_data[IDX_ZERO] != ONE,113+ if (strides_data[IDX_ZERO] != ONE) {
102- OP_LOGE(context->GetNodeName(), "Pooling stride size[0] %ld must be 1.", strides_data[IDX_ZERO]),114+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "strides[0]",
103- return GRAPH_FAILED);115+ std::to_string(strides_data[IDX_ZERO]).c_str(), "1");
104- OP_CHECK_IF(strides_data[IDX_ONE] != ONE,116+ return GRAPH_FAILED;
105- OP_LOGE(context->GetNodeName(), "Pooling stride size[1] %ld must be 1.", strides_data[IDX_ONE]),117+ }
106- return GRAPH_FAILED);118+ if (strides_data[IDX_ONE] != ONE) {
119+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "strides[1]",
120+ std::to_string(strides_data[IDX_ONE]).c_str(), "1");
121+ return GRAPH_FAILED;
122+ }
107 } else if (dataFormatStr == "NHWC") {123 } else if (dataFormatStr == "NHWC") {
108- OP_CHECK_IF(strides_data[IDX_ZERO] != ONE,124+ if (strides_data[IDX_ZERO] != ONE) {
109- OP_LOGE(context->GetNodeName(), "Pooling stride size[0] %ld must be 1.", strides_data[IDX_ZERO]),125+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "strides[0]",
110- return GRAPH_FAILED);126+ std::to_string(strides_data[IDX_ZERO]).c_str(), "1");
111- OP_CHECK_IF(strides_data[IDX_THREE] != ONE,127+ return GRAPH_FAILED;
112- OP_LOGE(context->GetNodeName(), "Pooling stride size[3] %ld must be 1.", strides_data[IDX_THREE]),128+ }
113- return GRAPH_FAILED);129+ if (strides_data[IDX_THREE] != ONE) {
130+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "strides[3]",
131+ std::to_string(strides_data[IDX_THREE]).c_str(), "1");
132+ return GRAPH_FAILED;
133+ }
114 }134 }
115 return ge::GRAPH_SUCCESS;135 return ge::GRAPH_SUCCESS;
116}136}
@@ -126,9 +146,11 @@ ge::graphStatus InferShape4AvgPoolGrad(gert::InferShapeContext* context)
126 OP_CHECK_NULL_WITH_CONTEXT(context, gradDesc);146 OP_CHECK_NULL_WITH_CONTEXT(context, gradDesc);
127 auto gradOriFormat = gradDesc->GetOriginFormat();147 auto gradOriFormat = gradDesc->GetOriginFormat();
128 148 
129- OP_CHECK_IF(149+ if (gradOriFormat != FORMAT_ND && gradOriFormat != FORMAT_NCHW && gradOriFormat != FORMAT_NHWC) {
130- gradOriFormat != FORMAT_ND && gradOriFormat != FORMAT_NCHW && gradOriFormat != FORMAT_NHWC,150+ OP_LOGE_FOR_INVALID_FORMAT(context->GetNodeName(), "input_grad",
131- OP_LOGE(context->GetNodeName(), "format only supports ND, NCHW, NHWC"), return GRAPH_FAILED);151+ Ops::Base::ToString(gradOriFormat).c_str(), "ND, NCHW or NHWC");
152+ return GRAPH_FAILED;
153+ }
132 154 
133 auto attrs = context->GetAttrs();155 auto attrs = context->GetAttrs();
134 OP_CHECK_NULL_WITH_CONTEXT(context, attrs);156 OP_CHECK_NULL_WITH_CONTEXT(context, attrs);
@@ -139,9 +161,10 @@ ge::graphStatus InferShape4AvgPoolGrad(gert::InferShapeContext* context)
139 161 
140 auto padding = attrs->GetAttrPointer<char>(ATTR_PADDING_POS);162 auto padding = attrs->GetAttrPointer<char>(ATTR_PADDING_POS);
141 OP_CHECK_NULL_WITH_CONTEXT(context, padding);163 OP_CHECK_NULL_WITH_CONTEXT(context, padding);
142- OP_CHECK_IF(164+ if (strcmp(padding, "SAME") != 0 && strcmp(padding, "VALID") != 0) {
143- strcmp(padding, "SAME") != 0 && strcmp(padding, "VALID") != 0,165+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "padding", padding, "SAME or VALID");
144- OP_LOGE(context->GetNodeName(),"attr padding(%s) only support SAME、 VALID", padding), return GRAPH_FAILED);166+ return GRAPH_FAILED;
167+ }
145 168 
146 ge::graphStatus checkStatus = CheckKernelAndStrides(context, dataFormatStr);169 ge::graphStatus checkStatus = CheckKernelAndStrides(context, dataFormatStr);
147 OP_CHECK_IF(checkStatus != ge::GRAPH_SUCCESS, OP_LOGD(context->GetNodeName(), "CheckKernelAndStrides failed"),170 OP_CHECK_IF(checkStatus != ge::GRAPH_SUCCESS, OP_LOGD(context->GetNodeName(), "CheckKernelAndStrides failed"),
@@ -151,10 +174,11 @@ ge::graphStatus InferShape4AvgPoolGrad(gert::InferShapeContext* context)
151 OP_CHECK_NULL_WITH_CONTEXT(context, inputShape0);174 OP_CHECK_NULL_WITH_CONTEXT(context, inputShape0);
152 size_t inputDimNum = static_cast<size_t>(inputShape0->GetOriginShape().GetShapeSize());175 size_t inputDimNum = static_cast<size_t>(inputShape0->GetOriginShape().GetShapeSize());
153 const int32_t* shapeValue = inputShape0->GetData<int32_t>();176 const int32_t* shapeValue = inputShape0->GetData<int32_t>();
154- OP_CHECK_IF(177+ if (inputDimNum != CHW_DIMS && inputDimNum != NCHW_DIMS) {
155- inputDimNum != CHW_DIMS && inputDimNum != NCHW_DIMS,178+ OP_LOGE_FOR_INVALID_SHAPESIZE(context->GetNodeName(), "orig_input_shape",
156- OP_LOGE(context->GetNodeName(), "input dim num should be 3 or 4, but get %zu.", inputDimNum),179+ std::to_string(inputDimNum).c_str(), "3 or 4");
157- return GRAPH_FAILED);180+ return GRAPH_FAILED;
181+ }
158 const gert::Shape* inputShape1 = context->GetInputShape(IDX_ORIGIN_INPUT);182 const gert::Shape* inputShape1 = context->GetInputShape(IDX_ORIGIN_INPUT);
159 OP_CHECK_NULL_WITH_CONTEXT(context, inputShape1);183 OP_CHECK_NULL_WITH_CONTEXT(context, inputShape1);
160 184
@@ -0,0 +1,509 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file test_avg_pool_grad_infershape.cpp
13+ * \brief
14+ */
15+ 
16+#include "exe_graph/runtime/storage_format.h"
17+#include "exe_graph/runtime/storage_shape.h"
18+#include "gtest/gtest.h"
19+#include "kernel_run_context_facker.h"
20+#include "log/log.h"
21+#include "register/op_impl_registry.h"
22+ 
23+static constexpr size_t INPUT_NUM = 2;
24+static constexpr size_t OUTPUT_NUM = 1;
25+ 
26+class AvgPoolGradInfershape : public testing::Test {
27+protected:
28+ static void SetUpTestCase()
29+ {
30+ std::cout << "AvgPoolGradInfershape SetUp" << std::endl;
31+ }
32+ 
33+ static void TearDownTestCase()
34+ {
35+ std::cout << "AvgPoolGradInfershape TearDown" << std::endl;
36+ }
37+};
38+ 
39+static void ExecuteAvgPoolGradInfershapeTest(
40+ const std::vector<int32_t>& inputShapeData,
41+ const gert::StorageShape& gradShape,
42+ ge::Format gradFormat,
43+ ge::DataType gradDtype,
44+ const std::string& dataFormat,
45+ const std::string& padding,
46+ const std::vector<int64_t>& ksize,
47+ const std::vector<int64_t>& strides,
48+ ge::graphStatus expectResult,
49+ const std::string& expectOutputStr)
50+{
51+ int64_t input0Size = static_cast<int64_t>(inputShapeData.size());
52+ gert::StorageShape input0Shape = {{input0Size}, {input0Size}};
53+ gert::StorageShape outputShape = {{}, {}};
54+ 
55+ size_t totalSize = 0;
56+ auto tensorHolder =
57+ gert::Tensor::CreateFollowing(input0Size, ge::DT_INT32, totalSize);
58+ auto tensor = reinterpret_cast<gert::Tensor*>(tensorHolder.get());
59+ tensor->MutableStorageShape().AppendDim(input0Size);
60+ tensor->MutableOriginShape().AppendDim(input0Size);
61+ tensor->SetOriginFormat(ge::FORMAT_ND);
62+ tensor->SetStorageFormat(ge::FORMAT_ND);
63+ (void)memcpy_s(
64+ tensor->GetData<uint8_t>(), totalSize - sizeof(gert::Tensor), inputShapeData.data(),
65+ inputShapeData.size() * sizeof(int32_t));
66+ 
67+ auto holder = gert::InferShapeContextFaker()
68+ .SetOpType("AvgPoolGrad")
69+ .NodeIoNum(INPUT_NUM, OUTPUT_NUM)
70+ .IrInstanceNum({1, 1})
71+ .InputShapes({tensor, const_cast<gert::StorageShape*>(&gradShape)})
72+ .OutputShapes({&outputShape})
73+ .NodeAttrs(
74+ {{"ksize", Ops::NN::AnyValue::CreateFrom<std::vector<int64_t>>(ksize)},
75+ {"strides", Ops::NN::AnyValue::CreateFrom<std::vector<int64_t>>(strides)},
76+ {"padding", Ops::NN::AnyValue::CreateFrom<std::string>(padding)},
77+ {"data_format", Ops::NN::AnyValue::CreateFrom<std::string>(dataFormat)}})
78+ .NodeInputTd(0, ge::DT_INT32, ge::FORMAT_ND, ge::FORMAT_ND)
79+ .NodeInputTd(1, gradDtype, gradFormat, gradFormat)
80+ .NodeOutputTd(0, gradDtype, ge::FORMAT_ND, ge::FORMAT_ND)
81+ .Build();
82+ 
83+ auto inferShapeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("AvgPoolGrad")->infer_shape;
84+ ASSERT_EQ(inferShapeFunc(holder.GetContext<gert::InferShapeContext>()), expectResult);
85+ if (expectResult == ge::GRAPH_SUCCESS) {
86+ auto output = holder.GetContext<gert::InferShapeContext>()->GetOutputShape(0);
87+ ASSERT_EQ(Ops::Base::ToString(*output), expectOutputStr);
88+ }
89+}
90+ 
91+// ======================== Success Cases ========================
92+ 
93+TEST_F(AvgPoolGradInfershape, nchw_4d_same)
94+{
95+ ExecuteAvgPoolGradInfershapeTest(
96+ {2, 3, 8, 8},
97+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
98+ ge::FORMAT_NCHW,
99+ ge::DT_FLOAT,
100+ "NCHW",
101+ "SAME",
102+ {1, 1, 2, 2},
103+ {1, 1, 2, 2},
104+ ge::GRAPH_SUCCESS,
105+ "[2, 3, 8, 8]");
106+}
107+ 
108+TEST_F(AvgPoolGradInfershape, nchw_4d_valid)
109+{
110+ ExecuteAvgPoolGradInfershapeTest(
111+ {2, 3, 8, 8},
112+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
113+ ge::FORMAT_NCHW,
114+ ge::DT_FLOAT,
115+ "NCHW",
116+ "VALID",
117+ {1, 1, 2, 2},
118+ {1, 1, 2, 2},
119+ ge::GRAPH_SUCCESS,
120+ "[2, 3, 8, 8]");
121+}
122+ 
123+TEST_F(AvgPoolGradInfershape, nhwc_4d_same)
124+{
125+ ExecuteAvgPoolGradInfershapeTest(
126+ {2, 8, 8, 3},
127+ {{2, 4, 4, 3}, {2, 4, 4, 3}},
128+ ge::FORMAT_NHWC,
129+ ge::DT_FLOAT,
130+ "NHWC",
131+ "SAME",
132+ {1, 2, 2, 1},
133+ {1, 2, 2, 1},
134+ ge::GRAPH_SUCCESS,
135+ "[2, 8, 8, 3]");
136+}
137+ 
138+TEST_F(AvgPoolGradInfershape, nd_format_4d)
139+{
140+ ExecuteAvgPoolGradInfershapeTest(
141+ {2, 3, 8, 8},
142+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
143+ ge::FORMAT_ND,
144+ ge::DT_FLOAT,
145+ "NCHW",
146+ "SAME",
147+ {1, 1, 2, 2},
148+ {1, 1, 2, 2},
149+ ge::GRAPH_SUCCESS,
150+ "[2, 3, 8, 8]");
151+}
152+ 
153+TEST_F(AvgPoolGradInfershape, nd_3d_input)
154+{
155+ ExecuteAvgPoolGradInfershapeTest(
156+ {3, 8, 8},
157+ {{3, 8, 8}, {3, 8, 8}},
158+ ge::FORMAT_ND,
159+ ge::DT_FLOAT,
160+ "NCHW",
161+ "SAME",
162+ {1, 1, 2, 2},
163+ {1, 1, 2, 2},
164+ ge::GRAPH_SUCCESS,
165+ "[3, 8, 8]");
166+}
167+ 
168+TEST_F(AvgPoolGradInfershape, nhwc_4d_valid)
169+{
170+ ExecuteAvgPoolGradInfershapeTest(
171+ {2, 8, 8, 3},
172+ {{2, 4, 4, 3}, {2, 4, 4, 3}},
173+ ge::FORMAT_NHWC,
174+ ge::DT_FLOAT,
175+ "NHWC",
176+ "VALID",
177+ {1, 2, 2, 1},
178+ {1, 2, 2, 1},
179+ ge::GRAPH_SUCCESS,
180+ "[2, 8, 8, 3]");
181+}
182+ 
183+// ======================== Failure Cases: OP_LOGE_FOR_INVALID_FORMAT ========================
184+ 
185+TEST_F(AvgPoolGradInfershape, fail_invalid_grad_format)
186+{
187+ ExecuteAvgPoolGradInfershapeTest(
188+ {2, 3, 8, 8},
189+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
190+ ge::FORMAT_FRACTAL_NZ,
191+ ge::DT_FLOAT,
192+ "NCHW",
193+ "SAME",
194+ {1, 1, 2, 2},
195+ {1, 1, 2, 2},
196+ ge::GRAPH_FAILED,
197+ "");
198+}
199+ 
200+// ======================== Failure Cases: OP_LOGE_FOR_INVALID_VALUE_WITH_REASON (padding) ========================
201+ 
202+TEST_F(AvgPoolGradInfershape, fail_invalid_padding)
203+{
204+ ExecuteAvgPoolGradInfershapeTest(
205+ {2, 3, 8, 8},
206+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
207+ ge::FORMAT_NCHW,
208+ ge::DT_FLOAT,
209+ "NCHW",
210+ "INVALID",
211+ {1, 1, 2, 2},
212+ {1, 1, 2, 2},
213+ ge::GRAPH_FAILED,
214+ "");
215+}
216+ 
217+// ======================== Failure Cases: OP_LOGE_FOR_INVALID_LISTSIZE (ksize) ========================
218+ 
219+TEST_F(AvgPoolGradInfershape, fail_invalid_ksize_length)
220+{
221+ ExecuteAvgPoolGradInfershapeTest(
222+ {2, 3, 8, 8},
223+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
224+ ge::FORMAT_NCHW,
225+ ge::DT_FLOAT,
226+ "NCHW",
227+ "SAME",
228+ {2, 2},
229+ {1, 1, 2, 2},
230+ ge::GRAPH_FAILED,
231+ "");
232+}
233+ 
234+// ======================== Failure Cases: OP_LOGE_FOR_INVALID_LISTSIZE (strides) ========================
235+ 
236+TEST_F(AvgPoolGradInfershape, fail_invalid_strides_length)
237+{
238+ ExecuteAvgPoolGradInfershapeTest(
239+ {2, 3, 8, 8},
240+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
241+ ge::FORMAT_NCHW,
242+ ge::DT_FLOAT,
243+ "NCHW",
244+ "SAME",
245+ {1, 1, 2, 2},
246+ {2, 2},
247+ ge::GRAPH_FAILED,
248+ "");
249+}
250+ 
251+// ======================== Failure Cases: OP_LOGE_FOR_INVALID_VALUE_WITH_REASON (NCHW ksize/strides) ========================
252+ 
253+TEST_F(AvgPoolGradInfershape, fail_nchw_ksize0_not_one)
254+{
255+ ExecuteAvgPoolGradInfershapeTest(
256+ {2, 3, 8, 8},
257+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
258+ ge::FORMAT_NCHW,
259+ ge::DT_FLOAT,
260+ "NCHW",
261+ "SAME",
262+ {2, 1, 2, 2},
263+ {1, 1, 2, 2},
264+ ge::GRAPH_FAILED,
265+ "");
266+}
267+ 
268+TEST_F(AvgPoolGradInfershape, fail_nchw_ksize1_not_one)
269+{
270+ ExecuteAvgPoolGradInfershapeTest(
271+ {2, 3, 8, 8},
272+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
273+ ge::FORMAT_NCHW,
274+ ge::DT_FLOAT,
275+ "NCHW",
276+ "SAME",
277+ {1, 2, 2, 2},
278+ {1, 1, 2, 2},
279+ ge::GRAPH_FAILED,
280+ "");
281+}
282+ 
283+TEST_F(AvgPoolGradInfershape, fail_nchw_strides0_not_one)
284+{
285+ ExecuteAvgPoolGradInfershapeTest(
286+ {2, 3, 8, 8},
287+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
288+ ge::FORMAT_NCHW,
289+ ge::DT_FLOAT,
290+ "NCHW",
291+ "SAME",
292+ {1, 1, 2, 2},
293+ {2, 1, 2, 2},
294+ ge::GRAPH_FAILED,
295+ "");
296+}
297+ 
298+TEST_F(AvgPoolGradInfershape, fail_nchw_strides1_not_one)
299+{
300+ ExecuteAvgPoolGradInfershapeTest(
301+ {2, 3, 8, 8},
302+ {{2, 3, 4, 4}, {2, 3, 4, 4}},
303+ ge::FORMAT_NCHW,
304+ ge::DT_FLOAT,
305+ "NCHW",
306+ "SAME",
307+ {1, 1, 2, 2},
308+ {1, 2, 2, 2},
309+ ge::GRAPH_FAILED,
310+ "");
311+}
312+ 
313+// ======================== Failure Cases: OP_LOGE_FOR_INVALID_VALUE_WITH_REASON (NHWC ksize/strides) ========================
314+ 
315+TEST_F(AvgPoolGradInfershape, fail_nhwc_ksize0_not_one)
316+{
317+ ExecuteAvgPoolGradInfershapeTest(
318+ {2, 8, 8, 3},
319+ {{2, 4, 4, 3}, {2, 4, 4, 3}},
320+ ge::FORMAT_NHWC,
321+ ge::DT_FLOAT,
322+ "NHWC",
323+ "SAME",
324+ {2, 2, 2, 1},
325+ {1, 2, 2, 1},
326+ ge::GRAPH_FAILED,
327+ "");
328+}
329+ 
330+TEST_F(AvgPoolGradInfershape, fail_nhwc_ksize3_not_one)
331+{
332+ ExecuteAvgPoolGradInfershapeTest(
333+ {2, 8, 8, 3},
334+ {{2, 4, 4, 3}, {2, 4, 4, 3}},
335+ ge::FORMAT_NHWC,
336+ ge::DT_FLOAT,
337+ "NHWC",
338+ "SAME",
339+ {1, 2, 2, 2},
340+ {1, 2, 2, 1},
341+ ge::GRAPH_FAILED,
342+ "");
343+}
344+ 
345+TEST_F(AvgPoolGradInfershape, fail_nhwc_strides0_not_one)
346+{
347+ ExecuteAvgPoolGradInfershapeTest(
348+ {2, 8, 8, 3},
349+ {{2, 4, 4, 3}, {2, 4, 4, 3}},
350+ ge::FORMAT_NHWC,
351+ ge::DT_FLOAT,
352+ "NHWC",
353+ "SAME",
354+ {1, 2, 2, 1},
355+ {2, 2, 2, 1},
356+ ge::GRAPH_FAILED,
357+ "");
358+}
359+ 
360+TEST_F(AvgPoolGradInfershape, fail_nhwc_strides3_not_one)
361+{
362+ ExecuteAvgPoolGradInfershapeTest(
363+ {2, 8, 8, 3},
364+ {{2, 4, 4, 3}, {2, 4, 4, 3}},
365+ ge::FORMAT_NHWC,
366+ ge::DT_FLOAT,
367+ "NHWC",
368+ "SAME",
369+ {1, 2, 2, 1},
370+ {1, 2, 2, 2},
371+ ge::GRAPH_FAILED,
372+ "");
373+}
374+ 
375+// ======================== Failure Cases: OP_LOGE_FOR_INVALID_SHAPEDIM ========================
376+ 
377+TEST_F(AvgPoolGradInfershape, fail_invalid_dim_count_5d)
378+{
379+ ExecuteAvgPoolGradInfershapeTest(
380+ {2, 3, 8, 8, 4},
381+ {{2, 3, 8, 8, 4}, {2, 3, 8, 8, 4}},
382+ ge::FORMAT_ND,
383+ ge::DT_FLOAT,
384+ "NCHW",
385+ "SAME",
386+ {1, 1, 2, 2},
387+ {1, 1, 2, 2},
388+ ge::GRAPH_FAILED,
389+ "");
390+}
391+ 
392+TEST_F(AvgPoolGradInfershape, fail_invalid_dim_count_2d)
393+{
394+ ExecuteAvgPoolGradInfershapeTest(
395+ {8, 8},
396+ {{8, 8}, {8, 8}},
397+ ge::FORMAT_ND,
398+ ge::DT_FLOAT,
399+ "NCHW",
400+ "SAME",
401+ {1, 1, 2, 2},
402+ {1, 1, 2, 2},
403+ ge::GRAPH_FAILED,
404+ "");
405+}
406+ 
407+TEST_F(AvgPoolGradInfershape, fail_invalid_dim_count_1d)
408+{
409+ ExecuteAvgPoolGradInfershapeTest(
410+ {8},
411+ {{8}, {8}},
412+ ge::FORMAT_ND,
413+ ge::DT_FLOAT,
414+ "NCHW",
415+ "SAME",
416+ {1, 1, 2, 2},
417+ {1, 1, 2, 2},
418+ ge::GRAPH_FAILED,
419+ "");
420+}
421+ 
422+// ======================== Unknown Dim Values (Dynamic Shape) ========================
423+ 
424+TEST_F(AvgPoolGradInfershape, infer_shape_unknown_dim_3d)
425+{
426+ ExecuteAvgPoolGradInfershapeTest(
427+ {-1, -1, -1},
428+ {{-1, -1, -1}, {-1, -1, -1}},
429+ ge::FORMAT_ND,
430+ ge::DT_FLOAT,
431+ "NCHW",
432+ "SAME",
433+ {1, 1, 2, 2},
434+ {1, 1, 2, 2},
435+ ge::GRAPH_SUCCESS,
436+ "[-1, -1, -1]");
437+}
438+ 
439+TEST_F(AvgPoolGradInfershape, infer_shape_unknown_dim_4d)
440+{
441+ ExecuteAvgPoolGradInfershapeTest(
442+ {-1, -1, -1, -1},
443+ {{-1, -1, -1, -1}, {-1, -1, -1, -1}},
444+ ge::FORMAT_NCHW,
445+ ge::DT_FLOAT,
446+ "NCHW",
447+ "SAME",
448+ {1, 1, 2, 2},
449+ {1, 1, 2, 2},
450+ ge::GRAPH_SUCCESS,
451+ "[-1, -1, -1, -1]");
452+}
453+ 
454+// ======================== Null Context Tests ========================
455+ 
456+TEST_F(AvgPoolGradInfershape, infer_shape_null_context)
457+{
458+ auto inferShapeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("AvgPoolGrad")->infer_shape;
459+ ASSERT_EQ(inferShapeFunc(nullptr), ge::GRAPH_FAILED);
460+}
461+ 
462+// ======================== InferDataType ========================
463+ 
464+TEST_F(AvgPoolGradInfershape, infer_dtype_float16)
465+{
466+ ge::DataType gradDtype = ge::DT_FLOAT16;
467+ ge::DataType outputDtype = ge::DT_UNDEFINED;
468+ auto holder = gert::InferDataTypeContextFaker()
469+ .NodeIoNum(INPUT_NUM, OUTPUT_NUM)
470+ .IrInstanceNum({1, 1})
471+ .NodeInputTd(0, ge::DT_INT32, ge::FORMAT_ND, ge::FORMAT_ND)
472+ .NodeInputTd(1, gradDtype, ge::FORMAT_NCHW, ge::FORMAT_NCHW)
473+ .NodeOutputTd(0, gradDtype, ge::FORMAT_ND, ge::FORMAT_ND)
474+ .InputDataTypes({nullptr, &gradDtype})
475+ .OutputDataTypes({&outputDtype})
476+ .Build();
477+ 
478+ auto inferDtypeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("AvgPoolGrad")->infer_datatype;
479+ auto context = holder.GetContext<gert::InferDataTypeContext>();
480+ ASSERT_NE(context, nullptr);
481+ ASSERT_EQ(inferDtypeFunc(context), ge::GRAPH_SUCCESS);
482+ EXPECT_EQ(context->GetOutputDataType(0), ge::DT_FLOAT16);
483+}
484+ 
485+TEST_F(AvgPoolGradInfershape, infer_dtype_float32)
486+{
487+ ge::DataType gradDtype = ge::DT_FLOAT;
488+ ge::DataType outputDtype = ge::DT_UNDEFINED;
489+ auto holder = gert::InferDataTypeContextFaker()
490+ .NodeIoNum(INPUT_NUM, OUTPUT_NUM)
491+ .IrInstanceNum({1, 1})
492+ .NodeInputTd(0, ge::DT_INT32, ge::FORMAT_ND, ge::FORMAT_ND)
493+ .NodeInputTd(1, gradDtype, ge::FORMAT_ND, ge::FORMAT_ND)
494+ .NodeOutputTd(0, gradDtype, ge::FORMAT_ND, ge::FORMAT_ND)
495+ .InputDataTypes({nullptr, &gradDtype})
496+ .OutputDataTypes({&outputDtype})
497+ .Build();
498+ 
499+ auto inferDtypeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("AvgPoolGrad")->infer_datatype;
500+ auto context = holder.GetContext<gert::InferDataTypeContext>();
501+ ASSERT_EQ(inferDtypeFunc(context), ge::GRAPH_SUCCESS);
502+ EXPECT_EQ(context->GetOutputDataType(0), ge::DT_FLOAT);
503+}
504+ 
505+TEST_F(AvgPoolGradInfershape, infer_dtype_null_context)
506+{
507+ auto inferDtypeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("AvgPoolGrad")->infer_datatype;
508+ ASSERT_EQ(inferDtypeFunc(nullptr), ge::GRAPH_FAILED);
509+}
@@ -63,7 +63,8 @@ static void ExecuteTestCase(
63 std::vector<int64_t> ksize, std::vector<int64_t> strides, std::string padding,63 std::vector<int64_t> ksize, std::vector<int64_t> strides, std::string padding,
64 std::string data_format,64 std::string data_format,
65 ge::DataType dtype, ge::DataType dtypeIdx, uint64_t except_tilingkey,65 ge::DataType dtype, ge::DataType dtypeIdx, uint64_t except_tilingkey,
66- int32_t* shape_data)66+ int32_t* shape_data, ge::graphStatus expect_status = ge::GRAPH_SUCCESS,
67+ int32_t shape_data_size = 4)
67{68{
68 dlog_setlevel(0, 0, 0);69 dlog_setlevel(0, 0, 0);
69 70 
@@ -81,7 +82,7 @@ static void ExecuteTestCase(
81 map<string, string> aicore_spec;82 map<string, string> aicore_spec;
82 map<string, string> intrinsics;83 map<string, string> intrinsics;
83 GetPlatFormInfos(compile_info_string.c_str(), soc_infos, aicore_spec, intrinsics);84 GetPlatFormInfos(compile_info_string.c_str(), soc_infos, aicore_spec, intrinsics);
84- std::map<std::string, std::string> soc_version_infos = {{"Short_SoC_version", "ascend950"}};85+ std::map<std::string, std::string> soc_version_infos = {{"Short_SoC_version", "Ascend950"}, {"NpuArch", "3510"}};
85 // platform info86 // platform info
86 fe::PlatFormInfos platform_info;87 fe::PlatFormInfos platform_info;
87 platform_info.Init();88 platform_info.Init();
@@ -94,7 +95,7 @@ static void ExecuteTestCase(
94 auto tiling_parse_func = gert::OpImplRegistry::GetInstance().GetOpImpl(op_type.c_str())->tiling_parse;95 auto tiling_parse_func = gert::OpImplRegistry::GetInstance().GetOpImpl(op_type.c_str())->tiling_parse;
95 96 
96 std::vector<std::pair<size_t, std::unique_ptr<uint8_t[]>>> const_tensors;97 std::vector<std::pair<size_t, std::unique_ptr<uint8_t[]>>> const_tensors;
97- SetConstInput(0, DT_INT32, shape_data, 4, const_tensors);98+ SetConstInput(0, DT_INT32, shape_data, shape_data_size, const_tensors);
98 99 
99 // tilingParseFunc simulate100 // tilingParseFunc simulate
100 auto kernel_holder =101 auto kernel_holder =
@@ -147,10 +148,11 @@ static void ExecuteTestCase(
147 holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetCoreNumByCoreType("AICore");148 holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetCoreNumByCoreType("AICore");
148 holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics);149 holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics);
149 150 
150- // workspaces nullptr return failed151+ EXPECT_EQ(tiling_func(tiling_context), expect_status);
151- EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_SUCCESS);152+ if (expect_status == ge::GRAPH_SUCCESS) {
152- auto tiling_key = tiling_context->GetTilingKey();153+ auto tiling_key = tiling_context->GetTilingKey();
153- ASSERT_EQ(tiling_key, except_tilingkey);154+ ASSERT_EQ(tiling_key, except_tilingkey);
155+ }
154}156}
155 157 
156TEST_F(AvgPoolGradTiling, AvgPoolGradTiling_Test_1)158TEST_F(AvgPoolGradTiling, AvgPoolGradTiling_Test_1)
@@ -208,4 +210,262 @@ TEST_F(AvgPoolGradTiling, AvgPoolGradTiling_Test_3)
208 ExecuteTestCase(210 ExecuteTestCase(
209 xShape, yShape, gradShape, ksize, strides, padding,211 xShape, yShape, gradShape, ksize, strides, padding,
210 data_format, dtype, dtypeIdx, except_tilingkey, shape_data);212 data_format, dtype, dtypeIdx, except_tilingkey, shape_data);
213+}
214+ 
215+// ======================== Failure Cases ========================
216+ 
217+TEST_F(AvgPoolGradTiling, fail_invalid_padding)
218+{
219+ gert::StorageShape xShape = {{4}, {4}};
220+ gert::StorageShape gradShape = {{1, 1, 1, 1}, {1, 1, 1, 1}};
221+ gert::StorageShape yShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
222+ std::vector<int64_t> ksize = {3, 3};
223+ std::vector<int64_t> strides = {1, 1};
224+ std::string padding = "INVALID";
225+ ge::DataType dtype = ge::DT_FLOAT;
226+ ge::DataType dtypeIdx = ge::DT_INT32;
227+ std::string data_format = "NHWC";
228+ int shape_data[4] = {1, 3, 3, 1};
229+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
230+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
231+}
232+ 
233+TEST_F(AvgPoolGradTiling, fail_invalid_strides_listsize)
234+{
235+ gert::StorageShape xShape = {{4}, {4}};
236+ gert::StorageShape gradShape = {{1, 1, 1, 1}, {1, 1, 1, 1}};
237+ gert::StorageShape yShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
238+ std::vector<int64_t> ksize = {3, 3};
239+ std::vector<int64_t> strides = {1, 1, 1};
240+ std::string padding = "VALID";
241+ ge::DataType dtype = ge::DT_FLOAT;
242+ ge::DataType dtypeIdx = ge::DT_INT32;
243+ std::string data_format = "NHWC";
244+ int shape_data[4] = {1, 3, 3, 1};
245+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
246+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
247+}
248+ 
249+TEST_F(AvgPoolGradTiling, fail_negative_stride)
250+{
251+ gert::StorageShape xShape = {{4}, {4}};
252+ gert::StorageShape gradShape = {{1, 1, 1, 1}, {1, 1, 1, 1}};
253+ gert::StorageShape yShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
254+ std::vector<int64_t> ksize = {3, 3};
255+ std::vector<int64_t> strides = {-1, 1};
256+ std::string padding = "VALID";
257+ ge::DataType dtype = ge::DT_FLOAT;
258+ ge::DataType dtypeIdx = ge::DT_INT32;
259+ std::string data_format = "NHWC";
260+ int shape_data[4] = {1, 3, 3, 1};
261+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
262+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
263+}
264+ 
265+TEST_F(AvgPoolGradTiling, fail_invalid_ksize_listsize)
266+{
267+ gert::StorageShape xShape = {{4}, {4}};
268+ gert::StorageShape gradShape = {{1, 1, 1, 1}, {1, 1, 1, 1}};
269+ gert::StorageShape yShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
270+ std::vector<int64_t> ksize = {3, 3, 3};
271+ std::vector<int64_t> strides = {1, 1};
272+ std::string padding = "VALID";
273+ ge::DataType dtype = ge::DT_FLOAT;
274+ ge::DataType dtypeIdx = ge::DT_INT32;
275+ std::string data_format = "NHWC";
276+ int shape_data[4] = {1, 3, 3, 1};
277+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
278+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
279+}
280+ 
281+TEST_F(AvgPoolGradTiling, fail_negative_ksize)
282+{
283+ gert::StorageShape xShape = {{4}, {4}};
284+ gert::StorageShape gradShape = {{1, 1, 1, 1}, {1, 1, 1, 1}};
285+ gert::StorageShape yShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
286+ std::vector<int64_t> ksize = {-1, 3};
287+ std::vector<int64_t> strides = {1, 1};
288+ std::string padding = "VALID";
289+ ge::DataType dtype = ge::DT_FLOAT;
290+ ge::DataType dtypeIdx = ge::DT_INT32;
291+ std::string data_format = "NHWC";
292+ int shape_data[4] = {1, 3, 3, 1};
293+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
294+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
295+}
296+ 
297+TEST_F(AvgPoolGradTiling, fail_invalid_grad_shape_dim)
298+{
299+ gert::StorageShape xShape = {{4}, {4}};
300+ gert::StorageShape gradShape = {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}};
301+ gert::StorageShape yShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
302+ std::vector<int64_t> ksize = {3, 3};
303+ std::vector<int64_t> strides = {1, 1};
304+ std::string padding = "VALID";
305+ ge::DataType dtype = ge::DT_FLOAT;
306+ ge::DataType dtypeIdx = ge::DT_INT32;
307+ std::string data_format = "NHWC";
308+ int shape_data[4] = {1, 3, 3, 1};
309+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
310+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
311+}
312+ 
313+TEST_F(AvgPoolGradTiling, fail_invalid_output_shape_dim)
314+{
315+ gert::StorageShape xShape = {{4}, {4}};
316+ gert::StorageShape gradShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
317+ gert::StorageShape yShape = {{1, 1, 3, 3, 1}, {1, 1, 3, 3, 1}};
318+ std::vector<int64_t> ksize = {3, 3};
319+ std::vector<int64_t> strides = {1, 1};
320+ std::string padding = "VALID";
321+ ge::DataType dtype = ge::DT_FLOAT;
322+ ge::DataType dtypeIdx = ge::DT_INT32;
323+ std::string data_format = "NHWC";
324+ int shape_data[4] = {1, 3, 3, 1};
325+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
326+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
327+}
328+ 
329+TEST_F(AvgPoolGradTiling, fail_invalid_format)
330+{
331+ gert::StorageShape xShape = {{4}, {4}};
332+ gert::StorageShape gradShape = {{1, 1, 1, 1}, {1, 1, 1, 1}};
333+ gert::StorageShape yShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
334+ std::vector<int64_t> ksize = {3, 3};
335+ std::vector<int64_t> strides = {1, 1};
336+ std::string padding = "VALID";
337+ ge::DataType dtype = ge::DT_FLOAT;
338+ ge::DataType dtypeIdx = ge::DT_INT32;
339+ std::string data_format = "UNKNOWN";
340+ int shape_data[4] = {1, 3, 3, 1};
341+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
342+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
343+}
344+ 
345+TEST_F(AvgPoolGradTiling, fail_invalid_dtype)
346+{
347+ gert::StorageShape xShape = {{4}, {4}};
348+ gert::StorageShape gradShape = {{1, 1, 1, 1}, {1, 1, 1, 1}};
349+ gert::StorageShape yShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
350+ std::vector<int64_t> ksize = {3, 3};
351+ std::vector<int64_t> strides = {1, 1};
352+ std::string padding = "VALID";
353+ ge::DataType dtype = ge::DT_DOUBLE;
354+ ge::DataType dtypeIdx = ge::DT_INT32;
355+ std::string data_format = "NHWC";
356+ int shape_data[4] = {1, 3, 3, 1};
357+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
358+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
359+}
360+ 
361+TEST_F(AvgPoolGradTiling, fail_invalid_orig_input_shape_dim)
362+{
363+ gert::StorageShape xShape = {{5}, {5}};
364+ gert::StorageShape gradShape = {{1, 1, 1, 1}, {1, 1, 1, 1}};
365+ gert::StorageShape yShape = {{1, 3, 3, 1, 1}, {1, 3, 3, 1, 1}};
366+ std::vector<int64_t> ksize = {3, 3};
367+ std::vector<int64_t> strides = {1, 1};
368+ std::string padding = "VALID";
369+ ge::DataType dtype = ge::DT_FLOAT;
370+ ge::DataType dtypeIdx = ge::DT_INT32;
371+ std::string data_format = "NHWC";
372+ int shape_data[5] = {1, 3, 3, 1, 1};
373+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
374+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED, 5);
375+}
376+ 
377+TEST_F(AvgPoolGradTiling, fail_n_dim_mismatch)
378+{
379+ gert::StorageShape xShape = {{4}, {4}};
380+ gert::StorageShape gradShape = {{2, 3, 4, 4}, {2, 3, 4, 4}};
381+ gert::StorageShape yShape = {{5, 3, 4, 4}, {5, 3, 4, 4}};
382+ std::vector<int64_t> ksize = {1, 1, 2, 2};
383+ std::vector<int64_t> strides = {1, 1, 2, 2};
384+ std::string padding = "VALID";
385+ ge::DataType dtype = ge::DT_FLOAT;
386+ ge::DataType dtypeIdx = ge::DT_INT32;
387+ std::string data_format = "NCHW";
388+ int shape_data[4] = {2, 3, 8, 8};
389+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
390+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
391+}
392+ 
393+TEST_F(AvgPoolGradTiling, fail_c_dim_mismatch)
394+{
395+ gert::StorageShape xShape = {{4}, {4}};
396+ gert::StorageShape gradShape = {{1, 5, 4, 4}, {1, 5, 4, 4}};
397+ gert::StorageShape yShape = {{1, 5, 4, 4}, {1, 5, 4, 4}};
398+ std::vector<int64_t> ksize = {1, 1, 2, 2};
399+ std::vector<int64_t> strides = {1, 1, 2, 2};
400+ std::string padding = "VALID";
401+ ge::DataType dtype = ge::DT_FLOAT;
402+ ge::DataType dtypeIdx = ge::DT_INT32;
403+ std::string data_format = "NHWC";
404+ int shape_data[4] = {1, 4, 4, 3};
405+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
406+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
407+}
408+ 
409+TEST_F(AvgPoolGradTiling, fail_h_dim_mismatch)
410+{
411+ gert::StorageShape xShape = {{4}, {4}};
412+ gert::StorageShape gradShape = {{1, 3, 8, 4}, {1, 3, 8, 4}};
413+ gert::StorageShape yShape = {{1, 3, 8, 4}, {1, 3, 8, 4}};
414+ std::vector<int64_t> ksize = {1, 1, 2, 2};
415+ std::vector<int64_t> strides = {1, 1, 2, 2};
416+ std::string padding = "VALID";
417+ ge::DataType dtype = ge::DT_FLOAT;
418+ ge::DataType dtypeIdx = ge::DT_INT32;
419+ std::string data_format = "NCHW";
420+ int shape_data[4] = {1, 3, 4, 8};
421+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
422+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
423+}
424+ 
425+TEST_F(AvgPoolGradTiling, fail_w_dim_mismatch)
426+{
427+ gert::StorageShape xShape = {{4}, {4}};
428+ gert::StorageShape gradShape = {{1, 4, 4, 3}, {1, 4, 4, 3}};
429+ gert::StorageShape yShape = {{1, 4, 4, 3}, {1, 4, 4, 3}};
430+ std::vector<int64_t> ksize = {1, 1, 2, 2};
431+ std::vector<int64_t> strides = {1, 1, 2, 2};
432+ std::string padding = "VALID";
433+ ge::DataType dtype = ge::DT_FLOAT;
434+ ge::DataType dtypeIdx = ge::DT_INT32;
435+ std::string data_format = "NHWC";
436+ int shape_data[4] = {1, 4, 8, 3};
437+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
438+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
439+}
440+ 
441+TEST_F(AvgPoolGradTiling, fail_grad_shape_mismatch_valid)
442+{
443+ gert::StorageShape xShape = {{4}, {4}};
444+ gert::StorageShape gradShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
445+ gert::StorageShape yShape = {{1, 8, 8, 1}, {1, 8, 8, 1}};
446+ std::vector<int64_t> ksize = {2, 2};
447+ std::vector<int64_t> strides = {2, 2};
448+ std::string padding = "VALID";
449+ ge::DataType dtype = ge::DT_FLOAT;
450+ ge::DataType dtypeIdx = ge::DT_INT32;
451+ std::string data_format = "NHWC";
452+ int shape_data[4] = {1, 8, 8, 1};
453+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
454+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
455+}
456+ 
457+TEST_F(AvgPoolGradTiling, fail_grad_shape_mismatch_same)
458+{
459+ gert::StorageShape xShape = {{4}, {4}};
460+ gert::StorageShape gradShape = {{1, 3, 3, 1}, {1, 3, 3, 1}};
461+ gert::StorageShape yShape = {{1, 8, 8, 1}, {1, 8, 8, 1}};
462+ std::vector<int64_t> ksize = {2, 2};
463+ std::vector<int64_t> strides = {2, 2};
464+ std::string padding = "SAME";
465+ ge::DataType dtype = ge::DT_FLOAT;
466+ ge::DataType dtypeIdx = ge::DT_INT32;
467+ std::string data_format = "NHWC";
468+ int shape_data[4] = {1, 8, 8, 1};
469+ ExecuteTestCase(xShape, yShape, gradShape, ksize, strides, padding,
470+ data_format, dtype, dtypeIdx, 0, shape_data, ge::GRAPH_FAILED);
211}471}
@@ -60,6 +60,9 @@ inline ge::graphStatus SetAllUnknownDim(const int64_t rank, gert::Shape* output_
60 60 
61ge::graphStatus InferShapeForMaxPoolWithArgmax(gert::InferShapeContext* context)61ge::graphStatus InferShapeForMaxPoolWithArgmax(gert::InferShapeContext* context)
62{62{
63+ if (context == nullptr) {
64+ return GRAPH_FAILED;
65+ }
63 OP_LOGD(context->GetNodeName(), "runtime2.0 MaxPoolWithArgmax infershape running");66 OP_LOGD(context->GetNodeName(), "runtime2.0 MaxPoolWithArgmax infershape running");
64 auto src_td = context->GetInputDesc(0);67 auto src_td = context->GetInputDesc(0);
65 OPS_CHECK_NULL_WITH_CONTEXT(context, src_td);68 OPS_CHECK_NULL_WITH_CONTEXT(context, src_td);
@@ -69,56 +72,74 @@ ge::graphStatus InferShapeForMaxPoolWithArgmax(gert::InferShapeContext* context)
69 auto indices_dtype = indices_td->GetDataType();72 auto indices_dtype = indices_td->GetDataType();
70 OP_LOGD(context->GetNodeName(), "indices_dtype = %d", indices_dtype);73 OP_LOGD(context->GetNodeName(), "indices_dtype = %d", indices_dtype);
71 74 
72- OP_CHECK_IF(input_format != FORMAT_ND && input_format != FORMAT_NCHW && input_format != FORMAT_NHWC,75+ if (input_format != FORMAT_ND && input_format != FORMAT_NCHW && input_format != FORMAT_NHWC) {
73- OP_LOGE(context->GetNodeName(), "format only supports ND, NCHW, NHWC"),76+ OP_LOGE_FOR_INVALID_FORMAT(context->GetNodeName(), "x",
74- return GRAPH_FAILED);77+ Ops::Base::ToString(input_format).c_str(), "ND, NCHW or NHWC");
78+ return GRAPH_FAILED;
79+ }
75 80 
76 auto attrs = context->GetAttrs();81 auto attrs = context->GetAttrs();
77 OPS_CHECK_NULL_WITH_CONTEXT(context, attrs);82 OPS_CHECK_NULL_WITH_CONTEXT(context, attrs);
78 83 
79 auto ksize = attrs->GetAttrPointer<gert::ContinuousVector>(INDEX_KSIZE);84 auto ksize = attrs->GetAttrPointer<gert::ContinuousVector>(INDEX_KSIZE);
80 OPS_CHECK_NULL_WITH_CONTEXT(context, ksize);85 OPS_CHECK_NULL_WITH_CONTEXT(context, ksize);
81- OP_CHECK_IF(ksize->GetSize() != ATTR_LIST_SHAPE_SIZE,86+ if (ksize->GetSize() != ATTR_LIST_SHAPE_SIZE) {
82- OP_LOGE(context->GetNodeName(), "Length of ksize %lu must be 4!", ksize->GetSize()),87+ OP_LOGE_FOR_INVALID_LISTSIZE(context->GetNodeName(), "ksize",
83- return GRAPH_FAILED);88+ std::to_string(ksize->GetSize()).c_str(), std::to_string(ATTR_LIST_SHAPE_SIZE).c_str());
89+ return GRAPH_FAILED;
90+ }
84 auto ksize_data = static_cast<const int64_t*>(ksize->GetData());91 auto ksize_data = static_cast<const int64_t*>(ksize->GetData());
85 92 
86 auto strides = attrs->GetAttrPointer<gert::ContinuousVector>(INDEX_STRIDES);93 auto strides = attrs->GetAttrPointer<gert::ContinuousVector>(INDEX_STRIDES);
87 OPS_CHECK_NULL_WITH_CONTEXT(context, strides);94 OPS_CHECK_NULL_WITH_CONTEXT(context, strides);
88- OP_CHECK_IF(strides->GetSize() != ATTR_LIST_SHAPE_SIZE,95+ if (strides->GetSize() != ATTR_LIST_SHAPE_SIZE) {
89- OP_LOGE(context->GetNodeName(), "Length of strides %lu must be 4!", strides->GetSize()),96+ OP_LOGE_FOR_INVALID_LISTSIZE(context->GetNodeName(), "strides",
90- return GRAPH_FAILED);97+ std::to_string(strides->GetSize()).c_str(), std::to_string(ATTR_LIST_SHAPE_SIZE).c_str());
98+ return GRAPH_FAILED;
99+ }
91 auto strides_data = static_cast<const int64_t*>(strides->GetData());100 auto strides_data = static_cast<const int64_t*>(strides->GetData());
92 101 
93 const char* dataFormatPtr = attrs->GetAttrPointer<char>(INDEX_DATA_FORMAT);102 const char* dataFormatPtr = attrs->GetAttrPointer<char>(INDEX_DATA_FORMAT);
94 OP_LOGE_IF(dataFormatPtr == nullptr, GRAPH_FAILED, context->GetNodeName(), "Get dataFormat failed.");103 OP_LOGE_IF(dataFormatPtr == nullptr, GRAPH_FAILED, context->GetNodeName(), "Get dataFormat failed.");
95 std::string dataFormatStr(dataFormatPtr);104 std::string dataFormatStr(dataFormatPtr);
96- OP_CHECK_IF(ksize_data[INDEX_ZERO] != KSIZE_STRIDES_FIXED_DIM_VALUE &&105+ if (ksize_data[INDEX_ZERO] != KSIZE_STRIDES_FIXED_DIM_VALUE &&
97- strides_data[INDEX_ZERO] != KSIZE_STRIDES_FIXED_DIM_VALUE,106+ strides_data[INDEX_ZERO] != KSIZE_STRIDES_FIXED_DIM_VALUE) {
98- OP_LOGE(context->GetNodeName(), "Pooling ksize[0] / strides[0] must be 1."),107+ std::string attrMsg = std::to_string(ksize_data[INDEX_ZERO]) + " and " +
99- return GRAPH_FAILED);108+ std::to_string(strides_data[INDEX_ZERO]);
109+ OP_LOGE_FOR_INVALID_VALUES_WITH_REASON(context->GetNodeName(), "ksize[0] and strides[0]", attrMsg.c_str(),
110+ "ksize[0] and strides[0] should be 1");
111+ return GRAPH_FAILED;
112+ }
100 if (dataFormatStr == "NHWC") {113 if (dataFormatStr == "NHWC") {
101- OP_CHECK_IF(114+ if (ksize_data[INDEX_THREE] != KSIZE_STRIDES_FIXED_DIM_VALUE) {
102- ksize_data[INDEX_THREE] != KSIZE_STRIDES_FIXED_DIM_VALUE,115+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "ksize[3]",
103- OP_LOGE(context->GetNodeName(), "Pooling ksize[3] must be 1."), return GRAPH_FAILED);116+ std::to_string(ksize_data[INDEX_THREE]).c_str(), "1");
104- OP_CHECK_IF(117+ return GRAPH_FAILED;
105- strides_data[INDEX_THREE] != KSIZE_STRIDES_FIXED_DIM_VALUE,118+ }
106- OP_LOGE(context->GetNodeName(), "Pooling strides[3] must be 1."), return GRAPH_FAILED);119+ if (strides_data[INDEX_THREE] != KSIZE_STRIDES_FIXED_DIM_VALUE) {
120+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "strides[3]",
121+ std::to_string(strides_data[INDEX_THREE]).c_str(), "1");
122+ return GRAPH_FAILED;
123+ }
107 } else {124 } else {
108 // NCHW125 // NCHW
109- OP_CHECK_IF(126+ if (ksize_data[INDEX_ONE] != KSIZE_STRIDES_FIXED_DIM_VALUE) {
110- ksize_data[INDEX_ONE] != KSIZE_STRIDES_FIXED_DIM_VALUE,127+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "ksize[1]",
111- OP_LOGE(context->GetNodeName(), "Pooling ksize[1] must be 1."), return GRAPH_FAILED);128+ std::to_string(ksize_data[INDEX_ONE]).c_str(), "1");
112- OP_CHECK_IF(129+ return GRAPH_FAILED;
113- strides_data[INDEX_ONE] != KSIZE_STRIDES_FIXED_DIM_VALUE,130+ }
114- OP_LOGE(context->GetNodeName(), "Pooling strides[1] must be 1."), return GRAPH_FAILED);131+ if (strides_data[INDEX_ONE] != KSIZE_STRIDES_FIXED_DIM_VALUE) {
132+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "strides[1]",
133+ std::to_string(strides_data[INDEX_ONE]).c_str(), "1");
134+ return GRAPH_FAILED;
135+ }
115 }136 }
116 137 
117 const char* paddingPtr = attrs->GetAttrPointer<char>(INDEX_PADS);138 const char* paddingPtr = attrs->GetAttrPointer<char>(INDEX_PADS);
118 OP_LOGE_IF(paddingPtr == nullptr, GRAPH_FAILED, context->GetNodeName(), "Get pads failed.");139 OP_LOGE_IF(paddingPtr == nullptr, GRAPH_FAILED, context->GetNodeName(), "Get pads failed.");
119 std::string padStr(paddingPtr);140 std::string padStr(paddingPtr);
120 if (padStr != "SAME" && padStr != "VALID") {141 if (padStr != "SAME" && padStr != "VALID") {
121- OP_LOGE(context->GetNodeName(), "Attr padding(%s) must in SAME and VALID", padStr.c_str());142+ OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "padding", padStr.c_str(), "SAME or VALID");
122 return GRAPH_FAILED;143 return GRAPH_FAILED;
123 }144 }
124 145 
@@ -154,9 +175,15 @@ ge::graphStatus InferShapeForMaxPoolWithArgmax(gert::InferShapeContext* context)
154 if (padStr == "SAME") {175 if (padStr == "SAME") {
155 int64_t outH = (in_shape->GetDim(h_dim) + strides_data[h_dim] - 1) / strides_data[h_dim];176 int64_t outH = (in_shape->GetDim(h_dim) + strides_data[h_dim] - 1) / strides_data[h_dim];
156 int64_t outW = (in_shape->GetDim(w_dim) + strides_data[w_dim] - 1) / strides_data[w_dim];177 int64_t outW = (in_shape->GetDim(w_dim) + strides_data[w_dim] - 1) / strides_data[w_dim];
157- OP_CHECK_IF(outH < 0 || outW < 0,178+ if (outH < 0 || outW < 0) {
158- OP_LOGE(context->GetNodeName(), "Pooling outShape H and W must > 0."),179+ std::string valMsg = "[" + std::to_string(in_shape->GetDim(h_dim)) + ", " +
159- return GRAPH_FAILED);180+ std::to_string(in_shape->GetDim(w_dim)) + "], [" +
181+ std::to_string(strides_data[h_dim]) + ", " +
182+ std::to_string(strides_data[w_dim]) + "]";
183+ OP_LOGE_FOR_INVALID_VALUES_WITH_REASON(context->GetNodeName(), "x[h_dim, w_dim], strides[h_dim, w_dim]", valMsg.c_str(),
184+ "these input values lead to inferred output H and W dimensions less than 0");
185+ return GRAPH_FAILED;
186+ }
160 out_shape->SetDim(h_dim, outH);187 out_shape->SetDim(h_dim, outH);
161 out_shape->SetDim(w_dim, outW);188 out_shape->SetDim(w_dim, outW);
162 out_indices_shape->SetDim(h_dim, outH);189 out_indices_shape->SetDim(h_dim, outH);
@@ -164,9 +191,17 @@ ge::graphStatus InferShapeForMaxPoolWithArgmax(gert::InferShapeContext* context)
164 } else {191 } else {
165 int64_t outH = (in_shape->GetDim(h_dim) - ksize_data[h_dim] + strides_data[h_dim]) / strides_data[h_dim];192 int64_t outH = (in_shape->GetDim(h_dim) - ksize_data[h_dim] + strides_data[h_dim]) / strides_data[h_dim];
166 int64_t outW = (in_shape->GetDim(w_dim) - ksize_data[w_dim] + strides_data[w_dim]) / strides_data[w_dim];193 int64_t outW = (in_shape->GetDim(w_dim) - ksize_data[w_dim] + strides_data[w_dim]) / strides_data[w_dim];
167- OP_CHECK_IF(outH < 0 || outW < 0,194+ if (outH < 0 || outW < 0) {
168- OP_LOGE(context->GetNodeName(), "Pooling outShape H and W must > 0."),195+ std::string valMsg = "[" + std::to_string(in_shape->GetDim(h_dim)) + ", " +
169- return GRAPH_FAILED);196+ std::to_string(in_shape->GetDim(w_dim)) + "], [" +
197+ std::to_string(ksize_data[h_dim]) + ", " +
198+ std::to_string(ksize_data[w_dim]) + "], [" +
199+ std::to_string(strides_data[h_dim]) + ", " +
200+ std::to_string(strides_data[w_dim]) + "]";
201+ OP_LOGE_FOR_INVALID_VALUES_WITH_REASON(context->GetNodeName(), "x[h_dim, w_dim], kernel_size[h_dim, w_dim], strides[h_dim, w_dim]", valMsg.c_str(),
202+ "these input values lead to inferred output H and W dimensions less than 0");
203+ return GRAPH_FAILED;
204+ }
170 out_shape->SetDim(h_dim, outH);205 out_shape->SetDim(h_dim, outH);
171 out_shape->SetDim(w_dim, outW);206 out_shape->SetDim(w_dim, outW);
172 out_indices_shape->SetDim(h_dim, outH);207 out_indices_shape->SetDim(h_dim, outH);
@@ -56,12 +56,14 @@ static ge::graphStatus CheckOutPutShapeForValid(gert::TilingContext* context, co
56 inputData.stride[W_DIM];56 inputData.stride[W_DIM];
57 if (static_cast<int64_t>(inputData.outShape[H_DIM]) != expectedH ||57 if (static_cast<int64_t>(inputData.outShape[H_DIM]) != expectedH ||
58 static_cast<int64_t>(inputData.outShape[W_DIM]) != expectedW) {58 static_cast<int64_t>(inputData.outShape[W_DIM]) != expectedW) {
59- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),59+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(
60- "MaxPoolWithArgmax: when padding is VALID, the outputshape in \60+ context->GetNodeName(), "y[h_dim, w_dim]",
61-h-dim and w-dim should be [%ld] [%ld], but got [%ld] [%ld]",61+ ("[" + std::to_string(static_cast<int64_t>(inputData.outShape[H_DIM])) + ", " +
62- expectedH, expectedW,62+ std::to_string(static_cast<int64_t>(inputData.outShape[W_DIM])) + "]")
63- static_cast<int64_t>(inputData.outShape[H_DIM]),63+ .c_str(),
64- static_cast<int64_t>(inputData.outShape[W_DIM]));64+ ("y[h_dim, w_dim] must be equal to the theoretical value [" + std::to_string(expectedH) + ", " +
65+ std::to_string(expectedW) + "]")
66+ .c_str());
65 return ge::GRAPH_FAILED;67 return ge::GRAPH_FAILED;
66 }68 }
67 return ge::GRAPH_SUCCESS;69 return ge::GRAPH_SUCCESS;
@@ -73,12 +75,14 @@ static ge::graphStatus CheckOutPutShapeForSame(gert::TilingContext* context, con
73 int64_t expectedW = (inputData.inputShape[W_DIM] + inputData.stride[W_DIM] - 1) / inputData.stride[W_DIM];75 int64_t expectedW = (inputData.inputShape[W_DIM] + inputData.stride[W_DIM] - 1) / inputData.stride[W_DIM];
74 if (static_cast<int64_t>(inputData.outShape[H_DIM]) != expectedH ||76 if (static_cast<int64_t>(inputData.outShape[H_DIM]) != expectedH ||
75 static_cast<int64_t>(inputData.outShape[W_DIM]) != expectedW) {77 static_cast<int64_t>(inputData.outShape[W_DIM]) != expectedW) {
76- VECTOR_INNER_ERR_REPORT_TILIING(context->GetNodeName(),78+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(
77- "MaxPoolWithArgmax: when padding is SAME, the outputshape in \79+ context->GetNodeName(), "y[h_dim, w_dim]",
78-h-dim and w-dim should be [%ld] [%ld], but got [%ld] [%ld]",80+ ("[" + std::to_string(static_cast<int64_t>(inputData.outShape[H_DIM])) + ", " +
79- expectedH, expectedW,81+ std::to_string(static_cast<int64_t>(inputData.outShape[W_DIM])) + "]")
80- static_cast<int64_t>(inputData.outShape[H_DIM]),82+ .c_str(),
81- static_cast<int64_t>(inputData.outShape[W_DIM]));83+ ("y[h_dim, w_dim] must be equal to the theoretical value [" + std::to_string(expectedH) + ", " +
84+ std::to_string(expectedW) + "]")
85+ .c_str());
82 return ge::GRAPH_FAILED;86 return ge::GRAPH_FAILED;
83 }87 }
84 return ge::GRAPH_SUCCESS;88 return ge::GRAPH_SUCCESS;
@@ -123,20 +127,19 @@ ge::graphStatus MaxPoolWithArgmaxBaseTiling::GetShapeAttrsInfo()
123 auto inputShape = EnsureNotScalar(inputX->GetStorageShape());127 auto inputShape = EnsureNotScalar(inputX->GetStorageShape());
124 128 
125 OP_TILING_CHECK(inputShape.GetDimNum() != NCHW_DIMS,129 OP_TILING_CHECK(inputShape.GetDimNum() != NCHW_DIMS,
126- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(),130+ OP_LOGE_FOR_INVALID_SHAPEDIM(context_->GetNodeName(), "x",
127- "MaxPoolWithArgmax: input shape dim = %zu, should be equal 4",131+ std::to_string(inputShape.GetDimNum()).c_str(), "4"),
128- inputShape.GetDimNum()),
129 return ge::GRAPH_FAILED);132 return ge::GRAPH_FAILED);
130 OP_TILING_CHECK(inputShape.GetShapeSize() <= 0,133 OP_TILING_CHECK(inputShape.GetShapeSize() <= 0,
131- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(),134+ OP_LOGE_FOR_INVALID_SHAPESIZE(context_->GetNodeName(), "x",
132- "MaxPoolWithArgmax: input shape size %ld less than zero failed",135+ std::to_string(inputShape.GetShapeSize()).c_str(), "greater than 0"),
133- inputShape.GetShapeSize()),
134 return ge::GRAPH_FAILED);136 return ge::GRAPH_FAILED);
135 auto inputDesc = context_->GetInputDesc(0);137 auto inputDesc = context_->GetInputDesc(0);
136 OPS_CHECK_NULL_WITH_CONTEXT(context_, inputDesc);138 OPS_CHECK_NULL_WITH_CONTEXT(context_, inputDesc);
137 dtype = inputDesc->GetDataType();139 dtype = inputDesc->GetDataType();
138 if (dtype != ge::DataType::DT_BF16 && dtype != ge::DataType::DT_FLOAT16 && dtype != ge::DataType::DT_FLOAT) {140 if (dtype != ge::DataType::DT_BF16 && dtype != ge::DataType::DT_FLOAT16 && dtype != ge::DataType::DT_FLOAT) {
139- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(), "MaxPoolWithArgmax: invalid dtype");141+ OP_LOGE_FOR_INVALID_DTYPE(
142+ context_->GetNodeName(), "x", Ops::Base::ToString(dtype).c_str(), "DT_FLOAT, DT_FLOAT16, or DT_BF16");
140 return ge::GRAPH_FAILED;143 return ge::GRAPH_FAILED;
141 }144 }
142 145 
@@ -147,8 +150,10 @@ ge::graphStatus MaxPoolWithArgmaxBaseTiling::GetShapeAttrsInfo()
147 OPS_CHECK_NULL_WITH_CONTEXT(context_, indicesX);150 OPS_CHECK_NULL_WITH_CONTEXT(context_, indicesX);
148 auto indicesShape = EnsureNotScalar(indicesX->GetStorageShape());151 auto indicesShape = EnsureNotScalar(indicesX->GetStorageShape());
149 if (indicesShape != outShape) {152 if (indicesShape != outShape) {
150- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(),153+ std::string errorMsg = Ops::Base::ToString(outShape) + " and " +
151- "MaxPoolWithArgmax: indices shape and values shape is different");154+ Ops::Base::ToString(indicesShape);
155+ OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(context_->GetNodeName(), "y and argmax",
156+ errorMsg.c_str(), "the shapes of y and argmax must be the same");
152 return ge::GRAPH_FAILED;157 return ge::GRAPH_FAILED;
153 }158 }
154 auto runtimeAttrs = context_->GetAttrs();159 auto runtimeAttrs = context_->GetAttrs();
@@ -174,16 +179,19 @@ ge::graphStatus MaxPoolWithArgmaxBaseTiling::GetShapeAttrsInfo()
174 inputData.nInput = inputShape.GetDim(MP_MAX_2D_DIM_ZERO);179 inputData.nInput = inputShape.GetDim(MP_MAX_2D_DIM_ZERO);
175 inputData.cInput = inputShape.GetDim(MP_MAX_2D_DIM_THREE);180 inputData.cInput = inputShape.GetDim(MP_MAX_2D_DIM_THREE);
176 } else {181 } else {
177- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(), "MaxPoolWithArgmax: not support format %s",182+ OP_LOGE_FOR_INVALID_VALUE(context_->GetNodeName(), "data_format",
178- inputFormatStr.c_str());183+ inputFormatStr.c_str(), "NCHW or NHWC");
179 return ge::GRAPH_FAILED;184 return ge::GRAPH_FAILED;
180 }185 }
181 186 
182- OP_TILING_CHECK(outShape.GetDim(h_dim) < 1 || outShape.GetDim(w_dim) < 1,187+ OP_TILING_CHECK(
183- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(),188+ outShape.GetDim(h_dim) < 1 || outShape.GetDim(w_dim) < 1,
184- "MaxPoolWithArgmax: output shape [%ld, %ld] not support",189+ OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(
185- outShape.GetDim(h_dim), outShape.GetDim(w_dim)),190+ context_->GetNodeName(), "y[h_dim, w_dim]",
186- return ge::GRAPH_FAILED);191+ ("[" + std::to_string(outShape.GetDim(h_dim)) + ", " + std::to_string(outShape.GetDim(w_dim)) + "]")
192+ .c_str(),
193+ "h_dim and w_dim shape of y should be greater than 0"),
194+ return ge::GRAPH_FAILED);
187 195 
188 inputData.inputShape =196 inputData.inputShape =
189 array<uint64_t, HW_DIMS>{uint64_t(inputShape.GetDim(h_dim)), uint64_t(inputShape.GetDim(w_dim))};197 array<uint64_t, HW_DIMS>{uint64_t(inputShape.GetDim(h_dim)), uint64_t(inputShape.GetDim(w_dim))};
@@ -199,18 +207,18 @@ ge::graphStatus MaxPoolWithArgmaxBaseTiling::GetShapeAttrsInfo()
199 cValue = *(kernelSize->GetData() + c_dim);207 cValue = *(kernelSize->GetData() + c_dim);
200 OP_TILING_CHECK(208 OP_TILING_CHECK(
201 (nValue != DIGIT_ONE) || (cValue != DIGIT_ONE),209 (nValue != DIGIT_ONE) || (cValue != DIGIT_ONE),
202- VECTOR_INNER_ERR_REPORT_TILIING(210+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ksize[n_dim, c_dim]",
203- context_->GetNodeName(),211+ ("[" + std::to_string(nValue) + ", " + std::to_string(cValue) + "]").c_str(),
204- "MaxPoolWithArgmax: ksize[n] and ksize[c] must be 1, but got ksize[n]: %d and ksize[c]: %d.", nValue,212+ "n_dim and c_dim of ksize must be 1"),
205- cValue),
206 return ge::GRAPH_FAILED);213 return ge::GRAPH_FAILED);
207 hValue = *(kernelSize->GetData() + h_dim);214 hValue = *(kernelSize->GetData() + h_dim);
208 wValue = *(kernelSize->GetData() + w_dim);215 wValue = *(kernelSize->GetData() + w_dim);
209 inputData.kernelSize = array<uint64_t, HW_DIMS>{uint64_t(hValue), uint64_t(wValue)};216 inputData.kernelSize = array<uint64_t, HW_DIMS>{uint64_t(hValue), uint64_t(wValue)};
210 OP_TILING_CHECK(217 OP_TILING_CHECK(
211 hValue <= 0 || wValue <= 0,218 hValue <= 0 || wValue <= 0,
212- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(),219+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "ksize[h_dim, w_dim]",
213- "MaxPoolWithArgmax: not support kernel shape [%d, %d]", hValue, wValue),220+ ("[" + std::to_string(hValue) + ", " + std::to_string(wValue) + "]").c_str(),
221+ "h_dim and w_dim of ksize should be greater than 0"),
214 return ge::GRAPH_FAILED);222 return ge::GRAPH_FAILED);
215 223 
216 const gert::TypedContinuousVector<int64_t>* stride = runtimeAttrs->GetListInt(STRIDE_POS);224 const gert::TypedContinuousVector<int64_t>* stride = runtimeAttrs->GetListInt(STRIDE_POS);
@@ -219,27 +227,25 @@ ge::graphStatus MaxPoolWithArgmaxBaseTiling::GetShapeAttrsInfo()
219 cValue = *(stride->GetData() + c_dim);227 cValue = *(stride->GetData() + c_dim);
220 OP_TILING_CHECK(228 OP_TILING_CHECK(
221 (nValue != DIGIT_ONE) || (cValue != DIGIT_ONE),229 (nValue != DIGIT_ONE) || (cValue != DIGIT_ONE),
222- VECTOR_INNER_ERR_REPORT_TILIING(230+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "strides[n_dim, c_dim]",
223- context_->GetNodeName(),231+ ("[" + std::to_string(nValue) + ", " + std::to_string(cValue) + "]").c_str(),
224- "MaxPoolWithArgmax: stride[0] and stride[1] must be 1, but got stride[n]: %d and stride[c]: %d.", nValue,232+ "n_dim and c_dim of strides must be 1"),
225- cValue),
226 return ge::GRAPH_FAILED);233 return ge::GRAPH_FAILED);
227 hValue = *(stride->GetData() + h_dim);234 hValue = *(stride->GetData() + h_dim);
228 wValue = *(stride->GetData() + w_dim);235 wValue = *(stride->GetData() + w_dim);
229 inputData.stride = array<uint64_t, HW_DIMS>{uint64_t(hValue), uint64_t(wValue)};236 inputData.stride = array<uint64_t, HW_DIMS>{uint64_t(hValue), uint64_t(wValue)};
230 OP_TILING_CHECK(237 OP_TILING_CHECK(
231 hValue <= 0 || wValue <= 0,238 hValue <= 0 || wValue <= 0,
232- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(),239+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(context_->GetNodeName(), "strides[h_dim, w_dim]",
233- "MaxPoolWithArgmax: not support stride shape [%d, %d]", hValue, wValue),240+ ("[" + std::to_string(hValue) + ", " + std::to_string(wValue) + "]").c_str(),
241+ "h_dim and w_dim of strides should be greater than 0"),
234 return ge::GRAPH_FAILED);242 return ge::GRAPH_FAILED);
235 243 
236 auto padModePtr = runtimeAttrs->GetStr(PADDING_POS);244 auto padModePtr = runtimeAttrs->GetStr(PADDING_POS);
237 string padMode(padModePtr);245 string padMode(padModePtr);
238 OP_TILING_CHECK(246 OP_TILING_CHECK(
239 padMode != "VALID" && padMode != "SAME",247 padMode != "VALID" && padMode != "SAME",
240- VECTOR_INNER_ERR_REPORT_TILIING(248+ OP_LOGE_FOR_INVALID_VALUE(context_->GetNodeName(), "padding", padMode.c_str(), "VALID or SAME"),
241- context_->GetNodeName(), "MaxPoolWithArgmax: unsupported pad mode [%s], only VALID and SAME are supported",
242- padMode.c_str()),
243 return ge::GRAPH_FAILED);249 return ge::GRAPH_FAILED);
244 inputData.isPad = 0;250 inputData.isPad = 0;
245 if (padMode == "VALID") {251 if (padMode == "VALID") {
@@ -261,9 +267,10 @@ ge::graphStatus MaxPoolWithArgmaxBaseTiling::GetShapeAttrsInfo()
261 inputData.pad = {hPadNeed / DIGIT_TWO, wPadNeed / DIGIT_TWO}; // top, left267 inputData.pad = {hPadNeed / DIGIT_TWO, wPadNeed / DIGIT_TWO}; // top, left
262 }268 }
263 269 
264- OP_TILING_CHECK(CheckOutPutShape(context_, inputData, padMode) != ge::GRAPH_SUCCESS,270+ ge::graphStatus res = CheckOutPutShape(context_, inputData, padMode);
265- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(), "MaxPoolWithArgmax: CheckOutPutShape fail."),271+ if (res != ge::GRAPH_SUCCESS) {
266- return ge::GRAPH_FAILED);272+ return res;
273+ }
267 274 
268 int indexDtype = MP_MAX_2D_TYPE_INT64;275 int indexDtype = MP_MAX_2D_TYPE_INT64;
269 const int* indexDtypePtr = runtimeAttrs->GetAttrPointer<int>(DTYPE_POS);276 const int* indexDtypePtr = runtimeAttrs->GetAttrPointer<int>(DTYPE_POS);
@@ -286,9 +293,12 @@ ge::graphStatus MaxPoolWithArgmaxBaseTiling::GetShapeAttrsInfo()
286 OPS_CHECK_NULL_WITH_CONTEXT(context_, includeBatchInIndex);293 OPS_CHECK_NULL_WITH_CONTEXT(context_, includeBatchInIndex);
287 inputData.includeBatchInIndex = static_cast<int64_t>(*includeBatchInIndex);294 inputData.includeBatchInIndex = static_cast<int64_t>(*includeBatchInIndex);
288 // only support false now295 // only support false now
289- OP_TILING_CHECK(inputData.includeBatchInIndex != 0,296+ OP_TILING_CHECK(
290- VECTOR_INNER_ERR_REPORT_TILIING(context_->GetNodeName(), "MaxPoolWithArgmax: includeBatchInIndex attr only support false now."),297+ inputData.includeBatchInIndex != 0,
291- return ge::GRAPH_FAILED);298+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
299+ context_->GetNodeName(), "include_batch_in_index", std::to_string(inputData.includeBatchInIndex).c_str(),
300+ "include_batch_in_index only support 0(false) now"),
301+ return ge::GRAPH_FAILED);
292 302 
293 const bool* nanProp = runtimeAttrs->GetAttrPointer<bool>(NAN_PROP_POS);303 const bool* nanProp = runtimeAttrs->GetAttrPointer<bool>(NAN_PROP_POS);
294 OPS_CHECK_NULL_WITH_CONTEXT(context_, nanProp);304 OPS_CHECK_NULL_WITH_CONTEXT(context_, nanProp);
@@ -215,4 +215,252 @@ TEST_F(MaxPoolWithArgmaxInfer, max_pool_with_argmax_inferdtype_success_01)
215 ASSERT_NE(context, nullptr);215 ASSERT_NE(context, nullptr);
216 EXPECT_EQ(context->GetOutputDataType(0), expect_output_dtype);216 EXPECT_EQ(context->GetOutputDataType(0), expect_output_dtype);
217}217}
218+static constexpr int64_t INT32_DTYPE = 3;
219+ 
220+static void ExecuteMaxPoolWithArgmaxInfershapeTest(
221+ const gert::StorageShape& xShape,
222+ ge::Format xFormat,
223+ ge::DataType xDtype,
224+ const std::vector<int64_t>& ksize,
225+ const std::vector<int64_t>& strides,
226+ const std::string& padding,
227+ int64_t targmax,
228+ const std::string& dataFormat,
229+ ge::graphStatus expectedResult)
230+{
231+ gert::StorageShape yShape = {{}, {}};
232+ gert::StorageShape indicesShape = {{}, {}};
233+ 
234+ auto holder = gert::InferShapeContextFaker()
235+ .SetOpType("MaxPoolWithArgmax")
236+ .NodeIoNum(1, 2)
237+ .IrInstanceNum({1, 2})
238+ .InputShapes({const_cast<gert::StorageShape*>(&xShape)})
239+ .OutputShapes({&yShape, &indicesShape})
240+ .NodeAttrs(
241+ {{"ksize", Ops::NN::AnyValue::CreateFrom<std::vector<int64_t>>(ksize)},
242+ {"strides", Ops::NN::AnyValue::CreateFrom<std::vector<int64_t>>(strides)},
243+ {"padding", Ops::NN::AnyValue::CreateFrom<std::string>(padding)},
244+ {"Targmax", Ops::NN::AnyValue::CreateFrom<int64_t>(targmax)},
245+ {"includeBatchInIndex", Ops::NN::AnyValue::CreateFrom<bool>(false)},
246+ {"dataFormat", Ops::NN::AnyValue::CreateFrom<std::string>(dataFormat)},
247+ {"nanProp", Ops::NN::AnyValue::CreateFrom<bool>(false)}})
248+ .NodeInputTd(0, xDtype, xFormat, xFormat)
249+ .NodeOutputTd(0, xDtype, xFormat, xFormat)
250+ .NodeOutputTd(1, targmax == INT32_DTYPE ? ge::DT_INT32 : ge::DT_INT64, xFormat, xFormat)
251+ .Build();
252+ 
253+ auto inferShapeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("MaxPoolWithArgmax")->infer_shape;
254+ ASSERT_EQ(inferShapeFunc(holder.GetContext<gert::InferShapeContext>()), expectedResult);
255+}
256+ 
257+TEST_F(MaxPoolWithArgmaxInfer, fail_invalid_input_format)
258+{
259+ ExecuteMaxPoolWithArgmaxInfershapeTest(
260+ {{4, 3, 8, 8}, {}},
261+ ge::FORMAT_FRACTAL_NZ,
262+ ge::DT_FLOAT,
263+ {1, 1, 2, 2},
264+ {1, 1, 2, 2},
265+ "SAME",
266+ INT32_DTYPE,
267+ "NCHW",
268+ ge::GRAPH_FAILED);
269+}
270+ 
271+TEST_F(MaxPoolWithArgmaxInfer, fail_invalid_ksize_length)
272+{
273+ ExecuteMaxPoolWithArgmaxInfershapeTest(
274+ {{4, 3, 8, 8}, {}},
275+ ge::FORMAT_NCHW,
276+ ge::DT_FLOAT,
277+ {2, 2},
278+ {1, 1, 2, 2},
279+ "SAME",
280+ INT32_DTYPE,
281+ "NCHW",
282+ ge::GRAPH_FAILED);
283+}
284+ 
285+TEST_F(MaxPoolWithArgmaxInfer, fail_invalid_strides_length)
286+{
287+ ExecuteMaxPoolWithArgmaxInfershapeTest(
288+ {{4, 3, 8, 8}, {}},
289+ ge::FORMAT_NCHW,
290+ ge::DT_FLOAT,
291+ {1, 1, 2, 2},
292+ {2, 2},
293+ "SAME",
294+ INT32_DTYPE,
295+ "NCHW",
296+ ge::GRAPH_FAILED);
297+}
298+ 
299+TEST_F(MaxPoolWithArgmaxInfer, fail_ksize0_and_strides0_not_one)
300+{
301+ ExecuteMaxPoolWithArgmaxInfershapeTest(
302+ {{4, 3, 8, 8}, {}},
303+ ge::FORMAT_NCHW,
304+ ge::DT_FLOAT,
305+ {2, 1, 2, 2},
306+ {2, 1, 2, 2},
307+ "SAME",
308+ INT32_DTYPE,
309+ "NCHW",
310+ ge::GRAPH_FAILED);
311+}
312+ 
313+TEST_F(MaxPoolWithArgmaxInfer, fail_nhwc_ksize3_not_one)
314+{
315+ ExecuteMaxPoolWithArgmaxInfershapeTest(
316+ {{5, 144, 256, 3}, {}},
317+ ge::FORMAT_NHWC,
318+ ge::DT_FLOAT,
319+ {1, 2, 2, 2},
320+ {1, 2, 2, 1},
321+ "SAME",
322+ INT32_DTYPE,
323+ "NHWC",
324+ ge::GRAPH_FAILED);
325+}
326+ 
327+TEST_F(MaxPoolWithArgmaxInfer, fail_nhwc_strides3_not_one)
328+{
329+ ExecuteMaxPoolWithArgmaxInfershapeTest(
330+ {{5, 144, 256, 3}, {}},
331+ ge::FORMAT_NHWC,
332+ ge::DT_FLOAT,
333+ {1, 2, 2, 1},
334+ {1, 2, 2, 2},
335+ "SAME",
336+ INT32_DTYPE,
337+ "NHWC",
338+ ge::GRAPH_FAILED);
339+}
340+ 
341+TEST_F(MaxPoolWithArgmaxInfer, fail_nchw_ksize1_not_one)
342+{
343+ ExecuteMaxPoolWithArgmaxInfershapeTest(
344+ {{4, 3, 8, 8}, {}},
345+ ge::FORMAT_NCHW,
346+ ge::DT_FLOAT,
347+ {1, 2, 2, 2},
348+ {1, 1, 2, 2},
349+ "SAME",
350+ INT32_DTYPE,
351+ "NCHW",
352+ ge::GRAPH_FAILED);
353+}
354+ 
355+TEST_F(MaxPoolWithArgmaxInfer, fail_nchw_strides1_not_one)
356+{
357+ ExecuteMaxPoolWithArgmaxInfershapeTest(
358+ {{4, 3, 8, 8}, {}},
359+ ge::FORMAT_NCHW,
360+ ge::DT_FLOAT,
361+ {1, 1, 2, 2},
362+ {1, 2, 2, 2},
363+ "SAME",
364+ INT32_DTYPE,
365+ "NCHW",
366+ ge::GRAPH_FAILED);
367+}
368+ 
369+TEST_F(MaxPoolWithArgmaxInfer, fail_invalid_padding)
370+{
371+ ExecuteMaxPoolWithArgmaxInfershapeTest(
372+ {{4, 3, 8, 8}, {}},
373+ ge::FORMAT_NCHW,
374+ ge::DT_FLOAT,
375+ {1, 1, 2, 2},
376+ {1, 1, 2, 2},
377+ "INVALID",
378+ INT32_DTYPE,
379+ "NCHW",
380+ ge::GRAPH_FAILED);
381+}
382+ 
383+TEST_F(MaxPoolWithArgmaxInfer, fail_valid_negative_output)
384+{
385+ gert::StorageShape xShape = {{2, 3, 1, 1}, {}};
386+ gert::StorageShape yShape = {{}, {}};
387+ gert::StorageShape indicesShape = {{}, {}};
388+ auto holder = gert::InferShapeContextFaker()
389+ .SetOpType("MaxPoolWithArgmax")
390+ .NodeIoNum(1, 2)
391+ .IrInstanceNum({1, 2})
392+ .InputShapes({&xShape})
393+ .OutputShapes({&yShape, &indicesShape})
394+ .NodeAttrs(
395+ {{"ksize", Ops::NN::AnyValue::CreateFrom<std::vector<int64_t>>({1, 1, 5, 5})},
396+ {"strides", Ops::NN::AnyValue::CreateFrom<std::vector<int64_t>>({1, 1, 1, 1})},
397+ {"padding", Ops::NN::AnyValue::CreateFrom<std::string>("VALID")},
398+ {"Targmax", Ops::NN::AnyValue::CreateFrom<int64_t>(INT32_DTYPE)},
399+ {"includeBatchInIndex", Ops::NN::AnyValue::CreateFrom<bool>(false)},
400+ {"dataFormat", Ops::NN::AnyValue::CreateFrom<std::string>("NCHW")},
401+ {"nanProp", Ops::NN::AnyValue::CreateFrom<bool>(false)}})
402+ .NodeInputTd(0, ge::DT_FLOAT, ge::FORMAT_NCHW, ge::FORMAT_NCHW)
403+ .NodeOutputTd(0, ge::DT_FLOAT, ge::FORMAT_NCHW, ge::FORMAT_NCHW)
404+ .NodeOutputTd(1, ge::DT_INT32, ge::FORMAT_NCHW, ge::FORMAT_NCHW)
405+ .Build();
406+ auto inferShapeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("MaxPoolWithArgmax")->infer_shape;
407+ ASSERT_EQ(inferShapeFunc(holder.GetContext<gert::InferShapeContext>()), ge::GRAPH_FAILED);
408+}
409+ 
410+TEST_F(MaxPoolWithArgmaxInfer, fail_same_negative_output)
411+{
412+ ExecuteMaxPoolWithArgmaxInfershapeTest(
413+ {{2, 3, -5, 8}, {}},
414+ ge::FORMAT_NCHW,
415+ ge::DT_FLOAT,
416+ {1, 1, 2, 2},
417+ {1, 1, 2, 2},
418+ "SAME",
419+ INT32_DTYPE,
420+ "NCHW",
421+ ge::GRAPH_FAILED);
422+}
423+ 
424+TEST_F(MaxPoolWithArgmaxInfer, infer_shape_null_context)
425+{
426+ auto inferShapeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("MaxPoolWithArgmax")->infer_shape;
427+ ASSERT_EQ(inferShapeFunc(nullptr), ge::GRAPH_FAILED);
428+}
429+ 
430+TEST_F(MaxPoolWithArgmaxInfer, infer_dtype_float32_int64)
431+{
432+ ge::DataType xDtype = ge::DT_FLOAT;
433+ ge::DataType yDtype = ge::DT_UNDEFINED;
434+ ge::DataType argmaxDtype = ge::DT_UNDEFINED;
435+ auto holder = gert::InferDataTypeContextFaker()
436+ .SetOpType("MaxPoolWithArgmax")
437+ .NodeIoNum(1, 2)
438+ .IrInstanceNum({1, 2})
439+ .NodeInputTd(0, ge::DT_FLOAT, ge::FORMAT_ND, ge::FORMAT_ND)
440+ .NodeOutputTd(0, ge::DT_FLOAT, ge::FORMAT_ND, ge::FORMAT_ND)
441+ .NodeOutputTd(1, ge::DT_INT64, ge::FORMAT_ND, ge::FORMAT_ND)
442+ .InputDataTypes({&xDtype})
443+ .OutputDataTypes({&yDtype, &argmaxDtype})
444+ .NodeAttrs(
445+ {{"ksize", Ops::NN::AnyValue::CreateFrom<std::vector<int64_t>>({1, 1, 2, 2})},
446+ {"strides", Ops::NN::AnyValue::CreateFrom<std::vector<int64_t>>({1, 1, 2, 2})},
447+ {"padding", Ops::NN::AnyValue::CreateFrom<std::string>("VALID")},
448+ {"Targmax", Ops::NN::AnyValue::CreateFrom<int64_t>(5)},
449+ {"includeBatchInIndex", Ops::NN::AnyValue::CreateFrom<bool>(false)},
450+ {"dataFormat", Ops::NN::AnyValue::CreateFrom<std::string>("NCHW")},
451+ {"nanProp", Ops::NN::AnyValue::CreateFrom<bool>(false)}})
452+ .Build();
453+ auto inferDtypeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("MaxPoolWithArgmax")->infer_datatype;
454+ auto context = holder.GetContext<gert::InferDataTypeContext>();
455+ ASSERT_NE(context, nullptr);
456+ ASSERT_EQ(inferDtypeFunc(context), ge::GRAPH_SUCCESS);
457+ EXPECT_EQ(context->GetOutputDataType(0), ge::DT_FLOAT);
458+ EXPECT_EQ(context->GetOutputDataType(1), ge::DT_INT64);
459+}
460+ 
461+TEST_F(MaxPoolWithArgmaxInfer, infer_dtype_null_context)
462+{
463+ auto inferDtypeFunc = gert::OpImplRegistry::GetInstance().GetOpImpl("MaxPoolWithArgmax")->infer_datatype;
464+ ASSERT_EQ(inferDtypeFunc(nullptr), ge::GRAPH_FAILED);
465+}
218} // namespace466} // namespace
@@ -55,7 +55,8 @@ protected:
55static void ExecuteTestCase(55static void ExecuteTestCase(
56 gert::StorageShape& xStorageShape, gert::StorageShape& yStorageShape, gert::StorageShape& argmaxStorageShape,56 gert::StorageShape& xStorageShape, gert::StorageShape& yStorageShape, gert::StorageShape& argmaxStorageShape,
57 std::vector<int64_t> ksize, std::vector<int64_t> strides, std::string pads, ge::DataType dtype, int64_t index_dtype,57 std::vector<int64_t> ksize, std::vector<int64_t> strides, std::string pads, ge::DataType dtype, int64_t index_dtype,
58- bool includeBatchInIndex, std::string data_format, bool nan_prop, uint64_t except_tilingkey, std::string expect)58+ bool includeBatchInIndex, std::string data_format, bool nan_prop, uint64_t except_tilingkey, std::string expect,
59+ ge::graphStatus expect_status = ge::GRAPH_SUCCESS)
59{60{
60 dlog_setlevel(0, 0, 0);61 dlog_setlevel(0, 0, 0);
61 62 
@@ -149,7 +150,10 @@ static void ExecuteTestCase(
149 holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics);150 holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics);
150 151 
151 // workspaces nullptr return failed152 // workspaces nullptr return failed
152- EXPECT_EQ(tiling_func(tiling_context), ge::GRAPH_SUCCESS);153+ EXPECT_EQ(tiling_func(tiling_context), expect_status);
154+ if (expect_status != ge::GRAPH_SUCCESS) {
155+ return;
156+ }
153 auto tiling_key = tiling_context->GetTilingKey();157 auto tiling_key = tiling_context->GetTilingKey();
154 ASSERT_EQ(tiling_key, except_tilingkey);158 ASSERT_EQ(tiling_key, except_tilingkey);
155 auto tilingData = tiling_context->GetRawTilingData();159 auto tilingData = tiling_context->GetRawTilingData();
@@ -358,4 +362,222 @@ TEST_F(MaxPoolWithArgmaxTiling, MaxPoolWithArgmaxTiling_Small_C_700011)
358 ExecuteTestCase(362 ExecuteTestCase(
359 xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,363 xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
360 nan_prop, except_tilingkey, expect);364 nan_prop, except_tilingkey, expect);
365+}
366+ 
367+// ======================== Failure Cases ========================
368+ 
369+TEST_F(MaxPoolWithArgmaxTiling, fail_invalid_input_dim)
370+{
371+ gert::StorageShape xStorageShape = {{1, 3, 3}, {1, 3, 3}};
372+ gert::StorageShape yStorageShape = {{1, 1, 1}, {1, 1, 1}};
373+ gert::StorageShape argmaxStorageShape = {{1, 1, 1}, {1, 1, 1}};
374+ std::vector<int64_t> ksize = {1, 2, 2, 1};
375+ std::vector<int64_t> strides = {1, 2, 2, 1};
376+ std::string pads = "VALID";
377+ ge::DataType dtype = ge::DT_FLOAT;
378+ int64_t index_dtype = 3;
379+ bool includeBatchInIndex = false;
380+ std::string data_format = "NHWC";
381+ bool nan_prop = false;
382+ ExecuteTestCase(
383+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
384+ nan_prop, 0, "", ge::GRAPH_FAILED);
385+}
386+ 
387+TEST_F(MaxPoolWithArgmaxTiling, fail_invalid_dtype)
388+{
389+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
390+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
391+ gert::StorageShape argmaxStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
392+ std::vector<int64_t> ksize = {1, 2, 2, 1};
393+ std::vector<int64_t> strides = {1, 2, 2, 1};
394+ std::string pads = "VALID";
395+ ge::DataType dtype = ge::DT_INT32;
396+ int64_t index_dtype = 3;
397+ bool includeBatchInIndex = false;
398+ std::string data_format = "NHWC";
399+ bool nan_prop = false;
400+ ExecuteTestCase(
401+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
402+ nan_prop, 0, "", ge::GRAPH_FAILED);
403+}
404+ 
405+TEST_F(MaxPoolWithArgmaxTiling, fail_y_argmax_shape_mismatch)
406+{
407+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
408+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
409+ gert::StorageShape argmaxStorageShape = {{1, 2, 2, 2}, {1, 2, 2, 2}};
410+ std::vector<int64_t> ksize = {1, 2, 2, 1};
411+ std::vector<int64_t> strides = {1, 2, 2, 1};
412+ std::string pads = "VALID";
413+ ge::DataType dtype = ge::DT_FLOAT;
414+ int64_t index_dtype = 3;
415+ bool includeBatchInIndex = false;
416+ std::string data_format = "NHWC";
417+ bool nan_prop = false;
418+ ExecuteTestCase(
419+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
420+ nan_prop, 0, "", ge::GRAPH_FAILED);
421+}
422+ 
423+TEST_F(MaxPoolWithArgmaxTiling, fail_invalid_data_format)
424+{
425+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
426+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
427+ gert::StorageShape argmaxStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
428+ std::vector<int64_t> ksize = {1, 2, 2, 1};
429+ std::vector<int64_t> strides = {1, 2, 2, 1};
430+ std::string pads = "VALID";
431+ ge::DataType dtype = ge::DT_FLOAT;
432+ int64_t index_dtype = 3;
433+ bool includeBatchInIndex = false;
434+ std::string data_format = "INVALID";
435+ bool nan_prop = false;
436+ ExecuteTestCase(
437+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
438+ nan_prop, 0, "", ge::GRAPH_FAILED);
439+}
440+ 
441+TEST_F(MaxPoolWithArgmaxTiling, fail_ksize_n_not_one)
442+{
443+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
444+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
445+ gert::StorageShape argmaxStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
446+ std::vector<int64_t> ksize = {2, 2, 2, 1};
447+ std::vector<int64_t> strides = {1, 2, 2, 1};
448+ std::string pads = "VALID";
449+ ge::DataType dtype = ge::DT_FLOAT;
450+ int64_t index_dtype = 3;
451+ bool includeBatchInIndex = false;
452+ std::string data_format = "NHWC";
453+ bool nan_prop = false;
454+ ExecuteTestCase(
455+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
456+ nan_prop, 0, "", ge::GRAPH_FAILED);
457+}
458+ 
459+TEST_F(MaxPoolWithArgmaxTiling, fail_ksize_hw_zero)
460+{
461+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
462+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
463+ gert::StorageShape argmaxStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
464+ std::vector<int64_t> ksize = {1, 0, 0, 1};
465+ std::vector<int64_t> strides = {1, 2, 2, 1};
466+ std::string pads = "VALID";
467+ ge::DataType dtype = ge::DT_FLOAT;
468+ int64_t index_dtype = 3;
469+ bool includeBatchInIndex = false;
470+ std::string data_format = "NHWC";
471+ bool nan_prop = false;
472+ ExecuteTestCase(
473+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
474+ nan_prop, 0, "", ge::GRAPH_FAILED);
475+}
476+ 
477+TEST_F(MaxPoolWithArgmaxTiling, fail_strides_n_not_one)
478+{
479+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
480+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
481+ gert::StorageShape argmaxStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
482+ std::vector<int64_t> ksize = {1, 2, 2, 1};
483+ std::vector<int64_t> strides = {2, 2, 2, 1};
484+ std::string pads = "VALID";
485+ ge::DataType dtype = ge::DT_FLOAT;
486+ int64_t index_dtype = 3;
487+ bool includeBatchInIndex = false;
488+ std::string data_format = "NHWC";
489+ bool nan_prop = false;
490+ ExecuteTestCase(
491+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
492+ nan_prop, 0, "", ge::GRAPH_FAILED);
493+}
494+ 
495+TEST_F(MaxPoolWithArgmaxTiling, fail_strides_hw_zero)
496+{
497+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
498+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
499+ gert::StorageShape argmaxStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
500+ std::vector<int64_t> ksize = {1, 2, 2, 1};
501+ std::vector<int64_t> strides = {1, 0, 0, 1};
502+ std::string pads = "VALID";
503+ ge::DataType dtype = ge::DT_FLOAT;
504+ int64_t index_dtype = 3;
505+ bool includeBatchInIndex = false;
506+ std::string data_format = "NHWC";
507+ bool nan_prop = false;
508+ ExecuteTestCase(
509+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
510+ nan_prop, 0, "", ge::GRAPH_FAILED);
511+}
512+ 
513+TEST_F(MaxPoolWithArgmaxTiling, fail_invalid_padding)
514+{
515+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
516+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
517+ gert::StorageShape argmaxStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
518+ std::vector<int64_t> ksize = {1, 2, 2, 1};
519+ std::vector<int64_t> strides = {1, 2, 2, 1};
520+ std::string pads = "INVALID";
521+ ge::DataType dtype = ge::DT_FLOAT;
522+ int64_t index_dtype = 3;
523+ bool includeBatchInIndex = false;
524+ std::string data_format = "NHWC";
525+ bool nan_prop = false;
526+ ExecuteTestCase(
527+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
528+ nan_prop, 0, "", ge::GRAPH_FAILED);
529+}
530+ 
531+TEST_F(MaxPoolWithArgmaxTiling, fail_include_batch_in_index_true)
532+{
533+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
534+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
535+ gert::StorageShape argmaxStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
536+ std::vector<int64_t> ksize = {1, 2, 2, 1};
537+ std::vector<int64_t> strides = {1, 2, 2, 1};
538+ std::string pads = "VALID";
539+ ge::DataType dtype = ge::DT_FLOAT;
540+ int64_t index_dtype = 3;
541+ bool includeBatchInIndex = true;
542+ std::string data_format = "NHWC";
543+ bool nan_prop = false;
544+ ExecuteTestCase(
545+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
546+ nan_prop, 0, "", ge::GRAPH_FAILED);
547+}
548+ 
549+TEST_F(MaxPoolWithArgmaxTiling, fail_y_shape_mismatch_valid)
550+{
551+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
552+ gert::StorageShape yStorageShape = {{1, 2, 2, 2}, {1, 2, 2, 2}};
553+ gert::StorageShape argmaxStorageShape = {{1, 2, 2, 2}, {1, 2, 2, 2}};
554+ std::vector<int64_t> ksize = {1, 2, 2, 1};
555+ std::vector<int64_t> strides = {1, 2, 2, 1};
556+ std::string pads = "VALID";
557+ ge::DataType dtype = ge::DT_FLOAT;
558+ int64_t index_dtype = 3;
559+ bool includeBatchInIndex = false;
560+ std::string data_format = "NHWC";
561+ bool nan_prop = false;
562+ ExecuteTestCase(
563+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
564+ nan_prop, 0, "", ge::GRAPH_FAILED);
565+}
566+ 
567+TEST_F(MaxPoolWithArgmaxTiling, fail_y_shape_mismatch_same)
568+{
569+ gert::StorageShape xStorageShape = {{1, 3, 3, 2}, {1, 3, 3, 2}};
570+ gert::StorageShape yStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
571+ gert::StorageShape argmaxStorageShape = {{1, 1, 1, 2}, {1, 1, 1, 2}};
572+ std::vector<int64_t> ksize = {1, 2, 2, 1};
573+ std::vector<int64_t> strides = {1, 2, 2, 1};
574+ std::string pads = "SAME";
575+ ge::DataType dtype = ge::DT_FLOAT;
576+ int64_t index_dtype = 3;
577+ bool includeBatchInIndex = false;
578+ std::string data_format = "NHWC";
579+ bool nan_prop = false;
580+ ExecuteTestCase(
581+ xStorageShape, yStorageShape, argmaxStorageShape, ksize, strides, pads, dtype, index_dtype, includeBatchInIndex, data_format,
582+ nan_prop, 0, "", ge::GRAPH_FAILED);
361}583}