diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index f78ea1266ff..e59429d93c5 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -1,5 +1,8 @@ #include "net_cost_handler.h" +#include "clustered_netlist_fwd.h" #include "globals.h" +#include "physical_types.h" +#include "physical_types_util.h" #include "placer_globals.h" #include "move_utils.h" #include "place_timing_update.h" @@ -55,14 +58,12 @@ static vtr::NdMatrix chanx_place_cost_fac({0, 0}); // [0...device_ctx. static vtr::NdMatrix chany_place_cost_fac({0, 0}); // [0...device_ctx.grid.height()-2] /** - * @brief Cost of a net, and a temporary cost of a net used during move assessment. + * @brief For each of the vectors in this struct, there is one entry per cluster level net: + * [0...cluster_ctx.clb_nlist.nets().size()-1]. + * net_cost and proposed_net_cost: Cost of a net, and a temporary cost of a net used during move assessment. * We also use negative cost values in proposed_net_cost as a flag to indicate that * the cost of a net has not yet been updated. - */ -static vtr::vector net_cost, proposed_net_cost; - -/** * - * @brief Flag array to indicate whether the specific bounding box has been updated + * bb_update_status: Flag array to indicate whether the specific bounding box has been updated * in this particular swap or not. If it has been updated before, the code * must use the updated data, instead of the out-of-date data passed into the * subroutine, particularly used in try_swap(). The value NOT_UPDATED_YET @@ -74,7 +75,12 @@ static vtr::vector net_cost, proposed_net_cost; * bounding box is got from scratch, so the bounding box would definitely be * right, DO NOT update again. */ -static vtr::vector bb_updated_before; // [0...cluster_ctx.clb_nlist.nets().size()-1] +struct PLNetCost { + vtr::vector net_cost; + vtr::vector proposed_net_cost; + vtr::vector bb_update_status; +}; +static struct PLNetCost pl_net_cost; /* The following arrays are used by the try_swap function for speed. */ @@ -88,14 +94,33 @@ static vtr::vector bb_updated_before; // [0...clus * layer_ts_bb_coord_new are used. */ -/* [0...cluster_ctx.clb_nlist.nets().size()-1] -> 3D bounding box*/ -static vtr::vector ts_bb_coord_new, ts_bb_edge_new; -/* [0...cluster_ctx.clb_nlist.nets().size()-1][0...num_layers-1] -> 2D bonding box on a layer*/ -static vtr::vector> layer_ts_bb_edge_new, layer_ts_bb_coord_new; -/* [0...cluster_ctx.clb_nlist.nets().size()-1][0...num_layers-1] -> number of sink pins on a layer*/ -static vtr::Matrix ts_layer_sink_pin_count; -/* [0...num_afftected_nets] -> net_id of the affected nets */ -static std::vector ts_nets_to_update; +struct TSInfo{ + /* [0...cluster_ctx.clb_nlist.nets().size()-1] -> 3D bounding box*/ + vtr::vector ts_bb_coord_new, ts_bb_edge_new; + /* [0...cluster_ctx.clb_nlist.nets().size()-1][0...num_layers-1] -> 2D bonding box on a layer*/ + vtr::vector> layer_ts_bb_edge_new, layer_ts_bb_coord_new; + /* [0...cluster_ctx.clb_nlist.nets().size()-1][0...num_layers-1] -> number of sink pins on a layer*/ + vtr::Matrix ts_layer_sink_pin_count; + /* [0...num_afftected_nets] -> net_id of the affected nets */ + std::vector ts_nets_to_update; +}; +static struct TSInfo ts_info; + +/** + * @brief This class is used to hide control flows needed to distinguish 2d and 3d placement + */ +class BB2D3DControlFlow { + bool cube_bb = false; +public: + void init(size_t num_nets, bool cube_bb); + void get_non_updatable_bb(const ClusterNetId& net); + bool is_driver(const t_physical_tile_type_ptr& blk_type, const ClusterPinId& blk_pin); + void update_bb(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, t_physical_tile_loc pin_new_loc, bool is_driver); + double get_net_cost(const ClusterNetId& net_id); + void set_ts_bb_coord(const ClusterNetId& net_id); + void set_ts_edge(const ClusterNetId& net_id); +}; +static BB2D3DControlFlow bb_2d_3d_control_flow; /** * @param net @@ -160,7 +185,7 @@ static void record_affected_net(const ClusterNetId net, int& num_affected_nets); * @param num_affected_nets A pointer to the first free element of ts_nets_to_update. If a new net is added, the pointer should be increamented. * @param is_src_moving Is the moving pin the source of a net. */ -static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm, +static void update_pl_net_cost_on_pin_move(const t_place_algorithm& place_algorithm, const PlaceDelayModel* delay_model, const PlacerCriticalities* criticalities, const ClusterBlockId& blk_id, @@ -206,26 +231,6 @@ static void get_non_updatable_bb(ClusterNetId net_id, t_bb& bb_coord_new, vtr::NdMatrixProxy num_sink_pin_layer); - -/** - * @brief Update the bounding box (per-layer) of the net connected to blk_pin. The old and new locations of the pin are - * stored in pl_moved_block. The updated bounding box will be stored in ts data structures. - * @details Finds the bounding box of a net and stores its coordinates in the bb_coord_new - * data structure. This routine should only be called for small nets, since it does not - * determine enough information for the bounding box to be updated incrementally later. - * Currently assumes channels on both sides of the CLBs forming the edges of the bounding box - * can be used. Essentially, I am assuming the pins always lie on the outside of the - * bounding box. - * @param net ID of the net for which the bounding box is requested - * @param blk ID of the moving block - * @param blk_pin ID of the pin connected to the net - * @param pl_moved_block Placement info about - */ -static void update_net_layer_bb(const ClusterNetId& net, - const ClusterBlockId& blk, - const ClusterPinId& blk_pin, - const t_pl_moved_block& pl_moved_block); - /** * @brief Calculate the per-layer bounding box of "net_id" from scratch (based on the block locations stored in place_ctx) and * store them in bb_coord_new @@ -448,7 +453,88 @@ static double wirelength_crossing_count(size_t fanout); static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c); /******************************* End of Function definitions ************************************/ +// Initialize the ts vectors +void BB2D3DControlFlow::init(size_t num_nets, bool cube_bb_in) { + const int num_layers = g_vpr_ctx.device().grid.get_num_layers(); + + cube_bb = cube_bb_in; + if (cube_bb) { + ts_info.ts_bb_edge_new.resize(num_nets, t_bb()); + ts_info.ts_bb_coord_new.resize(num_nets, t_bb()); + } else { + VTR_ASSERT_SAFE(!cube_bb); + ts_info.layer_ts_bb_edge_new.resize(num_nets, std::vector(num_layers, t_2D_bb())); + ts_info.layer_ts_bb_coord_new.resize(num_nets, std::vector(num_layers, t_2D_bb())); + } + + /*This initialize the whole matrix to OPEN which is an invalid value*/ + ts_info.ts_layer_sink_pin_count.resize({num_nets, size_t(num_layers)}, OPEN); + ts_info.ts_nets_to_update.resize(num_nets, ClusterNetId::INVALID()); +} + +void BB2D3DControlFlow::get_non_updatable_bb(const ClusterNetId& net) { + if(cube_bb) + ::get_non_updatable_bb(net, + ts_info.ts_bb_coord_new[net], + ts_info.ts_layer_sink_pin_count[size_t(net)]); + else + ::get_non_updatable_layer_bb(net, + ts_info.layer_ts_bb_coord_new[net], + ts_info.ts_layer_sink_pin_count[size_t(net)]); +} + +bool BB2D3DControlFlow::is_driver(const t_physical_tile_type_ptr& blk_type, const ClusterPinId& blk_pin) { + auto& cluster_ctx = g_vpr_ctx.clustering(); + if(cube_bb) + return cluster_ctx.clb_nlist.pin_type(blk_pin) == PinType::DRIVER; + else + return get_pin_type_from_pin_physical_num(blk_type, tile_pin_index(blk_pin)) == e_pin_type::DRIVER; +} + +void BB2D3DControlFlow::update_bb(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, t_physical_tile_loc pin_new_loc, bool is_driver) { + if (cube_bb) + ::update_bb(net_id, + ts_info.ts_bb_edge_new[net_id], + ts_info.ts_bb_coord_new[net_id], + ts_info.ts_layer_sink_pin_count[size_t(net_id)], + pin_old_loc, + pin_new_loc, + is_driver); + else + ::update_layer_bb(net_id, + ts_info.layer_ts_bb_edge_new[net_id], + ts_info.layer_ts_bb_coord_new[net_id], + ts_info.ts_layer_sink_pin_count[size_t(net_id)], + pin_old_loc, + pin_new_loc, + is_driver); +} + +double BB2D3DControlFlow::get_net_cost(const ClusterNetId& net_id) { + if(cube_bb) + return ::get_net_cost(net_id, ts_info.ts_bb_coord_new[net_id]); + else + 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)]); +} + +void BB2D3DControlFlow::set_ts_bb_coord(const ClusterNetId& net_id) { + auto& place_move_ctx = g_placer_ctx.mutable_move(); + if (cube_bb) { + place_move_ctx.bb_coords[net_id] = ts_info.ts_bb_coord_new[net_id]; + } else { + place_move_ctx.layer_bb_coords[net_id] = ts_info.layer_ts_bb_coord_new[net_id]; + } +} + +void BB2D3DControlFlow::set_ts_edge(const ClusterNetId& net_id) { + auto& place_move_ctx = g_placer_ctx.mutable_move(); + if (cube_bb) { + place_move_ctx.bb_num_on_edges[net_id] = ts_info.ts_bb_edge_new[net_id]; + } else { + place_move_ctx.layer_bb_num_on_edges[net_id] = ts_info.layer_ts_bb_edge_new[net_id]; + } +} //Returns true if 'net' is driven by one of the blocks in 'blocks_affected' static bool driven_by_moved_block(const ClusterNetId net, const int num_blocks, @@ -477,71 +563,27 @@ static void update_net_bb(const ClusterNetId& net, if (cluster_ctx.clb_nlist.net_sinks(net).size() < SMALL_NET) { //For small nets brute-force bounding box update is faster - if (bb_updated_before[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net - get_non_updatable_bb(net, - ts_bb_coord_new[net], - ts_layer_sink_pin_count[size_t(net)]); + if (pl_net_cost.bb_update_status[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net + bb_2d_3d_control_flow.get_non_updatable_bb(net); } } else { //For large nets, update bounding box incrementally int iblk_pin = tile_pin_index(blk_pin); - bool src_pin = cluster_ctx.clb_nlist.pin_type(blk_pin) == PinType::DRIVER; t_physical_tile_type_ptr blk_type = physical_tile_type(blk); int pin_width_offset = blk_type->pin_width_offset[iblk_pin]; int pin_height_offset = blk_type->pin_height_offset[iblk_pin]; + bool is_driver = bb_2d_3d_control_flow.is_driver(blk_type, blk_pin); //Incremental bounding box update - update_bb(net, - ts_bb_edge_new[net], - ts_bb_coord_new[net], - ts_layer_sink_pin_count[size_t(net)], - {pl_moved_block.old_loc.x + pin_width_offset, - pl_moved_block.old_loc.y + pin_height_offset, - pl_moved_block.old_loc.layer}, - {pl_moved_block.new_loc.x + pin_width_offset, - pl_moved_block.new_loc.y + pin_height_offset, - pl_moved_block.new_loc.layer}, - src_pin); - } -} - -static void update_net_layer_bb(const ClusterNetId& net, - const ClusterBlockId& blk, - const ClusterPinId& blk_pin, - const t_pl_moved_block& pl_moved_block) { - auto& cluster_ctx = g_vpr_ctx.clustering(); - - if (cluster_ctx.clb_nlist.net_sinks(net).size() < SMALL_NET) { - //For small nets brute-force bounding box update is faster - - if (bb_updated_before[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net - get_non_updatable_layer_bb(net, - layer_ts_bb_coord_new[net], - ts_layer_sink_pin_count[size_t(net)]); - } - } else { - //For large nets, update bounding box incrementally - int iblk_pin = tile_pin_index(blk_pin); - - t_physical_tile_type_ptr blk_type = physical_tile_type(blk); - int pin_width_offset = blk_type->pin_width_offset[iblk_pin]; - int pin_height_offset = blk_type->pin_height_offset[iblk_pin]; - - auto pin_dir = get_pin_type_from_pin_physical_num(blk_type, iblk_pin); - - //Incremental bounding box update - update_layer_bb(net, - layer_ts_bb_edge_new[net], - layer_ts_bb_coord_new[net], - ts_layer_sink_pin_count[size_t(net)], - {pl_moved_block.old_loc.x + pin_width_offset, - pl_moved_block.old_loc.y + pin_height_offset, - pl_moved_block.old_loc.layer}, - {pl_moved_block.new_loc.x + pin_width_offset, - pl_moved_block.new_loc.y + pin_height_offset, - pl_moved_block.new_loc.layer}, - pin_dir == e_pin_type::DRIVER); + bb_2d_3d_control_flow.update_bb(net, + {pl_moved_block.old_loc.x + pin_width_offset, + pl_moved_block.old_loc.y + pin_height_offset, + pl_moved_block.old_loc.layer}, + {pl_moved_block.new_loc.x + pin_width_offset, + pl_moved_block.new_loc.y + pin_height_offset, + pl_moved_block.new_loc.layer}, + is_driver); } } @@ -651,17 +693,17 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model, static void record_affected_net(const ClusterNetId net, int& num_affected_nets) { /* Record effected nets. */ - if (proposed_net_cost[net] < 0.) { + if (pl_net_cost.proposed_net_cost[net] < 0.) { /* Net not marked yet. */ - ts_nets_to_update[num_affected_nets] = net; + ts_info.ts_nets_to_update[num_affected_nets] = net; num_affected_nets++; /* Flag to say we've marked this net. */ - proposed_net_cost[net] = 1.; + pl_net_cost.proposed_net_cost[net] = 1.; } } -static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm, +static void update_pl_net_cost_on_pin_move(const t_place_algorithm& place_algorithm, const PlaceDelayModel* delay_model, const PlacerCriticalities* criticalities, const ClusterBlockId& blk_id, @@ -685,14 +727,8 @@ static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm /* Record effected nets */ record_affected_net(net_id, num_affected_nets); - const auto& cube_bb = g_vpr_ctx.placement().cube_bb; - /* Update the net bounding boxes. */ - if (cube_bb) { - update_net_bb(net_id, blk_id, pin_id, moving_blk_inf); - } else { - update_net_layer_bb(net_id, blk_id, pin_id, moving_blk_inf); - } + update_net_bb(net_id, blk_id, pin_id, moving_blk_inf); if (place_algorithm.is_timing_driven()) { /* Determine the change in connection delay and timing cost. */ @@ -875,18 +911,18 @@ static void update_bb(ClusterNetId net_id, pin_old_loc.layer_num = max(min(pin_old_loc.layer_num, device_ctx.grid.get_num_layers() - 1), 0); /* Check if the net had been updated before. */ - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { /* The net had been updated from scratch, DO NOT update again! */ return; } - vtr::NdMatrixProxy curr_num_sink_pin_layer = (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) ? place_move_ctx.num_sink_pin_layer[size_t(net_id)] : num_sink_pin_layer_new; + vtr::NdMatrixProxy curr_num_sink_pin_layer = (pl_net_cost.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) ? place_move_ctx.num_sink_pin_layer[size_t(net_id)] : num_sink_pin_layer_new; - if (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) { /* The net had NOT been updated before, could use the old values */ curr_bb_edge = &place_move_ctx.bb_num_on_edges[net_id]; curr_bb_coord = &place_move_ctx.bb_coords[net_id]; - bb_updated_before[net_id] = NetUpdateState::UPDATED_ONCE; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE; } else { /* The net had been updated before, must use the new values */ curr_bb_coord = &bb_coord_new; @@ -902,7 +938,7 @@ static void update_bb(ClusterNetId net_id, if (pin_old_loc.x == curr_bb_coord->xmax) { /* Old position at xmax. */ if (curr_bb_edge->xmax == 1) { get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new); - bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.xmax = curr_bb_edge->xmax - 1; @@ -934,7 +970,7 @@ static void update_bb(ClusterNetId net_id, if (pin_old_loc.x == curr_bb_coord->xmin) { /* Old position at xmin. */ if (curr_bb_edge->xmin == 1) { get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new); - bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.xmin = curr_bb_edge->xmin - 1; @@ -975,7 +1011,7 @@ static void update_bb(ClusterNetId net_id, if (pin_old_loc.y == curr_bb_coord->ymax) { /* Old position at ymax. */ if (curr_bb_edge->ymax == 1) { get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new); - bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.ymax = curr_bb_edge->ymax - 1; @@ -1007,7 +1043,7 @@ static void update_bb(ClusterNetId net_id, if (pin_old_loc.y == curr_bb_coord->ymin) { /* Old position at ymin. */ if (curr_bb_edge->ymin == 1) { get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new); - bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.ymin = curr_bb_edge->ymin - 1; @@ -1057,7 +1093,7 @@ static void update_bb(ClusterNetId net_id, if (pin_old_loc.layer_num == curr_bb_coord->layer_max) { if (curr_bb_edge->layer_max == 1) { get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new); - bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.layer_max = curr_bb_edge->layer_max - 1; @@ -1086,7 +1122,7 @@ static void update_bb(ClusterNetId net_id, if (pin_old_loc.layer_num == curr_bb_coord->layer_min) { if (curr_bb_edge->layer_min == 1) { get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new); - bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.layer_min = curr_bb_edge->layer_min - 1; @@ -1123,8 +1159,8 @@ static void update_bb(ClusterNetId net_id, bb_edge_new.layer_max = curr_bb_edge->layer_max; } - if (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) { - bb_updated_before[net_id] = NetUpdateState::UPDATED_ONCE; + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) { + pl_net_cost.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE; } } @@ -1145,19 +1181,19 @@ static void update_layer_bb(ClusterNetId net_id, pin_old_loc.y = max(min(pin_old_loc.y, device_ctx.grid.height() - 2), 1); //-2 for no perim channels /* Check if the net had been updated before. */ - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { /* The net had been updated from scratch, DO NOT update again! */ return; } - const vtr::NdMatrixProxy curr_layer_pin_sink_count = (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) ? place_move_ctx.num_sink_pin_layer[size_t(net_id)] : bb_pin_sink_count_new; + const vtr::NdMatrixProxy curr_layer_pin_sink_count = (pl_net_cost.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) ? place_move_ctx.num_sink_pin_layer[size_t(net_id)] : bb_pin_sink_count_new; const std::vector*curr_bb_edge, *curr_bb_coord; - if (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) { /* The net had NOT been updated before, could use the old values */ curr_bb_edge = &place_move_ctx.layer_bb_num_on_edges[net_id]; curr_bb_coord = &place_move_ctx.layer_bb_coords[net_id]; - bb_updated_before[net_id] = NetUpdateState::UPDATED_ONCE; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE; } else { /* The net had been updated before, must use the new values */ curr_bb_edge = &bb_edge_new; @@ -1199,8 +1235,8 @@ static void update_layer_bb(ClusterNetId net_id, bb_coord_new); } - if (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) { - bb_updated_before[net_id] = NetUpdateState::UPDATED_ONCE; + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) { + pl_net_cost.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE; } } @@ -1231,7 +1267,7 @@ static inline void update_bb_same_layer(ClusterNetId net_id, curr_bb_coord[layer_num].xmax, bb_edge_new[layer_num].xmax, bb_coord_new[layer_num].xmax); - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1254,7 +1290,7 @@ static inline void update_bb_same_layer(ClusterNetId net_id, curr_bb_coord[layer_num].xmin, bb_edge_new[layer_num].xmin, bb_coord_new[layer_num].xmin); - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1278,7 +1314,7 @@ static inline void update_bb_same_layer(ClusterNetId net_id, curr_bb_coord[layer_num].ymax, bb_edge_new[layer_num].ymax, bb_coord_new[layer_num].ymax); - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1301,7 +1337,7 @@ static inline void update_bb_same_layer(ClusterNetId net_id, curr_bb_coord[layer_num].ymin, bb_edge_new[layer_num].ymin, bb_coord_new[layer_num].ymin); - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1346,7 +1382,7 @@ static inline void update_bb_layer_changed(ClusterNetId net_id, curr_bb_coord[old_layer_num].xmax, bb_edge_new[old_layer_num].xmax, bb_coord_new[old_layer_num].xmax); - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } else if (x_old == curr_bb_coord[old_layer_num].xmin) { @@ -1358,7 +1394,7 @@ static inline void update_bb_layer_changed(ClusterNetId net_id, curr_bb_coord[old_layer_num].xmin, bb_edge_new[old_layer_num].xmin, bb_coord_new[old_layer_num].xmin); - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1372,7 +1408,7 @@ static inline void update_bb_layer_changed(ClusterNetId net_id, curr_bb_coord[old_layer_num].ymax, bb_edge_new[old_layer_num].ymax, bb_coord_new[old_layer_num].ymax); - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } else if (y_old == curr_bb_coord[old_layer_num].ymin) { @@ -1384,7 +1420,7 @@ static inline void update_bb_layer_changed(ClusterNetId net_id, curr_bb_coord[old_layer_num].ymin, bb_edge_new[old_layer_num].ymin, bb_coord_new[old_layer_num].ymin); - if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1424,7 +1460,7 @@ static inline void update_bb_edge(ClusterNetId net_id, bb_edge_new, bb_coord_new, bb_layer_pin_sink_count); - bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { new_num_block_on_edge = old_num_block_on_edge - 1; @@ -1838,7 +1874,7 @@ static double recompute_bb_cost() { for (auto net_id : cluster_ctx.clb_nlist.nets()) { /* for each net ... */ if (!cluster_ctx.clb_nlist.net_is_ignored(net_id)) { /* Do only if not ignored. */ /* Bounding boxes don't have to be recomputed; they're correct. */ - cost += net_cost[net_id]; + cost += pl_net_cost.net_cost[net_id]; } } @@ -1859,19 +1895,11 @@ static double wirelength_crossing_count(size_t fanout) { static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) { for (int inet_affected = 0; inet_affected < num_affected_nets; inet_affected++) { - ClusterNetId net_id = ts_nets_to_update[inet_affected]; - const auto& cube_bb = g_vpr_ctx.placement().cube_bb; - - if (cube_bb) { - proposed_net_cost[net_id] = get_net_cost(net_id, - ts_bb_coord_new[net_id]); - } else { - proposed_net_cost[net_id] = get_net_layer_bb_wire_cost(net_id, - layer_ts_bb_coord_new[net_id], - ts_layer_sink_pin_count[size_t(net_id)]); - } + ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; + + pl_net_cost.proposed_net_cost[net_id] = bb_2d_3d_control_flow.get_net_cost(net_id); - bb_delta_c += proposed_net_cost[net_id] - net_cost[net_id]; + bb_delta_c += pl_net_cost.proposed_net_cost[net_id] - pl_net_cost.net_cost[net_id]; } } @@ -1903,7 +1931,7 @@ int find_affected_nets_and_update_costs( blocks_affected.num_moved_blocks, blocks_affected.moved_blocks); } - update_net_info_on_pin_move(place_algorithm, + update_pl_net_cost_on_pin_move(place_algorithm, delay_model, criticalities, blk, @@ -1945,8 +1973,8 @@ double comp_bb_cost(e_cost_methods method) { place_move_ctx.num_sink_pin_layer[size_t(net_id)]); } - net_cost[net_id] = get_net_cost(net_id, place_move_ctx.bb_coords[net_id]); - cost += net_cost[net_id]; + pl_net_cost.net_cost[net_id] = get_net_cost(net_id, place_move_ctx.bb_coords[net_id]); + cost += pl_net_cost.net_cost[net_id]; if (method == CHECK) expected_wirelength += get_net_wirelength_estimate(net_id, place_move_ctx.bb_coords[net_id]); } @@ -1982,10 +2010,10 @@ double comp_layer_bb_cost(e_cost_methods method) { place_move_ctx.num_sink_pin_layer[size_t(net_id)]); } - net_cost[net_id] = get_net_layer_bb_wire_cost(net_id, + pl_net_cost.net_cost[net_id] = get_net_layer_bb_wire_cost(net_id, place_move_ctx.layer_bb_coords[net_id], place_move_ctx.num_sink_pin_layer[size_t(net_id)]); - cost += net_cost[net_id]; + cost += pl_net_cost.net_cost[net_id]; if (method == CHECK) expected_wirelength += get_net_wirelength_from_layer_bb(net_id, place_move_ctx.layer_bb_coords[net_id], @@ -2001,39 +2029,30 @@ double comp_layer_bb_cost(e_cost_methods method) { return cost; } -void update_move_nets(int num_nets_affected, - const bool cube_bb) { +void update_move_nets(int num_nets_affected) { /* update net cost functions and reset flags. */ auto& cluster_ctx = g_vpr_ctx.clustering(); auto& place_move_ctx = g_placer_ctx.mutable_move(); for (int inet_affected = 0; inet_affected < num_nets_affected; inet_affected++) { - ClusterNetId net_id = ts_nets_to_update[inet_affected]; + ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; - if (cube_bb) { - place_move_ctx.bb_coords[net_id] = ts_bb_coord_new[net_id]; - } else { - place_move_ctx.layer_bb_coords[net_id] = layer_ts_bb_coord_new[net_id]; - } + bb_2d_3d_control_flow.set_ts_bb_coord(net_id); for (int layer_num = 0; layer_num < g_vpr_ctx.device().grid.get_num_layers(); layer_num++) { - place_move_ctx.num_sink_pin_layer[size_t(net_id)][layer_num] = ts_layer_sink_pin_count[size_t(net_id)][layer_num]; + 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]; } if (cluster_ctx.clb_nlist.net_sinks(net_id).size() >= SMALL_NET) { - if (cube_bb) { - place_move_ctx.bb_num_on_edges[net_id] = ts_bb_edge_new[net_id]; - } else { - place_move_ctx.layer_bb_num_on_edges[net_id] = layer_ts_bb_edge_new[net_id]; - } + bb_2d_3d_control_flow.set_ts_edge(net_id); } - net_cost[net_id] = proposed_net_cost[net_id]; + pl_net_cost.net_cost[net_id] = pl_net_cost.proposed_net_cost[net_id]; /* negative proposed_net_cost value is acting as a flag to mean not computed yet. */ - proposed_net_cost[net_id] = -1; - bb_updated_before[net_id] = NetUpdateState::NOT_UPDATED_YET; + pl_net_cost.proposed_net_cost[net_id] = -1; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET; } } @@ -2041,9 +2060,9 @@ void reset_move_nets(int num_nets_affected) { /* Reset the net cost function flags first. */ for (int inet_affected = 0; inet_affected < num_nets_affected; inet_affected++) { - ClusterNetId net_id = ts_nets_to_update[inet_affected]; - proposed_net_cost[net_id] = -1; - bb_updated_before[net_id] = NetUpdateState::NOT_UPDATED_YET; + ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; + pl_net_cost.proposed_net_cost[net_id] = -1; + pl_net_cost.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET; } } @@ -2217,43 +2236,29 @@ void free_chan_w_factors_for_place_cost () { } void init_place_move_structs(size_t num_nets) { - net_cost.resize(num_nets, -1.); - proposed_net_cost.resize(num_nets, -1.); + pl_net_cost.net_cost.resize(num_nets, -1.); + pl_net_cost.proposed_net_cost.resize(num_nets, -1.); /* Used to store costs for moves not yet made and to indicate when a net's * * cost has been recomputed. proposed_net_cost[inet] < 0 means net's cost hasn't * * been recomputed. */ - bb_updated_before.resize(num_nets, NetUpdateState::NOT_UPDATED_YET); + pl_net_cost.bb_update_status.resize(num_nets, NetUpdateState::NOT_UPDATED_YET); } void free_place_move_structs() { - vtr::release_memory(net_cost); - vtr::release_memory(proposed_net_cost); - vtr::release_memory(bb_updated_before); + vtr::release_memory(pl_net_cost.net_cost); + vtr::release_memory(pl_net_cost.proposed_net_cost); + vtr::release_memory(pl_net_cost.bb_update_status); } void init_try_swap_net_cost_structs(size_t num_nets, bool cube_bb) { - const int num_layers = g_vpr_ctx.device().grid.get_num_layers(); - - if (cube_bb) { - ts_bb_edge_new.resize(num_nets, t_bb()); - ts_bb_coord_new.resize(num_nets, t_bb()); - } else { - VTR_ASSERT_SAFE(!cube_bb); - layer_ts_bb_edge_new.resize(num_nets, std::vector(num_layers, t_2D_bb())); - layer_ts_bb_coord_new.resize(num_nets, std::vector(num_layers, t_2D_bb())); - } - - /*This initialize the whole matrix to OPEN which is an invalid value*/ - ts_layer_sink_pin_count.resize({num_nets, size_t(num_layers)}, OPEN); - - ts_nets_to_update.resize(num_nets, ClusterNetId::INVALID()); + bb_2d_3d_control_flow.init(num_nets, cube_bb); } void free_try_swap_net_cost_structs() { - vtr::release_memory(ts_bb_edge_new); - vtr::release_memory(ts_bb_coord_new); - vtr::release_memory(layer_ts_bb_edge_new); - vtr::release_memory(layer_ts_bb_coord_new); - ts_layer_sink_pin_count.clear(); - vtr::release_memory(ts_nets_to_update); + vtr::release_memory(ts_info.ts_bb_edge_new); + vtr::release_memory(ts_info.ts_bb_coord_new); + vtr::release_memory(ts_info.layer_ts_bb_edge_new); + vtr::release_memory(ts_info.layer_ts_bb_coord_new); + ts_info.ts_layer_sink_pin_count.clear(); + vtr::release_memory(ts_info.ts_nets_to_update); } diff --git a/vpr/src/place/net_cost_handler.h b/vpr/src/place/net_cost_handler.h index 57c64cadca5..9815cc8baa0 100644 --- a/vpr/src/place/net_cost_handler.h +++ b/vpr/src/place/net_cost_handler.h @@ -83,10 +83,8 @@ double comp_layer_bb_cost(e_cost_methods method); /** * @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). * @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. - * @param cube_bb True if we should use the 3D bounding box (cube_bb), false otherwise. */ -void update_move_nets(int num_nets_affected, - const bool cube_bb); +void update_move_nets(int num_nets_affected); /** * @brief Reset the net cost function flags (proposed_net_cost and bb_updated_before) diff --git a/vpr/src/place/place.cpp b/vpr/src/place/place.cpp index 4e7f448c34b..61ba3807880 100644 --- a/vpr/src/place/place.cpp +++ b/vpr/src/place/place.cpp @@ -1481,8 +1481,7 @@ static e_move_result try_swap(const t_annealing_state* state, } /* Update net cost functions and reset flags. */ - update_move_nets(num_nets_affected, - g_vpr_ctx.placement().cube_bb); + update_move_nets(num_nets_affected); /* Update clb data structures since we kept the move. */ commit_move_blocks(blocks_affected);