Skip to content

Commit 6843921

Browse files
author
Yulang Luo
committed
[vpr][placer] creating ts struct and hiding 2d 3d control flow in class
1 parent 38c6a85 commit 6843921

File tree

3 files changed

+141
-142
lines changed

3 files changed

+141
-142
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 139 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "net_cost_handler.h"
2+
#include "clustered_netlist_fwd.h"
23
#include "globals.h"
4+
#include "physical_types.h"
5+
#include "physical_types_util.h"
36
#include "placer_globals.h"
47
#include "move_utils.h"
58
#include "place_timing_update.h"
@@ -91,14 +94,33 @@ static struct PLNetCost pl_net_cost;
9194
* layer_ts_bb_coord_new are used.
9295
*/
9396

94-
/* [0...cluster_ctx.clb_nlist.nets().size()-1] -> 3D bounding box*/
95-
static vtr::vector<ClusterNetId, t_bb> ts_bb_coord_new, ts_bb_edge_new;
96-
/* [0...cluster_ctx.clb_nlist.nets().size()-1][0...num_layers-1] -> 2D bonding box on a layer*/
97-
static vtr::vector<ClusterNetId, std::vector<t_2D_bb>> layer_ts_bb_edge_new, layer_ts_bb_coord_new;
98-
/* [0...cluster_ctx.clb_nlist.nets().size()-1][0...num_layers-1] -> number of sink pins on a layer*/
99-
static vtr::Matrix<int> ts_layer_sink_pin_count;
100-
/* [0...num_afftected_nets] -> net_id of the affected nets */
101-
static std::vector<ClusterNetId> ts_nets_to_update;
97+
struct TSInfo{
98+
/* [0...cluster_ctx.clb_nlist.nets().size()-1] -> 3D bounding box*/
99+
vtr::vector<ClusterNetId, t_bb> ts_bb_coord_new, ts_bb_edge_new;
100+
/* [0...cluster_ctx.clb_nlist.nets().size()-1][0...num_layers-1] -> 2D bonding box on a layer*/
101+
vtr::vector<ClusterNetId, std::vector<t_2D_bb>> layer_ts_bb_edge_new, layer_ts_bb_coord_new;
102+
/* [0...cluster_ctx.clb_nlist.nets().size()-1][0...num_layers-1] -> number of sink pins on a layer*/
103+
vtr::Matrix<int> ts_layer_sink_pin_count;
104+
/* [0...num_afftected_nets] -> net_id of the affected nets */
105+
std::vector<ClusterNetId> ts_nets_to_update;
106+
};
107+
static struct TSInfo ts_info;
108+
109+
/**
110+
* @brief This class is used to hide control flows needed to distinguish 2d and 3d placement
111+
*/
112+
class BB2D3DControlFlow {
113+
bool cube_bb = false;
114+
public:
115+
void init(size_t num_nets, bool cube_bb);
116+
void get_non_updatable_bb(const ClusterNetId& net);
117+
bool is_driver(const t_physical_tile_type_ptr& blk_type, const ClusterPinId& blk_pin);
118+
void update_bb(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, t_physical_tile_loc pin_new_loc, bool is_driver);
119+
double get_net_cost(const ClusterNetId& net_id);
120+
void set_ts_bb_coord(const ClusterNetId& net_id);
121+
void set_ts_edge(const ClusterNetId& net_id);
122+
};
123+
static BB2D3DControlFlow bb_2d_3d_control_flow;
102124

