|
| 1 | +//===- AIEPlacer.h ----------------------------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +// (c) Copyright 2024-2026 Advanced Micro Devices, Inc. |
| 8 | +// |
| 9 | +//===----------------------------------------------------------------------===// |
| 10 | +// This file contains the interface for tile placement algorithms. |
| 11 | +// Placers assign physical tile coordinates to logical tiles. |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#ifndef AIE_PLACER_H |
| 15 | +#define AIE_PLACER_H |
| 16 | + |
| 17 | +#include "aie/Dialect/AIE/IR/AIEDialect.h" |
| 18 | +#include "aie/Dialect/AIE/IR/AIETargetModel.h" |
| 19 | + |
| 20 | +namespace xilinx::AIE { |
| 21 | + |
| 22 | +// maps logical tile operations to physical coordinates |
| 23 | +using PlacementResult = llvm::DenseMap<mlir::Operation *, TileID>; |
| 24 | + |
| 25 | +// Track available tiles and resource usage |
| 26 | +struct TileAvailability { |
| 27 | + std::vector<TileID> compTiles; |
| 28 | + std::vector<TileID> nonCompTiles; // Memory and shim tiles |
| 29 | + |
| 30 | + llvm::DenseMap<TileID, int> inputChannelsUsed; |
| 31 | + llvm::DenseMap<TileID, int> outputChannelsUsed; |
| 32 | + |
| 33 | + void removeTile(TileID tile, AIETileType type); |
| 34 | +}; |
| 35 | + |
| 36 | +// Abstract placer interface |
| 37 | +class Placer { |
| 38 | +public: |
| 39 | + Placer() = default; |
| 40 | + virtual ~Placer() = default; |
| 41 | + |
| 42 | + virtual void initialize(DeviceOp device, |
| 43 | + const AIETargetModel &targetModel) = 0; |
| 44 | + |
| 45 | + virtual mlir::LogicalResult |
| 46 | + place(llvm::ArrayRef<mlir::Operation *> logicalTiles, |
| 47 | + llvm::ArrayRef<mlir::Operation *> objectFifos, |
| 48 | + llvm::ArrayRef<mlir::Operation *> cores, PlacementResult &result) = 0; |
| 49 | + |
| 50 | + virtual llvm::StringRef getName() const = 0; |
| 51 | +}; |
| 52 | + |
| 53 | +// Sequential placement algorithm |
| 54 | +// |
| 55 | +// Places logical tiles to physical tiles using a simple strategy: |
| 56 | +// - Compute tiles: Sequential row-major placement |
| 57 | +// - Memory/shim tiles: Channel capacity placement near common column |
| 58 | +// |
| 59 | +// Core-to-core connections are NOT validated because SequentialPlacer |
| 60 | +// doesn't account for shared memory optimization. |
| 61 | +// |
| 62 | +// Shim/Mem tiles with identical placement constraints and sufficient |
| 63 | +// DMA capacity are merged to the same physical tile. |
| 64 | +class SequentialPlacer : public Placer { |
| 65 | +public: |
| 66 | + SequentialPlacer(std::optional<int> coresPerCol = std::nullopt) |
| 67 | + : coresPerCol(coresPerCol) {} |
| 68 | + |
| 69 | + void initialize(DeviceOp device, const AIETargetModel &targetModel) override; |
| 70 | + |
| 71 | + mlir::LogicalResult place(llvm::ArrayRef<mlir::Operation *> logicalTiles, |
| 72 | + llvm::ArrayRef<mlir::Operation *> objectFifos, |
| 73 | + llvm::ArrayRef<mlir::Operation *> cores, |
| 74 | + PlacementResult &result) override; |
| 75 | + |
| 76 | + llvm::StringRef getName() const override { return "sequential_placer"; } |
| 77 | + |
| 78 | +private: |
| 79 | + std::optional<int> coresPerCol; |
| 80 | + TileAvailability availability; |
| 81 | + const AIETargetModel *targetModel; |
| 82 | + DeviceOp device; |
| 83 | + |
| 84 | + int getCommonColumn(const PlacementResult &result); |
| 85 | + |
| 86 | + std::optional<TileID> findTileWithCapacity(int targetCol, |
| 87 | + std::vector<TileID> &tiles, |
| 88 | + int requiredInputChannels, |
| 89 | + int requiredOutputChannels); |
| 90 | + |
| 91 | + void updateChannelUsage(TileID tile, bool isOutput, int numChannels); |
| 92 | + |
| 93 | + bool hasAvailableChannels(TileID tile, int inputChannels, int outputChannels); |
| 94 | + |
| 95 | + mlir::LogicalResult validateAndUpdateChannelUsage( |
| 96 | + LogicalTileOp logicalTile, TileID tile, |
| 97 | + const llvm::DenseMap<mlir::Operation *, std::pair<int, int>> |
| 98 | + &channelRequirements, |
| 99 | + bool isConstrained); |
| 100 | +}; |
| 101 | + |
| 102 | +// PlacementAnalysis integrates the Pathfinder class into the MLIR |
| 103 | +// environment. |
| 104 | +class PlacementAnalysis { |
| 105 | +public: |
| 106 | + PlacementAnalysis() : placer(std::make_shared<SequentialPlacer>()) {} |
| 107 | + explicit PlacementAnalysis(std::shared_ptr<Placer> p) |
| 108 | + : placer(std::move(p)) {} |
| 109 | + |
| 110 | + mlir::LogicalResult runAnalysis(DeviceOp &device); |
| 111 | + |
| 112 | + std::optional<TileID> getPlacement(mlir::Operation *logicalTile) const; |
| 113 | + |
| 114 | + Placer &getPlacer() { return *placer; } |
| 115 | + |
| 116 | +private: |
| 117 | + std::shared_ptr<Placer> placer; |
| 118 | + PlacementResult result; |
| 119 | +}; |
| 120 | + |
| 121 | +} // namespace xilinx::AIE |
| 122 | + |
| 123 | +#endif // AIE_PLACER_H |
0 commit comments