@@ -282,14 +282,14 @@ static LogicalResult verifyConvOp(T op) {
282
282
// tensors.
283
283
auto inputType = llvm::dyn_cast<RankedTensorType>(op.getInput ().getType ());
284
284
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 ();
287
287
}
288
288
289
289
auto weightType = llvm::dyn_cast<RankedTensorType>(op.getWeight ().getType ());
290
290
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 ();
293
293
}
294
294
295
295
auto inputEType = inputType.getElementType ();
@@ -2899,14 +2899,6 @@ LogicalResult TransposeConv2DOp::verify() {
2899
2899
return emitOpError (" expect all stride values to be >= 1, got [" )
2900
2900
<< strides << " ]" ;
2901
2901
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
-
2910
2902
const auto checkPadAgainstKernelDim =
2911
2903
[this ](int64_t pad_value, int64_t kernel_dim_size,
2912
2904
llvm::StringRef pad_name,
@@ -2920,69 +2912,77 @@ LogicalResult TransposeConv2DOp::verify() {
2920
2912
};
2921
2913
2922
2914
const llvm::ArrayRef<int64_t > padding = getOutPad ();
2923
-
2924
2915
const int64_t outPadTop = padding[0 ];
2925
2916
const int64_t outPadBottom = padding[1 ];
2917
+ const int64_t outPadLeft = padding[2 ];
2918
+ const int64_t outPadRight = padding[3 ];
2926
2919
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 ());
2938
2922
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 ();
2940
2929
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
+ }
2943
2934
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 ();
2948
2940
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
+ }
2952
2945
}
2953
2946
2954
2947
// Rest of the checks depend on the output type being a RankedTensorType
2948
+ const auto outputType =
2949
+ llvm::dyn_cast<RankedTensorType>(getOutput ().getType ());
2955
2950
if (!outputType)
2956
2951
return success ();
2957
2952
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
+ }
2972
2970
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 );
2975
2974
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
+ }
2986
2986
}
2987
2987
2988
2988
const auto biasType = llvm::dyn_cast<RankedTensorType>(getBias ().getType ());
0 commit comments