103125
/**
104126
* @param net
@@ -209,26 +231,6 @@ static void get_non_updatable_bb(ClusterNetId net_id,
209231
t_bb& bb_coord_new,
210232
vtr::NdMatrixProxy<int, 1> num_sink_pin_layer);
211233

212-
213-
/**
214-
* @brief Update the bounding box (per-layer) of the net connected to blk_pin. The old and new locations of the pin are
215-
* stored in pl_moved_block. The updated bounding box will be stored in ts data structures.
216-
* @details Finds the bounding box of a net and stores its coordinates in the bb_coord_new
217-
* data structure. This routine should only be called for small nets, since it does not
218-
* determine enough information for the bounding box to be updated incrementally later.
219-
* Currently assumes channels on both sides of the CLBs forming the edges of the bounding box
220-
* can be used. Essentially, I am assuming the pins always lie on the outside of the
221-
* bounding box.
222-
* @param net ID of the net for which the bounding box is requested
223-
* @param blk ID of the moving block
224-
* @param blk_pin ID of the pin connected to the net
225-
* @param pl_moved_block Placement info about
226-
*/
227-
static void update_net_layer_bb(const ClusterNetId& net,
228-
const ClusterBlockId& blk,
229-
const ClusterPinId& blk_pin,
230-
const t_pl_moved_block& pl_moved_block);
231-
232234
/**
233235
* @brief Calculate the per-layer bounding box of "net_id" from scratch (based on the block locations stored in place_ctx) and
234236
* store them in bb_coord_new
@@ -451,7 +453,88 @@ static double wirelength_crossing_count(size_t fanout);
451453
static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c);
452454

453455
/******************************* End of Function definitions ************************************/
456+
// Initialize the ts vectors
457+
void BB2D3DControlFlow::init(size_t num_nets, bool cube_bb_in) {
458+
const int num_layers = g_vpr_ctx.device().grid.get_num_layers();
454459

460+
cube_bb = cube_bb_in;
461+
if (cube_bb) {
462+
ts_info.ts_bb_edge_new.resize(num_nets, t_bb());
463+
ts_info.ts_bb_coord_new.resize(num_nets, t_bb());
464+
} else {
465+
VTR_ASSERT_SAFE(!cube_bb);
466+
ts_info.layer_ts_bb_edge_new.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
467+
ts_info.layer_ts_bb_coord_new.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
468+
}
469+
470+
/*This initialize the whole matrix to OPEN which is an invalid value*/
471+
ts_info.ts_layer_sink_pin_count.resize({num_nets, size_t(num_layers)}, OPEN);
472+
473+
ts_info.ts_nets_to_update.resize(num_nets, ClusterNetId::INVALID());
474+
}
475+
476+
void BB2D3DControlFlow::get_non_updatable_bb(const ClusterNetId& net) {
477+
if(cube_bb)
478+
::get_non_updatable_bb(net,
479+
ts_info.ts_bb_coord_new[net],
480+
ts_info.ts_layer_sink_pin_count[size_t(net)]);
481+
else
482+
::get_non_updatable_layer_bb(net,
483+
ts_info.layer_ts_bb_coord_new[net],
484+
ts_info.ts_layer_sink_pin_count[size_t(net)]);
485+
}
486+
487+
bool BB2D3DControlFlow::is_driver(const t_physical_tile_type_ptr& blk_type, const ClusterPinId& blk_pin) {
488+
auto& cluster_ctx = g_vpr_ctx.clustering();
489+
if(cube_bb)
490+
return cluster_ctx.clb_nlist.pin_type(blk_pin) == PinType::DRIVER;
491+
else
492+
return get_pin_type_from_pin_physical_num(blk_type, tile_pin_index(blk_pin)) == e_pin_type::DRIVER;
493+
}
494+
495+
void BB2D3DControlFlow::update_bb(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, t_physical_tile_loc pin_new_loc, bool is_driver) {
496+
if (cube_bb)
497+
::update_bb(net_id,
498+
ts_info.ts_bb_edge_new[net_id],
499+
ts_info.ts_bb_coord_new[net_id],
500+
ts_info.ts_layer_sink_pin_count[size_t(net_id)],
501+
pin_old_loc,
502+
pin_new_loc,
503+
is_driver);
504+
else
505+
::update_layer_bb(net_id,
506+
ts_info.layer_ts_bb_edge_new[net_id],
507+
ts_info.layer_ts_bb_coord_new[net_id],
508+
ts_info.ts_layer_sink_pin_count[size_t(net_id)],
509+
pin_old_loc,
510+
pin_new_loc,
511+
is_driver);
512+
}
513+
514+
double BB2D3DControlFlow::get_net_cost(const ClusterNetId& net_id) {
515+
if(cube_bb)
516+
return ::get_net_cost(net_id, ts_info.ts_bb_coord_new[net_id]);
517+
else
518+
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)]);
519+
}
520+
521+
void BB2D3DControlFlow::set_ts_bb_coord(const ClusterNetId& net_id) {
522+
auto& place_move_ctx = g_placer_ctx.mutable_move();
523+
if (cube_bb) {
524+
place_move_ctx.bb_coords[net_id] = ts_info.ts_bb_coord_new[net_id];
525+
} else {
526+
place_move_ctx.layer_bb_coords[net_id] = ts_info.layer_ts_bb_coord_new[net_id];
527+
}
528+
}
529+
530+
void BB2D3DControlFlow::set_ts_edge(const ClusterNetId& net_id) {
531+
auto& place_move_ctx = g_placer_ctx.mutable_move();
532+
if (cube_bb) {
533+
place_move_ctx.bb_num_on_edges[net_id] = ts_info.ts_bb_edge_new[net_id];
534+
} else {
535+
place_move_ctx.layer_bb_num_on_edges[net_id] = ts_info.layer_ts_bb_edge_new[net_id];
536+
}
537+
}
455538
//Returns true if 'net' is driven by one of the blocks in 'blocks_affected'
456539
static bool driven_by_moved_block(const ClusterNetId net,
457540
const int num_blocks,
@@ -481,70 +564,26 @@ static void update_net_bb(const ClusterNetId& net,
481564
//For small nets brute-force bounding box update is faster
482565

483566
if (pl_net_cost.bb_update_status[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net
484-
get_non_updatable_bb(net,
485-
ts_bb_coord_new[net],
486-
ts_layer_sink_pin_count[size_t(net)]);
567+
bb_2d_3d_control_flow.get_non_updatable_bb(net);
487568
}
488569
} else {
489570
//For large nets, update bounding box incrementally
490571
int iblk_pin = tile_pin_index(blk_pin);
491-
bool src_pin = cluster_ctx.clb_nlist.pin_type(blk_pin) == PinType::DRIVER;
492572

493573
t_physical_tile_type_ptr blk_type = physical_tile_type(blk);
494574
int pin_width_offset = blk_type->pin_width_offset[iblk_pin];
495575
int pin_height_offset = blk_type->pin_height_offset[iblk_pin];
576+
bool is_driver = bb_2d_3d_control_flow.is_driver(blk_type, blk_pin);
496577

497578
//Incremental bounding box update
498-
update_bb(net,
499-
ts_bb_edge_new[net],
500-
ts_bb_coord_new[net],
501-
ts_layer_sink_pin_count[size_t(net)],
502-
{pl_moved_block.old_loc.x + pin_width_offset,
503-
pl_moved_block.old_loc.y + pin_height_offset,
504-
pl_moved_block.old_loc.layer},
505-
{pl_moved_block.new_loc.x + pin_width_offset,
506-
pl_moved_block.new_loc.y + pin_height_offset,
507-
pl_moved_block.new_loc.layer},
508-
src_pin);
509-
}
510-
}
511-
512-
static void update_net_layer_bb(const ClusterNetId& net,
513-
const ClusterBlockId& blk,
514-
const ClusterPinId& blk_pin,
515-
const t_pl_moved_block& pl_moved_block) {
516-
auto& cluster_ctx = g_vpr_ctx.clustering();
517-
518-
if (cluster_ctx.clb_nlist.net_sinks(net).size() < SMALL_NET) {
519-
//For small nets brute-force bounding box update is faster
520-
521-
if (pl_net_cost.bb_update_status[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net
522-
get_non_updatable_layer_bb(net,
523-
layer_ts_bb_coord_new[net],
524-
ts_layer_sink_pin_count[size_t(net)]);
525-
}
526-
} else {
527-
//For large nets, update bounding box incrementally
528-
int iblk_pin = tile_pin_index(blk_pin);
529-
530-
t_physical_tile_type_ptr blk_type = physical_tile_type(blk);
531-
int pin_width_offset = blk_type->pin_width_offset[iblk_pin];
532-
int pin_height_offset = blk_type->pin_height_offset[iblk_pin];
533-
534-
auto pin_dir = get_pin_type_from_pin_physical_num(blk_type, iblk_pin);
535-
536-
//Incremental bounding box update
537-
update_layer_bb(net,
538-
layer_ts_bb_edge_new[net],
539-
layer_ts_bb_coord_new[net],
540-
ts_layer_sink_pin_count[size_t(net)],
541-
{pl_moved_block.old_loc.x + pin_width_offset,
542-
pl_moved_block.old_loc.y + pin_height_offset,
543-
pl_moved_block.old_loc.layer},
544-
{pl_moved_block.new_loc.x + pin_width_offset,
545-
pl_moved_block.new_loc.y + pin_height_offset,
546-
pl_moved_block.new_loc.layer},
547-
pin_dir == e_pin_type::DRIVER);
579+
bb_2d_3d_control_flow.update_bb(net,
580+
{pl_moved_block.old_loc.x + pin_width_offset,
581+
pl_moved_block.old_loc.y + pin_height_offset,
582+
pl_moved_block.old_loc.layer},
583+
{pl_moved_block.new_loc.x + pin_width_offset,
584+
pl_moved_block.new_loc.y + pin_height_offset,
585+
pl_moved_block.new_loc.layer},
586+
is_driver);
548587
}
549588
}
550589

@@ -656,7 +695,7 @@ static void record_affected_net(const ClusterNetId net,
656695
/* Record effected nets. */
657696
if (pl_net_cost.proposed_net_cost[net] < 0.) {
658697
/* Net not marked yet. */
659-
ts_nets_to_update[num_affected_nets] = net;
698+
ts_info.ts_nets_to_update[num_affected_nets] = net;
660699
num_affected_nets++;
661700

662701
/* Flag to say we've marked this net. */
@@ -688,14 +727,8 @@ static void update_pl_net_cost_on_pin_move(const t_place_algorithm& place_algori
688727
/* Record effected nets */
689728
record_affected_net(net_id, num_affected_nets);
690729

691-
const auto& cube_bb = g_vpr_ctx.placement().cube_bb;
692-
693730
/* Update the net bounding boxes. */
694-
if (cube_bb) {
695-
update_net_bb(net_id, blk_id, pin_id, moving_blk_inf);
696-
} else {
697-
update_net_layer_bb(net_id, blk_id, pin_id, moving_blk_inf);
698-
}
731+
update_net_bb(net_id, blk_id, pin_id, moving_blk_inf);
699732

700733
if (place_algorithm.is_timing_driven()) {
701734
/* Determine the change in connection delay and timing cost. */
@@ -1862,17 +1895,9 @@ static double wirelength_crossing_count(size_t fanout) {
18621895
static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) {
18631896
for (int inet_affected = 0; inet_affected < num_affected_nets;
18641897
inet_affected++) {
1865-
ClusterNetId net_id = ts_nets_to_update[inet_affected];
1866-
const auto& cube_bb = g_vpr_ctx.placement().cube_bb;
1867-
1868-
if (cube_bb) {
1869-
pl_net_cost.proposed_net_cost[net_id] = get_net_cost(net_id,
1870-
ts_bb_coord_new[net_id]);
1871-
} else {
1872-
pl_net_cost.proposed_net_cost[net_id] = get_net_layer_bb_wire_cost(net_id,
1873-
layer_ts_bb_coord_new[net_id],
1874-
ts_layer_sink_pin_count[size_t(net_id)]);
1875-
}
1898+
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
1899+
1900+
pl_net_cost.proposed_net_cost[net_id] = bb_2d_3d_control_flow.get_net_cost(net_id);
18761901

18771902
bb_delta_c += pl_net_cost.proposed_net_cost[net_id] - pl_net_cost.net_cost[net_id];
18781903
}
@@ -2004,32 +2029,23 @@ double comp_layer_bb_cost(e_cost_methods method) {
20042029
return cost;
20052030
}
20062031

2007-
void update_move_nets(int num_nets_affected,
2008-
const bool cube_bb) {
2032+
void update_move_nets(int num_nets_affected) {
20092033
/* update net cost functions and reset flags. */
20102034
auto& cluster_ctx = g_vpr_ctx.clustering();
20112035
auto& place_move_ctx = g_placer_ctx.mutable_move();
20122036

20132037
for (int inet_affected = 0; inet_affected < num_nets_affected;
20142038
inet_affected++) {
2015-
ClusterNetId net_id = ts_nets_to_update[inet_affected];
2039+
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
20162040

2017-
if (cube_bb) {
2018-
place_move_ctx.bb_coords[net_id] = ts_bb_coord_new[net_id];
2019-
} else {
2020-
place_move_ctx.layer_bb_coords[net_id] = layer_ts_bb_coord_new[net_id];
2021-
}
2041+
bb_2d_3d_control_flow.set_ts_bb_coord(net_id);
20222042

20232043
for (int layer_num = 0; layer_num < g_vpr_ctx.device().grid.get_num_layers(); layer_num++) {
2024-
place_move_ctx.num_sink_pin_layer[size_t(net_id)][layer_num] = ts_layer_sink_pin_count[size_t(net_id)][layer_num];
2044+
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];
20252045
}
20262046

20272047
if (cluster_ctx.clb_nlist.net_sinks(net_id).size() >= SMALL_NET) {
2028-
if (cube_bb) {
2029-
place_move_ctx.bb_num_on_edges[net_id] = ts_bb_edge_new[net_id];
2030-
} else {
2031-
place_move_ctx.layer_bb_num_on_edges[net_id] = layer_ts_bb_edge_new[net_id];
2032-
}
2048+
bb_2d_3d_control_flow.set_ts_edge(net_id);
20332049
}
20342050

20352051
pl_net_cost.net_cost[net_id] = pl_net_cost.proposed_net_cost[net_id];
@@ -2044,7 +2060,7 @@ void reset_move_nets(int num_nets_affected) {
20442060
/* Reset the net cost function flags first. */
20452061
for (int inet_affected = 0; inet_affected < num_nets_affected;
20462062
inet_affected++) {
2047-
ClusterNetId net_id = ts_nets_to_update[inet_affected];
2063+
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
20482064
pl_net_cost.proposed_net_cost[net_id] = -1;
20492065
pl_net_cost.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET;
20502066
}
@@ -2235,28 +2251,14 @@ void free_place_move_structs() {
22352251
}
22362252

22372253
void init_try_swap_net_cost_structs(size_t num_nets, bool cube_bb) {
2238-
const int num_layers = g_vpr_ctx.device().grid.get_num_layers();
2239-
2240-
if (cube_bb) {
2241-
ts_bb_edge_new.resize(num_nets, t_bb());
2242-
ts_bb_coord_new.resize(num_nets, t_bb());
2243-
} else {
2244-
VTR_ASSERT_SAFE(!cube_bb);
2245-
layer_ts_bb_edge_new.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
2246-
layer_ts_bb_coord_new.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
2247-
}
2248-
2249-
/*This initialize the whole matrix to OPEN which is an invalid value*/
2250-
ts_layer_sink_pin_count.resize({num_nets, size_t(num_layers)}, OPEN);
2251-
2252-
ts_nets_to_update.resize(num_nets, ClusterNetId::INVALID());
2254+
bb_2d_3d_control_flow.init(num_nets, cube_bb);
22532255
}
22542256

22552257
void free_try_swap_net_cost_structs() {
2256-
vtr::release_memory(ts_bb_edge_new);
2257-
vtr::release_memory(ts_bb_coord_new);
2258-
vtr::release_memory(layer_ts_bb_edge_new);
2259-
vtr::release_memory(layer_ts_bb_coord_new);
2260-
ts_layer_sink_pin_count.clear();
2261-
vtr::release_memory(ts_nets_to_update);
2258+
vtr::release_memory(ts_info.ts_bb_edge_new);
2259+
vtr::release_memory(ts_info.ts_bb_coord_new);
2260+
vtr::release_memory(ts_info.layer_ts_bb_edge_new);
2261+
vtr::release_memory(ts_info.layer_ts_bb_coord_new);
2262+
ts_info.ts_layer_sink_pin_count.clear();
2263+
vtr::release_memory(ts_info.ts_nets_to_update);
22622264
}

vpr/src/place/net_cost_handler.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ double comp_layer_bb_cost(e_cost_methods method);
8383
/**
8484
* @brief update net cost data structures (in placer context and net_cost in .cpp file) and reset flags (proposed_net_cost and bb_updated_before).
8585
* @param num_nets_affected The number of nets affected by the move. It is used to determine the index up to which elements in ts_nets_to_update are valid.
86-
* @param cube_bb True if we should use the 3D bounding box (cube_bb), false otherwise.
8786
*/
88-
void update_move_nets(int num_nets_affected,
89-
const bool cube_bb);
87+
void update_move_nets(int num_nets_affected);
9088

9189
/**
9290
* @brief Reset the net cost function flags (proposed_net_cost and bb_updated_before)

vpr/src/place/place.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,8 +1481,7 @@ static e_move_result try_swap(const t_annealing_state* state,
14811481
}
14821482

14831483
/* Update net cost functions and reset flags. */
1484-
update_move_nets(num_nets_affected,
1485-
g_vpr_ctx.placement().cube_bb);
1484+
update_move_nets(num_nets_affected);
14861485

14871486
/* Update clb data structures since we kept the move. */
14881487
commit_move_blocks(blocks_affected);

0 commit comments

Comments
 (0)