-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GPU] Add Implicit GEMM pipeline for LLVMGPU. (#16788)
Co-authored-by: MaheshRavishankar <mahesh@nod-labs.com> Co-authored-by: MaheshRavishankar <1663364+MaheshRavishankar@users.noreply.github.com>
- Loading branch information
1 parent
88787cb
commit d306196
Showing
16 changed files
with
918 additions
and
0 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
81 changes: 81 additions & 0 deletions
81
compiler/src/iree/compiler/Codegen/LLVMGPU/LLVMGPUIm2ColPass.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,81 @@ | ||
// 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/LLVMGPU/PassDetail.h" | ||
#include "iree/compiler/Codegen/LLVMGPU/Passes.h" | ||
#include "iree/compiler/Codegen/Transforms/Transforms.h" | ||
#include "mlir/Dialect/Linalg/IR/Linalg.h" | ||
#include "mlir/Dialect/Linalg/Transforms/Transforms.h" | ||
#include "mlir/Dialect/Linalg/Utils/Utils.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
|
||
namespace mlir::iree_compiler { | ||
|
||
namespace { | ||
|
||
class LLVMGPUIm2ColPass : public LLVMGPUIm2ColBase<LLVMGPUIm2ColPass> { | ||
|
||
public: | ||
void getDependentDialects(DialectRegistry ®istry) const override {} | ||
|
||
void runOnOperation() override; | ||
}; | ||
|
||
} // namespace | ||
|
||
template <typename OpTy> | ||
FailureOr<std::pair<Operation *, Operation *>> | ||
rewriteInIm2Col(RewriterBase &rewriter, OpTy op, | ||
SmallVector<NamedAttribute> &additionalAttributes) { | ||
additionalAttributes = linalg::getPrunedAttributeList(op); | ||
return rewriteInIm2Col(rewriter, op); | ||
} | ||
|
||
void LLVMGPUIm2ColPass::runOnOperation() { | ||
auto operation = getOperation(); | ||
|
||
IRRewriter rewriter(&getContext()); | ||
operation->walk([&](Operation *op) { | ||
IRRewriter::InsertionGuard g(rewriter); | ||
rewriter.setInsertionPointAfter(op); | ||
SmallVector<NamedAttribute> additionalAttributes; | ||
auto maybeTransformed = | ||
TypeSwitch<Operation *, FailureOr<std::pair<Operation *, Operation *>>>( | ||
op) | ||
.Case<linalg::Conv2DNhwcHwcfOp, linalg::Conv2DNhwcFhwcOp, | ||
linalg::DepthwiseConv2DNhwcHwcOp, linalg::Conv2DNchwFchwOp>( | ||
[&](auto op) { | ||
return rewriteInIm2Col(rewriter, op, additionalAttributes); | ||
}) | ||
.Default([&](Operation *op) { | ||
return rewriter.notifyMatchFailure(op, "not supported"); | ||
}); | ||
if (failed(maybeTransformed)) { | ||
return; | ||
} | ||
auto matmulOp = cast<tensor::ExpandShapeOp>(maybeTransformed->second) | ||
.getSrc() | ||
.getDefiningOp(); | ||
for (auto attr : additionalAttributes) { | ||
matmulOp->setAttr(attr.getName(), attr.getValue()); | ||
} | ||
}); | ||
|
||
// Bubble collapse | ||
RewritePatternSet patterns(&getContext()); | ||
linalg::populateFoldReshapeOpsByCollapsingPatterns( | ||
patterns, [](OpOperand *) { return true; }); | ||
populateReshapeToInterfaceTensorPatterns(patterns); | ||
linalg::FillOp::getCanonicalizationPatterns(patterns, &getContext()); | ||
(void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); | ||
} | ||
|
||
std::unique_ptr<InterfacePass<mlir::FunctionOpInterface>> | ||
createLLVMGPUIm2ColPass() { | ||
return std::make_unique<LLVMGPUIm2ColPass>(); | ||
} | ||
|
||
} // namespace mlir::iree_compiler |
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
Oops, something went wrong.