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

#sdy use applyPatternsGreedily with config.fold=false and config.cseConstants=false to avoid constant folding and CSE which is expensive. #281

Merged
merged 1 commit into from
Jan 8, 2025
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
27 changes: 21 additions & 6 deletions shardy/dialect/sdy/transforms/import/import_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ limitations under the License.
namespace mlir {
namespace sdy {

namespace {

GreedyRewriteConfig getCanonicalizerConfig(bool enableRegionSimplification) {
GreedyRewriteConfig config;
config.useTopDownTraversal = true;
config.enableRegionSimplification = enableRegionSimplification
? GreedySimplifyRegionLevel::Normal
: GreedySimplifyRegionLevel::Disabled;
config.fold = false;
config.cseConstants = false;
return config;
}

} // namespace

void addImportPipeline(OpPassManager& pm, StringRef dumpDirectory,
bool skipInline) {
pm.addPass(mlir::sdy::createSaveModuleOpPass(dumpDirectory,
Expand All @@ -33,7 +48,10 @@ void addImportPipeline(OpPassManager& pm, StringRef dumpDirectory,
// otherwise we would need to propagate shardings between call ops and callee
// functions.
if (!skipInline) {
pm.addPass(createInlinerPass());
pm.addPass(createInlinerPass({}, [&](OpPassManager& pm) {
pm.addPass(createCanonicalizerPass(
getCanonicalizerConfig(/*enableRegionSimplification=*/true)));
}));
}
pm.addPass(createSymbolDCEPass());
pm.addPass(createLiftInlinedMeshesPass());
Expand All @@ -45,12 +63,9 @@ void addImportPipeline(OpPassManager& pm, StringRef dumpDirectory,
// constraints. This ensures we can detect sharding conflicts between group
// members which have pre-propagation shardings due to sharding constraints.
pm.addPass(createShardingGroupImportPass());

GreedyRewriteConfig config;
config.useTopDownTraversal = true;
config.enableRegionSimplification = GreedySimplifyRegionLevel::Disabled;
pm.addPass(createCanonicalizerPass(
/*config=*/config, /*disabledPatterns=*/{},
getCanonicalizerConfig(/*enableRegionSimplification=*/false),
/*disabledPatterns=*/{},
/*enabledPatterns=*/{"DedupShardingGroupPattern"}));
pm.addPass(mlir::sdy::createSaveModuleOpPass(dumpDirectory,
"sdy_module_after_sdy_import"));
Expand Down
10 changes: 8 additions & 2 deletions shardy/dialect/sdy/transforms/propagation/basic_propagation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,14 @@ LogicalResult BasicPropagationPassImpl::propagate(
GreedyRewriteConfig config;
config.useTopDownTraversal = true;
config.enableRegionSimplification = mlir::GreedySimplifyRegionLevel::Disabled;
if (failed(applyPatternsAndFoldGreedily(moduleOp, std::move(patterns),
config))) {
config.fold = false;
config.cseConstants = false;
if (failed(applyPatternsGreedily(moduleOp, std::move(patterns), config))) {
// We should always converge in 2 iterations, if we don't, something is
// wrong.
moduleOp->emitError("Failed to converge after ")
<< config.maxIterations
<< " iterations. please contact the Shardy team.";
return failure();
}

Expand Down