[mlir][shard] Small fixes to partition pass#185050
Merged
Conversation
Member
|
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-bufferization Author: Frank Schlimbach (fschlimb) Changes
Enables llvm/lighthouse#65 Full diff: https://github.com/llvm/llvm-project/pull/185050.diff 3 Files Affected:
diff --git a/mlir/lib/Dialect/Bufferization/Extensions/ShardingExtensions.cpp b/mlir/lib/Dialect/Bufferization/Extensions/ShardingExtensions.cpp
index 7d6d2a8378813..40a26cf6334a2 100644
--- a/mlir/lib/Dialect/Bufferization/Extensions/ShardingExtensions.cpp
+++ b/mlir/lib/Dialect/Bufferization/Extensions/ShardingExtensions.cpp
@@ -12,22 +12,20 @@
#include "mlir/IR/DialectRegistry.h"
using namespace mlir;
-
-/// Variadic helper function.
-template <typename... OpTypes>
-static void registerAll(MLIRContext *ctx) {
- (OpTypes::template attachInterface<
- shard::IndependentParallelIteratorDomainShardingInterface<OpTypes>>(
- *ctx),
- ...);
-}
+using namespace mlir::bufferization;
+using namespace mlir::shard;
void mlir::bufferization::shard_ext::registerShardingInterfaceExternalModels(
DialectRegistry ®istry) {
- registry.addExtension(+[](MLIRContext *ctx,
- bufferization::BufferizationDialect *dialect) {
- registerAll<bufferization::AllocTensorOp, bufferization::DeallocTensorOp,
- bufferization::MaterializeInDestinationOp>(ctx);
+ registry.addExtension(+[](MLIRContext *ctx, BufferizationDialect *dialect) {
+ AllocTensorOp::attachInterface<
+ IndependentParallelIteratorDomainShardingInterface<AllocTensorOp>>(
+ *ctx);
+ DeallocTensorOp::attachInterface<
+ IndependentParallelIteratorDomainShardingInterface<DeallocTensorOp>>(
+ *ctx);
+ MaterializeInDestinationOp::attachInterface<
+ ElementwiseShardingInterface<MaterializeInDestinationOp>>(*ctx);
});
}
diff --git a/mlir/lib/Dialect/Shard/Transforms/ShardingPropagation.cpp b/mlir/lib/Dialect/Shard/Transforms/ShardingPropagation.cpp
index cff02d4f03143..1e7deda5c6377 100644
--- a/mlir/lib/Dialect/Shard/Transforms/ShardingPropagation.cpp
+++ b/mlir/lib/Dialect/Shard/Transforms/ShardingPropagation.cpp
@@ -364,12 +364,19 @@ struct ShardingPropagation
FunctionOpInterface funcOp = getOperation();
MLIRContext *ctx = funcOp.getContext();
Region ®ion = funcOp.getFunctionBody();
- OpBuilder builder(ctx);
+
+ if (region.empty())
+ return;
+
+ Block &block = region.front();
+ // Nothing to propagate if there is no sharding annotation in the block.
+ if (block.getOps<shard::ShardOp>().empty())
+ return;
+
if (!region.hasOneBlock()) {
funcOp.emitOpError() << "only one block is supported!";
return signalPassFailure();
}
- Block &block = region.front();
LLVM_DEBUG(
DBGS() << "print all the ops' iterator types and indexing maps in the "
@@ -379,10 +386,7 @@ struct ShardingPropagation
shardingOp.printLoopTypesAndIndexingMaps(llvm::dbgs());
});
- // Nothing to propagate if there is no sharding annotation in the block.
- if (block.getOps<shard::ShardOp>().empty())
- return;
-
+ OpBuilder builder(ctx);
auto traverse = [&](auto &&range, OpBuilder &builder,
const char *order) -> bool {
for (Operation &op : range) {
diff --git a/mlir/test/Dialect/Shard/sharding-propagation-failed.mlir b/mlir/test/Dialect/Shard/sharding-propagation-failed.mlir
index b5eb98d859c36..3459c1c9f6edc 100644
--- a/mlir/test/Dialect/Shard/sharding-propagation-failed.mlir
+++ b/mlir/test/Dialect/Shard/sharding-propagation-failed.mlir
@@ -1,4 +1,11 @@
// RUN: mlir-opt --pass-pipeline="builtin.module(func.func(sharding-propagation))" %s -verify-diagnostics
+shard.grid @grid(shape = 1) {sym_visibility = "private"}
// expected-error @+1 {{'func.func' op only one block is supported!}}
-func.func private @no_block_function(i64)
+func.func @multi_block_function(%arg0 : tensor<6x6xi32>) -> tensor<6x6xi32> {
+ %sharding = shard.sharding @grid split_axes = [[0]] : !shard.sharding
+ %sharded = shard.shard %arg0 to %sharding : tensor<6x6xi32>
+ cf.br ^bb1
+ ^bb1:
+ return %sharded : tensor<6x6xi32>
+}
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts Shard sharding propagation behavior to avoid flagging empty functions as failures and updates Bufferization dialect sharding interface registrations (notably for bufferization.materialize_in_destination) to support downstream sharding behavior.
Changes:
- Skip sharding propagation on empty function bodies (no blocks) instead of emitting an error.
- Reorder early-exit logic in sharding propagation based on presence of sharding annotations.
- Update Bufferization external sharding interface registration, switching
MaterializeInDestinationOpto an elementwise sharding model.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| mlir/test/Dialect/Shard/sharding-propagation-failed.mlir | Updates negative test to trigger the “multi-block not supported” diagnostic and adds grid/sharding setup. |
| mlir/lib/Dialect/Shard/Transforms/ShardingPropagation.cpp | Skips empty regions and adds early returns when no sharding is present before doing propagation work. |
| mlir/lib/Dialect/Bufferization/Extensions/ShardingExtensions.cpp | Adjusts external sharding interface attachments; uses elementwise sharding for MaterializeInDestinationOp. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enables llvm/lighthouse#65