MLIR-AIE 1.4.6.dev
AIERT.h
Go to the documentation of this file.
1//===- AIERT.h --------------------------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2024 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
8#ifndef AIE_AIERT_H
9#define AIE_AIERT_H
10
14
15#include "mlir/IR/Location.h"
16#include "llvm/Support/raw_ostream.h"
17
18#include <map>
19#include <optional>
20#include <string>
21#include <vector>
22
23namespace xilinx::AIE {
24struct AIERTControl;
25
26// RAII helper. Constructs while AIERTControl is recording an aie-codegen
27// transaction, captures the current XAie_TxnInst command count at entry, and
28// at scope end attributes every aie-codegen command produced during the scope
29// to `loc`. exportSerializedTransaction() projects the captured ranges onto the
30// serialized transaction's operations, and the AIEToConfiguration round-trip
31// reads them back out so re-emitted aiex.npu.* ops carry the source op's MLIR
32// Location instead of the device's fallback location.
34public:
35 TxnLocBracket(AIERTControl &ctl, mlir::Location loc);
37 TxnLocBracket(const TxnLocBracket &) = delete;
39
40private:
41 AIERTControl &ctl;
42 mlir::Location loc;
43 uint32_t startCmds;
44};
45
47
50
51 /// Diagnose, on `op`, a target this aie-rt lowering cannot configure.
52 /// Constructing an AIERTControl for such a target is a fatal error.
53 static mlir::LogicalResult isSupported(mlir::Operation *op,
54 const AIETargetModel &tm);
55
56 mlir::LogicalResult setIOBackend(bool aieSim, bool xaieDebug);
57 mlir::LogicalResult
58 pushToBdQueueAndEnable(mlir::Operation &op, int col, int row, int chNum,
59 const DMAChannelDir &channelDir, int bdId,
60 int repeatCount, uint32_t padValue = 0,
61 bool outOfOrder = false, bool configureChannel = true,
62 bool pushTask = true);
63 mlir::LogicalResult configureLocksAndBd(mlir::Block &block, int col, int row,
64 bool outOfOrder = false);
65 mlir::LogicalResult initLocks(DeviceOp &targetOp);
66 mlir::LogicalResult initBuffers(DeviceOp &targetOp);
67 mlir::LogicalResult configureSwitches(DeviceOp &targetOp,
68 bool skipCtrlPktOverlay = false);
69 mlir::LogicalResult addInitConfig(DeviceOp &targetOp,
70 bool skipCtrlPktOverlay = false);
71 mlir::LogicalResult addDmaActivation(DeviceOp &targetOp);
72 mlir::LogicalResult teardownSwitches(DeviceOp &targetOp,
73 bool skipCtrlPktOverlay = false);
74 mlir::LogicalResult disableCores(DeviceOp &targetOp);
75 mlir::LogicalResult resetDmaChannels(DeviceOp &targetOp);
76 mlir::LogicalResult addCoreEnable(DeviceOp &targetOp);
77 mlir::LogicalResult addAieElf(uint8_t col, uint8_t row,
78 const mlir::StringRef elfPath, bool aieSim);
79 mlir::LogicalResult addAieElfs(DeviceOp &targetOp,
80 const mlir::StringRef elfPath, bool aieSim);
81 void startTransaction();
82 void clearTransaction();
83 void dmaUpdateBdAddr(int col, int row, size_t addr, size_t bdId);
84 std::vector<uint8_t> exportSerializedTransaction();
85
86 // Source locations for the operations in the transaction binary returned by
87 // the last exportSerializedTransaction() call, in binary order. Derived
88 // there from the TxnLocBracket scopes around each per-source-op block in the
89 // AIERT methods; empty if nothing was bracketed. Entries the brackets did
90 // not cover are mlir::UnknownLoc.
91 const std::vector<mlir::Location> &getTxnOpLocs() const;
92
93 // Current XAie_TxnInst::NumCmds for the active transaction (zero if no
94 // transaction is being recorded). Used by TxnLocBracket.
95 uint32_t getCurrentTxnNumCmds() const;
96
97 // Append `loc` to the per-command locations at indices [startCmds, endCmds).
98 // Used by TxnLocBracket on scope exit.
99 void recordTxnLocRange(uint32_t startCmds, uint32_t endCmds,
100 mlir::Location loc);
101 mlir::LogicalResult resetPartition();
102 mlir::LogicalResult resetDMA(int col, int row, bool on);
103 mlir::LogicalResult resetCore(int col, int row);
104 mlir::LogicalResult resetCoreUnreset(int col, int row);
105 mlir::LogicalResult resetSwitch(int col, int row);
106 mlir::LogicalResult resetLock(int col, int row, int lockId);
107 mlir::LogicalResult resetSwitchConnection(int col, int row,
108 WireBundle sourceBundle,
109 int sourceChannel,
110 WireBundle destBundle,
111 int destChannel);
112 mlir::LogicalResult resetPerfCounters(int col, int row);
113
114private:
115 const AIETargetModel &targetModel;
116 struct AIERtImpl;
117 std::unique_ptr<AIERtImpl> aiert;
118};
119
120} // namespace xilinx::AIE
121
122#endif // AIE_AIERT_H
TxnLocBracket(const TxnLocBracket &)=delete
TxnLocBracket & operator=(const TxnLocBracket &)=delete
TxnLocBracket(AIERTControl &ctl, mlir::Location loc)
Definition AIERT.cpp:252
mlir::LogicalResult configureSwitches(DeviceOp &targetOp, bool skipCtrlPktOverlay=false)
Definition AIERT.cpp:769
mlir::LogicalResult resetPerfCounters(int col, int row)
Definition AIERT.cpp:1244
mlir::LogicalResult configureLocksAndBd(mlir::Block &block, int col, int row, bool outOfOrder=false)
Definition AIERT.cpp:679
mlir::LogicalResult resetCore(int col, int row)
Definition AIERT.cpp:1152
mlir::LogicalResult addDmaActivation(DeviceOp &targetOp)
Definition AIERT.cpp:1062
void dmaUpdateBdAddr(int col, int row, size_t addr, size_t bdId)
Definition AIERT.cpp:1320
mlir::LogicalResult resetPartition()
Definition AIERT.cpp:1135
mlir::LogicalResult resetCoreUnreset(int col, int row)
Definition AIERT.cpp:1186
mlir::LogicalResult setIOBackend(bool aieSim, bool xaieDebug)
Definition AIERT.cpp:341
uint32_t getCurrentTxnNumCmds() const
Definition AIERT.cpp:1413
std::vector< uint8_t > exportSerializedTransaction()
Definition AIERT.cpp:1390
AIERTControl(const xilinx::AIE::AIETargetModel &tm)
Definition AIERT.cpp:277
mlir::LogicalResult initLocks(DeviceOp &targetOp)
Definition AIERT.cpp:709
mlir::LogicalResult resetDMA(int col, int row, bool on)
Definition AIERT.cpp:1140
static mlir::LogicalResult isSupported(mlir::Operation *op, const AIETargetModel &tm)
Diagnose, on op, a target this aie-rt lowering cannot configure.
Definition AIERT.cpp:269
mlir::LogicalResult disableCores(DeviceOp &targetOp)
Definition AIERT.cpp:953
mlir::LogicalResult initBuffers(DeviceOp &targetOp)
Definition AIERT.cpp:742
mlir::LogicalResult resetSwitch(int col, int row)
Definition AIERT.cpp:1158
mlir::LogicalResult addCoreEnable(DeviceOp &targetOp)
Definition AIERT.cpp:1103
mlir::LogicalResult resetSwitchConnection(int col, int row, WireBundle sourceBundle, int sourceChannel, WireBundle destBundle, int destChannel)
Definition AIERT.cpp:1204
const std::vector< mlir::Location > & getTxnOpLocs() const
Definition AIERT.cpp:1409
mlir::LogicalResult addInitConfig(DeviceOp &targetOp, bool skipCtrlPktOverlay=false)
Definition AIERT.cpp:1003
mlir::LogicalResult addAieElf(uint8_t col, uint8_t row, const mlir::StringRef elfPath, bool aieSim)
Definition AIERT.cpp:1123
void recordTxnLocRange(uint32_t startCmds, uint32_t endCmds, mlir::Location loc)
Definition AIERT.cpp:1417
mlir::LogicalResult resetDmaChannels(DeviceOp &targetOp)
Definition AIERT.cpp:963
mlir::LogicalResult pushToBdQueueAndEnable(mlir::Operation &op, int col, int row, int chNum, const DMAChannelDir &channelDir, int bdId, int repeatCount, uint32_t padValue=0, bool outOfOrder=false, bool configureChannel=true, bool pushTask=true)
Definition AIERT.cpp:632
mlir::LogicalResult addAieElfs(DeviceOp &targetOp, const mlir::StringRef elfPath, bool aieSim)
Definition AIERT.cpp:1266
mlir::LogicalResult resetLock(int col, int row, int lockId)
Definition AIERT.cpp:1192
mlir::LogicalResult teardownSwitches(DeviceOp &targetOp, bool skipCtrlPktOverlay=false)
Definition AIERT.cpp:901