-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir][mesh] Add folding of ClusterShapeOp
If the mesh has static size on some of the requested axes, the result is substituted with a constant.
- Loading branch information
Showing
7 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// RUN: mlir-opt -test-mesh-folding %s | FileCheck %s | ||
|
||
mesh.cluster @mesh0(rank = 3, dim_sizes = 4x?x2) | ||
mesh.cluster @mesh1(rank = 2, dim_sizes = 2x3) | ||
|
||
// CHECK-LABEL: func.func @cluster_shape_op_folding | ||
func.func @cluster_shape_op_folding() -> (index, index) { | ||
// CHECK: %[[AXIS_2_SIZE:.*]] = arith.constant 2 : index | ||
// CHECK: %[[AXIS_1_SIZE:.*]] = mesh.cluster_shape @mesh0 axes = [1] : index | ||
%0:2 = mesh.cluster_shape @mesh0 axes = [2, 1] : index, index | ||
// CHECK: return %[[AXIS_2_SIZE]], %[[AXIS_1_SIZE]] | ||
return %0#0, %0#1 : index, index | ||
} | ||
|
||
// CHECK-LABEL: func.func @cluster_shape_op_folding_all_axes_static_mesh | ||
func.func @cluster_shape_op_folding_all_axes_static_mesh() -> (index, index) { | ||
// CHECK: %[[AXIS_0_SIZE:.*]] = arith.constant 2 : index | ||
// CHECK: %[[AXIS_1_SIZE:.*]] = arith.constant 3 : index | ||
%0:2 = mesh.cluster_shape @mesh1 : index, index | ||
// CHECK: return %[[AXIS_0_SIZE]], %[[AXIS_1_SIZE]] | ||
return %0#0, %0#1 : index, index | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//===- TestSimplification.cpp - Test simplification -----------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir/Dialect/Arith/IR/Arith.h" | ||
#include "mlir/Dialect/Mesh/IR/MeshOps.h" | ||
#include "mlir/Dialect/Mesh/Transforms/Simplifications.h" | ||
#include "mlir/IR/Diagnostics.h" | ||
#include "mlir/IR/SymbolTable.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Support/LogicalResult.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
#include <memory> | ||
|
||
using namespace mlir; | ||
|
||
namespace { | ||
|
||
struct TestMeshFoldingPass | ||
: public PassWrapper<TestMeshFoldingPass, OperationPass<>> { | ||
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMeshFoldingPass) | ||
|
||
void runOnOperation() override; | ||
void getDependentDialects(DialectRegistry ®istry) const override { | ||
registry.insert<mesh::MeshDialect>(); | ||
} | ||
StringRef getArgument() const final { return "test-mesh-folding"; } | ||
StringRef getDescription() const final { return "Test mesh folding."; } | ||
}; | ||
} // namespace | ||
|
||
void TestMeshFoldingPass::runOnOperation() { | ||
RewritePatternSet patterns(&getContext()); | ||
SymbolTableCollection symbolTables; | ||
mesh::populateFoldingPatterns(patterns, symbolTables); | ||
if (failed( | ||
applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)))) { | ||
getOperation()->emitError() | ||
<< "Rewrite patter application did not converge."; | ||
return signalPassFailure(); | ||
} | ||
} | ||
|
||
namespace mlir { | ||
namespace test { | ||
void registerTestMeshFoldingPass() { PassRegistration<TestMeshFoldingPass>(); } | ||
} // namespace test | ||
} // namespace mlir |
This file contains 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
This file contains 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