Skip to content

Commit d2ca437

Browse files
author
Yulang Luo
committed
[vpr][place] addressing pull request commemts
1 parent fa065b4 commit d2ca437

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "clustered_netlist_fwd.h"
2828
#include "globals.h"
2929
#include "physical_types.h"
30-
#include "physical_types_util.h"
3130
#include "placer_globals.h"
3231
#include "move_utils.h"
3332
#include "place_timing_update.h"
@@ -82,6 +81,7 @@ static const float cross_count[MAX_FANOUT_CROSSING_COUNT] = {/* [0..49] */ 1.0,
8281
static vtr::NdMatrix<float, 2> chanx_place_cost_fac({0, 0}); // [0...device_ctx.grid.width()-2]
8382
static vtr::NdMatrix<float, 2> chany_place_cost_fac({0, 0}); // [0...device_ctx.grid.height()-2]
8483

84+
namespace {
8585
/**
8686
* @brief For each of the vectors in this struct, there is one entry per cluster level net:
8787
* [0...cluster_ctx.clb_nlist.nets().size()-1].
@@ -105,16 +105,13 @@ struct PLNetCost {
105105
vtr::vector<ClusterNetId, double> proposed_net_cost;
106106
vtr::vector<ClusterNetId, NetUpdateState> bb_update_status;
107107
};
108-
static struct PLNetCost pl_net_cost;
109108

110109
/* The following arrays are used by the try_swap function for speed. */
111110

112111
/**
113-
* The wire length estimation is based on the bounding box of the net. In the case of the 2D architecture,
112+
* @brief The wire length estimation is based on the bounding box of the net. In the case of the 2D architecture,
114113
* we use a 3D BB with the z-dimension (layer) set to 1. In the case of 3D architecture, there 2 types of bounding box:
115114
* 3D and per-layer. The type is determined at the beginning of the placement and stored in the placement context.
116-
*
117-
*
118115
* If the bonding box is of the type 3D, ts_bb_coord_new and ts_bb_edge_new are used. Otherwise, layer_ts_bb_edge_new and
119116
* layer_ts_bb_coord_new are used.
120117
*/
@@ -129,12 +126,11 @@ struct TSInfo {
129126
/* [0...num_afftected_nets] -> net_id of the affected nets */
130127
std::vector<ClusterNetId> ts_nets_to_update;
131128
};
132-
static struct TSInfo ts_info;
133129

134130
/**
135131
* @brief This class is used to hide control flows needed to distinguish 2d and 3d placement
136132
*/
137-
class BB2D3DControlFlow {
133+
class BBUpdater {
138134
bool cube_bb = false;
139135

140136
public:
@@ -146,7 +142,13 @@ class BB2D3DControlFlow {
146142
void set_ts_bb_coord(const ClusterNetId& net_id);
147143
void set_ts_edge(const ClusterNetId& net_id);
148144
};
149-
static BB2D3DControlFlow bb_2d_3d_control_flow;
145+
} // namespace
146+
147+
static struct PLNetCost pl_net_cost;
148+
149+
static struct TSInfo ts_info;
150+
151+
static BBUpdater bb_updater;
150152

151153
/**
152154
* @param net
@@ -478,27 +480,28 @@ static double wirelength_crossing_count(size_t fanout);
478480
static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c);
479481

480482
/******************************* End of Function definitions ************************************/
483+
namespace {
481484
// Initialize the ts vectors
482-
void BB2D3DControlFlow::init(size_t num_nets, bool cube_bb_in) {
485+
void BBUpdater::init(size_t num_nets, bool cube_bb_in) {
483486
const int num_layers = g_vpr_ctx.device().grid.get_num_layers();
484487

485488
cube_bb = cube_bb_in;
489+
// Either 3D BB or per layer BB data structure are used, not both.
486490
if (cube_bb) {
487491
ts_info.ts_bb_edge_new.resize(num_nets, t_bb());
488492
ts_info.ts_bb_coord_new.resize(num_nets, t_bb());
489493
} else {
490-
VTR_ASSERT_SAFE(!cube_bb);
491494
ts_info.layer_ts_bb_edge_new.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
492495
ts_info.layer_ts_bb_coord_new.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
493496
}
494497

495-
/*This initialize the whole matrix to OPEN which is an invalid value*/
498+
/* This initializes the whole matrix to OPEN which is an invalid value*/
496499
ts_info.ts_layer_sink_pin_count.resize({num_nets, size_t(num_layers)}, OPEN);
497500

498501
ts_info.ts_nets_to_update.resize(num_nets, ClusterNetId::INVALID());
499502
}
500503

501-
void BB2D3DControlFlow::get_non_updatable_bb(const ClusterNetId& net) {
504+
void BBUpdater::get_non_updatable_bb(const ClusterNetId& net) {
502505
if (cube_bb)
503506
::get_non_updatable_bb(net,
504507
ts_info.ts_bb_coord_new[net],
@@ -509,15 +512,7 @@ void BB2D3DControlFlow::get_non_updatable_bb(const ClusterNetId& net) {
509512
ts_info.ts_layer_sink_pin_count[size_t(net)]);
510513
}
511514

512-
bool BB2D3DControlFlow::is_driver(const t_physical_tile_type_ptr& blk_type, const ClusterPinId& blk_pin) {
513-
auto& cluster_ctx = g_vpr_ctx.clustering();
514-
if (cube_bb)
515-
return cluster_ctx.clb_nlist.pin_type(blk_pin) == PinType::DRIVER;
516-
else
517-
return get_pin_type_from_pin_physical_num(blk_type, tile_pin_index(blk_pin)) == e_pin_type::DRIVER;
518-
}
519-
520-
void BB2D3DControlFlow::update_bb(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, t_physical_tile_loc pin_new_loc, bool is_driver) {
515+
void BBUpdater::update_bb(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, t_physical_tile_loc pin_new_loc, bool is_driver) {
521516
if (cube_bb)
522517
::update_bb(net_id,
523518
ts_info.ts_bb_edge_new[net_id],
@@ -536,14 +531,14 @@ void BB2D3DControlFlow::update_bb(ClusterNetId net_id, t_physical_tile_loc pin_o
536531
is_driver);
537532
}
538533

539-
double BB2D3DControlFlow::get_net_cost(const ClusterNetId& net_id) {
534+
double BBUpdater::get_net_cost(const ClusterNetId& net_id) {
540535
if (cube_bb)
541536
return ::get_net_cost(net_id, ts_info.ts_bb_coord_new[net_id]);
542537
else
543538
return ::get_net_layer_bb_wire_cost(net_id, ts_info.layer_ts_bb_coord_new[net_id], ts_info.ts_layer_sink_pin_count[size_t(net_id)]);
544539
}
545540

546-
void BB2D3DControlFlow::set_ts_bb_coord(const ClusterNetId& net_id) {
541+
void BBUpdater::set_ts_bb_coord(const ClusterNetId& net_id) {
547542
auto& place_move_ctx = g_placer_ctx.mutable_move();
548543
if (cube_bb) {
549544
place_move_ctx.bb_coords[net_id] = ts_info.ts_bb_coord_new[net_id];
@@ -552,14 +547,16 @@ void BB2D3DControlFlow::set_ts_bb_coord(const ClusterNetId& net_id) {
552547
}
553548
}
554549

555-
void BB2D3DControlFlow::set_ts_edge(const ClusterNetId& net_id) {
550+
void BBUpdater::set_ts_edge(const ClusterNetId& net_id) {
556551
auto& place_move_ctx = g_placer_ctx.mutable_move();
557552
if (cube_bb) {
558553
place_move_ctx.bb_num_on_edges[net_id] = ts_info.ts_bb_edge_new[net_id];
559554
} else {
560555
place_move_ctx.layer_bb_num_on_edges[net_id] = ts_info.layer_ts_bb_edge_new[net_id];
561556
}
562557
}
558+
} // namespace
559+
563560
//Returns true if 'net' is driven by one of the blocks in 'blocks_affected'
564561
static bool driven_by_moved_block(const ClusterNetId net,
565562
const int num_blocks,
@@ -589,7 +586,7 @@ static void update_net_bb(const ClusterNetId& net,
589586
//For small nets brute-force bounding box update is faster
590587

591588
if (pl_net_cost.bb_update_status[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net
592-
bb_2d_3d_control_flow.get_non_updatable_bb(net);
589+
bb_updater.get_non_updatable_bb(net);
593590
}
594591
} else {
595592
//For large nets, update bounding box incrementally
@@ -598,17 +595,17 @@ static void update_net_bb(const ClusterNetId& net,
598595
t_physical_tile_type_ptr blk_type = physical_tile_type(blk);
599596
int pin_width_offset = blk_type->pin_width_offset[iblk_pin];
600597
int pin_height_offset = blk_type->pin_height_offset[iblk_pin];
601-
bool is_driver = bb_2d_3d_control_flow.is_driver(blk_type, blk_pin);
598+
bool is_driver = cluster_ctx.clb_nlist.pin_type(blk_pin) == PinType::DRIVER;
602599

603600
//Incremental bounding box update
604-
bb_2d_3d_control_flow.update_bb(net,
605-
{pl_moved_block.old_loc.x + pin_width_offset,
606-
pl_moved_block.old_loc.y + pin_height_offset,
607-
pl_moved_block.old_loc.layer},
608-
{pl_moved_block.new_loc.x + pin_width_offset,
609-
pl_moved_block.new_loc.y + pin_height_offset,
610-
pl_moved_block.new_loc.layer},
611-
is_driver);
601+
bb_updater.update_bb(net,
602+
{pl_moved_block.old_loc.x + pin_width_offset,
603+
pl_moved_block.old_loc.y + pin_height_offset,
604+
pl_moved_block.old_loc.layer},
605+
{pl_moved_block.new_loc.x + pin_width_offset,
606+
pl_moved_block.new_loc.y + pin_height_offset,
607+
pl_moved_block.new_loc.layer},
608+
is_driver);
612609
}
613610
}
614611

@@ -1905,7 +1902,7 @@ static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) {
19051902
inet_affected++) {
19061903
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
19071904

1908-
pl_net_cost.proposed_net_cost[net_id] = bb_2d_3d_control_flow.get_net_cost(net_id);
1905+
pl_net_cost.proposed_net_cost[net_id] = bb_updater.get_net_cost(net_id);
19091906

19101907
bb_delta_c += pl_net_cost.proposed_net_cost[net_id] - pl_net_cost.net_cost[net_id];
19111908
}
@@ -2046,14 +2043,14 @@ void update_move_nets(int num_nets_affected) {
20462043
inet_affected++) {
20472044
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
20482045

2049-
bb_2d_3d_control_flow.set_ts_bb_coord(net_id);
2046+
bb_updater.set_ts_bb_coord(net_id);
20502047

20512048
for (int layer_num = 0; layer_num < g_vpr_ctx.device().grid.get_num_layers(); layer_num++) {
20522049
place_move_ctx.num_sink_pin_layer[size_t(net_id)][layer_num] = ts_info.ts_layer_sink_pin_count[size_t(net_id)][layer_num];
20532050
}
20542051

20552052
if (cluster_ctx.clb_nlist.net_sinks(net_id).size() >= SMALL_NET) {
2056-
bb_2d_3d_control_flow.set_ts_edge(net_id);
2053+
bb_updater.set_ts_edge(net_id);
20572054
}
20582055

20592056
pl_net_cost.net_cost[net_id] = pl_net_cost.proposed_net_cost[net_id];
@@ -2259,7 +2256,7 @@ void free_place_move_structs() {
22592256
}
22602257

22612258
void init_try_swap_net_cost_structs(size_t num_nets, bool cube_bb) {
2262-
bb_2d_3d_control_flow.init(num_nets, cube_bb);
2259+
bb_updater.init(num_nets, cube_bb);
22632260
}
22642261

22652262
void free_try_swap_net_cost_structs() {

0 commit comments

Comments
 (0)