Skip to content

Commit 8349c44

Browse files
add RoutingChanUtilEstimator class
When the placement was read from a file, NetCostHandler was never read, and channel util estimate was never computed. RoutingChanUtilEstimator computes BBs in the routing stage and calculates channel utilization there
1 parent 23f7763 commit 8349c44

File tree

7 files changed

+66
-35
lines changed

7 files changed

+66
-35
lines changed

vpr/src/base/vpr_api.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ void vpr_load_placement(t_vpr_setup& vpr_setup,
903903
auto& blk_loc_registry = place_ctx.mutable_blk_loc_registry();
904904
const auto& filename_opts = vpr_setup.FileNameOpts;
905905

906-
//Initialize the block location registry, which will be filled when loading placement
906+
// Initialize the block location registry, which will be filled when loading placement
907907
blk_loc_registry.init();
908908

909909
// Alloc and load the placement macros.
@@ -913,13 +913,12 @@ void vpr_load_placement(t_vpr_setup& vpr_setup,
913913
g_vpr_ctx.atom().netlist(),
914914
g_vpr_ctx.atom().lookup());
915915

916-
//Load an existing placement from a file
916+
// Load an existing placement from a file
917917
place_ctx.placement_id = read_place(filename_opts.NetFile.c_str(), filename_opts.PlaceFile.c_str(),
918918
blk_loc_registry,
919919
filename_opts.verify_file_digests, device_ctx.grid);
920920

921-
// Verify that the placement invariants are met after reading the placement
922-
// from a file.
921+
// Verify that the placement invariants are met after reading the placement from a file.
923922
unsigned num_errors = verify_placement(g_vpr_ctx);
924923
if (num_errors == 0) {
925924
VTR_LOG("Completed placement consistency check successfully.\n");

vpr/src/base/vpr_context.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,18 +554,11 @@ struct RoutingContext : public Context {
554554
RouterLookahead>
555555
cached_router_lookahead_;
556556

557-
/**
558-
* @brief User specified routing constraints
559-
*/
557+
/// @brief User specified routing constraints
560558
UserRouteConstraints constraints;
561559

562560
/** Is flat routing enabled? */
563561
bool is_flat;
564-
565-
/// @brief Post-placement estimate of CHANX routing utilization per (layer, x, y) location.
566-
vtr::NdMatrix<double, 3> chanx_util;
567-
/// @brief Post-placement estimate of CHANY routing utilization per (layer, x, y) location.
568-
vtr::NdMatrix<double, 3> chany_util;
569562
};
570563

571564
/**

vpr/src/place/net_cost_handler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,15 @@ void NetCostHandler::update_net_info_on_pin_move_(const PlaceDelayModel* delay_m
461461
return;
462462
}
463463

464-
/* Record effected nets */
464+
// Record effected nets
465465
record_affected_net_(net_id);
466466

467467
ClusterBlockId blk_id = moving_blk_inf.block_num;
468-
/* Update the net bounding boxes. */
468+
// Update the net bounding boxes.
469469
update_net_bb_(net_id, blk_id, pin_id, moving_blk_inf);
470470

471471
if (placer_opts_.place_algorithm.is_timing_driven()) {
472-
/* Determine the change in connection delay and timing cost. */
472+
// Determine the change in connection delay and timing cost.
473473
update_td_delta_costs_(delay_model,
474474
*criticalities,
475475
net_id,

vpr/src/place/placer.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void Placer::place() {
311311

312312
// Outer loop of the simulated annealing ends
313313
} while (annealer_->outer_loop_update_state());
314-
} //skip_anneal ends
314+
} // skip_anneal ends
315315

316316
// Start Quench
317317
annealer_->start_quench();
@@ -378,7 +378,6 @@ void Placer::place() {
378378

379379
void Placer::update_global_state() {
380380
auto& mutable_palce_ctx = g_vpr_ctx.mutable_placement();
381-
auto& mutable_routing_ctx = g_vpr_ctx.mutable_routing();
382381

383382
// the placement location variables should be unlocked before being accessed
384383
mutable_palce_ctx.unlock_loc_vars();
@@ -387,11 +386,6 @@ void Placer::update_global_state() {
387386
auto& global_blk_loc_registry = mutable_palce_ctx.mutable_blk_loc_registry();
388387
global_blk_loc_registry = placer_state_.blk_loc_registry();
389388

390-
auto [chanx_util, chany_util] = net_cost_handler_.estimate_routing_chan_util();
391-
392-
mutable_routing_ctx.chanx_util = std::move(chanx_util);
393-
mutable_routing_ctx.chany_util = std::move(chany_util);
394-
395389
#ifndef NO_GRAPHICS
396390
// update the graphics' reference to placement location variables
397391
get_draw_state_vars()->set_graphics_blk_loc_registry_ref(global_blk_loc_registry);

vpr/src/route/route_common.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "physical_types_util.h"
1010
#include "route_export.h"
1111
#include "vpr_utils.h"
12+
#include "route_utilization.h"
1213

1314
#if defined(VPR_USE_TBB)
1415
#include <tbb/parallel_for_each.h>
@@ -79,10 +80,15 @@ static bool classes_in_same_block(ParentBlockId blk_id, int first_class_ptc_num,
7980
* @param route_opts Contains channel utilization threshold and weighting factor
8081
* used to increase initial 'acc_cost' for nodes going through
8182
* congested channels.
83+
* @param chanx_util Post-placement estimate of CHANX routing utilization per (layer, x, y) location.
84+
* @param chany_util Post-placement estimate of CHANY routing utilization per (layer, x, y) location.
8285
* @return Initial `acc_cost` for the given RR node.
8386
*/
87+
8488
static float comp_initial_acc_cost(RRNodeId node_id,
85-
const t_router_opts& route_opts);
89+
const t_router_opts& route_opts,
90+
const vtr::NdMatrix<double, 3>& chanx_util,
91+
const vtr::NdMatrix<double, 3>& chany_util);
8692

8793
/************************** Subroutine definitions ***************************/
8894

@@ -430,7 +436,9 @@ void alloc_and_load_rr_node_route_structs(const t_router_opts& router_opts) {
430436
}
431437

432438
static float comp_initial_acc_cost(RRNodeId node_id,
433-
const t_router_opts& route_opts) {
439+
const t_router_opts& route_opts,
440+
const vtr::NdMatrix<double, 3>& chanx_util,
441+
const vtr::NdMatrix<double, 3>& chany_util) {
434442
const auto& route_ctx = g_vpr_ctx.routing();
435443
const auto& rr_graph = g_vpr_ctx.device().rr_graph;
436444

@@ -444,23 +452,22 @@ static float comp_initial_acc_cost(RRNodeId node_id,
444452
const double weight = route_opts.initial_acc_cost_chan_congestion_weight;
445453

446454
// TODO: We don't have an explicit CHANZ type. These wires are marked as CHANX. This should be fixed.
447-
if (is_chan(rr_type) && !route_ctx.chanx_util.empty()) {
448-
VTR_ASSERT_SAFE(!route_ctx.chany_util.empty());
455+
if (is_chan(rr_type)) {
449456
double max_util = 0.;
450457

451458
if (rr_type == e_rr_type::CHANX) {
452459
int y = rr_graph.node_ylow(node_id);
453460
int layer = rr_graph.node_layer(node_id);
454461
for (int x = rr_graph.node_xlow(node_id); x <= rr_graph.node_xhigh(node_id); x++) {
455-
max_util = std::max(max_util, route_ctx.chanx_util[layer][x][y]);
462+
max_util = std::max(max_util, chanx_util[layer][x][y]);
456463
}
457464

458465
} else {
459466
VTR_ASSERT_SAFE(rr_type == e_rr_type::CHANY);
460467
int x = rr_graph.node_xlow(node_id);
461468
int layer = rr_graph.node_layer(node_id);
462469
for (int y = rr_graph.node_ylow(node_id); y <= rr_graph.node_yhigh(node_id); y++) {
463-
max_util = std::max(max_util, route_ctx.chany_util[layer][x][y]);
470+
max_util = std::max(max_util, chany_util[layer][x][y]);
464471
}
465472
}
466473

@@ -475,14 +482,19 @@ void reset_rr_node_route_structs(const t_router_opts& route_opts) {
475482

476483
auto& route_ctx = g_vpr_ctx.mutable_routing();
477484
const auto& device_ctx = g_vpr_ctx.device();
485+
const auto& blk_loc_registry = g_vpr_ctx.placement().blk_loc_registry();
486+
const bool cube_bb = g_vpr_ctx.placement().cube_bb;
478487

479488
VTR_ASSERT(route_ctx.rr_node_route_inf.size() == size_t(device_ctx.rr_graph.num_nodes()));
480489

490+
RoutingChanUtilEstimator routing_chan_util_estimator(blk_loc_registry, cube_bb);
491+
const auto [chanx_util, chany_util] = routing_chan_util_estimator.estimate_routing_chan_util();
492+
481493
for (const RRNodeId rr_id : device_ctx.rr_graph.nodes()) {
482494
t_rr_node_route_inf& node_inf = route_ctx.rr_node_route_inf[rr_id];
483495

484496
node_inf.prev_edge = RREdgeId::INVALID();
485-
node_inf.acc_cost = comp_initial_acc_cost(rr_id, route_opts);
497+
node_inf.acc_cost = comp_initial_acc_cost(rr_id, route_opts, chanx_util, chany_util);
486498
node_inf.path_cost = std::numeric_limits<float>::infinity();
487499
node_inf.backward_path_cost = std::numeric_limits<float>::infinity();
488500
node_inf.set_occ(0);

vpr/src/route/route_utilization.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
#include "vpr_utils.h"
66
#include "route_common.h"
77

8+
RoutingChanUtilEstimator::RoutingChanUtilEstimator(const BlkLocRegistry& blk_loc_registry, bool cube_bb) {
9+
placer_state_ = std::make_unique<PlacerState>(/*placement_is_timing_driven=*/false);
10+
placer_state_->mutable_blk_loc_registry() = blk_loc_registry;
11+
12+
placer_opts_.place_algorithm = e_place_algorithm::BOUNDING_BOX_PLACE;
13+
net_cost_handler_ = std::make_unique<NetCostHandler>(placer_opts_, *placer_state_, cube_bb);
14+
}
15+
16+
std::pair<vtr::NdMatrix<double, 3>, vtr::NdMatrix<double, 3>> RoutingChanUtilEstimator::estimate_routing_chan_util() {
17+
// Compute net bounding boxes
18+
net_cost_handler_->comp_bb_cost(e_cost_methods::NORMAL);
19+
20+
// Estimate routing channel utilization using
21+
return net_cost_handler_->estimate_routing_chan_util();
22+
}
23+
824
vtr::Matrix<float> calculate_routing_usage(e_rr_type rr_type, bool is_flat, bool is_print) {
925
VTR_ASSERT(rr_type == e_rr_type::CHANX || rr_type == e_rr_type::CHANY);
1026

@@ -15,21 +31,21 @@ vtr::Matrix<float> calculate_routing_usage(e_rr_type rr_type, bool is_flat, bool
1531

1632
vtr::Matrix<float> usage({{device_ctx.grid.width(), device_ctx.grid.height()}}, 0.);
1733

18-
//Collect all the in-use RR nodes
34+
// Collect all the in-use RR nodes
1935
std::set<RRNodeId> rr_nodes;
20-
for (auto net : cluster_ctx.clb_nlist.nets()) {
21-
auto parent_id = get_cluster_net_parent_id(g_vpr_ctx.atom().lookup(), net, is_flat);
36+
for (ClusterNetId net : cluster_ctx.clb_nlist.nets()) {
37+
ParentNetId parent_id = get_cluster_net_parent_id(g_vpr_ctx.atom().lookup(), net, is_flat);
2238

2339
if (!route_ctx.route_trees[parent_id])
2440
continue;
25-
for (auto& rt_node : route_ctx.route_trees[parent_id].value().all_nodes()) {
41+
for (const RouteTreeNode& rt_node : route_ctx.route_trees[parent_id].value().all_nodes()) {
2642
if (rr_graph.node_type(rt_node.inode) == rr_type) {
2743
rr_nodes.insert(rt_node.inode);
2844
}
2945
}
3046
}
3147

32-
//Record number of used resources in each x/y channel
48+
// Record number of used resources in each x/y channel
3349
for (RRNodeId rr_node : rr_nodes) {
3450
#ifndef NO_GRAPHICS
3551
if (!is_print) {
@@ -66,7 +82,7 @@ vtr::Matrix<float> calculate_routing_usage(e_rr_type rr_type, bool is_flat, bool
6682
}
6783

6884
vtr::Matrix<float> calculate_routing_avail(e_rr_type rr_type) {
69-
//Calculate the number of available resources in each x/y channel
85+
// Calculate the number of available resources in each x/y channel
7086
VTR_ASSERT(rr_type == e_rr_type::CHANX || rr_type == e_rr_type::CHANY);
7187

7288
auto& device_ctx = g_vpr_ctx.device();

vpr/src/route/route_utilization.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
#include "rr_node_types.h"
44
#include "vtr_ndmatrix.h"
55

6+
#include "net_cost_handler.h"
7+
#include "placer_state.h"
8+
9+
class RoutingChanUtilEstimator {
10+
public:
11+
RoutingChanUtilEstimator(const BlkLocRegistry& blk_loc_registry, bool cube_bb);
12+
13+
std::pair<vtr::NdMatrix<double, 3>, vtr::NdMatrix<double, 3>> estimate_routing_chan_util();
14+
15+
private:
16+
std::unique_ptr<PlacerState> placer_state_;
17+
std::unique_ptr<NetCostHandler> net_cost_handler_;
18+
t_placer_opts placer_opts_;
19+
20+
};
21+
622
vtr::Matrix<float> calculate_routing_avail(e_rr_type rr_type);
723

824
/**
@@ -15,4 +31,5 @@ vtr::Matrix<float> calculate_routing_avail(e_rr_type rr_type);
1531
* drawing settings.
1632
*/
1733
vtr::Matrix<float> calculate_routing_usage(e_rr_type rr_type, bool is_flat, bool is_print);
34+
1835
float routing_util(float used, float avail);

0 commit comments

Comments
 (0)