CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
124 lines
4.2 KiB
C++
124 lines
4.2 KiB
C++
//===- TestReshardingPartition.cpp - Test resharding partition ------------===//
|
|
//
|
|
// 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/Func/IR/FuncOps.h"
|
|
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
|
|
#include "mlir/Dialect/Shard/IR/ShardOps.h"
|
|
#include "mlir/Dialect/Shard/Transforms/Partition.h"
|
|
#include "mlir/IR/BuiltinDialect.h"
|
|
#include "mlir/IR/BuiltinOps.h"
|
|
#include "mlir/IR/BuiltinTypeInterfaces.h"
|
|
#include "mlir/IR/Diagnostics.h"
|
|
#include "mlir/IR/ImplicitLocOpBuilder.h"
|
|
#include "mlir/IR/PatternMatch.h"
|
|
#include "mlir/IR/SymbolTable.h"
|
|
#include "mlir/IR/Value.h"
|
|
#include "mlir/Pass/Pass.h"
|
|
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::shard;
|
|
|
|
namespace {
|
|
|
|
struct TestReshardingRewritePattern : OpRewritePattern<ShardOp> {
|
|
using OpRewritePattern<ShardOp>::OpRewritePattern;
|
|
|
|
LogicalResult matchAndRewrite(ShardOp op,
|
|
PatternRewriter &rewriter) const override {
|
|
if (op.getAnnotateForUsers()) {
|
|
return failure();
|
|
}
|
|
|
|
SymbolTableCollection symbolTable;
|
|
shard::GridOp grid = symbolTable.lookupNearestSymbolFrom<shard::GridOp>(
|
|
op, cast<ShardingOp>(op.getSharding().getDefiningOp()).getGridAttr());
|
|
|
|
bool foundUser = false;
|
|
for (auto *user : op->getUsers()) {
|
|
if (auto targetShardOp = llvm::dyn_cast<ShardOp>(user)) {
|
|
if (targetShardOp.getAnnotateForUsers() &&
|
|
grid == symbolTable.lookupNearestSymbolFrom<shard::GridOp>(
|
|
targetShardOp,
|
|
cast<ShardingOp>(
|
|
targetShardOp.getSharding().getDefiningOp())
|
|
.getGridAttr())) {
|
|
foundUser = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!foundUser) {
|
|
return failure();
|
|
}
|
|
|
|
for (auto *user : op->getUsers()) {
|
|
auto targetShardOp = llvm::dyn_cast<ShardOp>(user);
|
|
if (!targetShardOp || !targetShardOp.getAnnotateForUsers() ||
|
|
symbolTable.lookupNearestSymbolFrom<shard::GridOp>(
|
|
targetShardOp,
|
|
cast<ShardingOp>(targetShardOp.getSharding().getDefiningOp())
|
|
.getGridAttr()) != grid) {
|
|
continue;
|
|
}
|
|
|
|
ImplicitLocOpBuilder builder(op->getLoc(), rewriter);
|
|
ShapedType sourceShardShape =
|
|
shardShapedType(op.getResult().getType(), grid, op.getSharding());
|
|
TypedValue<ShapedType> sourceShard = cast<TypedValue<ShapedType>>(
|
|
UnrealizedConversionCastOp::create(builder, sourceShardShape,
|
|
op.getSrc())
|
|
->getResult(0));
|
|
TypedValue<ShapedType> targetShard =
|
|
reshard(builder, grid, op, targetShardOp, sourceShard);
|
|
Value newTargetUnsharded =
|
|
UnrealizedConversionCastOp::create(
|
|
builder, targetShardOp.getResult().getType(), targetShard)
|
|
->getResult(0);
|
|
rewriter.replaceAllUsesWith(targetShardOp.getResult(),
|
|
newTargetUnsharded);
|
|
}
|
|
|
|
return success();
|
|
}
|
|
};
|
|
|
|
struct TestReshardingPass
|
|
: public PassWrapper<TestReshardingPass, OperationPass<ModuleOp>> {
|
|
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestReshardingPass)
|
|
|
|
void runOnOperation() override {
|
|
RewritePatternSet patterns(&getContext());
|
|
patterns.insert<TestReshardingRewritePattern>(&getContext());
|
|
if (failed(applyPatternsGreedily(getOperation().getOperation(),
|
|
std::move(patterns)))) {
|
|
return signalPassFailure();
|
|
}
|
|
}
|
|
void getDependentDialects(DialectRegistry ®istry) const override {
|
|
reshardingRegisterDependentDialects(registry);
|
|
registry.insert<BuiltinDialect>();
|
|
}
|
|
StringRef getArgument() const final {
|
|
return "test-grid-resharding-partition";
|
|
}
|
|
StringRef getDescription() const final {
|
|
return "Test Shard dialect resharding partition.";
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
namespace mlir {
|
|
namespace test {
|
|
void registerTestReshardingPartitionPass() {
|
|
PassRegistration<TestReshardingPass>();
|
|
}
|
|
} // namespace test
|
|
} // namespace mlir
|