forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LLVMGPU][NFC] Create LLVMGPU pass for IGEMM (iree-org#18871)
This PR refactors the ConvolutionToIGEMM pass to a shared transform function, and creates a new pass for LLVMGPU. This keeps the lowering config details in LLVMGPU separate from the common pass, and removes the need for passing a control function or config function in the pass constructor. This is also a precursor to adding some more complex logic in the control function for LLVMGPU, which will be added in a later PR. --------- Signed-off-by: Max Dawkins <max.dawkins@gmail.com>
- Loading branch information
Showing
15 changed files
with
230 additions
and
136 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
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
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
66 changes: 66 additions & 0 deletions
66
compiler/src/iree/compiler/Codegen/LLVMGPU/LLVMGPUConvolutionToIGEMM.cpp
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,66 @@ | ||
// Copyright 2024 The IREE Authors | ||
// | ||
// Licensed 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 "iree/compiler/Codegen/Common/Passes.h" | ||
#include "iree/compiler/Codegen/Common/Transforms.h" | ||
#include "iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenDialect.h" | ||
#include "iree/compiler/Codegen/LLVMGPU/Passes.h" | ||
#include "iree/compiler/Codegen/Utils/GPUUtils.h" | ||
#include "mlir/Dialect/Linalg/IR/Linalg.h" | ||
|
||
#define DEBUG_TYPE "iree-llvmgpu-convolution-to-igemm" | ||
|
||
namespace mlir::iree_compiler { | ||
|
||
#define GEN_PASS_DEF_LLVMGPUCONVOLUTIONTOIGEMMPASS | ||
#include "iree/compiler/Codegen/LLVMGPU/Passes.h.inc" | ||
|
||
namespace { | ||
|
||
/// Function for setting lowering configurations on contractions resulting from | ||
/// the IGEMM transformation. This currently uses the TileAndFuse pipeline, and | ||
/// tries to target MMA intrinsics. | ||
static LogicalResult llvmgpuConfigFn(linalg::GenericOp genericOp, | ||
IREE::LinalgExt::Im2colOp im2colOp) { | ||
auto funcOp = genericOp->getParentOfType<FunctionOpInterface>(); | ||
if (!funcOp) { | ||
return genericOp.emitError("cannot find parent funcOp"); | ||
} | ||
IREE::GPU::TargetAttr target = getGPUTargetAttr(funcOp); | ||
if (!target) { | ||
return funcOp.emitError("missing GPU target in parent funcOp"); | ||
} | ||
if (failed(IREE::GPU::setMatmulLoweringConfig(target, funcOp, genericOp))) { | ||
return IREE::GPU::setTileAndFuseLoweringConfig(target, funcOp, genericOp); | ||
} | ||
return success(); | ||
} | ||
|
||
static bool llvmgpuControlFn(Operation *op) { | ||
// Do not convert anything that already has a lowering configuration. | ||
if (getLoweringConfig(op)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
struct LLVMGPUConvolutionToIGEMMPass final | ||
: impl::LLVMGPUConvolutionToIGEMMPassBase<LLVMGPUConvolutionToIGEMMPass> { | ||
using impl::LLVMGPUConvolutionToIGEMMPassBase< | ||
LLVMGPUConvolutionToIGEMMPass>::LLVMGPUConvolutionToIGEMMPassBase; | ||
|
||
void runOnOperation() override; | ||
}; | ||
|
||
void LLVMGPUConvolutionToIGEMMPass::runOnOperation() { | ||
if (failed(convertToIGEMMAndSetConfig(getOperation(), llvmgpuConfigFn, | ||
llvmgpuControlFn))) { | ||
return signalPassFailure(); | ||
} | ||
} | ||
|
||
} // namespace | ||
} // namespace mlir::iree_compiler |
Oops, something went wrong.