Skip to content
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

Don't copy sharding constraints to sdy.data_flow_edge since they hold the sharding of multiple targets, not just the root. #26

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ limitations under the License.
#include "mlir/Support/LLVM.h"
#include "shardy/dialect/sdy/ir/dialect.h"
#include "shardy/dialect/sdy/ir/utils.h"
#include "third_party/openxla/shardy/src/shardy/dialect/sdy/ir/dialect.h"

namespace mlir {
namespace sdy {
Expand All @@ -34,8 +35,8 @@ namespace sdy {
namespace {

bool shouldApply(Value input, Operation* op) {
if (getSharding(input)) {
// `input` already has a sharding.
if (getSharding(input) || input.getDefiningOp<DataFlowEdgeOp>()) {
// `input` already has a sharding or is produced by a `DataFlowEdgeOp`.
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions shardy/dialect/sdy/transforms/import/passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def ApplyShardingConstraintsPass : Pass<"sdy-apply-sharding-constraints", "func:
all of the following:

* The input doesn't have an existing sharding.
* The input isn't produced by a `DataFlowEdgeOp`, which holds the sharding
of all targets of the edge.
* The input is either only used by the `ShardingConstraintOp` or the latter
doesn't have any uses (dangling) and the input doesn't have any other
users of type `ShardingConstraintOp` or `ManualComputationOp`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ func.func @input_has_one_use(%arg0: tensor<8x8xf32>) -> tensor<8x8xf32> {
return %1 : tensor<8x8xf32>
}

// CHECK-LABEL: func @input_produced_by_data_flow_edge
func.func @input_produced_by_data_flow_edge(%arg0: tensor<8x8xf32>) -> tensor<8x8xf32> {
// CHECK-NEXT: sdy.data_flow_edge %arg0 : tensor<8x8xf32>
// CHECK-NOT: sdy.sharding
// CHECK-NEXT: sdy.sharding_constraint
%0 = sdy.data_flow_edge %arg0 : tensor<8x8xf32>
%1 = sdy.sharding_constraint %0 <@mesh, [{}, {"b"}]> : tensor<8x8xf32>
return %1 : tensor<8x8xf32>
}

// CHECK-LABEL: func @input_is_func_input_with_one_use(
// CHECK-SAMEL %arg0: tensor<8x8xf32> {sdy.sharding = #sdy.sharding<@mesh, [{}, {"b"}]>})
func.func @input_is_func_input_with_one_use(%arg0: tensor<8x8xf32>) -> tensor<8x8xf32> {
Expand Down
20 changes: 19 additions & 1 deletion shardy/dialect/sdy/transforms/import/test/import_pipeline.mlir
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: sdy_opt %s -sdy-import-pipeline 2>&1 | FileCheck %s
// RUN: sdy_opt %s -split-input-file -sdy-import-pipeline 2>&1 | FileCheck %s

// Verifies that function `-inliner` pass is applied
// CHECK-LABEL: func @main
func.func @main(%arg0: tensor<16x16xf32>) -> (tensor<8x16xf32>, tensor<8x16xf32>) {
// CHECK-NEXT: %[[CONST_0:.*]] = sdy.constant dense<1.000000e+00>
Expand All @@ -19,3 +20,20 @@ func.func private @add_matmul_to_lhs(%arg0: tensor<8x16xf32>, %arg1: tensor<16x1
%1 = stablehlo.add %arg0, %0 : tensor<8x16xf32>
return %1 : tensor<8x16xf32>
}

// -----

sdy.mesh @mesh = <"a"=2>

// Verifies that `-apply-sharding-constraints` pass is applied after
// `-add-data_flow_edges` pass
// CHECK-LABEL: func @main
func.func @main(%arg0: tensor<32x96xf32>) -> tensor<32x96xf32> {
// CHECK-NEXT: %[[OPT_BARRIER:.*]] = stablehlo.optimization_barrier %arg0
// CHECK-NEXT: sdy.data_flow_edge %[[OPT_BARRIER]] : tensor<32x96xf32>
// CHECK-NOT: sdy.sharding
// CHECK-NEXT: sdy.sharding_constraint
%0 = stablehlo.optimization_barrier %arg0 : tensor<32x96xf32>
%1 = sdy.sharding_constraint %0 <@mesh, [{}, {"a"}]> : tensor<32x96xf32>
return %1 : tensor<32x96xf32>
}
Loading