@@ -282,14 +282,14 @@ static LogicalResult verifyConvOp(T op) {
282282 // tensors.
283283 auto inputType = llvm::dyn_cast<RankedTensorType>(op.getInput ().getType ());
284284 if (!inputType) {
285- op. emitOpError ( " expect a ranked tensor for input, got " ) << op. getInput ();
286- return failure ();
285+ // Skip following checks if input is not ranked
286+ return success ();
287287 }
288288
289289 auto weightType = llvm::dyn_cast<RankedTensorType>(op.getWeight ().getType ());
290290 if (!weightType) {
291- op. emitOpError ( " expect a ranked tensor for weight, got " ) << op. getWeight ();
292- return failure ();
291+ // Skip following checks if weight is not ranked
292+ return success ();
293293 }
294294
295295 auto inputEType = inputType.getElementType ();
@@ -2899,14 +2899,6 @@ LogicalResult TransposeConv2DOp::verify() {
28992899 return emitOpError (" expect all stride values to be >= 1, got [" )
29002900 << strides << " ]" ;
29012901
2902- const auto inputType = llvm::dyn_cast<RankedTensorType>(getInput ().getType ());
2903-
2904- const auto outputType =
2905- llvm::dyn_cast<RankedTensorType>(getOutput ().getType ());
2906-
2907- const auto weightType =
2908- llvm::dyn_cast<RankedTensorType>(getWeight ().getType ());
2909-
29102902 const auto checkPadAgainstKernelDim =
29112903 [this ](int64_t pad_value, int64_t kernel_dim_size,
29122904 llvm::StringRef pad_name,
@@ -2920,69 +2912,77 @@ LogicalResult TransposeConv2DOp::verify() {
29202912 };
29212913
29222914 const llvm::ArrayRef<int64_t > padding = getOutPad ();
2923-
29242915 const int64_t outPadTop = padding[0 ];
29252916 const int64_t outPadBottom = padding[1 ];
2917+ const int64_t outPadLeft = padding[2 ];
2918+ const int64_t outPadRight = padding[3 ];
29262919
2927- const int64_t kernelHeight = weightType.getDimSize (1 );
2928-
2929- if (!ShapedType::isDynamic (kernelHeight)) {
2930- if (failed (checkPadAgainstKernelDim (outPadTop, kernelHeight, " out_pad_top" ,
2931- " KH" )))
2932- return failure ();
2933-
2934- if (failed (checkPadAgainstKernelDim (outPadBottom, kernelHeight,
2935- " out_pad_bottom" , " KH" )))
2936- return failure ();
2937- }
2920+ const auto weightType =
2921+ llvm::dyn_cast<RankedTensorType>(getWeight ().getType ());
29382922
2939- const int64_t kernelWidth = weightType.getDimSize (2 );
2923+ if (weightType) {
2924+ const int64_t kernelHeight = weightType.getDimSize (1 );
2925+ if (!ShapedType::isDynamic (kernelHeight)) {
2926+ if (failed (checkPadAgainstKernelDim (outPadTop, kernelHeight,
2927+ " out_pad_top" , " KH" )))
2928+ return failure ();
29402929
2941- const int64_t outPadLeft = padding[2 ];
2942- const int64_t outPadRight = padding[3 ];
2930+ if (failed (checkPadAgainstKernelDim (outPadBottom, kernelHeight,
2931+ " out_pad_bottom" , " KH" )))
2932+ return failure ();
2933+ }
29432934
2944- if (!ShapedType::isDynamic (kernelWidth)) {
2945- if (failed (checkPadAgainstKernelDim (outPadLeft, kernelWidth, " out_pad_left" ,
2946- " KW" )))
2947- return failure ();
2935+ const int64_t kernelWidth = weightType.getDimSize (2 );
2936+ if (!ShapedType::isDynamic (kernelWidth)) {
2937+ if (failed (checkPadAgainstKernelDim (outPadLeft, kernelWidth,
2938+ " out_pad_left" , " KW" )))
2939+ return failure ();
29482940
2949- if (failed (checkPadAgainstKernelDim (outPadRight, kernelWidth,
2950- " out_pad_right" , " KW" )))
2951- return failure ();
2941+ if (failed (checkPadAgainstKernelDim (outPadRight, kernelWidth,
2942+ " out_pad_right" , " KW" )))
2943+ return failure ();
2944+ }
29522945 }
29532946
29542947 // Rest of the checks depend on the output type being a RankedTensorType
2948+ const auto outputType =
2949+ llvm::dyn_cast<RankedTensorType>(getOutput ().getType ());
29552950 if (!outputType)
29562951 return success ();
29572952
2958- const int64_t inputHeight = inputType.getDimSize (1 );
2959- const int64_t outputHeight = outputType.getDimSize (1 );
2960-
2961- if (!ShapedType::isDynamic (inputHeight) &&
2962- !ShapedType::isDynamic (outputHeight)) {
2963- if (outputHeight !=
2964- (inputHeight - 1 ) * strideY + outPadTop + outPadBottom + kernelHeight)
2965- return emitOpError (
2966- " dimension mismatch: expected OH == (IH - 1) * stride_y "
2967- " + out_pad_top + out_pad_bottom + KH, but got " )
2968- << outputHeight << " != (" << inputHeight << " - 1) * " << strideY
2969- << " + " << outPadTop << " + " << outPadBottom << " + "
2970- << kernelHeight;
2971- }
2953+ const auto inputType = llvm::dyn_cast<RankedTensorType>(getInput ().getType ());
2954+ if (inputType && weightType) {
2955+ const int64_t inputHeight = inputType.getDimSize (1 );
2956+ const int64_t kernelHeight = weightType.getDimSize (1 );
2957+ const int64_t outputHeight = outputType.getDimSize (1 );
2958+
2959+ if (!ShapedType::isDynamic (inputHeight) &&
2960+ !ShapedType::isDynamic (outputHeight)) {
2961+ if (outputHeight !=
2962+ (inputHeight - 1 ) * strideY + outPadTop + outPadBottom + kernelHeight)
2963+ return emitOpError (
2964+ " dimension mismatch: expected OH == (IH - 1) * stride_y "
2965+ " + out_pad_top + out_pad_bottom + KH, but got " )
2966+ << outputHeight << " != (" << inputHeight << " - 1) * "
2967+ << strideY << " + " << outPadTop << " + " << outPadBottom
2968+ << " + " << kernelHeight;
2969+ }
29722970
2973- const int64_t inputWidth = inputType.getDimSize (2 );
2974- const int64_t outputWidth = outputType.getDimSize (2 );
2971+ const int64_t inputWidth = inputType.getDimSize (2 );
2972+ const int64_t kernelWidth = weightType.getDimSize (2 );
2973+ const int64_t outputWidth = outputType.getDimSize (2 );
29752974
2976- if (!ShapedType::isDynamic (inputWidth) &&
2977- !ShapedType::isDynamic (outputWidth)) {
2978- if (outputWidth !=
2979- (inputWidth - 1 ) * strideX + outPadLeft + outPadRight + kernelWidth)
2980- return emitOpError (
2981- " dimension mismatch: expected OW == (IW - 1) * stride_x "
2982- " + out_pad_left + out_pad_right + KW, but got " )
2983- << outputWidth << " != (" << inputWidth << " - 1) * " << strideX
2984- << " + " << outPadLeft << " + " << outPadRight << " + "
2985- << kernelWidth;
2975+ if (!ShapedType::isDynamic (inputWidth) &&
2976+ !ShapedType::isDynamic (outputWidth)) {
2977+ if (outputWidth !=
2978+ (inputWidth - 1 ) * strideX + outPadLeft + outPadRight + kernelWidth)
2979+ return emitOpError (
2980+ " dimension mismatch: expected OW == (IW - 1) * stride_x "
2981+ " + out_pad_left + out_pad_right + KW, but got " )
2982+ << outputWidth << " != (" << inputWidth << " - 1) * " << strideX
2983+ << " + " << outPadLeft << " + " << outPadRight << " + "
2984+ << kernelWidth;
2985+ }
29862986 }
29872987
29882988 const auto biasType = llvm::dyn_cast<RankedTensorType>(getBias ().getType ());
0 commit comments