19#include "xaiengine/xaiegbl_defs.h"
21#include "xaiengine/xaie_txn.h"
22#include "xaiengine/xaiegbl.h"
25#include "llvm/Support/raw_ostream.h"
31#define AIERC_STR(x) x, #x
32static const std::map<AieRC, std::string> AIERCTOSTR = {
58 {
AIERC_STR(XAIE_INSUFFICIENT_BUFFER_SIZE)},
61static const std::map<XAie_TxnOpcode, std::string> AIETXNOPCODETOSTR = {
68 {
AIERC_STR(XAIE_CONFIG_SHIMDMA_DMABUF_BD)},
76static const std::map<xilinx::AIE::WireBundle, StrmSwPortType>
77 WIRE_BUNDLE_TO_STRM_SW_PORT_TYPE = {
78 {xilinx::AIE::WireBundle::Core, StrmSwPortType::CORE},
79 {xilinx::AIE::WireBundle::DMA, StrmSwPortType::DMA},
80 {xilinx::AIE::WireBundle::TileControl, StrmSwPortType::CTRL},
81 {xilinx::AIE::WireBundle::FIFO, StrmSwPortType::FIFO},
82 {xilinx::AIE::WireBundle::South, StrmSwPortType::SOUTH},
83 {xilinx::AIE::WireBundle::West, StrmSwPortType::WEST},
84 {xilinx::AIE::WireBundle::North, StrmSwPortType::NORTH},
85 {xilinx::AIE::WireBundle::East, StrmSwPortType::EAST},
88 {xilinx::AIE::WireBundle::Trace, StrmSwPortType::TRACE},
97 return out << label <<
"=" << std::forward<H1>(value);
100template <
typename H1,
typename... T>
102 H1 &&value, T &&...rest) {
103 const char *pcomma = strchr(label,
',');
105 <<
"=" << std::forward<H1>(value) <<
',',
106 pcomma + 1, std::forward<T>(rest)...);
109llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const XAie_LocType &loc);
111llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const XAie_Lock &lock);
113llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const XAie_Packet &packet);
115#define SHOW_AIERT_ARGS(os, ...) showAIEXRTArgs(os, #__VA_ARGS__, __VA_ARGS__)
119static_assert(XAIE_OK == 0);
121#define TRY_XAIE_API_FATAL_ERROR(API, ...) \
123 LLVM_DEBUG(llvm::dbgs() << "trying XAIE API: " << #API << " with args: "); \
124 LLVM_DEBUG(SHOW_AIERT_ARGS(llvm::dbgs(), __VA_ARGS__)); \
125 LLVM_DEBUG(llvm::dbgs() << "\n"); \
126 if (auto r = API(__VA_ARGS__)) \
127 llvm::report_fatal_error(llvm::Twine(#API " failed with ") + \
121#define TRY_XAIE_API_FATAL_ERROR(API, ...) \ …
131#define TRY_XAIE_API_EMIT_ERROR(OP, API, ...) \
133 LLVM_DEBUG(llvm::dbgs() << "trying XAIE API: " << #API << " with args: "); \
134 LLVM_DEBUG(SHOW_AIERT_ARGS(llvm::dbgs(), __VA_ARGS__)); \
135 LLVM_DEBUG(llvm::dbgs() << "\n"); \
136 if (auto r = API(__VA_ARGS__)) \
137 return OP.emitOpError() << #API " failed with " << AIERCTOSTR.at(r); \
131#define TRY_XAIE_API_EMIT_ERROR(OP, API, ...) \ …
140#define TRY_XAIE_API_LOGICAL_RESULT(API, ...) \
142 LLVM_DEBUG(llvm::dbgs() << "trying XAIE API: " << #API << " with args: "); \
143 LLVM_DEBUG(SHOW_AIERT_ARGS(llvm::dbgs(), __VA_ARGS__)); \
144 LLVM_DEBUG(llvm::dbgs() << "\n"); \
145 if (auto r = API(__VA_ARGS__)) { \
146 llvm::errs() << #API " failed with " << AIERCTOSTR.at(r); \
140#define TRY_XAIE_API_LOGICAL_RESULT(API, ...) \ …
153#define TRY_XAIE_API_FATAL_ERROR(API, ...) \
155 if (auto r = API(__VA_ARGS__)) \
156 llvm::report_fatal_error(llvm::Twine(#API " failed with ") + \
160#define TRY_XAIE_API_EMIT_ERROR(OP, API, ...) \
162 if (auto r = API(__VA_ARGS__)) \
163 return OP.emitOpError() << #API " failed with " << AIERCTOSTR.at(r); \
166#define TRY_XAIE_API_LOGICAL_RESULT(API, ...) \
168 if (auto r = API(__VA_ARGS__)) { \
169 llvm::errs() << #API " failed with " << AIERCTOSTR.at(r); \
176#define XAIE_BASE_ADDR 0x40000000
177#define XAIE_SHIM_ROW 0
178#define XAIE_MEM_TILE_ROW_START 1
179#define XAIE_PARTITION_BASE_ADDR 0x0
183#define EVEN_BD_NUM_START 0
184#define ODD_BD_NUM_START 24
194 mlir::LogicalResult
setIOBackend(
bool aieSim,
bool xaieDebug);
197 XAie_LocType &tileLoc,
int bdId,
198 std::optional<int> nextBdId);
200 XAie_LocType &tileLoc,
int chNum,
201 const DMAChannelDir &channelDir,
202 int bdId,
int repeatCount);
204 XAie_LocType tileLoc);
205 mlir::LogicalResult
initLocks(DeviceOp &targetOp);
206 mlir::LogicalResult
initBuffers(DeviceOp &targetOp);
212 XAie_LocType &tileLoc);
214 const mlir::StringRef elfPath,
bool aieSim);
215 mlir::LogicalResult
addAieElfs(DeviceOp &targetOp,
216 const mlir::StringRef workDirPath,
llvm::raw_ostream & showAIEXRTArgs(llvm::raw_ostream &out, const char *label, H1 &&value)
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const XAie_LocType &loc)
Include the generated interface declarations.
mlir::LogicalResult configureLocksAndBd(mlir::Block &block, XAie_LocType tileLoc)
void dmaUpdateBdAddr(int col, int row, size_t addr, size_t bdId)
mlir::LogicalResult addAieElfs(DeviceOp &targetOp, const mlir::StringRef workDirPath, bool aieSim)
mlir::LogicalResult setIOBackend(bool aieSim, bool xaieDebug)
mlir::LogicalResult configureBdInBlock(XAie_DmaDesc &dmaTileBd, mlir::Block &block, XAie_LocType &tileLoc, int bdId, std::optional< int > nextBdId)
mlir::LogicalResult initLocks(DeviceOp &targetOp)
mlir::LogicalResult configureSwitches(DeviceOp &targetOp)
mlir::LogicalResult initBuffers(DeviceOp &targetOp)
mlir::LogicalResult addCoreEnable(DeviceOp &targetOp)
mlir::LogicalResult pushToBdQueueAndEnable(mlir::Operation &op, XAie_LocType &tileLoc, int chNum, const DMAChannelDir &channelDir, int bdId, int repeatCount)
const BaseNPUTargetModel & targetModel
mlir::LogicalResult addAieElf(uint8_t col, uint8_t row, const mlir::StringRef elfPath, bool aieSim)
void exportSerializedTransaction()
mlir::LogicalResult addInitConfig(DeviceOp &targetOp)
mlir::LogicalResult configureLocksInBdBlock(XAie_DmaDesc &dmaTileBd, mlir::Block &block, XAie_LocType &tileLoc)