forked from Xilinx/mlir-aie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
533 additions
and
9 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
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
87 changes: 87 additions & 0 deletions
87
lib/Dialect/AIEX/Transforms/AIESubstituteShimDMAAllocations.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,87 @@ | ||
//===- AIESubstituteShimDMAAllocations.cpp -----------------------*- C++ | ||
//-*-===// | ||
// | ||
// This file is 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 | ||
// | ||
// (c) Copyright 2024 Advanced Micro Devices, Inc. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <algorithm> | ||
#include <iterator> | ||
|
||
#include "aie/Dialect/AIE/IR/AIEDialect.h" | ||
#include "aie/Dialect/AIEX/IR/AIEXDialect.h" | ||
#include "aie/Dialect/AIEX/Transforms/AIEXPasses.h" | ||
|
||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Transforms/DialectConversion.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
|
||
using namespace mlir; | ||
using namespace xilinx; | ||
using namespace xilinx::AIEX; | ||
|
||
struct DMAConfigureTaskForOpPattern : RewritePattern { | ||
|
||
DMAConfigureTaskForOpPattern(MLIRContext *ctx) | ||
: RewritePattern(DMAConfigureTaskForOp::getOperationName(), | ||
PatternBenefit(1), ctx) {} | ||
|
||
LogicalResult matchAndRewrite(Operation *op_any, | ||
PatternRewriter &rewriter) const override { | ||
DMAConfigureTaskForOp op = llvm::dyn_cast<DMAConfigureTaskForOp>(op_any); | ||
if (!op) { | ||
return failure(); | ||
} | ||
AIE::DeviceOp device = op->getParentOfType<AIE::DeviceOp>(); | ||
|
||
AIE::ShimDMAAllocationOp alloc_op = | ||
AIE::ShimDMAAllocationOp::getForSymbol(device, op.getAlloc()); | ||
if (!alloc_op) { | ||
return op.emitOpError("no shim DMA allocation found for symbol"); | ||
} | ||
|
||
const int col = alloc_op.getCol(); | ||
AIE::TileOp tile = AIE::TileOp::getOrCreate(rewriter, device, col, 0); | ||
DMAConfigureTaskOp new_op = rewriter.create<DMAConfigureTaskOp>( | ||
op.getLoc(), rewriter.getIndexType(), tile.getResult(), | ||
alloc_op.getChannelDir(), (int32_t)alloc_op.getChannelIndex(), | ||
op.getIssueToken(), op.getRepeatCount()); | ||
rewriter.replaceAllUsesWith(op.getResult(), new_op.getResult()); | ||
rewriter.inlineRegionBefore(op.getBody(), new_op.getBody(), | ||
new_op.getBody().begin()); | ||
rewriter.eraseOp(op); | ||
return success(); | ||
} | ||
}; | ||
|
||
struct AIESubstituteShimDMAAllocationsPass | ||
: AIESubstituteShimDMAAllocationsBase<AIESubstituteShimDMAAllocationsPass> { | ||
|
||
void runOnOperation() override { | ||
AIE::DeviceOp device = getOperation(); | ||
|
||
// Convert DMAConfigureTaskForOps that reference shim DMA allocations | ||
// to regular DMAConfigureTaskOps | ||
ConversionTarget target(getContext()); | ||
target.addLegalDialect<AIEXDialect>(); | ||
target.addIllegalOp<DMAConfigureTaskForOp>(); | ||
RewritePatternSet patterns(&getContext()); | ||
patterns.insert<DMAConfigureTaskForOpPattern>(&getContext()); | ||
|
||
GreedyRewriteConfig rewriter_config = GreedyRewriteConfig(); | ||
if (failed(applyPatternsAndFoldGreedily(device, std::move(patterns), | ||
rewriter_config))) { | ||
signalPassFailure(); | ||
} | ||
} | ||
}; | ||
|
||
std::unique_ptr<OperationPass<AIE::DeviceOp>> | ||
AIEX::createAIESubstituteShimDMAAllocationsPass() { | ||
return std::make_unique<AIESubstituteShimDMAAllocationsPass>(); | ||
} |
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
33 changes: 33 additions & 0 deletions
33
test/bd-chains-and-dma-tasks/assign-runtime-sequence-bd-ids/good-5.mlir
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,33 @@ | ||
// | ||
// This file is 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 | ||
// | ||
// (c) Copyright 2024 AMD Inc. | ||
|
||
// REQUIRES: ryzen_ai | ||
// | ||
// RUN: aie-opt --aie-substitute-shim-dma-allocations --aie-assign-runtime-sequence-bd-ids %s | FileCheck %s | ||
|
||
// This test ensures that all available 16 buffer descriptors are used. | ||
|
||
module { | ||
aie.device(npu1_4col) { | ||
%tile_0_0 = aie.tile(0, 0) | ||
%tile_0_2 = aie.tile(0, 2) | ||
|
||
aie.shim_dma_allocation @alloc0 (MM2S, 0, 0) | ||
|
||
aiex.runtime_sequence(%arg0: memref<8xi16>) { | ||
// Allocate all available BD IDs | ||
%t1 = aiex.dma_configure_task_for @alloc0 { | ||
// CHECK: aie.dma_bd(%arg0 : memref<8xi16>, 0, 8) {bd_id = 0 : i32} | ||
aie.dma_bd(%arg0 : memref<8xi16>, 0, 8) | ||
aie.end | ||
} | ||
aiex.dma_start_task(%t1) | ||
aiex.dma_await_task(%t1) | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.