Skip to content

Commit fafdd07

Browse files
fix a few issues to be compliant with break before binary operators
1 parent 400f6cc commit fafdd07

File tree

12 files changed

+218
-261
lines changed

12 files changed

+218
-261
lines changed

libs/libvtrutil/src/vtr_prefix_sum.h

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ class PrefixSum1D {
9494
* @brief Construct the 1D prefix sum from a vector.
9595
*/
9696
PrefixSum1D(std::vector<T> vals, T zero = T())
97-
: PrefixSum1D(vals.size(),
98-
[&](size_t x) noexcept {
99-
return vals[x];
100-
},
101-
zero) {}
97+
: PrefixSum1D(
98+
vals.size(),
99+
[&](size_t x) noexcept {
100+
return vals[x];
101+
},
102+
zero) {}
102103

103104
/**
104105
* @brief Get the sum of all values in the original array of values between
@@ -123,7 +124,7 @@ class PrefixSum1D {
123124
return prefix_sum_[upper_x + 1] - prefix_sum_[lower_x];
124125
}
125126

126-
private:
127+
private:
127128
/**
128129
* @brief The 1D prefix sum of the original array of values.
129130
*
@@ -213,10 +214,10 @@ class PrefixSum2D {
213214
// to (x - 1, y - 1) inclusive.
214215
for (size_t x = 1; x < w + 1; x++) {
215216
for (size_t y = 1; y < h + 1; y++) {
216-
prefix_sum_[x][y] = prefix_sum_[x - 1][y] +
217-
prefix_sum_[x][y - 1] +
218-
lookup(x - 1, y - 1) -
219-
prefix_sum_[x - 1][y - 1];
217+
prefix_sum_[x][y] = prefix_sum_[x - 1][y]
218+
+ prefix_sum_[x][y - 1]
219+
+ lookup(x - 1, y - 1)
220+
- prefix_sum_[x - 1][y - 1];
220221
}
221222
}
222223
}
@@ -225,12 +226,13 @@ class PrefixSum2D {
225226
* @brief Constructs a 2D prefix sum from a 2D grid of values.
226227
*/
227228
PrefixSum2D(const vtr::NdMatrix<T, 2>& vals, T zero = T())
228-
: PrefixSum2D(vals.dim_size(0),
229-
vals.dim_size(1),
230-
[&](size_t x, size_t y) {
231-
return vals[x][y];
232-
},
233-
zero) {}
229+
: PrefixSum2D(
230+
vals.dim_size(0),
231+
vals.dim_size(1),
232+
[&](size_t x, size_t y) {
233+
return vals[x][y];
234+
},
235+
zero) {}
234236

235237
/**
236238
* @brief Get the sum of all values in the original grid of values between
@@ -261,9 +263,10 @@ class PrefixSum2D {
261263
// Note: all of these are offset by 1 since the first row and column
262264
// are all zeros. This allows us to avoid bounds checking when
263265
// lower_x or lower_y are 0.
264-
return prefix_sum_[upper_x + 1][upper_y + 1] - prefix_sum_[lower_x][upper_y + 1]
265-
- prefix_sum_[upper_x + 1][lower_y]
266-
+ prefix_sum_[lower_x][lower_y];
266+
return prefix_sum_[upper_x + 1][upper_y + 1]
267+
- prefix_sum_[lower_x][upper_y + 1]
268+
- prefix_sum_[upper_x + 1][lower_y]
269+
+ prefix_sum_[lower_x][lower_y];
267270
}
268271

269272
private:
@@ -280,4 +283,3 @@ class PrefixSum2D {
280283
};
281284

282285
} // namespace vtr
283-

vpr/src/analytical_place/ap_netlist.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,12 @@ void APNetlist::set_block_loc(const APBlockId id, const APFixedBlockLoc& loc) {
5959
VTR_ASSERT_SAFE(valid_block_id(id));
6060

6161
// Check that the location is fixed; if all dims are unfixed then it is not fixed.
62-
if (loc.x == APFixedBlockLoc::UNFIXED_DIM &&
63-
loc.y == APFixedBlockLoc::UNFIXED_DIM &&
64-
loc.sub_tile == APFixedBlockLoc::UNFIXED_DIM &&
65-
loc.layer_num == APFixedBlockLoc::UNFIXED_DIM)
62+
if (loc.x == APFixedBlockLoc::UNFIXED_DIM && loc.y == APFixedBlockLoc::UNFIXED_DIM && loc.sub_tile == APFixedBlockLoc::UNFIXED_DIM && loc.layer_num == APFixedBlockLoc::UNFIXED_DIM)
6663
return;
6764

6865
// Ensure that the block is fixed to a single position on the grid (x, y, layer).
6966
// sub-tile is allowed to be unfixed.
70-
VTR_ASSERT(loc.x != APFixedBlockLoc::UNFIXED_DIM &&
71-
loc.y != APFixedBlockLoc::UNFIXED_DIM &&
72-
loc.layer_num != APFixedBlockLoc::UNFIXED_DIM &&
73-
"AP: Currently, AP assumes block is locked down to a single position on the device grid.");
67+
VTR_ASSERT(loc.x != APFixedBlockLoc::UNFIXED_DIM && loc.y != APFixedBlockLoc::UNFIXED_DIM && loc.layer_num != APFixedBlockLoc::UNFIXED_DIM && "AP: Currently, AP assumes block is locked down to a single position on the device grid.");
7468

7569
block_locs_[id] = loc;
7670
block_mobilities_[id] = APBlockMobility::FIXED;
@@ -207,4 +201,3 @@ bool APNetlist::validate_net_sizes_impl(size_t /*num_nets*/) const {
207201
// No AP-specific net data to check
208202
return true;
209203
}
210-

