Skip to content

Commit 1585edb

Browse files
add get_compressed_noc_grid()
1 parent e8feb3e commit 1585edb

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

vpr/src/place/initial_noc_placement.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ static void place_noc_routers_randomly(std::vector<ClusterBlockId>& unfixed_rout
5151
*/
5252
static void noc_routers_anneal(const t_noc_opts& noc_opts);
5353

54+
/**
55+
* @brief Returns the compressed grid of NoC.
56+
* @return const t_compressed_block_grid& The compressed grid of NoC.
57+
*/
58+
static const t_compressed_block_grid& get_compressed_noc_grid();
59+
60+
static const t_compressed_block_grid& get_compressed_noc_grid() {
61+
auto& noc_ctx = g_vpr_ctx.noc();
62+
auto& place_ctx = g_vpr_ctx.placement();
63+
auto& cluster_ctx = g_vpr_ctx.clustering();
64+
65+
// Get the logical block type for router
66+
const t_logical_block_type_ptr router_block_type = cluster_ctx.clb_nlist.block_type(noc_ctx.noc_traffic_flows_storage.get_router_clusters_in_netlist()[0]);
67+
68+
// Get the compressed grid for NoC
69+
const auto& compressed_noc_grid = place_ctx.compressed_block_grids[router_block_type->index];
70+
71+
return compressed_noc_grid;
72+
}
73+
5474
static bool accept_noc_swap(double delta_cost, double prob) {
5575
if (delta_cost <= 0.0) {
5676
return true;
@@ -99,7 +119,6 @@ static void place_constrained_noc_router(ClusterBlockId router_blk_id) {
99119
static void place_noc_routers_randomly(std::vector<ClusterBlockId>& unfixed_routers, int seed) {
100120
auto& place_ctx = g_vpr_ctx.placement();
101121
auto& noc_ctx = g_vpr_ctx.noc();
102-
auto& cluster_ctx = g_vpr_ctx.clustering();
103122
auto& device_ctx = g_vpr_ctx.device();
104123

105124
/*
@@ -123,15 +142,12 @@ static void place_noc_routers_randomly(std::vector<ClusterBlockId>& unfixed_rout
123142
vtr::RandState rand_state = seed;
124143
vtr::shuffle(noc_phy_routers.begin(), noc_phy_routers.end(), rand_state);
125144

126-
// Get the logical block type for router
127-
const auto router_block_type = cluster_ctx.clb_nlist.block_type(noc_ctx.noc_traffic_flows_storage.get_router_clusters_in_netlist()[0]);
128-
129145
// Get the compressed grid for NoC
130-
const auto& compressed_noc_grid = place_ctx.compressed_block_grids[router_block_type->index];
146+
const auto& compressed_noc_grid = get_compressed_noc_grid();
131147

132148
// Iterate over shuffled physical routers to place logical routers
133149
// Since physical routers are shuffled, router placement would be random
134-
for (const auto& phy_router : noc_phy_routers) {
150+
for (const NocRouter& phy_router : noc_phy_routers) {
135151
t_physical_tile_loc router_phy_loc = phy_router.get_router_physical_location();
136152

137153
// Find a compatible sub-tile
@@ -143,7 +159,7 @@ static void place_noc_routers_randomly(std::vector<ClusterBlockId>& unfixed_rout
143159

144160
if (place_ctx.grid_blocks.is_sub_tile_empty(router_phy_loc, sub_tile)) {
145161
// Pick one of the unplaced routers
146-
auto logical_router_bid = unfixed_routers.back();
162+
ClusterBlockId logical_router_bid = unfixed_routers.back();
147163
unfixed_routers.pop_back();
148164

149165
// Create a macro with a single member
@@ -179,11 +195,16 @@ static void noc_routers_anneal(const t_noc_opts& noc_opts) {
179195
update_noc_normalization_factors(costs);
180196
costs.cost = calculate_noc_cost(costs.noc_cost_terms, costs.noc_cost_norm_factors, noc_opts);
181197

182-
// Maximum distance in each direction that a router can travel in a move
183-
// It is assumed that NoC routers are organized in a square grid.
184-
// Each router can initially move within the entire grid with a single swap.
198+
const auto& compressed_noc_grid = get_compressed_noc_grid();
199+
const size_t n_noc_layers = compressed_noc_grid.get_layer_nums().size();
200+
201+
/* Maximum distance in each direction that a router can travel in a move
202+
* It is assumed that NoC routers are organized in a square grid.
203+
* Each router can initially move within the entire grid with a single swap.
204+
* For 3D NoCs, it is assumed that each layer has the same number of routers,
205+
* and each layer NoC routers are laid out in a square grid. */
185206
const size_t n_physical_routers = noc_ctx.noc_model.get_noc_routers().size();
186-
const float max_r_lim = ceilf(sqrtf((float)n_physical_routers));
207+
const float max_r_lim = ceilf(sqrtf((float)n_physical_routers / (float)n_noc_layers));
187208

188209
// At most, two routers are swapped
189210
t_pl_blocks_to_be_moved blocks_affected(2);
@@ -266,7 +287,7 @@ void initial_noc_placement(const t_noc_opts& noc_opts, const t_placer_opts& plac
266287
std::vector<ClusterBlockId> unfixed_routers;
267288

268289
// Check for floorplanning constraints and place constrained NoC routers
269-
for (auto router_blk_id : router_blk_ids) {
290+
for (const ClusterBlockId router_blk_id : router_blk_ids) {
270291
// The block is fixed and was placed in mark_fixed_blocks()
271292
if (is_block_placed((router_blk_id))) {
272293
continue;

vpr/src/place/move_utils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ bool find_to_loc_uniform(t_logical_block_type_ptr type,
743743
t_physical_tile_loc to_compressed_loc;
744744
bool legal = false;
745745

746-
//TODO: constraints should be adapted to 3D architecture
747746
if (is_cluster_constrained(b_from)) {
748747
bool intersect = intersect_range_limit_with_floorplan_constraints(b_from,
749748
search_range,
@@ -1137,7 +1136,7 @@ std::vector<t_physical_tile_loc> get_compressed_loc(const t_compressed_block_gri
11371136

11381137
const auto& compatible_layers = compressed_block_grid.get_layer_nums();
11391138

1140-
for (const auto& layer_num : compatible_layers) {
1139+
for (const int layer_num : compatible_layers) {
11411140
// This would cause a problem if two blocks of the same types are on different x/y locations of different layers
11421141
compressed_locs[layer_num] = compressed_block_grid.grid_loc_to_compressed_loc({grid_loc.x, grid_loc.y, layer_num});
11431142
}
@@ -1152,7 +1151,7 @@ std::vector<t_physical_tile_loc> get_compressed_loc_approx(const t_compressed_bl
11521151

11531152
const auto& compatible_layers = compressed_block_grid.get_layer_nums();
11541153

1155-
for (const auto& layer_num : compatible_layers) {
1154+
for (const int layer_num : compatible_layers) {
11561155
compressed_locs[layer_num] = compressed_block_grid.grid_loc_to_compressed_loc_approx({grid_loc.x, grid_loc.y, layer_num});
11571156
}
11581157

vpr/src/place/noc_place_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ static bool select_random_router_cluster(ClusterBlockId& b_from, t_pl_loc& from,
804804
return false;
805805
}
806806

807-
const int number_of_router_blocks = router_clusters.size();
807+
const int number_of_router_blocks = static_cast<int>(router_clusters.size());
808808

809809
//randomly choose a router block to move
810810
const int random_cluster_block_index = vtr::irand(number_of_router_blocks - 1);

0 commit comments

Comments
 (0)