8000 [mlir][loops] Reland Refactor LoopFuseSiblingOp and support parallel fusion #94391 by srcarroll · Pull Request #97607 · llvm/llvm-project · GitHub
[go: up one dir, main page]

Skip to content

[mlir][loops] Reland Refactor LoopFuseSiblingOp and support parallel fusion #94391 #97607

8000
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

Merged
merged 40 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5020e49
Add getters for multi dim loop variables in LoopLikeOpInterface
srcarroll Jun 5, 2024
50852d5
Refactor LoopFuseSiblingOp and support parallel fusion
srcarroll Jun 4, 2024
b73238a
add checkFusionStructuralLegality
srcarroll Jun 5, 2024
f5bbd13
replace isLoopWithIdenticalConfiguration with checkFusionStructuralLe…
srcarroll Jun 5, 2024
7d99581
address review comment
srcarroll Jun 5, 2024
a5fa3b3
Make return types optional and change names
srcarroll Jun 6, 2024
1babe68
change return type of getInductionVars to SmallVector<Value>
srcarroll Jun 6, 2024
009fd15
address maks's comments
srcarroll Jun 6, 2024
d34ad95
change interface method names again and revert steps operand change
srcarroll Jun 6, 2024
e0e5262
return option induction vars
srcarroll Jun 6, 2024
7115a6e
address review comments
srcarroll Jun 7, 2024
1d4a444
Merge branch 'main' into add-loop-like-interface-methods
srcarroll Jun 7, 2024
af6b030
Merge branch 'add-loop-like-interface-methods' into scf-parallel-loop…
srcarroll Jun 7, 2024
6336fdf
update after rebase
srcarroll Jun 7, 2024
aa15617
Merge branch 'main' into scf-parallel-loop-fusion
srcarroll Jun 7, 2024
7dbe646
Merge branch 'main' into scf-parallel-loop-fusion
srcarroll Jun 8, 2024
86406c3
refactor main parallel fusion logic from fuseIfLegal to util func
srcarroll Jun 9, 2024
694d589
remove unused functions
srcarroll Jun 9, 2024
67cb64f
refactor fuseIndependentSiblingForLoops to reuse replaceWithAdditiona…
srcarroll Jun 9, 2024
cc8599f
refactor fuseIndependentSiblingForallLoops to reuse replaceWithAdditi…
srcarroll Jun 9, 2024
48b1af9
wip
srcarroll Jun 10, 2024
7a51cb3
Decouple concrete loop type from `createFused` function
srcarroll Jun 17, 2024
3087326
Refactor ForallOp::replaceWithAdditionalYields
srcarroll Jun 17, 2024
bcf3d4a
revert unnecessary changes
srcarroll Jun 17, 2024
0cb3c4e
cleanup
srcarroll Jun 18, 2024
7e41a54
address some review comments
srcarroll Jun 21, 2024
cc95d75
move `createFused` to `LoopLikeInterface.h`
srcarroll Jun 24, 2024
3430a36
address more review comments
srcarroll Jun 26, 2024
8447c12
switch to function_ref
srcarroll Jun 27, 2024
fbd7b72
check optional values
srcarroll Jun 27, 2024
ffb73a7
replace equalIterationSpaces with checkFusionStructuredLegality
srcarroll Jun 27, 2024
a6d0588
check if isOpSibling in checkFusionStructuralLegality
srcarroll Jun 27, 2024
ff47980
remove extra dominance check
srcarroll Jun 27, 2024
c6847ec
address more review comments
srcarroll Jun 27, 2024
f50c6aa
add more lit tests for scf.parallel
srcarroll Jun 27, 2024
6dd68c1
check for equal loop types in checkFusionStructuralLegality
srcarroll Jun 27, 2024
99d821b
address more comments
srcarroll Jun 27, 2024
6825c15
Merge branch 'main' into scf-parallel-loop-fusion
srcarroll Jun 27, 2024
7f9c172
Fix bug in fusion refactor and add test
srcarroll Jul 3, 2024
4b4fd91
add comment
srcarroll Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
return option induction vars
  • Loading branch information