vpr/src/analytical_place/partial_legalizer.cpp

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ static std::unordered_set<FlatPlacementBinId> get_direct_neighbors_of_bin(
9797
// the bounding box. We need to ensure that the bin represents a tile (not
9898
// part of a tile). If it did represent part of a tile, this algorithm
9999
// would need to change.
100-
VTR_ASSERT_DEBUG(static_cast<double>(bl_x) == bin_region.bottom_left().x() &&
101-
static_cast<double>(bl_y) == bin_region.bottom_left().y() &&
102-
static_cast<double>(bin_width) == bin_region.width() &&
103-
static_cast<double>(bin_height) == bin_region.height());
100+
VTR_ASSERT_DEBUG(static_cast<double>(bl_x) == bin_region.bottom_left().x() && static_cast<double>(bl_y) == bin_region.bottom_left().y() && static_cast<double>(bin_width) == bin_region.width() && static_cast<double>(bin_height) == bin_region.height());
104101

105102
double placeable_region_width, placeable_region_height, placeable_region_depth;
106103
std::tie(placeable_region_width, placeable_region_height, placeable_region_depth) = density_manager.get_overall_placeable_region_size();
@@ -251,8 +248,7 @@ void FlowBasedLegalizer::compute_neighbors_of_bin(FlatPlacementBinId src_bin_id,
251248
q.push(dir_neighbor_bin_id);
252249
}
253250
// Check if all of the models have been found in all directions.
254-
all_models_found_in_all_directions = all_up_found && all_down_found &&
255-
all_left_found && all_right_found;
251+
all_models_found_in_all_directions = all_up_found && all_down_found && all_left_found && all_right_found;
256252
}
257253

