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

[ObjectFifo] Create a new pass to split L2 buffers #659

Merged
merged 22 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b72e687
[ObjectFifo] Create a new pass to split L2 buffers
Abhishek-Varma Aug 9, 2024
e5d70cf
[ObjectFifo] Add split-buffers pass to objectfifo pipeline
Abhishek-Varma Aug 9, 2024
2436d94
Review comments
Abhishek-Varma Aug 9, 2024
ed248cc
Add more lit tests
Abhishek-Varma Aug 9, 2024
11f8d76
Review comment address including offset/size/stride of linearized buffer
Abhishek-Varma Aug 12, 2024
93f5f03
Rectify L2's offset/size for L3->L2 and L2->L1
Abhishek-Varma Aug 14, 2024
6df1080
Add logic to find the offset/bias for the L3->L2 split
Abhishek-Varma Aug 26, 2024
1693a6d
L3->L2 split with new offsets
Abhishek-Varma Aug 27, 2024
9f1c25c
Update with comment as well as add two more amdaie.core ops
Abhishek-Varma Aug 27, 2024
5cf69bd
Review comment
Abhishek-Varma Aug 27, 2024
d285fbc
Review comments 2.0 + add another lit test + Handle edge cases via li…
Abhishek-Varma Aug 28, 2024
500e0a7
Address other corner cases + review comments
Abhishek-Varma Aug 29, 2024
a5ce10c
Create a separate splitting utility
Abhishek-Varma Aug 29, 2024
94ef347
Rename + refactor + lit test fix
Abhishek-Varma Aug 29, 2024
5d91974
Offline review comments
Abhishek-Varma Aug 29, 2024
75083a8
Removed unused DenseMap
Abhishek-Varma Aug 29, 2024
9bbcac1
nit TODO comment suggestion change
Abhishek-Varma Aug 29, 2024
8a11c00
bunch -> vector comment change
Abhishek-Varma Aug 29, 2024
20299cf
Review comments 2nd Sept
Abhishek-Varma Sep 2, 2024
1b605fd
Trivial review comments
Abhishek-Varma Sep 2, 2024
5b33560
Final review comment
Abhishek-Varma Sep 2, 2024
e65f66e
Review comment nit + tiny refactor
Abhishek-Varma Sep 2, 2024
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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

#ifndef IREE_AMD_AIE_TRANSFORMS_AMDAIELOGICALOBJFIFOSPLITTINGUTILS_H_
#define IREE_AMD_AIE_TRANSFORMS_AMDAIELOGICALOBJFIFOSPLITTINGUTILS_H_

#include "iree-amd-aie/IR/AMDAIEOps.h"

namespace mlir::iree_compiler::AMDAIE {

/// Utility to split logicalobjectfifos given a struct
/// `SplittingLogicalObjectFifoData` which contains all the required data to
/// perform the splitting.
LogicalResult splitLogicalObjectFifos(
IRRewriter &rewriter, SmallVector<AMDAIE::DmaCpyNdOp> &l2ToL1DmaOps,
MLIRContext *context);

} // namespace mlir::iree_compiler::AMDAIE

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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-amd-aie/IR/AMDAIEOps.h"
#include "iree-amd-aie/Transforms/AMDAIELogicalObjFifoSplittingUtils.h"
#include "iree-amd-aie/Transforms/Passes.h"
// #include "llvm/Support/Debug.h"
#include "mlir/IR/Iterators.h"
#include "mlir/Pass/Pass.h"

#define DEBUG_TYPE "iree-amdaie-split-logical-objectfifos-for-connection-reuse"

namespace mlir::iree_compiler::AMDAIE {

namespace {

/// Utility to help fetch those input DmaCpyNd Ops which needs to be split.
static SmallVector<AMDAIE::DmaCpyNdOp> fetchDmaCpyNdOpsToSplit(
ModuleOp moduleOp) {
SmallVector<AMDAIE::DmaCpyNdOp> l2ToL1DmaOps;
// We are currently walking through CoreOps gathering 3rd Input DmaOp (if
// applicable) from them.
// TODO(avarma): We will generalize this later.
moduleOp.walk([&](AMDAIE::CoreOp coreOp) {
SmallVector<Value> inputDmas = coreOp.getInputDmas();
if (inputDmas.size() != 3) return WalkResult::skip();
auto dmaCpyNdOp = inputDmas[2].getDefiningOp<AMDAIE::DmaCpyNdOp>();
assert(dmaCpyNdOp && "expected an amdaie.dma_cpy_nd op");
l2ToL1DmaOps.push_back(dmaCpyNdOp);
return WalkResult::advance();
});
return l2ToL1DmaOps;
}

class AMDAIESplitLogicalObjFifosForConnectionReusePass
: public impl::AMDAIESplitLogicalObjFifosForConnectionReuseBase<
AMDAIESplitLogicalObjFifosForConnectionReusePass> {
public:
using AMDAIESplitLogicalObjFifosForConnectionReuseBase::
AMDAIESplitLogicalObjFifosForConnectionReuseBase;

void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<AMDAIEDialect>();
}
void runOnOperation() override;
};

void AMDAIESplitLogicalObjFifosForConnectionReusePass::runOnOperation() {
ModuleOp moduleOp = getOperation();
MLIRContext *context = &getContext();
IRRewriter rewriter(context);

SmallVector<AMDAIE::DmaCpyNdOp> l2ToL1DmaOps =
fetchDmaCpyNdOpsToSplit(moduleOp);

if (failed(splitLogicalObjectFifos(rewriter, l2ToL1DmaOps, context))) {
LLVM_DEBUG(llvm::dbgs()
<< "Failed to perform splitting of logicalobjectfifos");
return signalPassFailure();
}
}

} // namespace

