[Torch Dialect] emit aten::mul and add folder (#3007)

pull/3010/head
Yuanqiang Liu 2024-03-11 19:59:34 +08:00 committed by GitHub
parent a3fe130f73
commit 229ca3a9e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 0 deletions

View File

@ -14275,6 +14275,31 @@ def Torch_Aten_SetItemTOp : Torch_Op<"aten._set_item.t", [
}]; }];
} }
def Torch_AtenMulOp : Torch_Op<"aten.mul", [
AllowsTypeRefinement,
HasValueSemantics,
ReadOnly
]> {
let summary = "Generated op for `aten::mul : (Scalar, Scalar) -> (Scalar)`";
let arguments = (ins
AnyTorchScalarType:$a,
AnyTorchScalarType:$b
);
let results = (outs
AnyTorchScalarType:$result
);
let hasCustomAssemblyFormat = 1;
let extraClassDefinition = [{
ParseResult AtenMulOp::parse(OpAsmParser &parser, OperationState &result) {
return parseDefaultTorchOp(parser, result, 2, 1);
}
void AtenMulOp::print(OpAsmPrinter &printer) {
printDefaultTorchOp(printer, *this, 2, 1);
}
}];
let hasFolder = 1;
}
def Torch_AtenDivOp : Torch_Op<"aten.div", [ def Torch_AtenDivOp : Torch_Op<"aten.div", [
AllowsTypeRefinement, AllowsTypeRefinement,
HasValueSemantics, HasValueSemantics,

View File

@ -3346,6 +3346,25 @@ OpFoldResult AtenAddOp::fold(FoldAdaptor adaptor) {
[](double a, double b) -> double { return a + b; }); [](double a, double b) -> double { return a + b; });
} }
//===----------------------------------------------------------------------===//
// AtenMulOp
//===----------------------------------------------------------------------===//
OpFoldResult AtenMulOp::fold(FoldAdaptor adaptor) {
if (!adaptor.getA() || !adaptor.getB()) {
return nullptr;
}
if (adaptor.getA().isa<IntegerAttr>() && adaptor.getB().isa<IntegerAttr>()) {
return atenBinaryIntOperatorFoldHelper(
adaptor.getOperands(),
[](int64_t a, int64_t b) -> int64_t { return a * b; });
}
return atenBinaryFloatOperatorFoldHelper(
adaptor.getOperands(),
[](double a, double b) -> double { return a * b; });
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// AtenSubOp // AtenSubOp
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -805,6 +805,7 @@ def emit_ops(emitter_td: TextEmitter, registry: Registry):
has_canonicalizer=True) has_canonicalizer=True)
emit("aten::__getitem__.t : (t[], int) -> (t)", has_canonicalizer=True) emit("aten::__getitem__.t : (t[], int) -> (t)", has_canonicalizer=True)
emit("aten::_set_item.t : (t[], int, t) -> (t[])") emit("aten::_set_item.t : (t[], int, t) -> (t[])")
emit("aten::mul : (Scalar, Scalar) -> (Scalar)", has_folder=True)
emit("aten::div : (Scalar, Scalar) -> (float)", has_folder=True) emit("aten::div : (Scalar, Scalar) -> (float)", has_folder=True)
emit("aten::add : (Scalar, Scalar) -> (Scalar)", has_folder=True) emit("aten::add : (Scalar, Scalar) -> (Scalar)", has_folder=True)
emit("aten::sub : (Scalar, Scalar) -> (Scalar)", has_folder=True) emit("aten::sub : (Scalar, Scalar) -> (Scalar)", has_folder=True)