258254
// Assign the results into the neighbors of the bin.
@@ -437,7 +433,7 @@ std::vector<std::vector<FlatPlacementBinId>> FlowBasedLegalizer::get_paths(
437433
const PrimitiveVector& starting_bin_supply = get_bin_supply(src_bin_id);
438434
while (!queue.empty() && demand < starting_bin_supply) {
439435
// Pop the current bin off the queue.
440-
std::vector<FlatPlacementBinId> &p = queue.front();
436+
std::vector<FlatPlacementBinId>& p = queue.front();
441437
FlatPlacementBinId tail_bin_id = p.back();
442438
// Look over its neighbors
443439
for (FlatPlacementBinId neighbor_bin_id : bin_neighbors_[tail_bin_id]) {
@@ -500,8 +496,7 @@ std::vector<std::vector<FlatPlacementBinId>> FlowBasedLegalizer::get_paths(
500496
starting_bin_supply.manhattan_norm());
501497

502498
// Sort the paths in increasing order of cost.
503-
std::sort(paths.begin(), paths.end(), [&](const std::vector<FlatPlacementBinId>& a,
504-
const std::vector<FlatPlacementBinId>& b) {
499+
std::sort(paths.begin(), paths.end(), [&](const std::vector<FlatPlacementBinId>& a, const std::vector<FlatPlacementBinId>& b) {
505500
return bin_cost[a.back()] < bin_cost[b.back()];
506501
});
507502

@@ -730,11 +725,11 @@ struct SpreadingWindow {
730725
} // namespace
731726

732727
BiPartitioningPartialLegalizer::BiPartitioningPartialLegalizer(
733-
const APNetlist& netlist,
734-
std::shared_ptr<FlatPlacementDensityManager> density_manager,
735-
int log_verbosity)
736-
: PartialLegalizer(netlist, log_verbosity)
737-
, density_manager_(density_manager) {}
728+
const APNetlist& netlist,
729+
std::shared_ptr<FlatPlacementDensityManager> density_manager,
730+
int log_verbosity)
731+
: PartialLegalizer(netlist, log_verbosity)
732+
, density_manager_(density_manager) {}
738733

739734
/**
740735
* @brief Identify spreading windows which contain overfilled bins on the device
@@ -750,8 +745,8 @@ BiPartitioningPartialLegalizer::BiPartitioningPartialLegalizer(
750745
* spreading easier.
751746
*/
752747
static std::vector<SpreadingWindow> identify_non_overlapping_windows(
753-
const APNetlist& netlist,
754-
FlatPlacementDensityManager& density_manager) {
748+
const APNetlist& netlist,
749+
FlatPlacementDensityManager& density_manager) {
755750
// Identify overfilled bins
756751
const std::unordered_set<FlatPlacementBinId>& overfilled_bins = density_manager.get_overfilled_bins();
757752

@@ -763,27 +758,27 @@ static std::vector<SpreadingWindow> identify_non_overlapping_windows(
763758
size_t width, height, layers;
764759
std::tie(width, height, layers) = density_manager.get_overall_placeable_region_size();
765760
vtr::PrefixSum2D<float> capacity_prefix_sum(width, height, [&](size_t x, size_t y) {
766-
FlatPlacementBinId bin_id = density_manager.get_bin(x, y, 0);
767-
// For now we take the L1 norm of the bin divided by its area.
768-
// The L1 norm is just a count of the number of primitives that
769-
// can fit into the bin (without caring for primitive type). We
770-
// divide by area such that large bins (1x4 for example) get
771-
// normalized to 1x1 regions.
772-
const vtr::Rect<double>& bin_region = density_manager.flat_placement_bins().bin_region(bin_id);
773-
float bin_area = bin_region.width() * bin_region.height();
774-
return density_manager.get_bin_capacity(bin_id).manhattan_norm() / bin_area;
775-
});
761+
FlatPlacementBinId bin_id = density_manager.get_bin(x, y, 0);
762+
// For now we take the L1 norm of the bin divided by its area.
763+
// The L1 norm is just a count of the number of primitives that
764+
// can fit into the bin (without caring for primitive type). We
765+
// divide by area such that large bins (1x4 for example) get
766+
// normalized to 1x1 regions.
767+
const vtr::Rect<double>& bin_region = density_manager.flat_placement_bins().bin_region(bin_id);
768+
float bin_area = bin_region.width() * bin_region.height();
769+
return density_manager.get_bin_capacity(bin_id).manhattan_norm() / bin_area;
770+
});
776771

777772
// Create a prefix sum for the utilization.
778773
// The utilization of the bins will change between routing iterations, so
779774
// this prefix sum must be recomputed.
780775
vtr::PrefixSum2D<float> utilization_prefix_sum(width, height, [&](size_t x, size_t y) {
781-
FlatPlacementBinId bin_id = density_manager.get_bin(x, y, 0);
782-
// This is computed the same way as the capacity prefix sum above.
783-
const vtr::Rect<double>& bin_region = density_manager.flat_placement_bins().bin_region(bin_id);
784-
float bin_area = bin_region.width() * bin_region.height();
785-
return density_manager.get_bin_utilization(bin_id).manhattan_norm() / bin_area;
786-
});
776+
FlatPlacementBinId bin_id = density_manager.get_bin(x, y, 0);
777+
// This is computed the same way as the capacity prefix sum above.
778+
const vtr::Rect<double>& bin_region = density_manager.flat_placement_bins().bin_region(bin_id);
779+
float bin_area = bin_region.width() * bin_region.height();
780+
return density_manager.get_bin_utilization(bin_id).manhattan_norm() / bin_area;
781+
});
787782

788783
// 1) For each of the overfilled bins, create and store a minimum window.
789784
// TODO: This is a very simple algorithm which currently only uses the number
@@ -808,8 +803,7 @@ static std::vector<SpreadingWindow> identify_non_overlapping_windows(
808803

809804
// If the region did not grow, exit. This is a maximal bin.
810805
// TODO: Maybe print warning.
811-
if (new_xmin == region.xmin() && new_xmax == region.xmax() &&
812-
new_ymin == region.ymin() && new_ymax == region.ymax()) {
806+
if (new_xmin == region.xmin() && new_xmax == region.xmax() && new_ymin == region.ymin() && new_ymax == region.ymax()) {
813807
break;
814808
}
815809

@@ -1040,15 +1034,15 @@ void BiPartitioningPartialLegalizer::legalize(PartialPlacement& p_placement) {
10401034
if (partition_dir == e_partition_dir::VERTICAL) {
10411035
// Sort the blocks in the window by the x coordinate.
10421036
std::sort(window.contained_blocks.begin(), window.contained_blocks.end(), [&](APBlockId a, APBlockId b) {
1043-
return p_placement.block_x_locs[a] < p_placement.block_x_locs[b];
1044-
});
1037+
return p_placement.block_x_locs[a] < p_placement.block_x_locs[b];
1038+
});
10451039

10461040
} else {
10471041
VTR_ASSERT(partition_dir == e_partition_dir::HORIZONTAL);
10481042
// Sort the blocks in the window by the y coordinate.
10491043
std::sort(window.contained_blocks.begin(), window.contained_blocks.end(), [&](APBlockId a, APBlockId b) {
1050-
return p_placement.block_y_locs[a] < p_placement.block_y_locs[b];
1051-
});
1044+
return p_placement.block_y_locs[a] < p_placement.block_y_locs[b];
1045+
});
10521046
}
10531047

10541048
// Find the pivot block position.
@@ -1092,4 +1086,3 @@ void BiPartitioningPartialLegalizer::legalize(PartialPlacement& p_placement) {
10921086
// Export the legalized placement to the partial placement.
10931087
density_manager_->export_placement_from_bins(p_placement);
10941088
}
1095-

vpr/src/base/load_flat_place.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ FlatPlacementInfo read_flat_placement(const std::string& read_flat_place_file_pa
159159

160160
// Check if this atom already has a flat placement
161161
// Using the x_pos and y_pos as identifiers.
162-
if (flat_placement_info.blk_x_pos[atom_blk_id] != FlatPlacementInfo::UNDEFINED_POS ||
163-
flat_placement_info.blk_y_pos[atom_blk_id] != FlatPlacementInfo::UNDEFINED_POS) {
162+
if (flat_placement_info.blk_x_pos[atom_blk_id] != FlatPlacementInfo::UNDEFINED_POS
163+
|| flat_placement_info.blk_y_pos[atom_blk_id] != FlatPlacementInfo::UNDEFINED_POS) {
164164
VTR_LOG_WARN("Flat placement file, line %d, atom %s has multiple "
165165
"placement definitions in the flat placement file.\n",
166166
line_num, atom_netlist.block_name(atom_blk_id).c_str());
@@ -202,12 +202,12 @@ bool load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
202202
}
203203

204204
void log_flat_placement_reconstruction_info(
205-
const FlatPlacementInfo& flat_placement_info,
206-
const vtr::vector_map<ClusterBlockId, t_block_loc>& block_locs,
207-
const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup,
208-
const AtomLookup& cluster_of_atom_lookup,
209-
const AtomNetlist& atom_netlist,
210-
const ClusteredNetlist& clustered_netlist) {
205+
const FlatPlacementInfo& flat_placement_info,
206+
const vtr::vector_map<ClusterBlockId, t_block_loc>& block_locs,
207+
const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup,
208+
const AtomLookup& cluster_of_atom_lookup,
209+
const AtomNetlist& atom_netlist,
210+
const ClusteredNetlist& clustered_netlist) {
211211
// Go through each cluster and see how many clusters have atoms that
212212
// do not belong (cluster is imperfect).
213213
unsigned num_imperfect_clusters = 0;
@@ -243,10 +243,7 @@ void log_flat_placement_reconstruction_info(
243243
// want to be in this cluster.
244244
// FIXME: This should take into account large blocks somehow, just
245245
// being 0.5 tiles away may not be sufficient.
246-
if (std::abs(centroid_x - flat_placement_info.blk_x_pos[atom_blk_id]) > 0.5f ||
247-
std::abs(centroid_y - flat_placement_info.blk_y_pos[atom_blk_id]) > 0.5f ||
248-
std::abs(centroid_layer - flat_placement_info.blk_layer[atom_blk_id]) > 0.5f ||
249-
std::abs(centroid_sub_tile - flat_placement_info.blk_sub_tile[atom_blk_id]) > 0.5f) {
246+
if (std::abs(centroid_x - flat_placement_info.blk_x_pos[atom_blk_id]) > 0.5f || std::abs(centroid_y - flat_placement_info.blk_y_pos[atom_blk_id]) > 0.5f || std::abs(centroid_layer - flat_placement_info.blk_layer[atom_blk_id]) > 0.5f || std::abs(centroid_sub_tile - flat_placement_info.blk_sub_tile[atom_blk_id]) > 0.5f) {
250247
num_imperfect_clusters++;
251248
break;
252249
}
@@ -298,13 +295,13 @@ void log_flat_placement_reconstruction_info(
298295
// TODO: Make this debug option of higher verbosity. Helpful for
299296
// debugging flat placement reconstruction.
300297
/*
301-
VTR_LOG("%s %d %d %d %d\n",
302-
g_vpr_ctx.atom().netlist().block_name(atom_blk_id).c_str(),
303-
clb_loc.loc.x,
304-
clb_loc.loc.y,
305-
clb_loc.loc.layer,
306-
clb_loc.loc.sub_tile);
307-
*/
298+
* VTR_LOG("%s %d %d %d %d\n",
299+
* g_vpr_ctx.atom().netlist().block_name(atom_blk_id).c_str(),
300+
* clb_loc.loc.x,
301+
* clb_loc.loc.y,
302+
* clb_loc.loc.layer,
303+
* clb_loc.loc.sub_tile);
304+
*/
308305
}
309306

310307
// Log the flat placement reconstruction info.
@@ -322,4 +319,3 @@ void log_flat_placement_reconstruction_info(
322319
VTR_LOG("\tPercent of atoms misplaced from the flat placement: %f\n",
323320
static_cast<float>(num_atoms_missplaced) / static_cast<float>(num_atoms));
324321
}
325-

0 commit comments

Comments
 (0)