std::unique_ptr<Pass> createAMDAIESplitLogicalObjFifosForConnectionReusePass() {
return std::make_unique<AMDAIESplitLogicalObjFifosForConnectionReusePass>();
}

} // namespace mlir::iree_compiler::AMDAIE
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ iree_cc_library(
"AMDAIEInsertLoopsForVectorization.cpp"
"AMDAIELinkExecutables.cpp"
"AMDAIELocalizeLogicalObjectFifo.cpp"
"AMDAIELogicalObjFifoSplittingUtils.cpp"
"AMDAIELowerExecutableTarget.cpp"
"AMDAIELowerFuncArgs.cpp"
"AMDAIELowerToAIE.cpp"
Expand All @@ -88,6 +89,7 @@ iree_cc_library(
"AMDAIEPeelForLoop.cpp"
"AMDAIEPropagateDataLayout.cpp"
"AMDAIESinkIntoCore.cpp"
"AMDAIESplitLogicalObjFifosForConnectionReuse.cpp"
"AMDAIETile.cpp"
"AMDAIETileAndFuse.cpp"
"AMDAIEUtils.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace mlir::iree_compiler::AMDAIE {
#define GEN_PASS_DEF_AMDAIEPEELFORLOOP
#define GEN_PASS_DEF_AMDAIEPROPAGATEDATALAYOUT
#define GEN_PASS_DEF_AMDAIESINKINTOCORE
#define GEN_PASS_DEF_AMDAIESPLITLOGICALOBJFIFOSFORCONNECTIONREUSE
#define GEN_PASS_DEF_AMDAIETILE
#define GEN_PASS_DEF_AMDAIETILEANDFUSE
#define GEN_PASS_DEF_AMDAIEVECTORIZATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ void addAMDAIEObjectFifoLoweringPasses(OpPassManager &passManager) {
passManager.addPass(createAMDAIEDistributeCoresAndObjectFifosPass());
passManager.addPass(createCSEPass());
passManager.addPass(createCanonicalizerPass());
passManager.addPass(createAMDAIESplitLogicalObjFifosForConnectionReusePass());

passManager.addPass(createAMDAIEDmaToCircularDmaPass());
passManager.addNestedPass<func::FuncOp>(createAMDAIECreateAIEWorkgroupPass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ std::unique_ptr<Pass> createAMDAIEPeelForLoopPass(
/// Create a pass to sink all dependencies into `amdaie.core` operations.
std::unique_ptr<Pass> createAMDAIESinkIntoCorePass();

/// Create a pass to split logicalobjectfifos for connection reuse.
std::unique_ptr<Pass> createAMDAIESplitLogicalObjFifosForConnectionReusePass();

/// Create pass to tile TilingInterface operations.
std::unique_ptr<Pass> createAMDAIETilePass(AMDAIETileOptions options = {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ def AMDAIESinkIntoCore :
let constructor = "mlir::iree_compiler::AMDAIE::createAMDAIESinkIntoCorePass()";
}

def AMDAIESplitLogicalObjFifosForConnectionReuse :
Pass<"iree-amdaie-split-logical-objectfifos-for-connection-reuse", "ModuleOp"> {
let summary = "Pass to split L2 buffers to share inputs of Matmul and Elementwise operations.";
let constructor = "mlir::iree_compiler::AMDAIE::createAMDAIESplitLogicalObjFifosForConnectionReusePass()";
}

def AMDAIETile :
InterfacePass<"iree-amdaie-tile", "mlir::FunctionOpInterface"> {
let summary = "Pass to tile TilingInterface operations.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ iree_lit_test_suite(
"peel_for_loop.mlir"
"propagate_data_layout.mlir"
"sink_into_core.mlir"
"split_logicalobjfifos_for_connection_reuse.mlir"
"tile_and_fuse_using_scf_for.mlir"
"tile_and_fuse_using_scf_forall.mlir"
"tile_copy_using_scf_for.mlir"
Expand Down
Loading
Loading