-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AffineParallelize] expose options when creating pass #124959
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
[AffineParallelize] expose options when creating pass #124959
Conversation
@llvm/pr-subscribers-mlir-affine @llvm/pr-subscribers-mlir Author: Scott Manley (rscottmanley) ChangesAdd a createAffineParallelizePass() that takes AffineParallelizeOptions Full diff: https://github.com/llvm/llvm-project/pull/124959.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Affine/Passes.h b/mlir/include/mlir/Dialect/Affine/Passes.h
index e152101236dc7a9..2d2b5f461e813e3 100644
--- a/mlir/include/mlir/Dialect/Affine/Passes.h
+++ b/mlir/include/mlir/Dialect/Affine/Passes.h
@@ -48,6 +48,10 @@ createAffineLoopInvariantCodeMotionPass();
/// ops.
std::unique_ptr<OperationPass<func::FuncOp>> createAffineParallelizePass();
+/// Creates a pass to convert all parallel affine.for's into 1-d affine.parallel
+/// ops using the specified parallelize options.
+std::unique_ptr<OperationPass<func::FuncOp>> createAffineParallelizePass(const AffineParallelizeOptions &options);
+
/// Apply normalization transformations to affine loop-like ops. If
/// `promoteSingleIter` is true, single iteration loops are promoted (i.e., the
/// loop is replaced by its loop body).
diff --git a/mlir/lib/Dialect/Affine/Transforms/AffineParallelize.cpp b/mlir/lib/Dialect/Affine/Transforms/AffineParallelize.cpp
index 64f2bc6e745c374..f841b83c5aecde0 100644
--- a/mlir/lib/Dialect/Affine/Transforms/AffineParallelize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/AffineParallelize.cpp
@@ -42,6 +42,14 @@ namespace {
/// Convert all parallel affine.for op into 1-D affine.parallel op.
struct AffineParallelize
: public affine::impl::AffineParallelizeBase<AffineParallelize> {
+
+ AffineParallelize() = default;
+
+ explicit AffineParallelize(const AffineParallelizeOptions &options) {
+ maxNested = std::move(options.maxNested);
+ parallelReductions = std::move(options.parallelReductions);
+ }
+
void runOnOperation() override;
};
@@ -95,3 +103,8 @@ std::unique_ptr<OperationPass<func::FuncOp>>
mlir::affine::createAffineParallelizePass() {
return std::make_unique<AffineParallelize>();
}
+
+std::unique_ptr<OperationPass<func::FuncOp>>
+mlir::affine::createAffineParallelizePass(const AffineParallelizeOptions &options) {
+ return std::make_unique<AffineParallelize>(options);
+}
|
afface6
to
f5c04c8
Compare
@@ -42,6 +42,14 @@ namespace { | |||
/// Convert all parallel affine.for op into 1-D affine.parallel op. | |||
struct AffineParallelize | |||
: public affine::impl::AffineParallelizeBase<AffineParallelize> { | |||
|
|||
AffineParallelize() = default; | |||
|
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.
These constructors should have been auto-generated in AffineParallelizeBase
. You probably just need to make it visible here with using AffineParallelizeBase<AffineParallelize>::AffineParallelizeBase
...
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.
Agree -- will change. Thanks for the review Diego!
@@ -95,3 +103,9 @@ std::unique_ptr<OperationPass<func::FuncOp>> | |||
mlir::affine::createAffineParallelizePass() { | |||
return std::make_unique<AffineParallelize>(); | |||
} | |||
|
|||
std::unique_ptr<OperationPass<func::FuncOp>> | |||
mlir::affine::createAffineParallelizePass( |
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.
There is also a way to have this auto-generated. I think if you go to Affine/Passes.td
and remove the line let constructor = "mlir::affine::createAffineParallelizePass()";
, tablegen should generate the respective createAffineParallelizePass
constructors.
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.
Ironically had done it this way before seeing how OneShotBufferize did it and then did it that way instead! I definitely prefer this way so I'll make that change.
Use the constructors auto generated in AffineParallelizeBase so AffineParallelizeOptions can be used when adding it to a pass pipeline. Also remove the constructor from the def in the pass table.
f5c04c8
to
db1f642
Compare
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.
Cool, thanks for modernizing this code!
Add a createAffineParallelizePass() that takes AffineParallelizeOptions
so it can be customized in a pass pipeline.