-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[mlir][scf] Add ReturnLike
to scf::InParallelOp
#148237
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-mlir Author: Fabian Mora (fabianmcg) ChangesThis patch adds the Full diff: https://github.com/llvm/llvm-project/pull/148237.diff 1 Files Affected:
diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
index 2d15544e871b3..23c987dd777e2 100644
--- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
@@ -633,6 +633,7 @@ def ForallOp : SCF_Op<"forall", [
def InParallelOp : SCF_Op<"forall.in_parallel", [
Pure,
Terminator,
+ ReturnLike,
DeclareOpInterfaceMethods<ParallelCombiningOpInterface>,
HasParent<"ForallOp">,
] # GraphRegionNoTerminator.traits> {
|
@llvm/pr-subscribers-mlir-scf Author: Fabian Mora (fabianmcg) ChangesThis patch adds the Full diff: https://github.com/llvm/llvm-project/pull/148237.diff 1 Files Affected:
diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
index 2d15544e871b3..23c987dd777e2 100644
--- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
@@ -633,6 +633,7 @@ def ForallOp : SCF_Op<"forall", [
def InParallelOp : SCF_Op<"forall.in_parallel", [
Pure,
Terminator,
+ ReturnLike,
DeclareOpInterfaceMethods<ParallelCombiningOpInterface>,
HasParent<"ForallOp">,
] # GraphRegionNoTerminator.traits> {
|
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.
Could you elaborate more on the reasoning here? ReturnLike
forwards its operands to the parent region along the control flow edge:
llvm-project/mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
Lines 324 to 327 in 00311cf
/// This trait indicates that a terminator operation is "return-like". This | |
/// means that it exits its current region and forwards its operands as "exit" | |
/// values to the parent region. Operations with this trait are not permitted to | |
/// contain successors or produce results. |
in_parallel
doesn't even have operands.
Sure. Right now, There were 2 bad options to start fixing the control-flow semantics in this case:
I opted for 2. This patch fixes The proper fix to this whole situation, (IMO) is to add a second region to Now, outside of this patch I would argue that control-flow semantics (outside blocks) in MLIR are somewhat broken, as this is not the first time I encounter a situation like this. But that's a larger conversation and out of scope for this patch. |
This sounds like a good idea, but you'll have to forward values from one region to another. For testing, we can follow what I suggested on another thread and have a custom version of
This is something that can be raised to the forums. I know the modeling is quite limited, but I don't know whether is broken. |
While the op does not have explicit operands, the op is actually implicitly capturing SSA value, which counts as operands to me. I don't quite see what's broken in terms of control-flow here? The fact that it is a parallel fan-out?
That wouldn't help alone: you would need to materialize the reduction in the same way that XLA/HLO does with its reduce: by taking two values, writing the combiner, and yield the new value (instead of the "magic" |
Yes, that's why I mentioned clang's Rewriter class, it would allow to keep the comments. However, since then I think it's easier to parse the comments into ops.
I think the semantics of the implementations are broken here, eg.
That's another thing I considered, extending the interface and other data structures to also work with ranges of ops. However, there were two things I learned while trying to do that approach:
Consequently, the proper fix there it's an even bigger breaking change. I'd argue this needs to happen anyways, but I don't want to propose that until we know how generic control-flow looks in MLIR, as the new system could potentially replace all control-flow and fix things in one go.
Yeah, a change in |
This patch adds the
ReturnLike
trait toscf::InParallelOp
. This is the first step to clean the branching semantics ofscf::ForallOp
andscf::InParallelOp
.