MLIR-AIE 1.4.5.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 /// The first claimant of a core stream port, and whether only packets use
34 /// it; circuit occupancy is exclusive.
35 struct StreamClaim {
36 mlir::Operation *owner;
37 bool packet;
38 };
39 mlir::DenseMap<std::tuple<mlir::Value, DMAChannelDir, int>, StreamClaim>
40 usedStreams;
41
42public:
43 DMAChannelAnalysis(DeviceOp &device);
44
45 /// Exclusive upper bound on channel indices eligible for this transfer.
46 static int getDMAChannelLimit(TileLike tile, DMAChannelDir dir,
47 bool requiresAdjacentTileAccessChannels);
48
49 /// Next free channel of `tile` in `dir`, or -1 when the tile has none left.
50 /// A channel an explicit flow routes is not free.
51 /// A channel reaching an adjacent MemTile's memory must come from the
52 /// target's restricted range at every compatible physical position.
53 int getDMAChannelIndex(TileLike tile, DMAChannelDir dir,
54 bool requiresAdjacentTileAccessChannels,
55 mlir::Operation *owner = nullptr);
56
57 /// Whether first-free assignment could hand out `channel`: nothing reserves
58 /// it and no explicit flow routes it.
59 bool isChannelFree(TileLike tile, DMAChannelDir dir, int channel);
60
61 /// Claim `channel` for (`tile`, `dir`) so first-free assignment cannot take
62 /// it. Returns the channel, or -1 when it is out of range or already
63 /// claimed; the caller reports, since it knows which endpoint asked.
64 int reservePinnedChannel(TileLike tile, DMAChannelDir dir, int channel,
65 mlir::Operation *owner = nullptr);
66
67 /// Operation reserving this channel, or else the flow routing it; null if
68 /// neither.
69 mlir::Operation *getDMAChannelOwner(TileLike tile, DMAChannelDir dir,
70 int channel);
71
72 /// Claim a raw stream port for `user`, reporting on it when the port is
73 /// taken; packet users may share it with other packets.
74 mlir::LogicalResult checkAIEStreamIndex(TileLike tile, DMAChannel chan,
75 mlir::Operation *user,
76 bool packet = false);
77};
78
79} // namespace xilinx::AIE
80
81#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 this channel, or else the flow routing it; null if neither.
bool isChannelFree(TileLike tile, DMAChannelDir dir, int channel)
Whether first-free assignment could hand out channel: nothing reserves it and no explicit flow routes...
int reservePinnedChannel(TileLike tile, DMAChannelDir dir, int channel, mlir::Operation *owner=nullptr)
Claim channel for (tile, dir) so first-free assignment cannot take it.
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...
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