Skip to content

Commit

Permalink
torch.aten.max pool2d with indices (#125)
Browse files Browse the repository at this point in the history
* Update to latest xilinx/llvm-project feature/backport_ea1_ops

* Decompose aten.max_pool2d_with_indices
  • Loading branch information
mgehre-amd authored Jul 21, 2023
1 parent 90856f5 commit 2174481
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
7 changes: 1 addition & 6 deletions e2e_testing/xfail_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,16 +1275,11 @@

# 'tensor.empty' op incorrect number of dynamic sizes, has 1, expected 0
"BatchNorm1DStaticShapeModule_basic",
"ResNet18StaticModule_basic",

# Dynamic shape, has extra unsupported broadcast ops
"Matmul_3d",

# failed to legalize operation 'torch.aten.max_pool2d_with_indices
"MaxPool2dEmptyStrideStaticModule_basic",
"MaxPool2dStaticCeilModeTrueModule_basic",
"MaxPool2dStaticModule_basic",
"ResNet18StaticModule_basic",

# Unimplemented operator 'aten._index_put_impl_.hacked_twin'
"IndexPutImpl1DFloatNonAccumulateModule_basic",
"IndexPutImpl1DIntNonAccumulateModule_basic",
Expand Down
2 changes: 1 addition & 1 deletion externals/llvm-project
Submodule llvm-project updated 26 files
+0 −1 mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
+4 −6 mlir/include/mlir/Dialect/Tosa/IR/TosaTypesBase.td
+4 −2 mlir/include/mlir/Dialect/Tosa/Transforms/Passes.h
+6 −0 mlir/include/mlir/Dialect/Tosa/Transforms/Passes.td
+26 −1 mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
+72 −80 mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
+34 −59 mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+1 −1 mlir/lib/Dialect/Tosa/Transforms/CMakeLists.txt
+0 −138 mlir/lib/Dialect/Tosa/Transforms/TosaFoldConstantTranspose.cpp
+1,036 −0 mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp
+3 −2 mlir/lib/Dialect/Tosa/Transforms/TosaLayerwiseConstantFoldPass.cpp
+20 −0 mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-i2.mlir
+25 −0 mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-named-i2.mlir
+16 −0 mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-ui3.mlir
+33 −7 mlir/test/Dialect/Tosa/canonicalize.mlir
+150 −0 mlir/test/Dialect/Tosa/constant-add-opt.mlir
+24 −0 mlir/test/Dialect/Tosa/constant-cast-opt-disable-int-folding.mlir
+243 −0 mlir/test/Dialect/Tosa/constant-cast-opt.mlir
+91 −0 mlir/test/Dialect/Tosa/constant-clamp-opt.mlir
+97 −0 mlir/test/Dialect/Tosa/constant-greater-fold.mlir
+12 −0 mlir/test/Dialect/Tosa/constant-logical_not-fold.mlir
+190 −0 mlir/test/Dialect/Tosa/constant-mul-opt.mlir
+102 −0 mlir/test/Dialect/Tosa/constant-pow-opt.mlir
+21 −0 mlir/test/Dialect/Tosa/constant-reciprocal-fold-multi-user.mlir
+137 −0 mlir/test/Dialect/Tosa/constant-reciprocal-fold.mlir
+137 −0 mlir/test/Dialect/Tosa/constant-rsqrt-opt.mlir
27 changes: 27 additions & 0 deletions lib/Dialect/Torch/Transforms/DecomposeComplexOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4628,6 +4628,31 @@ class DecomposeAtenFakeQuantizePerTensorAffineCachemaskOp
};
} // namespace

namespace {
// Decompose aten.max_pool2d_with_indices
// into aten.max_pool2d
// when the second result is unused.
class DecomposeAtenMaxPool2dWithIndicesOp
: public OpRewritePattern<AtenMaxPool2dWithIndicesOp> {
public:
using OpRewritePattern<
AtenMaxPool2dWithIndicesOp>::OpRewritePattern;
LogicalResult matchAndRewrite(AtenMaxPool2dWithIndicesOp op,
PatternRewriter &rewriter) const override {
if (!op->getResult(1).use_empty())
return failure();

auto newOp = rewriter.create<AtenMaxPool2dOp>(
op.getLoc(), op->getResult(0).getType(), op.getSelf(), op.getKernelSize(),
op.getStride(), op.getPadding(), op.getDilation(), op.getCeilMode());

rewriter.replaceAllUsesWith(op->getResult(0), newOp);
rewriter.eraseOp(op);
return success();
}
};
} // namespace

namespace {
class DecomposeComplexOpsPass
: public DecomposeComplexOpsBase<DecomposeComplexOpsPass> {
Expand Down Expand Up @@ -4803,6 +4828,8 @@ class DecomposeComplexOpsPass
addPatternIfTargetOpIsIllegal<DecomposePrimsSumOp>(patterns);
addPatternIfTargetOpIsIllegal<
DecomposeAtenFakeQuantizePerTensorAffineCachemaskOp>(patterns);
addPatternIfTargetOpIsIllegal<
DecomposeAtenMaxPool2dWithIndicesOp>(patterns);

GreedyRewriteConfig config;
config.useTopDownTraversal = true;
Expand Down

0 comments on commit 2174481

Please sign in to comment.