Skip to content

Commit

Permalink
Implement folder for unused empty.memory_formats (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaAMD authored Sep 8, 2023
1 parent 75ec45a commit de998c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/torch-mlir/Dialect/Torch/IR/GeneratedTorchOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -7348,6 +7348,7 @@ def Torch_AtenEmptyMemoryFormatOp : Torch_Op<"aten.empty.memory_format", [
printDefaultTorchOp(printer, *this, 6, 1);
}
}];
let hasCanonicalizer = 1;
}

def Torch_AtenExpandOp : Torch_Op<"aten.expand", [
Expand Down
15 changes: 15 additions & 0 deletions lib/Dialect/Torch/IR/TorchOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,21 @@ static OpFoldResult intComparatorFoldHelper(OpTy op,

OpFoldResult AtenDetachOp::fold(FoldAdaptor adaptor) { return getSelf(); }

//===----------------------------------------------------------------------===//
// AtenEmptyMemoryFormatOp
//===----------------------------------------------------------------------===//

void AtenEmptyMemoryFormatOp::getCanonicalizationPatterns(
RewritePatternSet &patterns, MLIRContext *context) {
patterns.add(+[](AtenEmptyMemoryFormatOp op, PatternRewriter &rewriter) {
if (!op->use_empty()) {
return failure();
}
rewriter.eraseOp(op);
return success();
});
}

//===----------------------------------------------------------------------===//
// AtenNeIntOp
//===----------------------------------------------------------------------===//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def emit_with_mutating_variants(key, **kwargs):
emit("aten::new_empty_strided : (Tensor, int[], int[], int?, int?, Device?, bool?) -> (Tensor)")
emit("aten::zeros_like : (Tensor, int?, int?, Device?, bool?, int?) -> (Tensor)")
emit("aten::ones_like : (Tensor, int?, int?, Device?, bool?, int?) -> (Tensor)")
emit("aten::empty.memory_format : (int[], int?, int?, Device?, bool?, int?) -> (Tensor)")
emit("aten::empty.memory_format : (int[], int?, int?, Device?, bool?, int?) -> (Tensor)", has_canonicalizer=True)
emit("aten::expand : (Tensor, int[], bool) -> (Tensor)")
emit("aten::expand_as : (Tensor, Tensor) -> (Tensor)")
emit("aten::broadcast_to : (Tensor, int[]) -> (Tensor)", has_canonicalizer=True)
Expand Down

0 comments on commit de998c0

Please sign in to comment.