srcarroll committed Jun 6, 2024
commit e0e526210a5ab6ce28fbc5fa5ee24f79cb1ee9a8
10 changes: 7 additions & 3 deletions mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
8000
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ def ForallOp : SCF_Op<"forall", [

let extraClassDeclaration = [{
SmallVector<Value> getInductionVars() {
return getLoopInductionVars();
auto maybeInductionVars = getLoopInductionVars();;
assert(maybeInductionVars.has_value() && "expected values");
return *maybeInductionVars;
}
// Get lower bounds as OpFoldResult.
SmallVector<OpFoldResult> getMixedLowerBound() {
Expand Down Expand Up @@ -591,7 +593,7 @@ def ForallOp : SCF_Op<"forall", [
}

::mlir::Value getInductionVar(int64_t idx) {
return getLoopInductionVars()[idx];
return getInductionVars()[idx];
}

::mlir::Block::BlockArgListType getRegionOutArgs() {
Expand Down Expand Up @@ -850,7 +852,9 @@ def ParallelOp : SCF_Op<"parallel",
let extraClassDeclaration = [{
// Get induction variables.
SmallVector<Value> getInductionVars() {
return getLoopInductionVars();
auto maybeInductionVars = getLoopInductionVars();;
assert(maybeInductionVars.has_value() && "expected values");
return *maybeInductionVars;
}
unsigned getNumLoops() { return getStep().size(); }
unsigned getNumReductions() { return getInitVals().size(); }
Expand Down
8 changes: 4 additions & 4 deletions mlir/include/mlir/Interfaces/LoopLikeInterface.td
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
InterfaceMethod<[{
Return all induction variables.
}],
/*retTy=*/"::llvm::SmallVector<::mlir::Value>",
/*retTy=*/"::std::optional<::llvm::SmallVector<::mlir::Value>>",
/*methodName=*/"getLoopInductionVars",
/*args=*/(ins),
/*methodBody=*/"",
/*defaultImplementation=*/[{
return {};
return std::nullopt;
}]
>,
InterfaceMethod<[{
Expand Down Expand Up @@ -235,8 +235,8 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
/// std::nullopt.
::std::optional<::mlir::Value> getSingleInductionVar() {
auto inductionVars = this->getLoopInductionVars();
if (inductionVars.size() == 1)
return inductionVars[0];
if (inductionVars.has_value() && (*inductionVars).size() == 1)
return (*inductionVars)[0];
return std::nullopt;
}
/// Return the single lower bound value or attribute if it exists, otherwise
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/Affine/IR/AffineOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2454,8 +2454,8 @@ bool AffineForOp::matchingBoundOperandList() {

SmallVector<Region *> AffineForOp::getLoopRegions() { return {&getRegion()}; }

SmallVector<Value> AffineForOp::getLoopInductionVars() {
return {getInductionVar()};
std::optional<SmallVector<Value>> AffineForOp::getLoopInductionVars() {
return SmallVector<Value>{getInductionVar()};
}

std::optional<SmallVector<OpFoldResult>> AffineForOp::getLoopLowerBounds() {
Expand Down
8 changes: 5 additions & 3 deletions mlir/lib/Dialect/SCF/IR/SCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ LogicalResult ForOp::verifyRegions() {
return success();
}

SmallVector<Value> ForOp::getLoopInductionVars() { return {getInductionVar()}; }
std::optional<SmallVector<Value>> ForOp::getLoopInductionVars() {
return SmallVector<Value, 1>{getInductionVar()};
}

std::optional<SmallVector<OpFoldResult>> ForOp::getLoopLowerBounds() {
return SmallVector<OpFoldResult, 1>{OpFoldResult(getLowerBound())};
Expand Down Expand Up @@ -1426,7 +1428,7 @@ SmallVector<Operation *> ForallOp::getCombiningOps(BlockArgument bbArg) {
return storeOps;
}

SmallVector<Value> ForallOp::getLoopInductionVars() {
std::optional<SmallVector<Value>> ForallOp::getLoopInductionVars() {
return SmallVector<Value>{getBody()->getArguments().take_front(getRank())};
}

Expand Down Expand Up @@ -3004,7 +3006,7 @@ void ParallelOp::print(OpAsmPrinter &p) {

SmallVector<Region *> ParallelOp::getLoopRegions() { return {&getRegion()}; }

SmallVector<Value> ParallelOp::getLoopInductionVars() {
std::optional<SmallVector<Value>> ParallelOp::getLoopInductionVars() {
return SmallVector<Value>{getBody()->getArguments()};
}

Expand Down
10 changes: 8 additions & 2 deletions mlir/unittests/Dialect/SCF/LoopLikeSCFOpsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class SCFLoopLikeTest : public ::testing::Test {
loopLikeOp.getLoopSteps();
EXPECT_TRUE(maybeStep.has_value());
EXPECT_EQ((*maybeStep).size(), 1u);
EXPECT_EQ(loopLikeOp.getLoopInductionVars().size(), 1u);
std::optional<SmallVector<Value>> maybeInductionVars =
loopLikeOp.getLoopInductionVars();
EXPECT_TRUE(maybeInductionVars.has_value());
EXPECT_EQ((*maybeInductionVars).size(), 1u);
}

void checkMultidimensional(LoopLikeOpInterface loopLikeOp) {
Expand Down Expand Up @@ -79,7 +82,10 @@ class SCFLoopLikeTest : public ::testing::Test {
loopLikeOp.getLoopSteps();
EXPECT_TRUE(maybeStep.has_value());
EXPECT_EQ((*maybeStep).size(), 2u);
EXPECT_EQ(loopLikeOp.getLoopInductionVars().size(), 2u);
std::optional<SmallVector<Value>> maybeInductionVars =
loopLikeOp.getLoopInductionVars();
EXPECT_TRUE(maybeInductionVars.has_value());
EXPECT_EQ((*maybeInductionVars).size(), 2u);
}

MLIRContext context;
Expand Down
0