-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add support for integer division to TCP #97
Changes from 5 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 |
---|---|---|
|
@@ -160,6 +160,46 @@ def Tcp_DivFOp : Tcp_BinaryElementwiseOp<"divf", [SameOperandsAndResultElementTy | |
let assemblyFormat = "$in1 `,` $in2 attr-dict `:` type($in1) `,` type($in2) `->` type($out)"; | ||
} | ||
|
||
def Tcp_DivSIOp : Tcp_BinaryElementwiseOp<"divsi", [SameOperandsAndResultElementType]> { | ||
let summary = "Computes elementwise signed integer division"; | ||
|
||
let description = [{ | ||
Computes the signed integer division of `in1` and `in2`. | ||
}]; | ||
|
||
let arguments = (ins | ||
Tcp_IntTensor:$in1, | ||
Tcp_IntTensor:$in2, | ||
Tcp_RoundingModeAttr:$rounding_mode | ||
); | ||
|
||
let results = (outs | ||
Tcp_IntTensor:$out | ||
); | ||
|
||
let assemblyFormat = "$in1 `,` $in2 attr-dict `:` type($in1) `,` type($in2) `->` type($out)"; | ||
} | ||
|
||
def Tcp_DivUIOp : Tcp_BinaryElementwiseOp<"divui", [SameOperandsAndResultElementType]> { | ||
let summary = "Computes elementwise unsigned integer division"; | ||
|
||
let description = [{ | ||
Computes the unsigned integer division of `in1` and `in2`. | ||
}]; | ||
|
||
let arguments = (ins | ||
Tcp_IntTensor:$in1, | ||
Tcp_IntTensor:$in2, | ||
Tcp_RoundingModeAttr:$rounding_mode | ||
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 we need the rounding mode here? Should we just stick to using 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. Given that the arith dialect has straightforward mapping to ceildiv, why not just have it for the sake of expressibility? I do not have a strong opinion on this though. We could just leave it out now and introduce it later if we find a need for it. |
||
); | ||
|
||
let results = (outs | ||
Tcp_IntTensor:$out | ||
); | ||
|
||
let assemblyFormat = "$in1 `,` $in2 attr-dict `:` type($in1) `,` type($in2) `->` type($out)"; | ||
} | ||
|
||
def Tcp_ConstOp : Tcp_Op<"const", [ConstantLike, Pure]> { | ||
let summary = "Constant op"; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,32 @@ createLinalgPayloadForElementwiseOp(Operation *op, | |
"createLinalgPayloadForElementwiseOp for tcp.divf"); | ||
} | ||
|
||
if (auto divOp = dyn_cast<DivSIOp>(op)) { | ||
if (!elemType.isa<mlir::IntegerType>()) | ||
llvm_unreachable("unsupported element type in " | ||
"createLinalgPayloadForElementwiseOp for tcp.divsi"); | ||
if (divOp.getRoundingMode() == RoundingMode::Trunc) | ||
return {b.create<arith::DivSIOp>(loc, payloadArgs[0], payloadArgs[1])}; | ||
else if (divOp.getRoundingMode() == RoundingMode::Ceil) | ||
return { | ||
b.create<arith::CeilDivUIOp>(loc, payloadArgs[0], payloadArgs[1])}; | ||
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. Shouldn't this be 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. yikes :( thanks for the typo fix. |
||
else | ||
return { | ||
b.create<arith::FloorDivSIOp>(loc, payloadArgs[0], payloadArgs[1])}; | ||
} | ||
|
||
if (auto divOp = dyn_cast<DivUIOp>(op)) { | ||
if (!elemType.isa<mlir::IntegerType>()) | ||
llvm_unreachable("unsupported element type in " | ||
"createLinalgPayloadForElementwiseOp for tcp.divui"); | ||
if (divOp.getRoundingMode() == RoundingMode::Trunc || | ||
divOp.getRoundingMode() == RoundingMode::Floor) | ||
return {b.create<arith::DivUIOp>(loc, payloadArgs[0], payloadArgs[1])}; | ||
else | ||
return { | ||
b.create<arith::CeilDivUIOp>(loc, payloadArgs[0], payloadArgs[1])}; | ||
} | ||
|
||
if (isa<Atan2Op>(op)) { | ||
if (elemType.isa<mlir::FloatType>()) | ||
return {b.create<math::Atan2Op>(loc, payloadArgs[0], payloadArgs[1])}; | ||
|
@@ -330,6 +356,8 @@ void mlir::TcpToLinalg::populateElementwisePatternsAndLegality( | |
INSERT_TCP_TO_LINALG_PATTERN(ClampOp); | ||
INSERT_TCP_TO_LINALG_PATTERN(MulOp); | ||
INSERT_TCP_TO_LINALG_PATTERN(DivFOp); | ||
INSERT_TCP_TO_LINALG_PATTERN(DivSIOp); | ||
INSERT_TCP_TO_LINALG_PATTERN(DivUIOp); | ||
INSERT_TCP_TO_LINALG_PATTERN(SubOp); | ||
INSERT_TCP_TO_LINALG_PATTERN(TanhOp); | ||
INSERT_TCP_TO_LINALG_PATTERN(SigmoidOp); | ||
|
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.
minor nit: fix spacing here and below