Skip to content

Commit f77c3c7

Browse files
Merge branch 'master' into refactor_atom_pb_from_packing
2 parents dfb6462 + c6802d6 commit f77c3c7

35 files changed

+473
-266
lines changed

libs/librrgraph/src/base/rr_node_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cstdint>
1111
#include "vtr_range.h"
1212
#include "vtr_ndmatrix.h"
13+
#include "rr_graph_fwd.h"
1314

1415
/**
1516
* @brief Type of a routing resource node.
@@ -123,6 +124,6 @@ struct t_rr_rc_data {
123124

124125
// This is the data type of fast lookups of an rr-node given an (rr_type, layer, x, y, and the side)
125126
//[0..num_rr_types-1][0..num_layer-1][0..grid_width-1][0..grid_height-1][0..NUM_2D_SIDES-1][0..max_ptc-1]
126-
typedef std::array<vtr::NdMatrix<std::vector<int>, 4>, NUM_RR_TYPES> t_rr_node_indices;
127+
typedef std::array<vtr::NdMatrix<std::vector<RRNodeId>, 4>, NUM_RR_TYPES> t_rr_node_indices;
127128

128129
#endif

libs/librrgraph/src/base/rr_spatial_lookup.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ RRNodeId RRSpatialLookup::find_node(int layer,
7575
return RRNodeId::INVALID();
7676
}
7777

78-
return RRNodeId(rr_node_indices_[type][layer][node_x][node_y][node_side][ptc]);
78+
return rr_node_indices_[type][layer][node_x][node_y][node_side][ptc];
7979
}
8080

8181
std::vector<RRNodeId> RRSpatialLookup::find_nodes_in_range(int layer,
@@ -155,14 +155,14 @@ std::vector<RRNodeId> RRSpatialLookup::find_nodes(int layer,
155155
/* Reserve space to avoid memory fragmentation */
156156
size_t num_nodes = 0;
157157
for (const auto& node : rr_node_indices_[type][layer][node_x][node_y][side]) {
158-
if (RRNodeId(node)) {
158+
if (node.is_valid()) {
159159
num_nodes++;
160160
}
161161
}
162162

163163
nodes.reserve(num_nodes);
164164
for (const auto& node : rr_node_indices_[type][layer][node_x][node_y][side]) {
165-
if (RRNodeId(node)) {
165+
if (node.is_valid()) {
166166
nodes.emplace_back(node);
167167
}
168168
}
@@ -272,11 +272,11 @@ void RRSpatialLookup::add_node(RRNodeId node,
272272

273273
if (size_t(ptc) >= rr_node_indices_[type][layer][x][y][side].size()) {
274274
/* Deposit invalid ids to newly allocated elements while original elements are untouched */
275-
rr_node_indices_[type][layer][x][y][side].resize(ptc + 1, int(RRNodeId::INVALID()));
275+
rr_node_indices_[type][layer][x][y][side].resize(ptc + 1, RRNodeId::INVALID());
276276
}
277277

278278
/* Resize on demand finished; Register the node */
279-
rr_node_indices_[type][layer][x][y][side][ptc] = int(node);
279+
rr_node_indices_[type][layer][x][y][side][ptc] = node;
280280
}
281281

282282
bool RRSpatialLookup::remove_node(RRNodeId node,
@@ -302,11 +302,11 @@ bool RRSpatialLookup::remove_node(RRNodeId node,
302302
if ((size_t)y >= rr_node_indices_[type].dim_size(2)) return false;
303303
if (side >= rr_node_indices_[type].dim_size(3)) return false;
304304
if ((size_t)ptc >= rr_node_indices_[type][layer][x][y][side].size()) return false;
305-
if (rr_node_indices_[type][layer][x][y][side][ptc] != int(node)) return false;
305+
if (rr_node_indices_[type][layer][x][y][side][ptc] != node) return false;
306306

307307
// The node was in the spatial lookup; remove it. -1 corresponds to an invalid node id,
308308
// and so is treated as absent in the spatial lookup
309-
rr_node_indices_[type][layer][x][y][side][ptc] = -1;
309+
rr_node_indices_[type][layer][x][y][side][ptc] = RRNodeId::INVALID();
310310
return true;
311311
}
312312

@@ -353,8 +353,8 @@ void RRSpatialLookup::reorder(const vtr::vector<RRNodeId, RRNodeId> dest_order)
353353
for (size_t y = 0; y < grid.dim_size(2); y++) {
354354
for (size_t s = 0; s < grid.dim_size(3); s++) {
355355
for (auto &node: grid[l][x][y][s]) {
356-
if (node != OPEN) {
357-
node = size_t(dest_order[RRNodeId(node)]);
356+
if (node.is_valid()) {
357+
node = dest_order[node];
358358
}
359359
}
360360
}

libs/libvtrutil/src/tl_optional.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ struct is_nothrow_swappable
281281

282282
// std::void_t from C++17
283283
template<class...>
284-
struct voider { using type = void; };
284+
struct voider {
285+
using type = void;
286+
};
285287
template<class... Ts>
286288
using void_t = typename voider<Ts...>::type;
287289

vpr/src/analytical_place/detailed_placer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
#include "detailed_placer.h"
99
#include <memory>
10-
#include "FlatPlacementInfo.h"
1110
#include "PlacementDelayModelCreator.h"
1211
#include "ap_flow_enums.h"
1312
#include "atom_netlist.h"
1413
#include "clustered_netlist.h"
1514
#include "clustered_netlist_utils.h"
1615
#include "echo_files.h"
16+
#include "flat_placement_types.h"
1717
#include "globals.h"
1818
#include "physical_types.h"
1919
#include "place_and_route.h"
@@ -22,6 +22,7 @@
2222
#include "vpr_error.h"
2323
#include "vpr_types.h"
2424
#include "vpr_utils.h"
25+
#include "vtr_time.h"
2526

2627
std::unique_ptr<DetailedPlacer> make_detailed_placer(e_ap_detailed_placer detailed_placer_type,
2728
const BlkLocRegistry& curr_clustered_placement,
@@ -89,6 +90,9 @@ AnnealerDetailedPlacer::AnnealerDetailedPlacer(const BlkLocRegistry& curr_cluste
8990
}
9091

9192
void AnnealerDetailedPlacer::optimize_placement() {
93+
// Create a scoped timer for the detailed placer.
94+
vtr::ScopedStartFinishTimer full_legalizer_timer("AP Detailed Placer");
95+
9296
// Prevent the annealer from directly modifying the global legal placement.
9397
// It should only modify its own, local placement.
9498
g_vpr_ctx.mutable_placement().lock_loc_vars();

vpr/src/analytical_place/full_legalizer.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616
#include <unordered_set>
1717
#include <vector>
1818

19-
#include "FlatPlacementInfo.h"
20-
#include "ap_flow_enums.h"
21-
#include "blk_loc_registry.h"
22-
#include "device_grid.h"
23-
#include "load_flat_place.h"
24-
#include "noc_place_utils.h"
25-
#include "partial_placement.h"
2619
#include "ShowSetup.h"
20+
#include "ap_flow_enums.h"
2721
#include "ap_netlist_fwd.h"
22+
#include "blk_loc_registry.h"
2823
#include "check_netlist.h"
2924
#include "cluster_legalizer.h"
3025
#include "cluster_util.h"
3126
#include "clustered_netlist.h"
27+
#include "device_grid.h"
28+
#include "flat_placement_types.h"
3229
#include "globals.h"
3330
#include "initial_placement.h"
31+
#include "load_flat_place.h"
3432
#include "logic_types.h"
33+
#include "noc_place_utils.h"
3534
#include "pack.h"
35+
#include "partial_placement.h"
3636
#include "physical_types.h"
3737
#include "place.h"
3838
#include "place_and_route.h"
@@ -523,12 +523,6 @@ void APPack::legalize(const PartialPlacement& p_placement) {
523523
// The Packer stores the clusters into a .net file. Load the packing file.
524524
// FIXME: This should be removed. Reading from a file is strange.
525525
vpr_load_packing(vpr_setup_, arch_);
526-
const ClusteredNetlist& clb_nlist = g_vpr_ctx.clustering().clb_nlist;
527-
528-
// Verify the packing and print some info
529-
check_netlist(vpr_setup_.PackerOpts.pack_verbosity);
530-
writeClusteredNetlistStats(vpr_setup_.FileNameOpts.write_block_usage);
531-
print_pb_type_count(clb_nlist);
532526

533527
// Setup the global variables for placement.
534528
g_vpr_ctx.mutable_placement().init_placement_context(vpr_setup_.PlacerOpts, arch_.directs);

vpr/src/analytical_place/global_placer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,24 @@ SimPLGlobalPlacer::SimPLGlobalPlacer(e_partial_legalizer partial_legalizer_type,
6969
// This can be a long method. Good to time this to see how long it takes to
7070
// construct the global placer.
7171
vtr::ScopedStartFinishTimer global_placer_building_timer("Constructing Global Placer");
72+
7273
// Build the solver.
74+
VTR_LOGV(log_verbosity_ >= 10, "\tBuilding the solver...\n");
7375
solver_ = make_analytical_solver(e_analytical_solver::QP_HYBRID,
7476
ap_netlist_);
77+
7578
// Build the density manager used by the partial legalizer.
79+
VTR_LOGV(log_verbosity_ >= 10, "\tBuilding the density manager...\n");
7680
density_manager_ = std::make_shared<FlatPlacementDensityManager>(ap_netlist_,
7781
prepacker,
7882
atom_netlist,
7983
device_grid,
8084
logical_block_types,
8185
physical_tile_types,
8286
log_verbosity_);
87+
8388
// Build the partial legalizer
89+
VTR_LOGV(log_verbosity_ >= 10, "\tBuilding the partial legalizer...\n");
8490
partial_legalizer_ = make_partial_legalizer(partial_legalizer_type,
8591
ap_netlist_,
8692
density_manager_,

vpr/src/base/FlatPlacementInfo.h renamed to vpr/src/base/flat_placement_types.h

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,54 @@
11
/**
22
* @file
33
* @author Alex Singer
4-
* @date January 2025
5-
* @brief Declaration of the FlatPlacementInfo object, which is used to store
6-
* flat placement information used by the packer.
4+
* @date March 2025
5+
* @brief Declaration of flat placement types used throughout VPR.
76
*/
87

98
#pragma once
109

1110
#include "atom_netlist.h"
11+
#include "vtr_assert.h"
1212
#include "vtr_vector.h"
1313

14+
/**
15+
* @brief A structure representing a flat placement location on the device.
16+
*
17+
* This is related to the t_pl_loc type; however this uses floating point
18+
* coordinates, allowing for blocks to be placed in illegal positions.
19+
*/
20+
struct t_flat_pl_loc {
21+
float x; /**< The x-coordinate of the location. */
22+
float y; /**< The y-coordinate of the location. */
23+
float layer; /**< The layer of the location. */
24+
25+
/**
26+
* @brief Adds the coordinates of another t_flat_pl_loc to this one.
27+
*
28+
* @param other The other t_flat_pl_loc whose coordinates are to be added.
29+
* @return A reference to this t_flat_pl_loc after addition.
30+
*/
31+
t_flat_pl_loc& operator+=(const t_flat_pl_loc& other) {
32+
x += other.x;
33+
y += other.y;
34+
layer += other.layer;
35+
return *this;
36+
}
37+
38+
/**
39+
* @brief Divides the coordinates of this t_flat_pl_loc by a divisor.
40+
*
41+
* @param divisor The value by which to divide the coordinates.
42+
* @return A reference to this t_flat_pl_loc after division.
43+
*/
44+
t_flat_pl_loc& operator/=(float divisor) {
45+
x /= divisor;
46+
y /= divisor;
47+
layer /= divisor;
48+
return *this;
49+
}
50+
};
51+
1452
/**
1553
* @brief Flat placement storage class.
1654
*
@@ -55,6 +93,15 @@ class FlatPlacementInfo {
5593
/// object, false otherwise.
5694
bool valid;
5795

96+
/**
97+
* @brief Get the flat placement location of the given atom block.
98+
*/
99+
inline t_flat_pl_loc get_pos(AtomBlockId blk_id) const {
100+
VTR_ASSERT_SAFE_MSG(blk_id.is_valid(), "Block ID is invalid");
101+
VTR_ASSERT_SAFE_MSG(valid, "FlatPlacementInfo not initialized");
102+
return {blk_x_pos[blk_id], blk_y_pos[blk_id], blk_layer[blk_id]};
103+
}
104+
58105
/**
59106
* @brief Default constructor of this class.
60107
*

vpr/src/base/flat_placement_utils.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @file
3+
* @author Alex Singer
4+
* @date March 2025
5+
* @brief Utility methods for working with flat placements.
6+
*/
7+
8+
#pragma once
9+
10+
#include <cstdlib>
11+
#include "flat_placement_types.h"
12+
13+
/**
14+
* @brief Returns the manhattan distance (L1 distance) between two flat
15+
* placement locations.
16+
*/
17+
inline float get_manhattan_distance(const t_flat_pl_loc& loc_a,
18+
const t_flat_pl_loc& loc_b) {
19+
return std::abs(loc_a.x - loc_b.x) + std::abs(loc_a.y - loc_b.y) + std::abs(loc_a.layer - loc_b.layer);
20+
}

vpr/src/base/load_flat_place.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "atom_lookup.h"
1515
#include "atom_netlist.h"
1616
#include "clustered_netlist.h"
17-
#include "FlatPlacementInfo.h"
17+
#include "flat_placement_types.h"
1818
#include "globals.h"
1919
#include "vpr_context.h"
2020
#include "vpr_error.h"

vpr/src/base/place_and_route.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <cmath>
55
#include <algorithm>
66

7-
#include "FlatPlacementInfo.h"
7+
#include "flat_placement_types.h"
88
#include "place_macro.h"
99
#include "vtr_assert.h"
1010
#include "vtr_log.h"

vpr/src/base/vpr_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <memory>
1818
#include <vector>
1919

20-
#include "FlatPlacementInfo.h"
20+
#include "flat_placement_types.h"
2121
#include "cluster_util.h"
2222
#include "physical_types.h"
2323
#include "place_macro.h"

vpr/src/base/vpr_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <vector>
66
#include <mutex>
77

8-
#include "FlatPlacementInfo.h"
8+
#include "flat_placement_types.h"
99
#include "physical_types.h"
1010
#include "place_macro.h"
1111
#include "user_place_constraints.h"

0 commit comments

Comments
 (0)