-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[mlir][tosa] Change 'shape' of RESHAPE from attribute to input shape … #125789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,10 +55,11 @@ struct DepthwiseConv2DIsMul : public OpRewritePattern<tosa::DepthwiseConv2DOp> { | |
| inputType = RankedTensorType::get( | ||
| revisedInputShape, | ||
| dyn_cast<RankedTensorType>(input.getType()).getElementType()); | ||
| auto revisedInputShapeValue = | ||
| getTosaConstShape(rewriter, op.getLoc(), revisedInputShape); | ||
| input = rewriter | ||
| .create<tosa::ReshapeOp>( | ||
| op.getLoc(), inputType, input, | ||
| rewriter.getDenseI64ArrayAttr(revisedInputShape)) | ||
| .create<tosa::ReshapeOp>(op.getLoc(), inputType, input, | ||
| revisedInputShapeValue) | ||
| .getResult(); | ||
|
|
||
| Type inputETy = inputType.getElementType(); | ||
|
|
@@ -153,9 +154,10 @@ struct DepthwiseConv2DIsMul : public OpRewritePattern<tosa::DepthwiseConv2DOp> { | |
| auto outputShapeType = RankedTensorType::get( | ||
| outputShape, | ||
| dyn_cast<RankedTensorType>(input.getType()).getElementType()); | ||
| auto outputShapeValue = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. directly in the function below? |
||
| getTosaConstShape(rewriter, op->getLoc(), outputShape); | ||
| Value outputValue = rewriter.create<tosa::ReshapeOp>( | ||
| op.getLoc(), outputShapeType, mulValue, | ||
| rewriter.getDenseI64ArrayAttr(outputShape)); | ||
| op.getLoc(), outputShapeType, mulValue, outputShapeValue); | ||
|
|
||
| Value bias = op.getBias(); | ||
| if (EqualizeRanks(rewriter, op.getLoc(), outputValue, bias).failed()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,9 +159,11 @@ class TransposeConvStridedConverter | |
| outputChannels, weightHeight / stride[0], | ||
| stride[0], weightWidth / stride[1], | ||
| stride[1], inputChannels}; | ||
|
|
||
| ImplicitLocOpBuilder builder(op->getLoc(), rewriter); | ||
| weight = CreateOpAndInferShape<tosa::ReshapeOp>( | ||
| rewriter, loc, UnrankedTensorType::get(weightETy), weight, | ||
| rewriter.getDenseI64ArrayAttr(weightReshapeDims0)); | ||
| builder, UnrankedTensorType::get(weightETy), weight, | ||
| getTosaConstShape(rewriter, loc, weightReshapeDims0)); | ||
|
|
||
| // Transpose the factored-out stride to the output channels. | ||
| Value transposeWeightVal = rewriter.create<tosa::ConstOp>( | ||
|
|
@@ -173,12 +175,13 @@ class TransposeConvStridedConverter | |
| transposeWeightVal); | ||
|
|
||
| // Collapse the strides and output channels into a single dimension. | ||
| llvm::SmallVector<int64_t, 6> weightReshapeDims1 = { | ||
| llvm::SmallVector<int64_t, 4> weightReshapeDims1 = { | ||
| outputChannels * stride[0] * stride[1], weightHeight / stride[0], | ||
| weightWidth / stride[1], inputChannels}; | ||
|
|
||
| weight = CreateOpAndInferShape<tosa::ReshapeOp>( | ||
| rewriter, loc, UnrankedTensorType::get(weightETy), weight, | ||
| rewriter.getDenseI64ArrayAttr(weightReshapeDims1)); | ||
| getTosaConstShape(rewriter, loc, weightReshapeDims1)); | ||
| ShapedType restridedWeightTy = cast<ShapedType>(weight.getType()); | ||
|
|
||
| weight = CreateOpAndInferShape<tosa::ReverseOp>( | ||
|
|
@@ -257,9 +260,13 @@ class TransposeConvStridedConverter | |
| // Factor striding out of the convolution result. | ||
| llvm::SmallVector<int64_t, 6> convReshapeDims0 = { | ||
| batch, convHeight, convWidth, stride[0], stride[1], outputChannels}; | ||
|
|
||
| auto convReshapeDims0Value = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directly to the function below? |
||
| getTosaConstShape(rewriter, loc, convReshapeDims0); | ||
|
|
||
| conv2d = CreateOpAndInferShape<tosa::ReshapeOp>( | ||
| rewriter, loc, UnrankedTensorType::get(resultETy), conv2d, | ||
| rewriter.getDenseI64ArrayAttr(convReshapeDims0)); | ||
| convReshapeDims0Value); | ||
|
|
||
| // Transpose the factored-out stride to the output channels. | ||
| Value transposeConvVal = rewriter.create<tosa::ConstOp>( | ||
|
|
@@ -273,9 +280,13 @@ class TransposeConvStridedConverter | |
| // Fuse striding behavior back into width / height. | ||
| llvm::SmallVector<int64_t, 6> convReshapeDims1 = { | ||
| batch, convHeight * stride[0], convWidth * stride[1], outputChannels}; | ||
|
|
||
| auto convReshapeDims1Value = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need the new variable? You can put it directly in the function below? |
||
| getTosaConstShape(rewriter, loc, convReshapeDims1); | ||
|
|
||
| conv2d = CreateOpAndInferShape<tosa::ReshapeOp>( | ||
| rewriter, loc, UnrankedTensorType::get(resultETy), conv2d, | ||
| rewriter.getDenseI64ArrayAttr(convReshapeDims1)); | ||
| convReshapeDims1Value); | ||
|
|
||
| // Determine the amount to slice / pad from the result start. | ||
| int64_t resultSliceTop = std::max<int64_t>(0, -pad[0]); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this two-stage setup for the shape obscure. Would prefer an optional but probably worth a separate patch