1
1
#include " net_cost_handler.h"
2
+ #include " clustered_netlist_fwd.h"
2
3
#include " globals.h"
4
+ #include " physical_types.h"
5
+ #include " physical_types_util.h"
3
6
#include " placer_globals.h"
4
7
#include " move_utils.h"
5
8
#include " place_timing_update.h"
@@ -91,14 +94,33 @@ static struct PLNetCost pl_net_cost;
91
94
* layer_ts_bb_coord_new are used.
92
95
*/
93
96
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;
102
124
103
125
/* *
104
126
* @param net
@@ -209,26 +231,6 @@ static void get_non_updatable_bb(ClusterNetId net_id,
209
231
t_bb& bb_coord_new,
210
232
vtr::NdMatrixProxy<int , 1 > num_sink_pin_layer);
211
233
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
-
232
234
/* *
233
235
* @brief Calculate the per-layer bounding box of "net_id" from scratch (based on the block locations stored in place_ctx) and
234
236
* store them in bb_coord_new
@@ -451,7 +453,88 @@ static double wirelength_crossing_count(size_t fanout);
451
453
static void set_bb_delta_cost (const int num_affected_nets, double & bb_delta_c);
452
454
453
455
/* ****************************** 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 ();
454
459
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
+ }
455
538
// Returns true if 'net' is driven by one of the blocks in 'blocks_affected'
456
539
static bool driven_by_moved_block (const ClusterNetId net,
457
540
const int num_blocks,
@@ -481,70 +564,26 @@ static void update_net_bb(const ClusterNetId& net,
481
564
// For small nets brute-force bounding box update is faster
482
565
483
566
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);
487
568
}
488
569
} else {
489
570
// For large nets, update bounding box incrementally
490
571
int iblk_pin = tile_pin_index (blk_pin);
491
- bool src_pin = cluster_ctx.clb_nlist .pin_type (blk_pin) == PinType::DRIVER;
492
572
493
573
t_physical_tile_type_ptr blk_type = physical_tile_type (blk);
494
574
int pin_width_offset = blk_type->pin_width_offset [iblk_pin];
495
575
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);
496
577
497
578
// 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);
548
587
}
549
588
}
550
589
@@ -656,7 +695,7 @@ static void record_affected_net(const ClusterNetId net,
656
695
/* Record effected nets. */
657
696
if (pl_net_cost.proposed_net_cost [net] < 0 .) {
658
697
/* Net not marked yet. */
659
- ts_nets_to_update[num_affected_nets] = net;
698
+ ts_info. ts_nets_to_update [num_affected_nets] = net;
660
699
num_affected_nets++;
661
700
662
701
/* 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
688
727
/* Record effected nets */
689
728
record_affected_net (net_id, num_affected_nets);
690
729
691
- const auto & cube_bb = g_vpr_ctx.placement ().cube_bb ;
692
-
693
730
/* 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);
699
732
700
733
if (place_algorithm.is_timing_driven ()) {
701
734
/* Determine the change in connection delay and timing cost. */
@@ -1862,17 +1895,9 @@ static double wirelength_crossing_count(size_t fanout) {
1862
1895
static void set_bb_delta_cost (const int num_affected_nets, double & bb_delta_c) {
1863
1896
for (int inet_affected = 0 ; inet_affected < num_affected_nets;
1864
1897
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);
1876
1901
1877
1902
bb_delta_c += pl_net_cost.proposed_net_cost [net_id] - pl_net_cost.net_cost [net_id];
1878
1903
}
@@ -2004,32 +2029,23 @@ double comp_layer_bb_cost(e_cost_methods method) {
2004
2029
return cost;
2005
2030
}
2006
2031
2007
- void update_move_nets (int num_nets_affected,
2008
- const bool cube_bb) {
2032
+ void update_move_nets (int num_nets_affected) {
2009
2033
/* update net cost functions and reset flags. */
2010
2034
auto & cluster_ctx = g_vpr_ctx.clustering ();
2011
2035
auto & place_move_ctx = g_placer_ctx.mutable_move ();
2012
2036
2013
2037
for (int inet_affected = 0 ; inet_affected < num_nets_affected;
2014
2038
inet_affected++) {
2015
- ClusterNetId net_id = ts_nets_to_update[inet_affected];
2039
+ ClusterNetId net_id = ts_info. ts_nets_to_update [inet_affected];
2016
2040
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);
2022
2042
2023
2043
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];
2025
2045
}
2026
2046
2027
2047
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);
2033
2049
}
2034
2050
2035
2051
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) {
2044
2060
/* Reset the net cost function flags first. */
2045
2061
for (int inet_affected = 0 ; inet_affected < num_nets_affected;
2046
2062
inet_affected++) {
2047
- ClusterNetId net_id = ts_nets_to_update[inet_affected];
2063
+ ClusterNetId net_id = ts_info. ts_nets_to_update [inet_affected];
2048
2064
pl_net_cost.proposed_net_cost [net_id] = -1 ;
2049
2065
pl_net_cost.bb_update_status [net_id] = NetUpdateState::NOT_UPDATED_YET;
2050
2066
}
@@ -2235,28 +2251,14 @@ void free_place_move_structs() {
2235
2251
}
2236
2252
2237
2253
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);
2253
2255
}
2254
2256
2255
2257
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 );
2262
2264
}
0 commit comments