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

[LLVMGPU] Extract subgroup size from export op to use for vector distribution #14826

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -574,11 +574,13 @@ static Value simpleWarpShuffleFunction(Location loc, OpBuilder &builder,

static void populatePropagateVectorDistribution(Operation *target,
RewritePatternSet &patterns,
PatternBenefit benefit) {
auto groupReductionFn = [](Location loc, OpBuilder &builder, Value input,
vector::CombiningKind kind, uint32_t size) {
PatternBenefit benefit,
unsigned subgroupSize) {
auto groupReductionFn = [subgroupSize](
Location loc, OpBuilder &builder, Value input,
vector::CombiningKind kind, uint32_t size) {
return mlir::iree_compiler::emitGPUGroupReduction(loc, builder, input, kind,
size, 32);
size, subgroupSize);
};
assert(target->hasTrait<OpTrait::IsIsolatedFromAbove>());
vector::populatePropagateWarpVectorDistributionPatterns(
Expand All @@ -604,14 +606,30 @@ static void populateWarpExecuteOnLane0ToScf(

DiagnosedSilenceableFailure
transform_dialect::VectorWarpDistributionOp::applyToOne(
transform::TransformRewriter &rewriter, Operation *target,
transform::TransformRewriter &rewriter, func::FuncOp target,
transform::ApplyToEachResultList &results,
transform::TransformState &state) {
if (!target->hasTrait<OpTrait::IsIsolatedFromAbove>()) {
target->emitOpError(
"applies only to isolated-from-above targets because it "
"needs to apply "
"patterns greedily");
if (!isa<HAL::ExecutableOp, HAL::ExecutableVariantOp>(state.getTopLevel())) {
qedawkins marked this conversation as resolved.
Show resolved Hide resolved
state.getTopLevel()->emitOpError(
"requires HAL::ExecutableOp or HAL::ExecutableVariantOp "
"toplevel to extract subgroup size information");
return emitDefaultDefiniteFailure(target);
}

IREE::HAL::ExecutableExportOp exportOp;
state.getTopLevel()->walk([&](IREE::HAL::ExecutableExportOp op) {
if (op.getSymName() == target.getName())
exportOp = op;
});
if (!exportOp) {
state.getTopLevel()->emitOpError("no IREE::HAL::ExecutableExportOp found");
return emitDefaultDefiniteFailure(target);
}

std::optional<llvm::APInt> subgroupSize = exportOp.getSubgroupSize();
if (!subgroupSize) {
state.getTopLevel()->emitOpError(
"could not extract subgroup size from IREE::HAL::ExecutableExportOp");
return emitDefaultDefiniteFailure(target);
}

Expand Down Expand Up @@ -645,7 +663,8 @@ transform_dialect::VectorWarpDistributionOp::applyToOne(
populateVectorTransferWriteDistribution(target, patterns,
/*benefit=*/2);
populatePropagateVectorDistribution(target, patterns,
/*benefit=*/1);
/*benefit=*/1,
subgroupSize->getSExtValue());
if (failed(
applyPatternsAndFoldGreedily(target, std::move(patterns), config))) {
return mlir::emitDefiniteFailure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def VectorWarpDistributionOp : Op<Transform_Dialect, "iree.vector.warp_distribut
let extraClassDeclaration = [{
::mlir::DiagnosedSilenceableFailure applyToOne(
::mlir::transform::TransformRewriter &rewriter,
::mlir::Operation *target,
::mlir::func::FuncOp target,
::mlir::transform::ApplyToEachResultList &results,
::mlir::transform::TransformState &state);
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

hal.executable private @reduce_dispatch_0 {
hal.executable.variant public @cuda_nvptx_fb, target = #executable_target_cuda_nvptx_fb {
hal.executable.export public @reduce_dispatch_0 ordinal(0) layout(#pipeline_layout) attributes { workgroup_size = [64: index, 1: index, 1: index] }
hal.executable.export public @reduce_dispatch_0 ordinal(0) layout(#pipeline_layout) attributes { workgroup_size = [64: index, 1: index, 1: index], subgroup_size = 32 : index }
builtin.module {
func.func @reduce_dispatch_0() {
%c0 = arith.constant 0 : index
Expand Down
Loading