mirror of https://github.com/llvm/torch-mlir
Add lowering of `torch.log` op
The lowering of `torch.log` op has been added. Signed-off-by: Prashant Kumar <prashant@nod-labs.com>pull/395/head snapshot-20211102.60
parent
6dde5b347e
commit
127c7d8e27
|
@ -343,3 +343,20 @@ class RsubModule_noalpha(torch.nn.Module):
|
|||
@register_test_case(module_factory=lambda: RsubModule_noalpha())
|
||||
def RsubModule_noalpha_basic(module, tu: TestUtils):
|
||||
module.forward(tu.rand(3, 4))
|
||||
|
||||
class ElementwiseLogModule(torch.nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@export
|
||||
@annotate_args([
|
||||
None,
|
||||
([-1, -1], torch.float32, True),
|
||||
])
|
||||
def forward(self, a):
|
||||
return torch.log(a)
|
||||
|
||||
|
||||
@register_test_case(module_factory=lambda: ElementwiseLogModule())
|
||||
def ElementwiseLogModule_basic(module, tu: TestUtils):
|
||||
module.forward(tu.rand(3, 4))
|
||||
|
|
|
@ -72,6 +72,34 @@ def Torch_AtenRelu_Op : Torch_Op<"aten.relu_", [
|
|||
let assemblyFormat = "$self attr-dict `:` type($self) `->` type($result)";
|
||||
}
|
||||
|
||||
def Torch_AtenLogOp : Torch_Op<"aten.log", [
|
||||
AllowsTypeRefinement,
|
||||
HasValueSemantics
|
||||
]> {
|
||||
let summary = "Generated op for `aten::log : (Tensor) -> (Tensor)`";
|
||||
let arguments = (ins
|
||||
AnyTorchTensorType:$self
|
||||
);
|
||||
let results = (outs
|
||||
AnyTorchTensorType:$result
|
||||
);
|
||||
let assemblyFormat = "$self attr-dict `:` type($self) `->` type($result)";
|
||||
}
|
||||
|
||||
def Torch_AtenLog_Op : Torch_Op<"aten.log_", [
|
||||
IsTrailingUnderscoreInplaceVariant,
|
||||
AllowsTypeRefinement
|
||||
]> {
|
||||
let summary = "Generated op for `aten::log_ : (Tensor) -> (Tensor)`";
|
||||
let arguments = (ins
|
||||
AnyTorchTensorType:$self
|
||||
);
|
||||
let results = (outs
|
||||
AnyTorchTensorType:$result
|
||||
);
|
||||
let assemblyFormat = "$self attr-dict `:` type($self) `->` type($result)";
|
||||
}
|
||||
|
||||
def Torch_AtenSigmoidOp : Torch_Op<"aten.sigmoid", [
|
||||
AllowsTypeRefinement,
|
||||
HasValueSemantics
|
||||
|
|
|
@ -1278,6 +1278,8 @@ static Value createLinalgPayloadCalculationForElementwiseOp(
|
|||
return b.create<math::TanhOp>(loc, payloadArgs[0]);
|
||||
if (isa<AtenExpOp>(op))
|
||||
return b.create<math::ExpOp>(loc, payloadArgs[0]);
|
||||
if (isa<AtenLogOp>(op))
|
||||
return b.create<math::LogOp>(loc, payloadArgs[0]);
|
||||
if (isa<AtenSigmoidOp>(op)) {
|
||||
Type elementType = payloadArgs[0].getType();
|
||||
auto one = b.create<arith::ConstantOp>(loc, FloatAttr::get(elementType, 1));
|
||||
|
@ -1661,7 +1663,7 @@ struct ConvertElementwiseOp : ConversionPattern {
|
|||
if (!isa<AtenTanhOp, AtenReluOp, AtenGeluOp, AtenAddTensorOp,
|
||||
AtenMulTensorOp, AtenDivTensorOp, AtenSubTensorOp,
|
||||
AtenLerpTensorOp, AtenSigmoidOp, AtenExpOp, AtenMinimumOp,
|
||||
AtenMaximumOp, AtenClampOp, AtenRsubScalarOp>(op))
|
||||
AtenMaximumOp, AtenClampOp, AtenRsubScalarOp, AtenLogOp>(op))
|
||||
return rewriter.notifyMatchFailure(op, "not a supported elementwise op");
|
||||
|
||||
if (failed(verifyLinalgCompatibleTypes(op, rewriter)))
|
||||
|
@ -2797,7 +2799,7 @@ public:
|
|||
target.addIllegalOp<AtenTanhOp, AtenReluOp, AtenGeluOp, AtenAddTensorOp,
|
||||
AtenMulTensorOp, AtenDivTensorOp, AtenSubTensorOp,
|
||||
AtenLerpTensorOp, AtenSigmoidOp, AtenMinimumOp,
|
||||
AtenMaximumOp, AtenClampOp, AtenRsubScalarOp>();
|
||||
AtenMaximumOp, AtenClampOp, AtenRsubScalarOp, AtenLogOp>();
|
||||
patterns.add<ConvertElementwiseOp>(typeConverter, context);
|
||||
target.addIllegalOp<AtenUnsqueezeOp>();
|
||||
patterns.add<ConvertAtenUnsqueezeOp>(typeConverter, context);
|
||||
|
|
|
@ -230,7 +230,7 @@ public:
|
|||
DerefineOp, AtenToPrimDeviceOp, AtenCpuOp, AtenContiguousOp,
|
||||
AtenFill_ScalarOp, AtenDetachOp, AtenMaskedFill_ScalarOp,
|
||||
AtenCopy_Op, AtenIndexPut_Op, AtenCopy_Op, AtenCumsumOp,
|
||||
AtenLayerNormOp, AtenClampOp, AtenRsubScalarOp>(op)) {
|
||||
AtenLayerNormOp, AtenClampOp, AtenRsubScalarOp, AtenLogOp>(op)) {
|
||||
return getLatticeElement(op->getResult(0)).join(*operands[0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -439,6 +439,7 @@ def emit_aten_ops(torch_ir_dir: str, registry: Registry):
|
|||
for key in [
|
||||
"aten::tanh : (Tensor) -> (Tensor)",
|
||||
"aten::relu : (Tensor) -> (Tensor)",
|
||||
"aten::log : (Tensor) -> (Tensor)",
|
||||
"aten::sigmoid : (Tensor) -> (Tensor)",
|
||||
"aten::sin : (Tensor) -> (Tensor)",
|
||||
"aten::exp : (Tensor) -> (Tensor)",
|
||||
|
|
Loading…
Reference in New Issue