-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pass that iteratively calls the `DmaLoopSubsumption` and `CombineStridedOps` pattern rewriters as both can enable new composition opportunities for each other.
- Loading branch information
Showing
13 changed files
with
311 additions
and
49 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
79 changes: 79 additions & 0 deletions
79
compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/AMDAIEDmaComposition.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,79 @@ | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file composes more complex strided DMA ops by iteratively: | ||
// 1. Combining ops in the same block. | ||
// 2. Subsuming loop iterations into the strided access pattern. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "iree-amd-aie/Transforms/AMDAIEDmaUtils.h" | ||
#include "iree-amd-aie/Transforms/AMDAIEUtils.h" | ||
#include "iree-amd-aie/Transforms/Passes.h" | ||
#include "iree-amd-aie/Transforms/Transforms.h" | ||
#include "iree-amd-aie/aie_runtime/iree_aie_runtime.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
|
||
#define DEBUG_TYPE "iree-amdaie-dma-composition" | ||
|
||
namespace mlir::iree_compiler::AMDAIE { | ||
|
||
namespace { | ||
|
||
class AMDAIEDmaCompositionPass | ||
: public impl::AMDAIEDmaCompositionBase<AMDAIEDmaCompositionPass> { | ||
public: | ||
AMDAIEDmaCompositionPass() = default; | ||
AMDAIEDmaCompositionPass(const AMDAIEDmaCompositionPass &pass){}; | ||
AMDAIEDmaCompositionPass(const AMDAIEDmaCompositionOptions &options) | ||
: AMDAIEDmaCompositionBase(options) {} | ||
void runOnOperation() override; | ||
}; | ||
|
||
void AMDAIEDmaCompositionPass::runOnOperation() { | ||
Operation *parentOp = getOperation(); | ||
MLIRContext *context = &getContext(); | ||
RewritePatternSet patterns(context); | ||
{ | ||
auto targetAttr = IREE::HAL::ExecutableTargetAttr::lookup(parentOp); | ||
std::optional<AMDAIEDevice> maybeDevice = getConfigAMDAIEDevice(targetAttr); | ||
if (!maybeDevice) { | ||
parentOp->emitOpError() | ||
<< "has no AMDAIEDevice in the target attribute configuration. This " | ||
"device-specific information is required to determine when loops " | ||
"can be subsumed into DMA operations, and must be attached to a " | ||
"containing ModuleOp."; | ||
return signalPassFailure(); | ||
} | ||
AMDAIE::AMDAIEDeviceModel deviceModel = | ||
AMDAIE::getDeviceModel(maybeDevice.value()); | ||
populateDmaLoopSubsumptionPattern(patterns, std::move(deviceModel), | ||
onlyZeroStrideOnOuterDim); | ||
} | ||
populateStridedOpCombinationPattern(patterns); | ||
if (failed(applyPatternsAndFoldGreedily(parentOp, std::move(patterns)))) { | ||
parentOp->emitOpError("failed to compose strided operations"); | ||
return signalPassFailure(); | ||
} | ||
|
||
IRRewriter rewriter(parentOp->getContext()); | ||
if (failed(moveNpuDmaSyncUsersAfterAncestorInSameBlock(rewriter, parentOp))) { | ||
parentOp->emitOpError() << "failed to move DMA users to correct scope " | ||
"after strided op composition"; | ||
return signalPassFailure(); | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<Pass> createAMDAIEDmaCompositionPass( | ||
AMDAIEDmaCompositionOptions options) { | ||
return std::make_unique<AMDAIEDmaCompositionPass>(options); | ||
} | ||
|
||
} // namespace mlir::iree_compiler::AMDAIE |
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
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
Oops, something went wrong.