Skip to content

Commit b896475

Browse files
[AP][PartialLegalizer] Updated Comments and Verification
1 parent dc5593c commit b896475

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

vpr/src/analytical_place/flat_placement_bins.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ap_netlist.h"
1515
#include "vtr_assert.h"
1616
#include "vtr_geometry.h"
17+
#include "vtr_log.h"
1718
#include "vtr_range.h"
1819
#include "vtr_strong_id.h"
1920
#include "vtr_vector.h"
@@ -133,6 +134,51 @@ class FlatPlacementBins {
133134
bin_contained_blocks_[bin_id].clear();
134135
}
135136

137+
/**
138+
* @brief Verify the internal members of this class are consistent.
139+
*/
140+
inline bool verify() const {
141+
// Ensure all bin IDs are valid and consistent.
142+
for (FlatPlacementBinId bin_id : bin_ids_) {
143+
if (!bin_id.is_valid()) {
144+
VTR_LOG("Bin Verify: Invalid bin ID in bins.\n");
145+
return false;
146+
}
147+
if (bin_ids_.count(bin_id) != 1) {
148+
VTR_LOG("Bin Verify: Found a bin ID not in the bin IDs array.\n");
149+
return false;
150+
}
151+
if (bin_ids_[bin_id] != bin_id) {
152+
VTR_LOG("Bin Verify: Bin ID found which is not consistent.\n");
153+
return false;
154+
}
155+
}
156+
157+
// Ensure the data members of this class are all the correct size.
158+
size_t num_bins = bin_ids_.size();
159+
if (bin_contained_blocks_.size() != num_bins) {
160+
VTR_LOG("Bin Verify: bin_constained_blocks_ not the correct size.\n");
161+
return false;
162+
}
163+
if (bin_region_.size() != num_bins) {
164+
VTR_LOG("Bin Verify: bin_region_ not the correct size.\n");
165+
return false;
166+
}
167+
168+
// Make sure that the bin_contained_blocks_ and the block_bin_ are
169+
// consistent.
170+
for (FlatPlacementBinId bin_id : bin_ids_) {
171+
for (APBlockId blk_id : bin_contained_blocks_[bin_id]) {
172+
if (block_bin_[blk_id] != bin_id) {
173+
VTR_LOG("Bin Verify: Block is contained within a bin but does not agree.\n");
174+
return false;
175+
}
176+
}
177+
}
178+
179+
return true;
180+
}
181+
136182
private:
137183
/// @brief A vector of the Flat Placement Bin IDs. If any of them are invalid,
138184
/// then that means that the bin has been destroyed.

vpr/src/analytical_place/flat_placement_density_manager.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ vtr::Point<double> FlatPlacementDensityManager::get_block_location_in_bin(
193193

194194
void FlatPlacementDensityManager::export_placement_from_bins(PartialPlacement& p_placement) const {
195195
// Updates the partial placement with the location of the blocks in the bin
196-
// by moiving the blocks to the point with the bin closest to where they
196+
// by moving the blocks to the point with the bin closest to where they
197197
// were originally.
198198
for (APBlockId blk_id : ap_netlist_.blocks()) {
199199
// Only the moveable block locations should be exported.
@@ -227,6 +227,11 @@ void FlatPlacementDensityManager::empty_bins() {
227227
}
228228

229229
bool FlatPlacementDensityManager::verify() const {
230+
// Verify the bins for consistency.
231+
if (!bins_.verify()) {
232+
VTR_LOG("Bins failed to verify.\n");
233+
return false;
234+
}
230235
// Make sure that every block has a bin.
231236
for (APBlockId blk_id : ap_netlist_.blocks()) {
232237
if (!bins_.block_bin(blk_id).is_valid()) {

vpr/src/analytical_place/flat_placement_density_manager.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ struct t_physical_tile_type;
3838
* bins and how overfilled / underfilled they are.
3939
*
4040
* Currently, a bin is created for each tile in the FPGA grid (with a unique
41-
* root tile location). The capacity of each bin is the capacity of the tile
42-
* it represents (as computed by the flat placement mass calculator). When
43-
* AP blocks are added / removed from bins, this class will maintain the current
44-
* utilization of the bin. Since these masses / capacities are repesented by
45-
* M-dimensional quantities (where M is the number of models in the architecture),
46-
* the overfill and underfill of each bin is given as an M-dimensional vector.
47-
* For example, in an architecture of only LUTs and FFs, an overfill of <3, 1>
48-
* means that a bin has 3 too many LUTs and 1 too many FFs.
41+
* root tile location). For example, a CLB taking up a single tile would be a
42+
* 1x1 bin, while a DSP block taking up multiple tiles may be a 4x1 bin. The
43+
* capacity of each bin is the capacity of the tile it represents (as computed
44+
* by the flat placement mass calculator). When AP blocks are added / removed
45+
* from bins, this class will maintain the current utilization of the bin. Since
46+
* these masses / capacities are repesented by M-dimensional quantities (where
47+
* M is the number of models in the architecture), the overfill and underfill of
48+
* each bin is given as an M-dimensional vector. For example, in an architecture
49+
* of only LUTs and FFs, an overfill of <3, 1> means that a bin has 3 too many
50+
* LUTs and 1 too many FFs.
4951
*
5052
* This class is able to answer questions about the current density of the flat
5153
* placement such as which bins are currently overfilled, what bin is at the
@@ -199,6 +201,15 @@ class FlatPlacementDensityManager {
199201
*
200202
* This will return the position of the block that is closest to the position
201203
* in the given flat placement, while still being within the the bin region.
204+
*
205+
* For example, if the block is located within the bin, its position will
206+
* be returned (unmodified). If the block is located to the left of the bin
207+
* (y coordinate is within the bounds of the bin), then this will return
208+
* the point on the left edge of the bin with the same y coordinate as the
209+
* block.
210+
*
211+
* TODO: It may be a good idea to investigate placing blocks at the input
212+
* or output pin locations of the bin.
202213
*/
203214
vtr::Point<double> get_block_location_in_bin(APBlockId blk_id,
204215
const vtr::Rect<double>& bin_region,
@@ -235,6 +246,8 @@ class FlatPlacementDensityManager {
235246

236247
/// @brief Spatial lookup for an (layer, x, y) position to the bin at that
237248
/// location.
249+
///
250+
/// Access: [0..grid.num_layers-1][0..grid.width-1][0..grid.height-1]
238251
vtr::NdMatrix<FlatPlacementBinId, 3> bin_spatial_lookup_;
239252

240253
/// @brief The capacity of each bin.

0 commit comments

Comments
 (0)