-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
amdaie.flow
for packet flow lowering
- Loading branch information
Showing
26 changed files
with
622 additions
and
166 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
2 changes: 1 addition & 1 deletion
2
compiler/plugins/target/AMD-AIE/iree-amd-aie/Test/samples/matmul_pack_peel_objectfifo.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
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
67 changes: 67 additions & 0 deletions
67
compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/AMDAIEAssignPacketIds.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,67 @@ | ||
// 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/AMDAIEUtils.h" | ||
#include "iree-amd-aie/Transforms/Passes.h" | ||
#include "iree-amd-aie/Transforms/Transforms.h" | ||
|
||
#define DEBUG_TYPE "iree-amdaie-assign-packet-ids" | ||
|
||
namespace mlir::iree_compiler::AMDAIE { | ||
|
||
namespace { | ||
|
||
class AMDAIEAssignPacketIdsPass | ||
: public impl::AMDAIEAssignPacketIdsBase<AMDAIEAssignPacketIdsPass> { | ||
public: | ||
void getDependentDialects(DialectRegistry ®istry) const override { | ||
registry.insert<AMDAIEDialect>(); | ||
} | ||
void runOnOperation() override; | ||
}; | ||
|
||
void AMDAIEAssignPacketIdsPass::runOnOperation() { | ||
Operation *parentOp = getOperation(); | ||
IRRewriter rewriter(parentOp->getContext()); | ||
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 assign packet IDs " | ||
"within the resource constraints"; | ||
return signalPassFailure(); | ||
} | ||
AMDAIE::AMDAIEDeviceModel deviceModel = | ||
AMDAIE::getDeviceModel(maybeDevice.value()); | ||
int pktFlowIndex{0}; | ||
WalkResult res = parentOp->walk([&](AMDAIE::FlowOp flowOp) { | ||
if (pktFlowIndex > deviceModel.getPacketIdMaxIdx()) { | ||
flowOp.emitOpError() << "ran out of packet IDs to assign"; | ||
return WalkResult::interrupt(); | ||
} | ||
rewriter.setInsertionPoint(flowOp); | ||
auto ui8ty = | ||
IntegerType::get(rewriter.getContext(), 8, IntegerType::Unsigned); | ||
IntegerAttr pktIdAttr = flowOp.getIsPacketFlow() | ||
? IntegerAttr::get(ui8ty, pktFlowIndex++) | ||
: nullptr; | ||
rewriter.replaceOpWithNewOp<AMDAIE::FlowOp>( | ||
flowOp, flowOp.getSources(), flowOp.getTargets(), | ||
flowOp.getIsPacketFlow(), pktIdAttr); | ||
return WalkResult::advance(); | ||
}); | ||
if (res.wasInterrupted()) return signalPassFailure(); | ||
} | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<Pass> createAMDAIEAssignPacketIdsPass() { | ||
return std::make_unique<AMDAIEAssignPacketIdsPass>(); | ||
} | ||
|
||
} // namespace mlir::iree_compiler::AMDAIE |
57 changes: 57 additions & 0 deletions
57
compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/AMDAIEConnectionToFlow.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,57 @@ | ||
// 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/Passes.h" | ||
#include "iree-amd-aie/Transforms/Transforms.h" | ||
|
||
#define DEBUG_TYPE "iree-amdaie-connection-to-flow" | ||
|
||
namespace mlir::iree_compiler::AMDAIE { | ||
|
||
namespace { | ||
|
||
class AMDAIEConnectionToFlowPass | ||
: public impl::AMDAIEConnectionToFlowBase<AMDAIEConnectionToFlowPass> { | ||
public: | ||
void getDependentDialects(DialectRegistry ®istry) const override { | ||
registry.insert<AMDAIEDialect>(); | ||
} | ||
void runOnOperation() override; | ||
}; | ||
|
||
void AMDAIEConnectionToFlowPass::runOnOperation() { | ||
Operation *parentOp = getOperation(); | ||
IRRewriter rewriter(parentOp->getContext()); | ||
// TODO(jornt): currently, don't delete connections as they are still | ||
// needed for lowering to AIE dialect dma_bds. This will be changed in the | ||
// future. | ||
WalkResult res = parentOp->walk([&](AMDAIE::ConnectionOp connectionOp) { | ||
rewriter.setInsertionPoint(connectionOp); | ||
std::optional<AMDAIE::ConnectionType> connectionType = | ||
connectionOp.getConnectionType(); | ||
bool isPacketFlow = connectionType && connectionType.value() == | ||
AMDAIE::ConnectionType::Packet; | ||
auto flowOp = rewriter.create<AMDAIE::FlowOp>( | ||
rewriter.getUnknownLoc(), connectionOp.getSourceChannels(), | ||
connectionOp.getTargetChannels(), isPacketFlow, nullptr); | ||
rewriter.replaceOpWithNewOp<AMDAIE::ConnectionOp>( | ||
connectionOp, connectionOp.getTarget(), | ||
connectionOp.getTargetChannels(), connectionOp.getSource(), | ||
connectionOp.getSourceChannels(), connectionOp.getConnectionTypeAttr(), | ||
flowOp); | ||
return WalkResult::advance(); | ||
}); | ||
if (res.wasInterrupted()) return signalPassFailure(); | ||
} | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<Pass> createAMDAIEConnectionToFlowPass() { | ||
return std::make_unique<AMDAIEConnectionToFlowPass>(); | ||
} | ||
|
||
} // namespace mlir::iree_compiler::AMDAIE |
Oops, something went wrong.