MLIR-AIE 1.4.6.dev
AIEDMAChannelAnalysis.h
Go to the documentation of this file.
1//===- AIEDMAChannelAnalysis.h ----------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2021-2022 Xilinx, Inc.
4// Copyright (C) 2022-2026 Advanced Micro Devices, Inc.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef AIE_DIALECT_AIE_TRANSFORMS_AIEDMACHANNELANALYSIS_H
10#define AIE_DIALECT_AIE_TRANSFORMS_AIEDMACHANNELANALYSIS_H
11
13
14#include "llvm/ADT/DenseMap.h"
15
16namespace xilinx::AIE {
17
18/// Which DMA channels of each tile are already spoken for, so that a channel is
19/// handed out at most once across everything that programs one.
21 /// Fully resolved tile aliases name the same hardware resources. Unresolved
22 /// tiles retain their SSA identity until placement establishes co-location.
23 mlir::DenseMap<std::pair<int, int>, mlir::Value> tilesByCoordinate;
24 mlir::Value getTileKey(mlir::Value tile);
25
26 /// Keep the reserving operation so diagnostics retain its MLIR location.
27 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, mlir::Operation *>
28 usedChannels;
29 /// DMA channels an explicit flow routes. First-free assignment skips them;
30 /// a pinned request may still claim one.
31 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, mlir::Operation *>
32 streamedChannels;
33 /// Channels whose claimants all share them. Several packet-switched sources
34 /// coexist on one; a circuit claim is exclusive.
35 mlir::DenseSet<std::tuple<mlir::Value, DMAChannelDir, int>> sharedChannels;
36 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, mlir::Operation *>
37 shareableChannels;
38 /// The first claimant of a core stream port, and whether only packets use
39 /// it; circuit occupancy is exclusive.
40 struct StreamClaim {
41 mlir::Operation *owner;
42 bool packet;
43 };
44 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, StreamClaim>
45 usedStreams;
46
47public:
48 DMAChannelAnalysis(DeviceOp &device);
49
50 /// Exclusive upper bound on channel indices eligible for this transfer.
51 static int getDMAChannelLimit(TileLike tile, DMAChannelDir dir,
52 bool requiresAdjacentTileAccessChannels);
53
54 /// Next free channel of `tile` in `dir`, or -1 when the tile has none left.
55 /// A channel an explicit flow routes is not free.
56 /// A channel reaching an adjacent MemTile's memory must come from the
57 /// target's restricted range at every compatible physical position.
58 int getDMAChannelIndex(TileLike tile, DMAChannelDir dir,
59 bool requiresAdjacentTileAccessChannels,
60 mlir::Operation *owner = nullptr);
61
62 /// Whether first-free assignment could hand out `channel`: nothing reserves
63 /// it and no explicit flow routes it.
64 bool isChannelFree(TileLike tile, DMAChannelDir dir, int channel);
65
66 /// Claim `channel` for (`tile`, `dir`) so first-free assignment cannot take
67 /// it. Returns the channel, or -1 when it is out of range or already
68 /// claimed; the caller reports, since it knows which endpoint asked.
69 /// `shareable` claimants join a channel other shareable ones hold.
70 int reservePinnedChannel(TileLike tile, DMAChannelDir dir, int channel,
71 mlir::Operation *owner = nullptr,
72 bool shareable = false);
73
74 /// Operation reserving or routing this channel; null if none.
75 mlir::Operation *getDMAChannelOwner(TileLike tile, DMAChannelDir dir,
76 int channel);
77
78 /// Claim a raw stream port for `user`, reporting on it when the port is
79 /// taken; packet users may share it with other packets.
80 mlir::LogicalResult checkAIEStreamIndex(TileLike tile, DMAChannel chan,
81 mlir::Operation *user,
82 bool packet = false);
83};
84
85} // namespace xilinx::AIE
86
87#endif // AIE_DIALECT_AIE_TRANSFORMS_AIEDMACHANNELANALYSIS_H
int getDMAChannelIndex(TileLike tile, DMAChannelDir dir, bool requiresAdjacentTileAccessChannels, mlir::Operation *owner=nullptr)
Next free channel of tile in dir, or -1 when the tile has none left.
mlir::Operation * getDMAChannelOwner(TileLike tile, DMAChannelDir dir, int channel)
Operation reserving or routing this channel; null if none.
bool isChannelFree(TileLike tile, DMAChannelDir dir, int channel)
Whether first-free assignment could hand out channel: nothing reserves it and no explicit flow routes...
static int getDMAChannelLimit(TileLike tile, DMAChannelDir dir, bool requiresAdjacentTileAccessChannels)
Exclusive upper bound on channel indices eligible for this transfer.
mlir::LogicalResult checkAIEStreamIndex(TileLike tile, DMAChannel chan, mlir::Operation *user, bool packet=false)
Claim a raw stream port for user, reporting on it when the port is taken; packet users may share it w...
int reservePinnedChannel(TileLike tile, DMAChannelDir dir, int channel, mlir::Operation *owner=nullptr, bool shareable=false)
Claim channel for (tile, dir) so first-free assignment cannot take it.
struct DMAChannel { DMAChannelDir direction; int channel; bool operator==(const DMAChannel &rhs) const { return std::tie(direction, channel)==std::tie(rhs.direction, rhs.channel); } } DMAChannel
Definition AIEDialect.h:314