MLIR-AIE 1.4.6.dev
AIEAssignBufferDescriptorIDs.h
Go to the documentation of this file.
1//===- AIEAssignBufferDescriptorIDs.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_ASSIGN_BUFFER_DESCRIPTOR_IDS_H
9#define AIE_ASSIGN_BUFFER_DESCRIPTOR_IDS_H
10
13
14#include "llvm/ADT/ArrayRef.h"
15#include "llvm/ADT/SmallVector.h"
16
17#include <optional>
18#include <set>
19#include <utility>
20
21using namespace xilinx::AIE;
22
23// Hands out one tile's BD ids, tracked per BD pool so private pools can reuse
24// ids.
26 const int col;
27 const int row;
29 // (pool, id) pairs in use.
30 std::set<std::pair<uint32_t, uint32_t>> alreadyAssigned;
31 // Held by static DMAs; nextBdId skips them and freeBdId leaves them alone.
32 std::set<std::pair<uint32_t, uint32_t>> reserved;
33
35
36 // The lowest free id in the channel's pool that is a multiple of
37 // `alignment`.
38 std::optional<uint32_t> nextBdId(int channelIndex, DMAChannelDir dir,
39 uint32_t alignment = 1);
40
41 // Act on the channel's pool; an id outside it is treated as tile-wide.
42 void assignBdId(int channelIndex, DMAChannelDir dir, uint32_t bdId);
43 bool bdIdAlreadyAssigned(int channelIndex, DMAChannelDir dir, uint32_t bdId);
44 void freeBdId(int channelIndex, DMAChannelDir dir, uint32_t bdId);
45
46 // Act on every pool holding `bdId`, for when the channel is unknown.
47 void assignBdId(uint32_t bdId);
48 bool bdIdAlreadyAssigned(uint32_t bdId);
49 // Releases an id taken with assignBdId(bdId); a channel's own ids use the
50 // per-channel form.
51 void freeBdId(uint32_t bdId);
52
53 // Per-channel and tile-wide forms, as above.
54 void reserveBdId(int channelIndex, DMAChannelDir dir, uint32_t bdId);
55 void reserveBdId(uint32_t bdId);
56 bool isReserved(int channelIndex, DMAChannelDir dir, uint32_t bdId) const;
57 bool isReserved(uint32_t bdId) const;
58
59 // Whether the per-channel form acts on every pool holding `bdId`.
60 bool holdsTileWide(int channelIndex, DMAChannelDir dir, uint32_t bdId) const;
61
62private:
63 // The pools that hold `bdId`; a sentinel pool for an id in none of them.
64 llvm::SmallVector<uint32_t, 2> poolsHolding(uint32_t bdId) const;
65 std::optional<uint32_t> poolOf(int channelIndex, DMAChannelDir dir,
66 uint32_t bdId) const;
67};
68
69// BD ids a runtime sequence pins, recorded on each aie.tile:
70// `aiex.reserved_bd_ids` (every pool holding them) and
71// `aiex.reserved_channel_bd_ids` (`<dir>_<channel>` -> ids in that pool).
72namespace xilinx::AIE {
73
75 // None means every pool holding the id.
76 std::optional<std::pair<int, DMAChannelDir>> channel;
77 int32_t id;
78};
79
80llvm::SmallVector<ReservedBdId> getReservedBdIds(TileOp tile);
81
82void setReservedBdIds(TileOp tile, llvm::ArrayRef<ReservedBdId> ids);
83
84bool isReservedBdIdsAttr(llvm::StringRef name);
85
86} // namespace xilinx::AIE
87
88#endif
void setReservedBdIds(TileOp tile, llvm::ArrayRef< ReservedBdId > ids)
bool isReservedBdIdsAttr(llvm::StringRef name)
llvm::SmallVector< ReservedBdId > getReservedBdIds(TileOp tile)
bool isReserved(int channelIndex, DMAChannelDir dir, uint32_t bdId) const
bool holdsTileWide(int channelIndex, DMAChannelDir dir, uint32_t bdId) const
const AIETargetModel & targetModel
std::set< std::pair< uint32_t, uint32_t > > alreadyAssigned
std::set< std::pair< uint32_t, uint32_t > > reserved
void reserveBdId(int channelIndex, DMAChannelDir dir, uint32_t bdId)
std::optional< uint32_t > nextBdId(int channelIndex, DMAChannelDir dir, uint32_t alignment=1)
void freeBdId(int channelIndex, DMAChannelDir dir, uint32_t bdId)
BdIdGenerator(int col, int row, const AIETargetModel &targetModel)
void assignBdId(int channelIndex, DMAChannelDir dir, uint32_t bdId)
bool bdIdAlreadyAssigned(int channelIndex, DMAChannelDir dir, uint32_t bdId)
std::optional< std::pair< int, DMAChannelDir > > channel