From 1a21e0775683c5b0f1fdba5afeb9f305c8b3e453 Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Sat, 13 Jul 2024 15:21:48 -0400 Subject: [PATCH 01/11] [vpr][place] refactoring variables in net_cost_handler inet_cost, proposed_net_cost, and bb_updated_before grouped in a struct. bb_updated_before renamed to bb_update_status. --- vpr/src/place/net_cost_handler.cpp | 283 +++++++++++++++-------------- 1 file changed, 142 insertions(+), 141 deletions(-) diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index ad0f643ceb4..ed42365eea8 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -1,26 +1,26 @@ /** * @file net_cost_handler.cpp * @brief This file contains the implementation of functions used to update placement cost when a new move is proposed/committed. - * - * VPR placement cost consists of three terms which represent wirelength, timing, and NoC cost. - * - * To get an estimation of the wirelength of each net, the Half Perimeter Wire Length (HPWL) approach is used. In this approach, - * half of the perimeter of the bounding box which contains all terminals of the net is multiplied by a correction factor, - * and the resulting number is considered as an estimation of the bounding box. - * - * Currently, we have two types of bounding boxes: 3D bounding box (or Cube BB) and per-layer bounding box. - * If the FPGA grid is a 2D structure, a Cube bounding box is used, which will always have the z direction equal to 1. For 3D architectures, - * the user can specify the type of bounding box. If no type is specified, the RR graph is analyzed. If all inter-die connections happen from OPINs, - * the Cube bounding box is chosen; otherwise, the per-layer bounding box is chosen. In the Cube bounding box, when a net is stretched across multiple layers, - * the edges of the bounding box are determined by all of the blocks on all layers. - * When the per-layer bounding box is used, a separate bounding box for each layer is created, and the wirelength estimation for each layer is calculated. - * To get the total wirelength of a net, the wirelength estimation on all layers is summed up. For more details, please refer to Amin Mohaghegh's MASc thesis. - * - * For timing estimation, the placement delay model is used. For 2D architectures, you can think of the placement delay model as a 2D array indexed by dx and dy. - * To get a delay estimation of a connection (from a source to a sink), first, dx and dy between these two points should be calculated, - * and these two numbers are the indices to access this 2D array. By default, the placement delay model is created by iterating over the router lookahead + * + * VPR placement cost consists of three terms which represent wirelength, timing, and NoC cost. + * + * To get an estimation of the wirelength of each net, the Half Perimeter Wire Length (HPWL) approach is used. In this approach, + * half of the perimeter of the bounding box which contains all terminals of the net is multiplied by a correction factor, + * and the resulting number is considered as an estimation of the bounding box. + * + * Currently, we have two types of bounding boxes: 3D bounding box (or Cube BB) and per-layer bounding box. + * If the FPGA grid is a 2D structure, a Cube bounding box is used, which will always have the z direction equal to 1. For 3D architectures, + * the user can specify the type of bounding box. If no type is specified, the RR graph is analyzed. If all inter-die connections happen from OPINs, + * the Cube bounding box is chosen; otherwise, the per-layer bounding box is chosen. In the Cube bounding box, when a net is stretched across multiple layers, + * the edges of the bounding box are determined by all of the blocks on all layers. + * When the per-layer bounding box is used, a separate bounding box for each layer is created, and the wirelength estimation for each layer is calculated. + * To get the total wirelength of a net, the wirelength estimation on all layers is summed up. For more details, please refer to Amin Mohaghegh's MASc thesis. + * + * For timing estimation, the placement delay model is used. For 2D architectures, you can think of the placement delay model as a 2D array indexed by dx and dy. + * To get a delay estimation of a connection (from a source to a sink), first, dx and dy between these two points should be calculated, + * and these two numbers are the indices to access this 2D array. By default, the placement delay model is created by iterating over the router lookahead * to get the minimum cost for each dx and dy. - * + * * @date July 12, 2024 */ #include "net_cost_handler.h" @@ -35,8 +35,8 @@ using std::max; using std::min; /** - * @brief for the states of the bounding box. - * Stored as char for memory efficiency. + * @brief for the states of the bounding box. + * Stored as char for memory efficiency. */ enum class NetUpdateState { NOT_UPDATED_YET, @@ -44,19 +44,19 @@ enum class NetUpdateState { GOT_FROM_SCRATCH }; -/** - * @brief The error tolerance due to round off for the total cost computation. - * When we check it from scratch vs. incrementally. 0.01 means that there is a 1% error tolerance. +/** + * @brief The error tolerance due to round off for the total cost computation. + * When we check it from scratch vs. incrementally. 0.01 means that there is a 1% error tolerance. */ #define ERROR_TOL .01 const int MAX_FANOUT_CROSSING_COUNT = 50; -/** - * @brief Crossing counts for nets with different #'s of pins. From - * ICCAD 94 pp. 690 - 695 (with linear interpolation applied by me). - * Multiplied to bounding box of a net to better estimate wire length - * for higher fanout nets. Each entry is the correction factor for the +/** + * @brief Crossing counts for nets with different #'s of pins. From + * ICCAD 94 pp. 690 - 695 (with linear interpolation applied by me). + * Multiplied to bounding box of a net to better estimate wire length + * for higher fanout nets. Each entry is the correction factor for the * fanout index-1 */ static const float cross_count[MAX_FANOUT_CROSSING_COUNT] = {/* [0..49] */ 1.0, 1.0, 1.0, 1.0828, @@ -67,39 +67,40 @@ static const float cross_count[MAX_FANOUT_CROSSING_COUNT] = {/* [0..49] */ 1.0, 2.5610, 2.5864, 2.6117, 2.6371, 2.6625, 2.6887, 2.7148, 2.7410, 2.7671, 2.7933}; -/** - * @brief Matrices below are used to precompute the inverse of the average - * number of tracks per channel between [subhigh] and [sublow]. Access - * them as chan?_place_cost_fac[subhigh][sublow]. They are used to - * speed up the computation of the cost function that takes the length - * of the net bounding box in each dimension, divided by the average - * number of tracks in that direction; for other cost functions they - * will never be used. +/** + * @brief Matrices below are used to precompute the inverse of the average + * number of tracks per channel between [subhigh] and [sublow]. Access + * them as chan?_place_cost_fac[subhigh][sublow]. They are used to + * speed up the computation of the cost function that takes the length + * of the net bounding box in each dimension, divided by the average + * number of tracks in that direction; for other cost functions they + * will never be used. */ static vtr::NdMatrix chanx_place_cost_fac({0, 0}); // [0...device_ctx.grid.width()-2] 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. - * We also use negative cost values in proposed_net_cost as a flag to indicate that + * @brief For the first two element in the struct: 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 - * 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 - * indicates that the net has not been updated before, UPDATED_ONCE indicated + * For the last one element in the struct: 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 + * indicates that the net has not been updated before, UPDATED_ONCE indicated * that the net has been updated once, if it is going to be updated again, the - * values from the previous update must be used. GOT_FROM_SCRATCH is only - * applicable for nets larger than SMALL_NETS and it indicates that the + * values from the previous update must be used. GOT_FROM_SCRATCH is only + * applicable for nets larger than SMALL_NETS and it indicates that the * particular bounding box is not incrementally updated, and hence the * bounding box is got from scratch, so the bounding box would definitely be - * right, DO NOT update again. + * right, DO NOT update again. */ -static vtr::vector bb_updated_before; // [0...cluster_ctx.clb_nlist.nets().size()-1] +struct NetInfo { + vtr::vector net_cost; + vtr::vector proposed_net_cost; + vtr::vector bb_update_status; // [0...cluster_ctx.clb_nlist.nets().size()-1] +} NetInfo; +static struct NetInfo net_info; /* The following arrays are used by the try_swap function for speed. */ @@ -132,7 +133,7 @@ static bool driven_by_moved_block(const ClusterNetId net, const std::vector& moved_blocks); /** * @brief Update the bounding box (3D) 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. Do not update the net + * stored in pl_moved_block. The updated bounding box will be stored in ts data structures. Do not update the net * cost here since it should only be updated once per net, not once per pin. * @param net * @param blk @@ -146,7 +147,7 @@ static void update_net_bb(const ClusterNetId& net, /** * @brief Calculate the new connection delay and timing cost of all the - * sink pins affected by moving a specific pin to a new location. Also + * sink pins affected by moving a specific pin to a new location. Also * calculates the total change in the timing cost. * @param delay_model * @param criticalities @@ -195,16 +196,16 @@ static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm double& timing_delta_c, int& num_affected_nets, bool is_src_moving); - + /** * @brief Update the 3D bounding box of "net_id" incrementally based on the old and new locations of a pin on that net - * @details Updates the bounding box of a net by storing its coordinates in the bb_coord_new data structure and the - * number of blocks on each edge in the bb_edge_new data structure. This routine should only be called for large nets, - * since it has some overhead relative to just doing a brute force bounding box calculation. The bounding box coordinate - * and edge information for inet must be valid before this routine is called. 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. The x and y coordinates are the pin's x and y coordinates. IO blocks are considered to be one - * cell in for simplicity. + * @details Updates the bounding box of a net by storing its coordinates in the bb_coord_new data structure and the + * number of blocks on each edge in the bb_edge_new data structure. This routine should only be called for large nets, + * since it has some overhead relative to just doing a brute force bounding box calculation. The bounding box coordinate + * and edge information for inet must be valid before this routine is called. 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. The x and y coordinates are the pin's x and y coordinates. IO blocks are considered to be one + * cell in for simplicity. * @param bb_edge_new Number of blocks on the edges of the bounding box * @param bb_coord_new Coordinates of the bounding box * @param num_sink_pin_layer_new Number of sinks of the given net on each layer @@ -235,12 +236,12 @@ static void get_non_updatable_bb(ClusterNetId net_id, /** * @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. + * @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 @@ -265,12 +266,12 @@ static void get_non_updatable_layer_bb(ClusterNetId net_id, /** * @brief Update the per-layer bounding box of "net_id" incrementally based on the old and new locations of a pin on that net - * @details Updates the bounding box of a net by storing its coordinates in the bb_coord_new data structure and - * the number of blocks on each edge in the bb_edge_new data structure. This routine should only be called for - * large nets, since it has some overhead relative to just doing a brute force bounding box calculation. - * The bounding box coordinate and edge information for inet must be valid before this routine is called. - * 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. The x and y coordinates + * @details Updates the bounding box of a net by storing its coordinates in the bb_coord_new data structure and + * the number of blocks on each edge in the bb_edge_new data structure. This routine should only be called for + * large nets, since it has some overhead relative to just doing a brute force bounding box calculation. + * The bounding box coordinate and edge information for inet must be valid before this routine is called. + * 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. The x and y coordinates * are the pin's x and y coordinates. IO blocks are considered to be one cell in for simplicity. * @param bb_edge_new Number of blocks on the edges of the bounding box * @param bb_coord_new Coordinates of the bounding box @@ -307,11 +308,11 @@ static inline void update_bb_layer_changed(ClusterNetId net_id, vtr::NdMatrixProxy bb_pin_sink_count_new, std::vector& bb_edge_new, std::vector& bb_coord_new); - + /** * @brief Calculate the per-layer BB of a large net from scratch and update coord, edge, and num_sink_pin_layer data structures. - * @details This routine finds the bounding box of each net from scratch when the bounding box is of type per-layer (i.e. from - * only the block location information). It updates the coordinate, number of pins on each edge information, and the + * @details This routine finds the bounding box of each net from scratch when the bounding box is of type per-layer (i.e. from + * only the block location information). It updates the coordinate, number of pins on each edge information, and the * number of sinks on each layer. It should only be called when the bounding box information is not valid. * @param net_id ID of the net which the moving pin belongs to * @param coords Bounding box coordinates of the net. It is calculated in this function @@ -421,8 +422,8 @@ static void add_block_to_bb(const t_physical_tile_loc& new_pin_loc, /** * @brief Calculate the 3D BB of a large net from scratch and update coord, edge, and num_sink_pin_layer data structures. - * @details This routine finds the bounding box of each net from scratch (i.e. from only the block location information). It updates both the - * coordinate and number of pins on each edge information. It should only be called when the bounding box + * @details This routine finds the bounding box of each net from scratch (i.e. from only the block location information). It updates both the + * coordinate and number of pins on each edge information. It should only be called when the bounding box * information is not valid. * @param net_id ID of the net which the moving pin belongs to * @param coords Bounding box coordinates of the net. It is calculated in this function @@ -462,16 +463,16 @@ static double get_net_wirelength_estimate(ClusterNetId net_id, const t_bb& bb); static double recompute_bb_cost(); /** - * @brief To get the wirelength cost/est, BB perimeter is multiplied by a factor to approximately correct for the half-perimeter + * @brief To get the wirelength cost/est, BB perimeter is multiplied by a factor to approximately correct for the half-perimeter * bounding box wirelength's underestimate of wiring for nets with fanout greater than 2. * @return Multiplicative wirelength correction factor */ static double wirelength_crossing_count(size_t fanout); /** - * @brief Calculates and returns the total bb (wirelength) cost change that would result from moving the blocks + * @brief Calculates and returns the total bb (wirelength) cost change that would result from moving the blocks * indicated in the blocks_affected data structure. - * @param num_affected_nets Number of valid elements in ts_bb_coord_new + * @param num_affected_nets Number of valid elements in ts_bb_coord_new * @param bb_delta_c Cost difference after and before moving the block */ static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c); @@ -506,7 +507,7 @@ 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 + if (net_info.bb_update_status[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)]); @@ -544,7 +545,7 @@ static void update_net_layer_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 + if (net_info.bb_update_status[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)]); @@ -670,13 +671,13 @@ 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 (net_info.proposed_net_cost[net] < 0.) { /* Net not marked yet. */ ts_nets_to_update[num_affected_nets] = net; num_affected_nets++; /* Flag to say we've marked this net. */ - proposed_net_cost[net] = 1.; + net_info.proposed_net_cost[net] = 1.; } } @@ -894,19 +895,19 @@ 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 (net_info.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 = (net_info.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 (net_info.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; + net_info.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; @@ -922,7 +923,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; + net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.xmax = curr_bb_edge->xmax - 1; @@ -954,7 +955,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; + net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.xmin = curr_bb_edge->xmin - 1; @@ -995,7 +996,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; + net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.ymax = curr_bb_edge->ymax - 1; @@ -1027,7 +1028,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; + net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.ymin = curr_bb_edge->ymin - 1; @@ -1077,7 +1078,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; + net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.layer_max = curr_bb_edge->layer_max - 1; @@ -1106,7 +1107,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; + net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { bb_edge_new.layer_min = curr_bb_edge->layer_min - 1; @@ -1143,8 +1144,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 (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) { + net_info.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE; } } @@ -1165,20 +1166,20 @@ 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 (net_info.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 = (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) ? const std::vector*curr_bb_edge, *curr_bb_coord; - if (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) { + if (net_info.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; + net_info.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; @@ -1220,8 +1221,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 (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) { + net_info.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE; } } @@ -1252,7 +1253,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1275,7 +1276,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1299,7 +1300,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1322,7 +1323,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1367,7 +1368,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } else if (x_old == curr_bb_coord[old_layer_num].xmin) { @@ -1379,7 +1380,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1393,7 +1394,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } else if (y_old == curr_bb_coord[old_layer_num].ymin) { @@ -1405,7 +1406,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1445,7 +1446,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; + net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH; return; } else { new_num_block_on_edge = old_num_block_on_edge - 1; @@ -1461,7 +1462,7 @@ static void add_block_to_bb(const t_physical_tile_loc& new_pin_loc, int x_new = new_pin_loc.x; int y_new = new_pin_loc.y; - /* + /* This function is called to only update the bounding box on the new layer from a block moving to this layer from another layer. Thus, we only need to assess the effect of this new block on the edges. @@ -1774,10 +1775,10 @@ static double get_net_layer_bb_wire_cost(ClusterNetId /* net_id */, if (layer_pin_sink_count[layer_num] == 0) { continue; } - /* - adjust the bounding box half perimeter by the wirelength correction - factor based on terminal count, which is 1 for the source + the number - of sinks on this layer. + /* + adjust the bounding box half perimeter by the wirelength correction + factor based on terminal count, which is 1 for the source + the number + of sinks on this layer. */ crossing = wirelength_crossing_count(layer_pin_sink_count[layer_num] + 1); @@ -1859,7 +1860,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 += net_info.net_cost[net_id]; } } @@ -1884,15 +1885,15 @@ static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) { const auto& cube_bb = g_vpr_ctx.placement().cube_bb; if (cube_bb) { - proposed_net_cost[net_id] = get_net_cost(net_id, + net_info.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, + net_info.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)]); } - bb_delta_c += proposed_net_cost[net_id] - net_cost[net_id]; + bb_delta_c += net_info.proposed_net_cost[net_id] - net_info.net_cost[net_id]; } } @@ -1966,8 +1967,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]; + net_info.net_cost[net_id] = get_net_cost(net_id, place_move_ctx.bb_coords[net_id]); + cost += net_info.net_cost[net_id]; if (method == CHECK) expected_wirelength += get_net_wirelength_estimate(net_id, place_move_ctx.bb_coords[net_id]); } @@ -2003,10 +2004,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, + net_info.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 += net_info.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], @@ -2050,11 +2051,11 @@ void update_move_nets(int num_nets_affected, } } - net_cost[net_id] = proposed_net_cost[net_id]; + net_info.net_cost[net_id] = net_info.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; + net_info.proposed_net_cost[net_id] = -1; + net_info.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET; } } @@ -2063,8 +2064,8 @@ void reset_move_nets(int num_nets_affected) { 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; + net_info.proposed_net_cost[net_id] = -1; + net_info.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET; } } @@ -2147,9 +2148,9 @@ void alloc_and_load_chan_w_factors_for_place_cost(float place_cost_exp) { auto& device_ctx = g_vpr_ctx.device(); - /* - Access arrays below as chan?_place_cost_fac[subhigh][sublow]. Since subhigh must be greater than or - equal to sublow, we will only access the lower half of a matrix, but we allocate the whole matrix anyway + /* + Access arrays below as chan?_place_cost_fac[subhigh][sublow]. Since subhigh must be greater than or + equal to sublow, we will only access the lower half of a matrix, but we allocate the whole matrix anyway for simplicity so we can use the vtr utility matrix functions. */ @@ -2238,18 +2239,18 @@ 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.); + net_info.net_cost.resize(num_nets, -1.); + net_info.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); + net_info.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(net_info.net_cost); + vtr::release_memory(net_info.proposed_net_cost); + vtr::release_memory(net_info.bb_update_status); } void init_try_swap_net_cost_structs(size_t num_nets, bool cube_bb) { From 7986dd10d49ca0b7c314411cec45ff429d5e2a49 Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Sat, 13 Jul 2024 18:23:19 -0400 Subject: [PATCH 02/11] [vpr][place] fixing comments and better variable names --- vpr/src/place/net_cost_handler.cpp | 263 ++++++++++++++--------------- 1 file changed, 125 insertions(+), 138 deletions(-) diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index ed42365eea8..0b1af0a43cf 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -60,12 +60,12 @@ const int MAX_FANOUT_CROSSING_COUNT = 50; * fanout index-1 */ static const float cross_count[MAX_FANOUT_CROSSING_COUNT] = {/* [0..49] */ 1.0, 1.0, 1.0, 1.0828, - 1.1536, 1.2206, 1.2823, 1.3385, 1.3991, 1.4493, 1.4974, 1.5455, 1.5937, - 1.6418, 1.6899, 1.7304, 1.7709, 1.8114, 1.8519, 1.8924, 1.9288, 1.9652, - 2.0015, 2.0379, 2.0743, 2.1061, 2.1379, 2.1698, 2.2016, 2.2334, 2.2646, - 2.2958, 2.3271, 2.3583, 2.3895, 2.4187, 2.4479, 2.4772, 2.5064, 2.5356, - 2.5610, 2.5864, 2.6117, 2.6371, 2.6625, 2.6887, 2.7148, 2.7410, 2.7671, - 2.7933}; + 1.1536, 1.2206, 1.2823, 1.3385, 1.3991, 1.4493, 1.4974, 1.5455, 1.5937, + 1.6418, 1.6899, 1.7304, 1.7709, 1.8114, 1.8519, 1.8924, 1.9288, 1.9652, + 2.0015, 2.0379, 2.0743, 2.1061, 2.1379, 2.1698, 2.2016, 2.2334, 2.2646, + 2.2958, 2.3271, 2.3583, 2.3895, 2.4187, 2.4479, 2.4772, 2.5064, 2.5356, + 2.5610, 2.5864, 2.6117, 2.6371, 2.6625, 2.6887, 2.7148, 2.7410, 2.7671, + 2.7933}; /** * @brief Matrices below are used to precompute the inverse of the average @@ -80,10 +80,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 For the first two element in the struct: Cost of a net, and a temporary cost of a net used during move assessment. + * @brief For each of the vector 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. - * For the last one element in the struct: 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 @@ -95,12 +97,12 @@ static vtr::NdMatrix chany_place_cost_fac({0, 0}); // [0...device_ctx. * bounding box is got from scratch, so the bounding box would definitely be * right, DO NOT update again. */ -struct NetInfo { +struct PLNetCost { vtr::vector net_cost; vtr::vector proposed_net_cost; - vtr::vector bb_update_status; // [0...cluster_ctx.clb_nlist.nets().size()-1] -} NetInfo; -static struct NetInfo net_info; + vtr::vector bb_update_status; +}; +static struct PLNetCost pl_net_cost; /* The following arrays are used by the try_swap function for speed. */ @@ -186,16 +188,16 @@ 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, - const PlaceDelayModel* delay_model, - const PlacerCriticalities* criticalities, - const ClusterBlockId& blk_id, - const ClusterPinId& pin_id, - const t_pl_moved_block& moving_blk_inf, - std::vector& affected_pins, - double& timing_delta_c, - int& num_affected_nets, - bool is_src_moving); +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, + const ClusterPinId& pin_id, + const t_pl_moved_block& moving_blk_inf, + std::vector& affected_pins, + double& timing_delta_c, + int& num_affected_nets, + bool is_src_moving); /** * @brief Update the 3D bounding box of "net_id" incrementally based on the old and new locations of a pin on that net @@ -229,9 +231,8 @@ static void update_bb(ClusterNetId net_id, * @param num_sink_pin_layer Store the number of sink pins of "net_id" on each layer */ static void get_non_updatable_bb(ClusterNetId net_id, - t_bb& bb_coord_new, - vtr::NdMatrixProxy num_sink_pin_layer); - + 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 @@ -263,7 +264,6 @@ static void get_non_updatable_layer_bb(ClusterNetId net_id, std::vector& bb_coord_new, vtr::NdMatrixProxy num_sink_layer); - /** * @brief Update the per-layer bounding box of "net_id" incrementally based on the old and new locations of a pin on that net * @details Updates the bounding box of a net by storing its coordinates in the bb_coord_new data structure and @@ -332,8 +332,8 @@ static void get_layer_bb_from_scratch(ClusterNetId net_id, * @return Wirelength cost of the net */ static double get_net_layer_bb_wire_cost(ClusterNetId /* net_id */, - const std::vector& bb, - const vtr::NdMatrixProxy layer_pin_sink_count); + const std::vector& bb, + const vtr::NdMatrixProxy layer_pin_sink_count); /** * @brief Given the per-layer BB, calculate the wire-length estimate of the net on each layer @@ -343,8 +343,8 @@ static double get_net_layer_bb_wire_cost(ClusterNetId /* net_id */, * @return Wirelength estimate of the net */ static double get_net_wirelength_from_layer_bb(ClusterNetId /* net_id */, - const std::vector& bb, - const vtr::NdMatrixProxy layer_pin_sink_count); + const std::vector& bb, + const vtr::NdMatrixProxy layer_pin_sink_count); /** * @brief This function is called in update_layer_bb to update the net's bounding box incrementally if @@ -443,8 +443,6 @@ static void get_bb_from_scratch(ClusterNetId net_id, */ static double get_net_cost(ClusterNetId net_id, const t_bb& bb); - - /** * @brief Given the 3D BB, calculate the wire-length estimate of the net * @param net_id ID of the net which wirelength estimate is requested @@ -453,8 +451,6 @@ static double get_net_cost(ClusterNetId net_id, const t_bb& bb); */ static double get_net_wirelength_estimate(ClusterNetId net_id, const t_bb& bb); - - /** * @brief To mitigate round-off errors, every once in a while, the costs of nets are summed up from scratch. * This functions is called to do that for bb cost. It doesn't calculate the BBs from scratch, it would only add the costs again. @@ -507,7 +503,7 @@ 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 (net_info.bb_update_status[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net + if (pl_net_cost.bb_update_status[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)]); @@ -527,11 +523,11 @@ static void update_net_bb(const ClusterNetId& 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.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}, + pl_moved_block.new_loc.y + pin_height_offset, + pl_moved_block.new_loc.layer}, src_pin); } } @@ -545,7 +541,7 @@ static void update_net_layer_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 (net_info.bb_update_status[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net + if (pl_net_cost.bb_update_status[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)]); @@ -582,7 +578,6 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model, std::vector& affected_pins, double& delta_timing_cost, bool is_src_moving) { - /** * Assumes that the blocks have been moved to the proposed new locations. * Otherwise, the routine comp_td_single_connection_delay() will not be @@ -671,26 +666,26 @@ 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 (net_info.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; num_affected_nets++; /* Flag to say we've marked this net. */ - net_info.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, - const PlaceDelayModel* delay_model, - const PlacerCriticalities* criticalities, - const ClusterBlockId& blk_id, - const ClusterPinId& pin_id, - const t_pl_moved_block& moving_blk_inf, - std::vector& affected_pins, - double& timing_delta_c, - int& num_affected_nets, - bool is_src_moving) { +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, + const ClusterPinId& pin_id, + const t_pl_moved_block& moving_blk_inf, + std::vector& affected_pins, + double& timing_delta_c, + int& num_affected_nets, + bool is_src_moving) { const auto& cluster_ctx = g_vpr_ctx.clustering(); const ClusterNetId net_id = cluster_ctx.clb_nlist.pin_net(pin_id); VTR_ASSERT_SAFE_MSG(net_id, @@ -727,8 +722,8 @@ static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm } static void get_non_updatable_bb(ClusterNetId net_id, - t_bb& bb_coord_new, - vtr::NdMatrixProxy num_sink_pin_layer) { + t_bb& bb_coord_new, + vtr::NdMatrixProxy num_sink_pin_layer) { //TODO: account for multiple physical pin instances per logical pin int xmax, ymax, layer_max, xmin, ymin, layer_min, x, y, layer; @@ -895,19 +890,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 (net_info.bb_update_status[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 = (net_info.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; + 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 (net_info.bb_update_status[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]; - net_info.bb_update_status[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; @@ -923,7 +917,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); - net_info.bb_update_status[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; @@ -955,7 +949,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); - net_info.bb_update_status[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; @@ -996,7 +990,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); - net_info.bb_update_status[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; @@ -1028,7 +1022,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); - net_info.bb_update_status[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; @@ -1078,7 +1072,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); - net_info.bb_update_status[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; @@ -1089,7 +1083,6 @@ static void update_bb(ClusterNetId net_id, bb_edge_new.layer_max = curr_bb_edge->layer_max; } - if (pin_new_loc.layer_num < curr_bb_coord->layer_min) { bb_coord_new.layer_min = pin_new_loc.layer_num; bb_edge_new.layer_min = 1; @@ -1102,12 +1095,10 @@ static void update_bb(ClusterNetId net_id, } } else if (pin_new_loc.layer_num > pin_old_loc.layer_num) { - - 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); - net_info.bb_update_status[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; @@ -1129,23 +1120,22 @@ static void update_bb(ClusterNetId net_id, bb_edge_new.layer_max = curr_bb_edge->layer_max; } - - } else {//pin_new_loc.layer_num == pin_old_loc.layer_num + } else { //pin_new_loc.layer_num == pin_old_loc.layer_num bb_coord_new.layer_min = curr_bb_coord->layer_min; bb_coord_new.layer_max = curr_bb_coord->layer_max; bb_edge_new.layer_min = curr_bb_edge->layer_min; bb_edge_new.layer_max = curr_bb_edge->layer_max; } - } else {// num_layers == 1 + } else { // num_layers == 1 bb_coord_new.layer_min = curr_bb_coord->layer_min; bb_coord_new.layer_max = curr_bb_coord->layer_max; bb_edge_new.layer_min = curr_bb_edge->layer_min; bb_edge_new.layer_max = curr_bb_edge->layer_max; } - if (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) { - net_info.bb_update_status[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; } } @@ -1156,7 +1146,6 @@ static void update_layer_bb(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, t_physical_tile_loc pin_new_loc, bool is_output_pin) { - auto& device_ctx = g_vpr_ctx.device(); auto& place_move_ctx = g_placer_ctx.move(); @@ -1166,20 +1155,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 (net_info.bb_update_status[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; } - place_move_ctx.num_sink_pin_layer[size_t(net_id)] : bb_pin_sink_count_new; - const vtr::NdMatrixProxy curr_layer_pin_sink_count = (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) ? + 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 (net_info.bb_update_status[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]; - net_info.bb_update_status[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; @@ -1221,8 +1209,8 @@ static void update_layer_bb(ClusterNetId net_id, bb_coord_new); } - if (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) { - net_info.bb_update_status[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; } } @@ -1253,7 +1241,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1276,7 +1264,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1300,7 +1288,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1323,7 +1311,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1368,7 +1356,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 (net_info.bb_update_status[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) { @@ -1380,7 +1368,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1394,7 +1382,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 (net_info.bb_update_status[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) { @@ -1406,7 +1394,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 (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { + if (pl_net_cost.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) { return; } } @@ -1446,7 +1434,7 @@ static inline void update_bb_edge(ClusterNetId net_id, bb_edge_new, bb_coord_new, bb_layer_pin_sink_count); - net_info.bb_update_status[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; @@ -1613,7 +1601,6 @@ static void get_bb_from_scratch(ClusterNetId net_id, VTR_ASSERT_DEBUG(layer_min >= 0 && layer_min < device_ctx.grid.get_num_layers()); VTR_ASSERT_DEBUG(layer_max >= 0 && layer_max < device_ctx.grid.get_num_layers()); - num_on_edges.xmin = xmin_edge; num_on_edges.xmax = xmax_edge; num_on_edges.ymin = ymin_edge; @@ -1761,8 +1748,8 @@ static double get_net_cost(ClusterNetId net_id, const t_bb& bb) { } static double get_net_layer_bb_wire_cost(ClusterNetId /* net_id */, - const std::vector& bb, - const vtr::NdMatrixProxy layer_pin_sink_count) { + const std::vector& bb, + const vtr::NdMatrixProxy layer_pin_sink_count) { /* Finds the cost due to one net by looking at its coordinate bounding * * box. */ @@ -1821,8 +1808,8 @@ static double get_net_wirelength_estimate(ClusterNetId net_id, const t_bb& bb) { } static double get_net_wirelength_from_layer_bb(ClusterNetId /* net_id */, - const std::vector& bb, - const vtr::NdMatrixProxy layer_pin_sink_count) { + const std::vector& bb, + const vtr::NdMatrixProxy layer_pin_sink_count) { /* WMF: Finds the estimate of wirelength due to one net by looking at * * its coordinate bounding box. */ @@ -1831,7 +1818,7 @@ static double get_net_wirelength_from_layer_bb(ClusterNetId /* net_id */, int num_layers = g_vpr_ctx.device().grid.get_num_layers(); for (int layer_num = 0; layer_num < num_layers; layer_num++) { - VTR_ASSERT_SAFE (layer_pin_sink_count[layer_num] != OPEN); + VTR_ASSERT_SAFE(layer_pin_sink_count[layer_num] != OPEN); if (layer_pin_sink_count[layer_num] == 0) { continue; } @@ -1860,7 +1847,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_info.net_cost[net_id]; + cost += pl_net_cost.net_cost[net_id]; } } @@ -1885,15 +1872,15 @@ static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) { const auto& cube_bb = g_vpr_ctx.placement().cube_bb; if (cube_bb) { - net_info.proposed_net_cost[net_id] = get_net_cost(net_id, - ts_bb_coord_new[net_id]); + pl_net_cost.proposed_net_cost[net_id] = get_net_cost(net_id, + ts_bb_coord_new[net_id]); } else { - net_info.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)]); + pl_net_cost.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)]); } - bb_delta_c += net_info.proposed_net_cost[net_id] - net_info.net_cost[net_id]; + bb_delta_c += pl_net_cost.proposed_net_cost[net_id] - pl_net_cost.net_cost[net_id]; } } @@ -1925,16 +1912,16 @@ int find_affected_nets_and_update_costs( blocks_affected.num_moved_blocks, blocks_affected.moved_blocks); } - update_net_info_on_pin_move(place_algorithm, - delay_model, - criticalities, - blk, - blk_pin, - moving_block_inf, - affected_pins, - timing_delta_c, - num_affected_nets, - is_src_moving); + update_pl_net_cost_on_pin_move(place_algorithm, + delay_model, + criticalities, + blk, + blk_pin, + moving_block_inf, + affected_pins, + timing_delta_c, + num_affected_nets, + is_src_moving); } } @@ -1967,8 +1954,8 @@ double comp_bb_cost(e_cost_methods method) { place_move_ctx.num_sink_pin_layer[size_t(net_id)]); } - net_info.net_cost[net_id] = get_net_cost(net_id, place_move_ctx.bb_coords[net_id]); - cost += net_info.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]); } @@ -2004,14 +1991,14 @@ double comp_layer_bb_cost(e_cost_methods method) { place_move_ctx.num_sink_pin_layer[size_t(net_id)]); } - net_info.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_info.net_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 += 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], - place_move_ctx.num_sink_pin_layer[size_t(net_id)]); + place_move_ctx.layer_bb_coords[net_id], + place_move_ctx.num_sink_pin_layer[size_t(net_id)]); } } @@ -2051,11 +2038,11 @@ void update_move_nets(int num_nets_affected, } } - net_info.net_cost[net_id] = net_info.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. */ - net_info.proposed_net_cost[net_id] = -1; - net_info.bb_update_status[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; } } @@ -2064,16 +2051,16 @@ void reset_move_nets(int num_nets_affected) { for (int inet_affected = 0; inet_affected < num_nets_affected; inet_affected++) { ClusterNetId net_id = ts_nets_to_update[inet_affected]; - net_info.proposed_net_cost[net_id] = -1; - net_info.bb_update_status[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; } } void recompute_costs_from_scratch(const t_placer_opts& placer_opts, - const t_noc_opts& noc_opts, - const PlaceDelayModel* delay_model, - const PlacerCriticalities* criticalities, - t_placer_costs* costs) { + const t_noc_opts& noc_opts, + const PlaceDelayModel* delay_model, + const PlacerCriticalities* criticalities, + t_placer_costs* costs) { auto check_and_print_cost = [](double new_cost, double old_cost, const std::string& cost_name) { @@ -2233,24 +2220,24 @@ void alloc_and_load_chan_w_factors_for_place_cost(float place_cost_exp) { } } -void free_chan_w_factors_for_place_cost () { +void free_chan_w_factors_for_place_cost() { chanx_place_cost_fac.clear(); chany_place_cost_fac.clear(); } void init_place_move_structs(size_t num_nets) { - net_info.net_cost.resize(num_nets, -1.); - net_info.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. */ - net_info.bb_update_status.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_info.net_cost); - vtr::release_memory(net_info.proposed_net_cost); - vtr::release_memory(net_info.bb_update_status); + 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) { From ea9f04d58bdaef5f1f31095cc9934598a965e0c8 Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Sun, 14 Jul 2024 16:14:13 -0400 Subject: [PATCH 03/11] [vpr][placer] fixed comment's grammar --- vpr/src/place/net_cost_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index 0b1af0a43cf..9d541abc1f8 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -80,7 +80,7 @@ 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 For each of the vector in this struct, there is one entry per cluster level net: + * @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 From fa065b4faad1e53ef90cfe38dcb058fe3e54befd Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Thu, 18 Jul 2024 02:16:35 -0400 Subject: [PATCH 04/11] [vpr][placer] creating ts struct and hiding 2d 3d control flow in class --- vpr/src/place/net_cost_handler.cpp | 276 +++++++++++++++-------------- vpr/src/place/net_cost_handler.h | 4 +- vpr/src/place/place.cpp | 3 +- 3 files changed, 142 insertions(+), 141 deletions(-) diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index 9d541abc1f8..43dddd183d9 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -24,7 +24,10 @@ * @date July 12, 2024 */ #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" @@ -116,14 +119,34 @@ static struct PLNetCost pl_net_cost; * 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 @@ -234,25 +257,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 @@ -474,7 +478,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, @@ -504,70 +589,26 @@ static void update_net_bb(const ClusterNetId& net, //For small nets brute-force bounding box update is faster if (pl_net_cost.bb_update_status[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)]); + 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 (pl_net_cost.bb_update_status[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); } } @@ -668,7 +709,7 @@ static void record_affected_net(const ClusterNetId net, /* Record effected nets. */ 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. */ @@ -700,14 +741,8 @@ static void update_pl_net_cost_on_pin_move(const t_place_algorithm& place_algori /* 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. */ @@ -1868,17 +1903,9 @@ 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) { - pl_net_cost.proposed_net_cost[net_id] = get_net_cost(net_id, - ts_bb_coord_new[net_id]); - } else { - pl_net_cost.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 += pl_net_cost.proposed_net_cost[net_id] - pl_net_cost.net_cost[net_id]; } @@ -2010,32 +2037,23 @@ 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); } pl_net_cost.net_cost[net_id] = pl_net_cost.proposed_net_cost[net_id]; @@ -2050,7 +2068,7 @@ 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]; + 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; } @@ -2241,28 +2259,14 @@ void free_place_move_structs() { } 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 134ff8fb772..14fa847e970 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); From d2ca437934f8ac9b165b576b36d9b648843fefd8 Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Mon, 22 Jul 2024 10:17:27 -0400 Subject: [PATCH 05/11] [vpr][place] addressing pull request commemts --- vpr/src/place/net_cost_handler.cpp | 73 ++++++++++++++---------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index 43dddd183d9..81d98cfb7a4 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -27,7 +27,6 @@ #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" @@ -82,6 +81,7 @@ static const float cross_count[MAX_FANOUT_CROSSING_COUNT] = {/* [0..49] */ 1.0, static vtr::NdMatrix chanx_place_cost_fac({0, 0}); // [0...device_ctx.grid.width()-2] static vtr::NdMatrix chany_place_cost_fac({0, 0}); // [0...device_ctx.grid.height()-2] +namespace { /** * @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]. @@ -105,16 +105,13 @@ struct PLNetCost { 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. */ /** - * The wire length estimation is based on the bounding box of the net. In the case of the 2D architecture, + * @brief The wire length estimation is based on the bounding box of the net. In the case of the 2D architecture, * 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: * 3D and per-layer. The type is determined at the beginning of the placement and stored in the placement context. - * - * * 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 * layer_ts_bb_coord_new are used. */ @@ -129,12 +126,11 @@ struct TSInfo { /* [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 { +class BBUpdater { bool cube_bb = false; public: @@ -146,7 +142,13 @@ class BB2D3DControlFlow { void set_ts_bb_coord(const ClusterNetId& net_id); void set_ts_edge(const ClusterNetId& net_id); }; -static BB2D3DControlFlow bb_2d_3d_control_flow; +} // namespace + +static struct PLNetCost pl_net_cost; + +static struct TSInfo ts_info; + +static BBUpdater bb_updater; /** * @param net @@ -478,27 +480,28 @@ 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 ************************************/ +namespace { // Initialize the ts vectors -void BB2D3DControlFlow::init(size_t num_nets, bool cube_bb_in) { +void BBUpdater::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; + // Either 3D BB or per layer BB data structure are used, not both. 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*/ + /* This initializes 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) { +void BBUpdater::get_non_updatable_bb(const ClusterNetId& net) { if (cube_bb) ::get_non_updatable_bb(net, ts_info.ts_bb_coord_new[net], @@ -509,15 +512,7 @@ void BB2D3DControlFlow::get_non_updatable_bb(const ClusterNetId& 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) { +void BBUpdater::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], @@ -536,14 +531,14 @@ void BB2D3DControlFlow::update_bb(ClusterNetId net_id, t_physical_tile_loc pin_o is_driver); } -double BB2D3DControlFlow::get_net_cost(const ClusterNetId& net_id) { +double BBUpdater::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) { +void BBUpdater::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]; @@ -552,7 +547,7 @@ void BB2D3DControlFlow::set_ts_bb_coord(const ClusterNetId& net_id) { } } -void BB2D3DControlFlow::set_ts_edge(const ClusterNetId& net_id) { +void BBUpdater::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]; @@ -560,6 +555,8 @@ void BB2D3DControlFlow::set_ts_edge(const ClusterNetId& net_id) { place_move_ctx.layer_bb_num_on_edges[net_id] = ts_info.layer_ts_bb_edge_new[net_id]; } } +} // namespace + //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, @@ -589,7 +586,7 @@ static void update_net_bb(const ClusterNetId& net, //For small nets brute-force bounding box update is faster 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); + bb_updater.get_non_updatable_bb(net); } } else { //For large nets, update bounding box incrementally @@ -598,17 +595,17 @@ static void update_net_bb(const ClusterNetId& net, 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); + bool is_driver = cluster_ctx.clb_nlist.pin_type(blk_pin) == PinType::DRIVER; //Incremental bounding box update - 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); + bb_updater.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); } } @@ -1905,7 +1902,7 @@ static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) { inet_affected++) { 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); + pl_net_cost.proposed_net_cost[net_id] = bb_updater.get_net_cost(net_id); bb_delta_c += pl_net_cost.proposed_net_cost[net_id] - pl_net_cost.net_cost[net_id]; } @@ -2046,14 +2043,14 @@ void update_move_nets(int num_nets_affected) { inet_affected++) { ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; - bb_2d_3d_control_flow.set_ts_bb_coord(net_id); + bb_updater.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_info.ts_layer_sink_pin_count[size_t(net_id)][layer_num]; } if (cluster_ctx.clb_nlist.net_sinks(net_id).size() >= SMALL_NET) { - bb_2d_3d_control_flow.set_ts_edge(net_id); + bb_updater.set_ts_edge(net_id); } pl_net_cost.net_cost[net_id] = pl_net_cost.proposed_net_cost[net_id]; @@ -2259,7 +2256,7 @@ void free_place_move_structs() { } void init_try_swap_net_cost_structs(size_t num_nets, bool cube_bb) { - bb_2d_3d_control_flow.init(num_nets, cube_bb); + bb_updater.init(num_nets, cube_bb); } void free_try_swap_net_cost_structs() { From 2df533665ccc907c4292578199497ac5b7bbbb9c Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Thu, 18 Jul 2024 02:40:20 -0400 Subject: [PATCH 06/11] [vpr][place] ts_nets_to_update now uses size() instead of num_nets --- vpr/src/place/net_cost_handler.cpp | 97 ++++++++++++++---------------- vpr/src/place/net_cost_handler.h | 60 +++++++++--------- vpr/src/place/place.cpp | 27 ++++----- 3 files changed, 88 insertions(+), 96 deletions(-) diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index 81d98cfb7a4..032c69e14c9 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -193,11 +193,10 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model, bool is_src_moving); /** - * @brief if "net" is not already stored as an affected net, mark it in ts_nets_to_update and increment num_affected_nets + * @brief if "net" is not already stored as an affected net, mark it in ts_nets_to_update and increment the size ofts_nets_to_update. * @param net ID of a net affected by a move - * @param num_affected_nets Incremented if this is a new net affected, and returned via reference. */ -static void record_affected_net(const ClusterNetId net, int& num_affected_nets); +static void record_affected_net(const ClusterNetId net); /** * @brief Call suitable function based on the bounding box type to update the bounding box of the net connected to pin_id. Also, @@ -210,19 +209,17 @@ static void record_affected_net(const ClusterNetId net, int& num_affected_nets); * @param moving_blk_inf Data structure that holds information, e.g., old location and new locatoin, about all moving blocks * @param affected_pins Netlist pins which are affected, in terms placement cost, by the proposed move. * @param timing_delta_c Timing cost change based on the proposed move - * @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_pl_net_cost_on_pin_move(const t_place_algorithm& place_algorithm, - const PlaceDelayModel* delay_model, - const PlacerCriticalities* criticalities, - const ClusterBlockId& blk_id, - const ClusterPinId& pin_id, - const t_pl_moved_block& moving_blk_inf, - std::vector& affected_pins, - double& timing_delta_c, - int& num_affected_nets, - bool is_src_moving); +static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm, + const PlaceDelayModel* delay_model, + const PlacerCriticalities* criticalities, + const ClusterBlockId& blk_id, + const ClusterPinId& pin_id, + const t_pl_moved_block& moving_blk_inf, + std::vector& affected_pins, + double& timing_delta_c, + bool is_src_moving); /** * @brief Update the 3D bounding box of "net_id" incrementally based on the old and new locations of a pin on that net @@ -474,10 +471,9 @@ static double wirelength_crossing_count(size_t fanout); /** * @brief Calculates and returns the total bb (wirelength) cost change that would result from moving the blocks * indicated in the blocks_affected data structure. - * @param num_affected_nets Number of valid elements in ts_bb_coord_new * @param bb_delta_c Cost difference after and before moving the block */ -static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c); +static void set_bb_delta_cost(double& bb_delta_c); /******************************* End of Function definitions ************************************/ namespace { @@ -701,29 +697,29 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model, } ///@brief Record effected nets. -static void record_affected_net(const ClusterNetId net, - int& num_affected_nets) { +static void record_affected_net(const ClusterNetId net) { /* Record effected nets. */ if (pl_net_cost.proposed_net_cost[net] < 0.) { /* Net not marked yet. */ - ts_info.ts_nets_to_update[num_affected_nets] = net; - num_affected_nets++; + size_t last_size = ts_info.ts_nets_to_update.size(); + VTR_ASSERT(last_size < ts_info.ts_nets_to_update.capacity()); + ts_info.ts_nets_to_update.resize(last_size + 1); + ts_info.ts_nets_to_update[last_size] = net; /* Flag to say we've marked this net. */ pl_net_cost.proposed_net_cost[net] = 1.; } } -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, - const ClusterPinId& pin_id, - const t_pl_moved_block& moving_blk_inf, - std::vector& affected_pins, - double& timing_delta_c, - int& num_affected_nets, - bool is_src_moving) { +static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm, + const PlaceDelayModel* delay_model, + const PlacerCriticalities* criticalities, + const ClusterBlockId& blk_id, + const ClusterPinId& pin_id, + const t_pl_moved_block& moving_blk_inf, + std::vector& affected_pins, + double& timing_delta_c, + bool is_src_moving) { const auto& cluster_ctx = g_vpr_ctx.clustering(); const ClusterNetId net_id = cluster_ctx.clb_nlist.pin_net(pin_id); VTR_ASSERT_SAFE_MSG(net_id, @@ -736,7 +732,7 @@ static void update_pl_net_cost_on_pin_move(const t_place_algorithm& place_algori } /* Record effected nets */ - record_affected_net(net_id, num_affected_nets); + record_affected_net(net_id); /* Update the net bounding boxes. */ update_net_bb(net_id, blk_id, pin_id, moving_blk_inf); @@ -1897,8 +1893,8 @@ 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; +static void set_bb_delta_cost(double& bb_delta_c) { + for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size(); inet_affected++) { ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; @@ -1908,7 +1904,7 @@ static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) { } } -int find_affected_nets_and_update_costs( +void find_affected_nets_and_update_costs( const t_place_algorithm& place_algorithm, const PlaceDelayModel* delay_model, const PlacerCriticalities* criticalities, @@ -1919,7 +1915,7 @@ int find_affected_nets_and_update_costs( VTR_ASSERT_SAFE(timing_delta_c == 0.); auto& clb_nlist = g_vpr_ctx.clustering().clb_nlist; - int num_affected_nets = 0; + ts_info.ts_nets_to_update.resize(0); /* Go through all the blocks moved. */ for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; iblk++) { @@ -1936,24 +1932,21 @@ int find_affected_nets_and_update_costs( blocks_affected.num_moved_blocks, blocks_affected.moved_blocks); } - update_pl_net_cost_on_pin_move(place_algorithm, - delay_model, - criticalities, - blk, - blk_pin, - moving_block_inf, - affected_pins, - timing_delta_c, - num_affected_nets, - is_src_moving); + update_net_info_on_pin_move(place_algorithm, + delay_model, + criticalities, + blk, + blk_pin, + moving_block_inf, + affected_pins, + timing_delta_c, + is_src_moving); } } /* Now update the bounding box costs (since the net bounding * * boxes are up-to-date). The cost is only updated once per net. */ - set_bb_delta_cost(num_affected_nets, bb_delta_c); - - return num_affected_nets; + set_bb_delta_cost(bb_delta_c); } double comp_bb_cost(e_cost_methods method) { @@ -2034,12 +2027,12 @@ double comp_layer_bb_cost(e_cost_methods method) { return cost; } -void update_move_nets(int num_nets_affected) { +void update_move_nets() { /* 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; + for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size(); inet_affected++) { ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; @@ -2061,9 +2054,9 @@ void update_move_nets(int num_nets_affected) { } } -void reset_move_nets(int num_nets_affected) { +void reset_move_nets() { /* Reset the net cost function flags first. */ - for (int inet_affected = 0; inet_affected < num_nets_affected; + for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size(); inet_affected++) { ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; pl_net_cost.proposed_net_cost[net_id] = -1; diff --git a/vpr/src/place/net_cost_handler.h b/vpr/src/place/net_cost_handler.h index 9815cc8baa0..36ded2db2db 100644 --- a/vpr/src/place/net_cost_handler.h +++ b/vpr/src/place/net_cost_handler.h @@ -6,8 +6,8 @@ /** * @brief The method used to calculate palcement cost - * @details For comp_cost. NORMAL means use the method that generates updateable bounding boxes for speed. - * CHECK means compute all bounding boxes from scratch using a very simple routine to allow checks + * @details For comp_cost. NORMAL means use the method that generates updateable bounding boxes for speed. + * CHECK means compute all bounding boxes from scratch using a very simple routine to allow checks * of the other costs. * NORMAL: Compute cost efficiently using incremental techniques. * CHECK: Brute-force cost computation; useful to validate the more complex incremental cost update code. @@ -36,7 +36,7 @@ enum e_cost_methods { * * The change in the bounding box cost is stored in `bb_delta_c`. * The change in the timing cost is stored in `timing_delta_c`. - * + * * @param place_algorithm * @param delay_model * @param criticalities @@ -45,7 +45,7 @@ enum e_cost_methods { * @param timing_delta_c * @return The number of affected nets. */ -int find_affected_nets_and_update_costs( +void find_affected_nets_and_update_costs( const t_place_algorithm& place_algorithm, const PlaceDelayModel* delay_model, const PlacerCriticalities* criticalities, @@ -54,27 +54,27 @@ int find_affected_nets_and_update_costs( double& timing_delta_c); /** - * @brief Finds the bb cost from scratch (based on 3D BB). - * Done only when the placement has been radically changed - * (i.e. after initial placement). Otherwise find the cost - * change incrementally. If method check is NORMAL, we find - * bounding boxes that are updatable for the larger nets. - * If method is CHECK, all bounding boxes are found via the - * non_updateable_bb routine, to provide a cost which can be - * used to check the correctness of the other routine. + * @brief Finds the bb cost from scratch (based on 3D BB). + * Done only when the placement has been radically changed + * (i.e. after initial placement). Otherwise find the cost + * change incrementally. If method check is NORMAL, we find + * bounding boxes that are updatable for the larger nets. + * If method is CHECK, all bounding boxes are found via the + * non_updateable_bb routine, to provide a cost which can be + * used to check the correctness of the other routine. * @param method * @return The bounding box cost of the placement, computed by the 3D method. */ double comp_bb_cost(e_cost_methods method); /** - * @brief Finds the bb cost from scratch (based on per-layer BB). - * Done only when the placement has been radically changed - * (i.e. after initial placement). Otherwise find the cost change - * incrementally. If method check is NORMAL, we find bounding boxes - * that are updateable for the larger nets. If method is CHECK, all - * bounding boxes are found via the non_updateable_bb routine, to provide - * a cost which can be used to check the correctness of the other routine. + * @brief Finds the bb cost from scratch (based on per-layer BB). + * Done only when the placement has been radically changed + * (i.e. after initial placement). Otherwise find the cost change + * incrementally. If method check is NORMAL, we find bounding boxes + * that are updateable for the larger nets. If method is CHECK, all + * bounding boxes are found via the non_updateable_bb routine, to provide + * a cost which can be used to check the correctness of the other routine. * @param method * @return The placement bounding box cost, computed by the per layer method. */ @@ -84,17 +84,17 @@ 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. */ -void update_move_nets(int num_nets_affected); +void update_move_nets(); /** * @brief Reset the net cost function flags (proposed_net_cost and bb_updated_before) * @param num_nets_affected */ -void reset_move_nets(int num_nets_affected); +void reset_move_nets(); /** * @brief re-calculates different terms of the cost function (wire-length, timing, NoC) and update "costs" accordingly. It is important to note that - * in this function bounding box and connection delays are not calculated from scratch. However, it iterates over all nets and connections and updates + * in this function bounding box and connection delays are not calculated from scratch. However, it iterates over all nets and connections and updates * their costs by a complete summation, rather than incrementally. * @param placer_opts * @param noc_opts @@ -103,16 +103,16 @@ void reset_move_nets(int num_nets_affected); * @param costs passed by reference and computed by this routine (i.e. returned by reference) */ void recompute_costs_from_scratch(const t_placer_opts& placer_opts, - const t_noc_opts& noc_opts, - const PlaceDelayModel* delay_model, - const PlacerCriticalities* criticalities, - t_placer_costs* costs); + const t_noc_opts& noc_opts, + const PlaceDelayModel* delay_model, + const PlacerCriticalities* criticalities, + t_placer_costs* costs); /** * @brief Allocates and loads the chanx_place_cost_fac and chany_place_cost_fac * arrays with the inverse of the average number of tracks per channel * between [subhigh] and [sublow]. - * @param place_cost_exp It is an exponent to which you take the average inverse channel + * @param place_cost_exp It is an exponent to which you take the average inverse channel * capacity; a higher value would favour wider channels more over narrower channels during placement (usually we use 1). */ void alloc_and_load_chan_w_factors_for_place_cost(float place_cost_exp); @@ -120,7 +120,7 @@ void alloc_and_load_chan_w_factors_for_place_cost(float place_cost_exp); /** * @brief Frees the chanx_place_cost_fac and chany_place_cost_fac arrays. */ -void free_chan_w_factors_for_place_cost (); +void free_chan_w_factors_for_place_cost(); /** * @brief Resize net_cost, proposed_net_cost, and bb_updated_before data structures to accommodate all nets. @@ -134,8 +134,8 @@ void init_place_move_structs(size_t num_nets); void free_place_move_structs(); /** - * @brief Resize temporary storage data structures needed to determine which nets are affected by a move and data needed per net - * about where their terminals are in order to quickly (incrementally) update their wirelength costs. These data structures are + * @brief Resize temporary storage data structures needed to determine which nets are affected by a move and data needed per net + * about where their terminals are in order to quickly (incrementally) update their wirelength costs. These data structures are * (layer_)ts_bb_edge_new, (layer_)ts_bb_coord_new, ts_layer_sink_pin_count, and ts_nets_to_update. * @param num_nets Number of nets in the netlist used by the placement engine (currently clustered netlist) * @param cube_bb True if the 3D bounding box should be used, false otherwise. diff --git a/vpr/src/place/place.cpp b/vpr/src/place/place.cpp index 14fa847e970..391665286f8 100644 --- a/vpr/src/place/place.cpp +++ b/vpr/src/place/place.cpp @@ -1325,8 +1325,8 @@ static e_move_result try_swap(const t_annealing_state* state, if (manual_move_enabled) { #ifndef NO_GRAPHICS create_move_outcome = manual_move_display_and_propose(manual_move_generator, blocks_affected, proposed_action.move_type, rlim, placer_opts, criticalities); -#else //NO_GRAPHICS - //Cast to void to explicitly avoid warning. +#else //NO_GRAPHICS \ + //Cast to void to explicitly avoid warning. (void)manual_move_generator; #endif //NO_GRAPHICS } else if (router_block_move) { @@ -1378,7 +1378,7 @@ static e_move_result try_swap(const t_annealing_state* state, // //Also find all the pins affected by the swap, and calculates new connection //delays and timing costs and store them in proposed_* data structures. - int num_nets_affected = find_affected_nets_and_update_costs( + find_affected_nets_and_update_costs( place_algorithm, delay_model, criticalities, blocks_affected, bb_delta_c, timing_delta_c); @@ -1481,7 +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); + update_move_nets(); /* Update clb data structures since we kept the move. */ commit_move_blocks(blocks_affected); @@ -1505,7 +1505,7 @@ static e_move_result try_swap(const t_annealing_state* state, VTR_ASSERT_SAFE(move_outcome == REJECTED); /* Reset the net cost function flags first. */ - reset_move_nets(num_nets_affected); + reset_move_nets(); /* Restore the place_ctx.block_locs data structures to their state before the move. */ revert_move_blocks(blocks_affected); @@ -1568,7 +1568,7 @@ static e_move_result try_swap(const t_annealing_state* state, calculate_reward_and_process_outcome(placer_opts, move_outcome_stats, delta_c, timing_bb_factor, move_generator); } else { -// std::cout << "Group move delta cost: " << delta_c << std::endl; + // std::cout << "Group move delta cost: " << delta_c << std::endl; } #ifdef VTR_ENABLE_DEBUG_LOGGING @@ -1626,9 +1626,9 @@ static bool is_cube_bb(const e_place_bounding_box_mode place_bb_mode, * loop iteration of the placement. At each temperature change, these * values are updated so that we can balance the tradeoff between the * different placement cost components (timing, wirelength and NoC). - * Depending on the placement mode the corresponding normalization factors are + * Depending on the placement mode the corresponding normalization factors are * updated. - * + * * @param costs Contains the normalization factors which need to be updated * @param placer_opts Determines the placement mode * @param noc_opts Determines if placement includes the NoC @@ -1651,7 +1651,7 @@ static void update_placement_cost_normalization_factors(t_placer_costs* costs, c /** * @brief Compute the total normalized cost for a given placement. This * computation will vary depending on the placement modes. - * + * * @param costs The current placement cost components and their normalization * factors * @param placer_opts Determines the placement mode @@ -1915,7 +1915,7 @@ static void alloc_and_load_placement_structs(float place_cost_exp, elem = OPEN; } - alloc_and_load_chan_w_factors_for_place_cost (place_cost_exp); + alloc_and_load_chan_w_factors_for_place_cost(place_cost_exp); alloc_and_load_try_swap_structs(cube_bb); @@ -1955,7 +1955,7 @@ static void free_placement_structs(const t_placer_opts& placer_opts, const t_noc place_move_ctx.num_sink_pin_layer.clear(); - free_chan_w_factors_for_place_cost (); + free_chan_w_factors_for_place_cost(); free_try_swap_structs(); @@ -2184,7 +2184,7 @@ int check_macro_placement_consistency() { error++; } } // Finish going through all the members - } // Finish going through all the macros + } // Finish going through all the macros return error; } @@ -2372,10 +2372,9 @@ static void print_placement_move_types_stats(const MoveTypeStat& move_type_stat) int total_moves = 0; for (size_t i = 0; i < move_type_stat.blk_type_moves.size(); ++i) { - total_moves += move_type_stat.blk_type_moves.get(i); + total_moves += move_type_stat.blk_type_moves.get(i); } - auto& device_ctx = g_vpr_ctx.device(); int count = 0; int num_of_avail_moves = move_type_stat.blk_type_moves.size() / device_ctx.logical_block_types.size(); From 97d71113c116956b6abcf85988608609d5b5f42e Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Fri, 19 Jul 2024 01:21:35 -0400 Subject: [PATCH 07/11] [vpr][place] moved_block uses size() to indicate valid elements --- vpr/src/place/move_transactions.cpp | 25 ++++++++++++++++++------- vpr/src/place/move_transactions.h | 7 ++----- vpr/src/place/move_utils.cpp | 2 +- vpr/src/place/net_cost_handler.cpp | 7 ++----- vpr/src/place/noc_place_utils.cpp | 4 ++-- vpr/src/place/place.cpp | 2 +- vpr/src/place/place_constraints.h | 2 +- vpr/test/test_noc_place_utils.cpp | 10 +++++----- 8 files changed, 32 insertions(+), 27 deletions(-) diff --git a/vpr/src/place/move_transactions.cpp b/vpr/src/place/move_transactions.cpp index f36dd4d5e39..a01b3145513 100644 --- a/vpr/src/place/move_transactions.cpp +++ b/vpr/src/place/move_transactions.cpp @@ -1,8 +1,20 @@ #include "move_utils.h" #include "globals.h" +// Is this needed? #include "place_util.h" +t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved(size_t max_blocks){ + moved_blocks.reserve(max_blocks); + moved_blocks.resize(0); +} + +size_t t_pl_blocks_to_be_moved::get_size_and_increment() { + VTR_ASSERT(moved_blocks.size() < moved_blocks.capacity()); + moved_blocks.resize(moved_blocks.size() + 1); + return moved_blocks.size() - 1; +} + //Records that block 'blk' should be moved to the specified 'to' location e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId blk, t_pl_loc to) { auto res = blocks_affected.moved_to.emplace(to); @@ -24,11 +36,10 @@ e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected, VTR_ASSERT_SAFE(to.sub_tile < int(place_ctx.grid_blocks.num_blocks_at_location({to.x, to.y, to.layer}))); // Sets up the blocks moved - int imoved_blk = blocks_affected.num_moved_blocks; + size_t imoved_blk = blocks_affected.get_size_and_increment(); blocks_affected.moved_blocks[imoved_blk].block_num = blk; blocks_affected.moved_blocks[imoved_blk].old_loc = from; blocks_affected.moved_blocks[imoved_blk].new_loc = to; - blocks_affected.num_moved_blocks++; return e_block_move_result::VALID; } @@ -40,7 +51,7 @@ void apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { //Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks //yet since we don't know whether the swap will be accepted - for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { + for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; const t_pl_loc& old_loc = blocks_affected.moved_blocks[iblk].old_loc; @@ -67,7 +78,7 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { auto& place_ctx = g_vpr_ctx.mutable_placement(); /* Swap physical location */ - for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { + for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; const t_pl_loc& to = blocks_affected.moved_blocks[iblk].new_loc; @@ -97,7 +108,7 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { auto& device_ctx = g_vpr_ctx.device(); // Swap the blocks back, nets not yet swapped they don't need to be changed - for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { + for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; const t_pl_loc& old_loc = blocks_affected.moved_blocks[iblk].old_loc; @@ -126,10 +137,10 @@ void clear_move_blocks(t_pl_blocks_to_be_moved& blocks_affected) { blocks_affected.moved_to.clear(); blocks_affected.moved_from.clear(); - //For run-time, we just reset num_moved_blocks to zero, but do not free the blocks_affected + //For run-time, we just reset size of blocks_affected.moved_blocks to zero, but do not free the blocks_affected //array to avoid memory allocation - blocks_affected.num_moved_blocks = 0; + blocks_affected.moved_blocks.resize(0); blocks_affected.affected_pins.clear(); } diff --git a/vpr/src/place/move_transactions.h b/vpr/src/place/move_transactions.h index 27dd2b1b3c6..05b7486cc35 100644 --- a/vpr/src/place/move_transactions.h +++ b/vpr/src/place/move_transactions.h @@ -25,8 +25,6 @@ struct t_pl_moved_block { * placement, in the form of array of structs instead of struct with * * arrays for cache effifiency * * - * num_moved_blocks: total number of blocks moved when * - * swapping two blocks. * * moved blocks: a list of moved blocks data structure with * * information on the move. * * [0...max_blocks-1] * @@ -34,15 +32,14 @@ struct t_pl_moved_block { * incrementally invalidate parts of the timing * * graph. */ struct t_pl_blocks_to_be_moved { - explicit t_pl_blocks_to_be_moved(size_t max_blocks) - : moved_blocks(max_blocks) {} + explicit t_pl_blocks_to_be_moved(size_t max_blocks); - int num_moved_blocks = 0; std::vector moved_blocks; std::unordered_set moved_from; std::unordered_set moved_to; std::vector affected_pins; + size_t get_size_and_increment(); }; enum class e_block_move_result { diff --git a/vpr/src/place/move_utils.cpp b/vpr/src/place/move_utils.cpp index 8c6ae2a6249..a97462062d2 100644 --- a/vpr/src/place/move_utils.cpp +++ b/vpr/src/place/move_utils.cpp @@ -488,7 +488,7 @@ std::set determine_locations_emptied_by_move(t_pl_blocks_to_be_moved& std::set moved_from; std::set moved_to; - for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { + for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { //When a block is moved its old location becomes free moved_from.emplace(blocks_affected.moved_blocks[iblk].old_loc); diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index 032c69e14c9..ea686ca39cc 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -156,7 +156,6 @@ static BBUpdater bb_updater; * @return True if the driver block of the net is among the moving blocks */ static bool driven_by_moved_block(const ClusterNetId net, - const int num_blocks, const std::vector& moved_blocks); /** * @brief Update the bounding box (3D) of the net connected to blk_pin. The old and new locations of the pin are @@ -555,14 +554,13 @@ void BBUpdater::set_ts_edge(const ClusterNetId& 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, const std::vector& moved_blocks) { auto& clb_nlist = g_vpr_ctx.clustering().clb_nlist; bool is_driven_by_move_blk = false; ClusterBlockId net_driver_block = clb_nlist.net_driver_block( net); - for (int block_num = 0; block_num < num_blocks; block_num++) { + for (size_t block_num = 0; block_num < moved_blocks.size(); block_num++) { if (net_driver_block == moved_blocks[block_num].block_num) { is_driven_by_move_blk = true; break; @@ -1918,7 +1916,7 @@ void find_affected_nets_and_update_costs( ts_info.ts_nets_to_update.resize(0); /* Go through all the blocks moved. */ - for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; iblk++) { + for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); iblk++) { const auto& moving_block_inf = blocks_affected.moved_blocks[iblk]; auto& affected_pins = blocks_affected.affected_pins; ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; @@ -1929,7 +1927,6 @@ void find_affected_nets_and_update_costs( if (clb_nlist.pin_type(blk_pin) == PinType::SINK) { ClusterNetId net_id = clb_nlist.pin_net(blk_pin); is_src_moving = driven_by_moved_block(net_id, - blocks_affected.num_moved_blocks, blocks_affected.moved_blocks); } update_net_info_on_pin_move(place_algorithm, diff --git a/vpr/src/place/noc_place_utils.cpp b/vpr/src/place/noc_place_utils.cpp index 0b9e274b85b..b610500def6 100644 --- a/vpr/src/place/noc_place_utils.cpp +++ b/vpr/src/place/noc_place_utils.cpp @@ -136,7 +136,7 @@ void find_affected_noc_routers_and_update_noc_costs(const t_pl_blocks_to_be_move affected_noc_links.clear(); // go through the moved blocks and process them only if they are NoC routers - for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { + for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; // check if the current moved block is a noc router @@ -291,7 +291,7 @@ void revert_noc_traffic_flow_routes(const t_pl_blocks_to_be_moved& blocks_affect std::unordered_set reverted_traffic_flows; // go through the moved blocks and process them only if they are NoC routers - for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) { + for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; // check if the current moved block is a noc router diff --git a/vpr/src/place/place.cpp b/vpr/src/place/place.cpp index 391665286f8..b098f088f94 100644 --- a/vpr/src/place/place.cpp +++ b/vpr/src/place/place.cpp @@ -150,7 +150,7 @@ std::unique_ptr f_move_stats_file(nullptr, t, \ int(b_from), int(b_to), \ from_type->name, (to_type ? to_type->name : "EMPTY"), \ - affected_blocks.num_moved_blocks); \ + affected_blocks.moved_blocks.size()); \ } \ } while (false) diff --git a/vpr/src/place/place_constraints.h b/vpr/src/place/place_constraints.h index ff5aacbb092..bb35e03a001 100644 --- a/vpr/src/place/place_constraints.h +++ b/vpr/src/place/place_constraints.h @@ -100,7 +100,7 @@ void print_macro_constraint_error(const t_pl_macro& pl_macro); inline bool floorplan_legal(const t_pl_blocks_to_be_moved& blocks_affected) { bool floorplan_legal; - for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + for (size_t i = 0; i < blocks_affected.moved_blocks.size(); i++) { floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); if (!floorplan_legal) { diff --git a/vpr/test/test_noc_place_utils.cpp b/vpr/test/test_noc_place_utils.cpp index 80023cf8b81..8d3ba5c346f 100644 --- a/vpr/test/test_noc_place_utils.cpp +++ b/vpr/test/test_noc_place_utils.cpp @@ -748,7 +748,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_ } while (swap_router_block_one == swap_router_block_two); //set up the moved blocks datastructure for the test function - blocks_affected.num_moved_blocks = 2; + blocks_affected.moved_blocks.resize(2); blocks_affected.moved_blocks[0].block_num = swap_router_block_one; blocks_affected.moved_blocks[0].old_loc = t_pl_loc(noc_ctx.noc_model.get_single_noc_router(router_where_cluster_is_placed[swap_router_block_one]).get_router_grid_position_x(), @@ -903,7 +903,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_ // now perform the swap //set up the moved blocks datastructure for the test function - blocks_affected.num_moved_blocks = 2; + blocks_affected.moved_blocks.resize(2); blocks_affected.moved_blocks[0].block_num = swap_router_block_one; @@ -1039,7 +1039,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_ // now perform the swap //set up the moved blocks datastructure for the test function - blocks_affected.num_moved_blocks = 2; + blocks_affected.moved_blocks.resize(2); blocks_affected.moved_blocks[0].block_num = swap_router_block_one; @@ -1142,7 +1142,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_ // now perform the swap //set up the moved blocks datastructure for the test function - blocks_affected.num_moved_blocks = 2; + blocks_affected.moved_blocks.resize(2); blocks_affected.moved_blocks[0].block_num = swap_router_block_one; @@ -1584,7 +1584,7 @@ TEST_CASE("test_revert_noc_traffic_flow_routes", "[noc_place_utils]") { //set up the moved blocks datastructure for the test function // this is needed for the test function (it needs to know what blocks were swapped, so it can undo it) - blocks_affected.num_moved_blocks = 2; + blocks_affected.moved_blocks.resize(2); blocks_affected.moved_blocks[0].block_num = swap_router_block_one; blocks_affected.moved_blocks[0].old_loc = t_pl_loc(noc_ctx.noc_model.get_single_noc_router(router_where_cluster_is_placed[swap_router_block_one]).get_router_grid_position_x(), From 96a2e5441911204b8722e095630978eef4b4f94a Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Fri, 19 Jul 2024 01:31:10 -0400 Subject: [PATCH 08/11] [vpr][place] remove unused include directory --- vpr/src/place/move_transactions.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/vpr/src/place/move_transactions.cpp b/vpr/src/place/move_transactions.cpp index a01b3145513..72d2205d815 100644 --- a/vpr/src/place/move_transactions.cpp +++ b/vpr/src/place/move_transactions.cpp @@ -1,8 +1,6 @@ #include "move_utils.h" #include "globals.h" -// Is this needed? -#include "place_util.h" t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved(size_t max_blocks){ moved_blocks.reserve(max_blocks); From 8a30f6df99cc23f06d3a9c7613f4db1afe033a3d Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Mon, 22 Jul 2024 13:27:08 -0400 Subject: [PATCH 09/11] [vpr][place] rebased all branch and fixed PR comments --- vpr/src/place/move_transactions.cpp | 27 ++++++++++++++------------- vpr/src/place/move_utils.cpp | 13 +++---------- vpr/src/place/net_cost_handler.cpp | 27 ++++++++++++--------------- vpr/src/place/net_cost_handler.h | 1 + vpr/src/place/noc_place_utils.cpp | 12 ++++++------ vpr/src/place/place.cpp | 23 ++--------------------- vpr/src/place/place_constraints.h | 15 +++++++-------- 7 files changed, 45 insertions(+), 73 deletions(-) diff --git a/vpr/src/place/move_transactions.cpp b/vpr/src/place/move_transactions.cpp index 72d2205d815..a113842b420 100644 --- a/vpr/src/place/move_transactions.cpp +++ b/vpr/src/place/move_transactions.cpp @@ -1,6 +1,7 @@ #include "move_utils.h" #include "globals.h" +#include "vtr_assert.h" t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved(size_t max_blocks){ moved_blocks.reserve(max_blocks); @@ -8,7 +9,7 @@ t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved(size_t max_blocks){ } size_t t_pl_blocks_to_be_moved::get_size_and_increment() { - VTR_ASSERT(moved_blocks.size() < moved_blocks.capacity()); + VTR_ASSERT_SAFE(moved_blocks.size() < moved_blocks.capacity()); moved_blocks.resize(moved_blocks.size() + 1); return moved_blocks.size() - 1; } @@ -49,11 +50,11 @@ void apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { //Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks //yet since we don't know whether the swap will be accepted - for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { - ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; + for (const auto& block : blocks_affected.moved_blocks) { + ClusterBlockId blk = block.block_num; - const t_pl_loc& old_loc = blocks_affected.moved_blocks[iblk].old_loc; - const t_pl_loc& new_loc = blocks_affected.moved_blocks[iblk].new_loc; + const t_pl_loc& old_loc = block.old_loc; + const t_pl_loc& new_loc = block.new_loc; // move the block to its new location place_ctx.block_locs[blk].loc = new_loc; @@ -76,11 +77,11 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { auto& place_ctx = g_vpr_ctx.mutable_placement(); /* Swap physical location */ - for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { - ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; + for (const auto& block : blocks_affected.moved_blocks) { + ClusterBlockId blk = block.block_num; - const t_pl_loc& to = blocks_affected.moved_blocks[iblk].new_loc; - const t_pl_loc& from = blocks_affected.moved_blocks[iblk].old_loc; + const t_pl_loc& to = block.new_loc; + const t_pl_loc& from = block.old_loc; //Remove from old location only if it hasn't already been updated by a previous block update if (place_ctx.grid_blocks.block_at_location(from) == blk) { @@ -106,11 +107,11 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { auto& device_ctx = g_vpr_ctx.device(); // Swap the blocks back, nets not yet swapped they don't need to be changed - for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { - ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; + for (const auto& block : blocks_affected.moved_blocks) { + ClusterBlockId blk = block.block_num; - const t_pl_loc& old_loc = blocks_affected.moved_blocks[iblk].old_loc; - const t_pl_loc& new_loc = blocks_affected.moved_blocks[iblk].new_loc; + const t_pl_loc& old_loc = block.old_loc; + const t_pl_loc& new_loc = block.new_loc; // return the block to where it was before the swap place_ctx.block_locs[blk].loc = old_loc; diff --git a/vpr/src/place/move_utils.cpp b/vpr/src/place/move_utils.cpp index a97462062d2..e62936d0ed4 100644 --- a/vpr/src/place/move_utils.cpp +++ b/vpr/src/place/move_utils.cpp @@ -1,13 +1,6 @@ #include "move_utils.h" - -#include "place_util.h" #include "globals.h" - #include "vtr_random.h" - -#include "draw_debug.h" -#include "draw.h" - #include "place_constraints.h" #include "placer_globals.h" @@ -488,12 +481,12 @@ std::set determine_locations_emptied_by_move(t_pl_blocks_to_be_moved& std::set moved_from; std::set moved_to; - for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { + for (const auto& block : blocks_affected.moved_blocks) { //When a block is moved its old location becomes free - moved_from.emplace(blocks_affected.moved_blocks[iblk].old_loc); + moved_from.emplace(block.old_loc); //But any block later moved to a position fills it - moved_to.emplace(blocks_affected.moved_blocks[iblk].new_loc); + moved_to.emplace(block.new_loc); } std::set empty_locs; diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index ea686ca39cc..a2b027f51e6 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -192,7 +192,7 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model, bool is_src_moving); /** - * @brief if "net" is not already stored as an affected net, mark it in ts_nets_to_update and increment the size ofts_nets_to_update. + * @brief if "net" is not already stored as an affected net, add it in ts_nets_to_update. * @param net ID of a net affected by a move */ static void record_affected_net(const ClusterNetId net); @@ -560,8 +560,8 @@ static bool driven_by_moved_block(const ClusterNetId net, ClusterBlockId net_driver_block = clb_nlist.net_driver_block( net); - for (size_t block_num = 0; block_num < moved_blocks.size(); block_num++) { - if (net_driver_block == moved_blocks[block_num].block_num) { + for (const auto& block : moved_blocks) { + if (net_driver_block == block.block_num) { is_driven_by_move_blk = true; break; } @@ -1892,9 +1892,8 @@ static double wirelength_crossing_count(size_t fanout) { } static void set_bb_delta_cost(double& bb_delta_c) { - for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size(); - inet_affected++) { - ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; + for (const auto& ts_net: ts_info.ts_nets_to_update) { + ClusterNetId net_id = ts_net; pl_net_cost.proposed_net_cost[net_id] = bb_updater.get_net_cost(net_id); @@ -1916,10 +1915,10 @@ void find_affected_nets_and_update_costs( ts_info.ts_nets_to_update.resize(0); /* Go through all the blocks moved. */ - for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); iblk++) { - const auto& moving_block_inf = blocks_affected.moved_blocks[iblk]; + for (const auto& block : blocks_affected.moved_blocks) { + const auto& moving_block_inf = block; auto& affected_pins = blocks_affected.affected_pins; - ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; + ClusterBlockId blk = block.block_num; /* Go through all the pins in the moved block. */ for (ClusterPinId blk_pin : clb_nlist.block_pins(blk)) { @@ -2029,9 +2028,8 @@ void update_move_nets() { auto& cluster_ctx = g_vpr_ctx.clustering(); auto& place_move_ctx = g_placer_ctx.mutable_move(); - for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size(); - inet_affected++) { - ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; + for (const auto& ts_net : ts_info.ts_nets_to_update) { + ClusterNetId net_id = ts_net; bb_updater.set_ts_bb_coord(net_id); @@ -2053,9 +2051,8 @@ void update_move_nets() { void reset_move_nets() { /* Reset the net cost function flags first. */ - for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size(); - inet_affected++) { - ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected]; + for (const auto& ts_net : ts_info.ts_nets_to_update) { + ClusterNetId net_id = ts_net; pl_net_cost.proposed_net_cost[net_id] = -1; pl_net_cost.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET; } diff --git a/vpr/src/place/net_cost_handler.h b/vpr/src/place/net_cost_handler.h index 36ded2db2db..0e72611b323 100644 --- a/vpr/src/place/net_cost_handler.h +++ b/vpr/src/place/net_cost_handler.h @@ -36,6 +36,7 @@ enum e_cost_methods { * * The change in the bounding box cost is stored in `bb_delta_c`. * The change in the timing cost is stored in `timing_delta_c`. + * ts_nets_to_update is also extended with the latest net. * * @param place_algorithm * @param delay_model diff --git a/vpr/src/place/noc_place_utils.cpp b/vpr/src/place/noc_place_utils.cpp index b610500def6..d8d9b481ec1 100644 --- a/vpr/src/place/noc_place_utils.cpp +++ b/vpr/src/place/noc_place_utils.cpp @@ -136,8 +136,8 @@ void find_affected_noc_routers_and_update_noc_costs(const t_pl_blocks_to_be_move affected_noc_links.clear(); // go through the moved blocks and process them only if they are NoC routers - for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { - ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; + for (const auto& block : blocks_affected.moved_blocks) { + ClusterBlockId blk = block.block_num; // check if the current moved block is a noc router if (noc_traffic_flows_storage.check_if_cluster_block_has_traffic_flows(blk)) { @@ -291,8 +291,8 @@ void revert_noc_traffic_flow_routes(const t_pl_blocks_to_be_moved& blocks_affect std::unordered_set reverted_traffic_flows; // go through the moved blocks and process them only if they are NoC routers - for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) { - ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num; + for (const auto& block : blocks_affected.moved_blocks) { + ClusterBlockId blk = block.block_num; // check if the current moved block is a noc router if (noc_traffic_flows_storage.check_if_cluster_block_has_traffic_flows(blk)) { @@ -323,7 +323,7 @@ void re_route_traffic_flow(NocTrafficFlowId traffic_flow_id, // get the current traffic flow info const t_noc_traffic_flow& curr_traffic_flow = noc_traffic_flows_storage.get_single_noc_traffic_flow(traffic_flow_id); - /* since the current traffic flow route will be + /* since the current traffic flow route will be * changed, first we need to decrement the bandwidth * usage of all links that are part of * the existing traffic flow route @@ -994,4 +994,4 @@ static std::vector find_affected_links_by_flow_reroute(std::vector #include #include -#include -#include -#include -#include -#include - -#include "NetPinTimingInvalidator.h" #include "vtr_assert.h" #include "vtr_log.h" #include "vtr_util.h" #include "vtr_random.h" -#include "vtr_geometry.h" #include "vtr_time.h" -#include "vtr_math.h" #include "vtr_ndmatrix.h" #include "vpr_types.h" @@ -27,11 +18,6 @@ #include "placer_globals.h" #include "read_place.h" #include "draw.h" -#include "place_and_route.h" -#include "net_delay.h" -#include "timing_place_lookup.h" -#include "timing_place.h" -#include "read_xml_arch_file.h" #include "echo_files.h" #include "place_macro.h" #include "histogram.h" @@ -45,10 +31,7 @@ #include "read_place.h" #include "place_constraints.h" #include "manual_moves.h" -#include "buttons.h" -#include "static_move_generator.h" -#include "simpleRL_move_generator.h" #include "manual_move_generator.h" #include "PlacementDelayCalculator.h" @@ -59,13 +42,11 @@ #include "tatum/echo_writer.hpp" #include "tatum/TimingReporter.hpp" -#include "placer_breakpoint.h" #include "RL_agent_util.h" #include "place_checkpoint.h" #include "clustered_netlist_utils.h" -#include "cluster_placement.h" #include "noc_place_utils.h" @@ -150,7 +131,7 @@ std::unique_ptr f_move_stats_file(nullptr, t, \ int(b_from), int(b_to), \ from_type->name, (to_type ? to_type->name : "EMPTY"), \ - affected_blocks.moved_blocks.size()); \ + affected_blocks.moved_blocks.size()); \ } \ } while (false) @@ -1325,7 +1306,7 @@ static e_move_result try_swap(const t_annealing_state* state, if (manual_move_enabled) { #ifndef NO_GRAPHICS create_move_outcome = manual_move_display_and_propose(manual_move_generator, blocks_affected, proposed_action.move_type, rlim, placer_opts, criticalities); -#else //NO_GRAPHICS \ +#else //NO_GRAPHICS //Cast to void to explicitly avoid warning. (void)manual_move_generator; #endif //NO_GRAPHICS diff --git a/vpr/src/place/place_constraints.h b/vpr/src/place/place_constraints.h index bb35e03a001..3f8767fa27c 100644 --- a/vpr/src/place/place_constraints.h +++ b/vpr/src/place/place_constraints.h @@ -10,7 +10,6 @@ */ #include "move_transactions.h" #include "region.h" -#include "clustered_netlist_utils.h" #include "partition_region.h" #include "place_macro.h" #include "grid_tile_lookup.h" @@ -100,16 +99,16 @@ void print_macro_constraint_error(const t_pl_macro& pl_macro); inline bool floorplan_legal(const t_pl_blocks_to_be_moved& blocks_affected) { bool floorplan_legal; - for (size_t i = 0; i < blocks_affected.moved_blocks.size(); i++) { - floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, - blocks_affected.moved_blocks[i].new_loc); + for (const auto& block : blocks_affected.moved_blocks) { + floorplan_legal = cluster_floorplanning_legal(block.block_num, + block.new_loc); if (!floorplan_legal) { VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\tMove aborted for block %zu, location tried was x: %d, y: %d, subtile: %d \n", - size_t(blocks_affected.moved_blocks[i].block_num), - blocks_affected.moved_blocks[i].new_loc.x, - blocks_affected.moved_blocks[i].new_loc.y, - blocks_affected.moved_blocks[i].new_loc.sub_tile); + size_t(block.block_num), + block.new_loc.x, + block.new_loc.y, + block.new_loc.sub_tile); return false; } } From 3e5e210dae1bd1739c6b6f172dcdc2016742ea7b Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Wed, 24 Jul 2024 14:42:21 -0400 Subject: [PATCH 10/11] [vpr][place] fixing CI compiler warning --- vpr/src/place/move_transactions.cpp | 1 + vpr/src/place/move_utils.cpp | 7 +++++++ vpr/src/place/place.cpp | 19 +++++++++++++++++++ vpr/src/place/place_constraints.h | 1 + 4 files changed, 28 insertions(+) diff --git a/vpr/src/place/move_transactions.cpp b/vpr/src/place/move_transactions.cpp index a113842b420..3063948285c 100644 --- a/vpr/src/place/move_transactions.cpp +++ b/vpr/src/place/move_transactions.cpp @@ -1,6 +1,7 @@ #include "move_utils.h" #include "globals.h" +#include "place_util.h" #include "vtr_assert.h" t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved(size_t max_blocks){ diff --git a/vpr/src/place/move_utils.cpp b/vpr/src/place/move_utils.cpp index e62936d0ed4..143fe0fd8d8 100644 --- a/vpr/src/place/move_utils.cpp +++ b/vpr/src/place/move_utils.cpp @@ -1,6 +1,13 @@ #include "move_utils.h" + +#include "place_util.h" #include "globals.h" + #include "vtr_random.h" + +#include "draw_debug.h" +#include "draw.h" + #include "place_constraints.h" #include "placer_globals.h" diff --git a/vpr/src/place/place.cpp b/vpr/src/place/place.cpp index bd69f22967b..31621994f92 100644 --- a/vpr/src/place/place.cpp +++ b/vpr/src/place/place.cpp @@ -1,11 +1,20 @@ #include #include #include +#include +#include +#include +#include +#include + +#include "NetPinTimingInvalidator.h" #include "vtr_assert.h" #include "vtr_log.h" #include "vtr_util.h" #include "vtr_random.h" +#include "vtr_geometry.h" #include "vtr_time.h" +#include "vtr_math.h" #include "vtr_ndmatrix.h" #include "vpr_types.h" @@ -18,6 +27,11 @@ #include "placer_globals.h" #include "read_place.h" #include "draw.h" +#include "place_and_route.h" +#include "net_delay.h" +#include "timing_place_lookup.h" +#include "timing_place.h" +#include "read_xml_arch_file.h" #include "echo_files.h" #include "place_macro.h" #include "histogram.h" @@ -31,7 +45,10 @@ #include "read_place.h" #include "place_constraints.h" #include "manual_moves.h" +#include "buttons.h" +#include "static_move_generator.h" +#include "simpleRL_move_generator.h" #include "manual_move_generator.h" #include "PlacementDelayCalculator.h" @@ -42,11 +59,13 @@ #include "tatum/echo_writer.hpp" #include "tatum/TimingReporter.hpp" +#include "placer_breakpoint.h" #include "RL_agent_util.h" #include "place_checkpoint.h" #include "clustered_netlist_utils.h" +#include "cluster_placement.h" #include "noc_place_utils.h" diff --git a/vpr/src/place/place_constraints.h b/vpr/src/place/place_constraints.h index 3f8767fa27c..c4695d8819e 100644 --- a/vpr/src/place/place_constraints.h +++ b/vpr/src/place/place_constraints.h @@ -10,6 +10,7 @@ */ #include "move_transactions.h" #include "region.h" +#include "clustered_netlist_utils.h" #include "partition_region.h" #include "place_macro.h" #include "grid_tile_lookup.h" From c7cbf3388da1cf2ddb6496376fbd8b6e515b9690 Mon Sep 17 00:00:00 2001 From: Yulang Luo Date: Sun, 28 Jul 2024 00:15:57 -0400 Subject: [PATCH 11/11] [vpr][place] addressing PR comments --- vpr/src/place/initial_noc_placement.cpp | 2 +- vpr/src/place/move_transactions.cpp | 76 ++++++++++++++++--------- vpr/src/place/move_transactions.h | 36 ++++++++---- vpr/src/place/move_utils.cpp | 36 +++--------- vpr/src/place/move_utils.h | 2 - vpr/src/place/net_cost_handler.cpp | 69 ++++++++++++---------- vpr/src/place/place.cpp | 9 +-- vpr/src/place/place_constraints.h | 14 ++--- vpr/src/place/placer_breakpoint.cpp | 2 +- vpr/src/place/placer_breakpoint.h | 2 +- vpr/test/test_noc_place_utils.cpp | 8 +-- 11 files changed, 138 insertions(+), 118 deletions(-) diff --git a/vpr/src/place/initial_noc_placement.cpp b/vpr/src/place/initial_noc_placement.cpp index 2cf2bf3f1f3..8532d063133 100644 --- a/vpr/src/place/initial_noc_placement.cpp +++ b/vpr/src/place/initial_noc_placement.cpp @@ -220,7 +220,7 @@ static void noc_routers_anneal(const t_noc_opts& noc_opts) { // Generate and evaluate router moves for (int i_move = 0; i_move < N_MOVES; i_move++) { e_create_move create_move_outcome = e_create_move::ABORT; - clear_move_blocks(blocks_affected); + blocks_affected.clear_move_blocks(); // Shrink the range limit over time float r_lim_decayed = 1.0f + (N_MOVES - i_move) * (max_r_lim / N_MOVES); create_move_outcome = propose_router_swap(blocks_affected, r_lim_decayed); diff --git a/vpr/src/place/move_transactions.cpp b/vpr/src/place/move_transactions.cpp index 3063948285c..db06d34e608 100644 --- a/vpr/src/place/move_transactions.cpp +++ b/vpr/src/place/move_transactions.cpp @@ -1,3 +1,4 @@ +#include "move_transactions.h" #include "move_utils.h" #include "globals.h" @@ -6,7 +7,6 @@ t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved(size_t max_blocks){ moved_blocks.reserve(max_blocks); - moved_blocks.resize(0); } size_t t_pl_blocks_to_be_moved::get_size_and_increment() { @@ -16,9 +16,9 @@ size_t t_pl_blocks_to_be_moved::get_size_and_increment() { } //Records that block 'blk' should be moved to the specified 'to' location -e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId blk, t_pl_loc to) { - auto res = blocks_affected.moved_to.emplace(to); - if (!res.second) { +e_block_move_result t_pl_blocks_to_be_moved::record_block_move(ClusterBlockId blk, t_pl_loc to) { + auto [to_it, to_success] = moved_to.emplace(to); + if (!to_success) { log_move_abort("duplicate block move to location"); return e_block_move_result::ABORT; } @@ -27,8 +27,9 @@ e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected, t_pl_loc from = place_ctx.block_locs[blk].loc; - auto res2 = blocks_affected.moved_from.emplace(from); - if (!res2.second) { + auto [_, from_success] = moved_from.emplace(from); + if (!from_success) { + moved_to.erase(to_it); log_move_abort("duplicate block move from location"); return e_block_move_result::ABORT; } @@ -36,14 +37,35 @@ e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected, VTR_ASSERT_SAFE(to.sub_tile < int(place_ctx.grid_blocks.num_blocks_at_location({to.x, to.y, to.layer}))); // Sets up the blocks moved - size_t imoved_blk = blocks_affected.get_size_and_increment(); - blocks_affected.moved_blocks[imoved_blk].block_num = blk; - blocks_affected.moved_blocks[imoved_blk].old_loc = from; - blocks_affected.moved_blocks[imoved_blk].new_loc = to; + size_t imoved_blk = get_size_and_increment(); + moved_blocks[imoved_blk].block_num = blk; + moved_blocks[imoved_blk].old_loc = from; + moved_blocks[imoved_blk].new_loc = to; return e_block_move_result::VALID; } +//Examines the currently proposed move and determine any empty locations +std::set t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved::determine_locations_emptied_by_move() { + std::set moved_from_set; + std::set moved_to_set; + + for (const t_pl_moved_block& moved_block : moved_blocks) { + //When a block is moved its old location becomes free + moved_from_set.emplace(moved_block.old_loc); + + //But any block later moved to a position fills it + moved_to_set.emplace(moved_block.new_loc); + } + + std::set empty_locs; + std::set_difference(moved_from_set.begin(), moved_from_set.end(), + moved_to_set.begin(), moved_to_set.end(), + std::inserter(empty_locs, empty_locs.begin())); + + return empty_locs; +} + //Moves the blocks in blocks_affected to their new locations void apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { auto& place_ctx = g_vpr_ctx.mutable_placement(); @@ -51,11 +73,11 @@ void apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { //Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks //yet since we don't know whether the swap will be accepted - for (const auto& block : blocks_affected.moved_blocks) { - ClusterBlockId blk = block.block_num; + for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) { + ClusterBlockId blk = moved_block.block_num; - const t_pl_loc& old_loc = block.old_loc; - const t_pl_loc& new_loc = block.new_loc; + const t_pl_loc& old_loc = moved_block.old_loc; + const t_pl_loc& new_loc = moved_block.new_loc; // move the block to its new location place_ctx.block_locs[blk].loc = new_loc; @@ -78,11 +100,11 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { auto& place_ctx = g_vpr_ctx.mutable_placement(); /* Swap physical location */ - for (const auto& block : blocks_affected.moved_blocks) { - ClusterBlockId blk = block.block_num; + for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) { + ClusterBlockId blk = moved_block.block_num; - const t_pl_loc& to = block.new_loc; - const t_pl_loc& from = block.old_loc; + const t_pl_loc& to = moved_block.new_loc; + const t_pl_loc& from = moved_block.old_loc; //Remove from old location only if it hasn't already been updated by a previous block update if (place_ctx.grid_blocks.block_at_location(from) == blk) { @@ -108,11 +130,11 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { auto& device_ctx = g_vpr_ctx.device(); // Swap the blocks back, nets not yet swapped they don't need to be changed - for (const auto& block : blocks_affected.moved_blocks) { - ClusterBlockId blk = block.block_num; + for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) { + ClusterBlockId blk = moved_block.block_num; - const t_pl_loc& old_loc = block.old_loc; - const t_pl_loc& new_loc = block.new_loc; + const t_pl_loc& old_loc = moved_block.old_loc; + const t_pl_loc& new_loc = moved_block.new_loc; // return the block to where it was before the swap place_ctx.block_locs[blk].loc = old_loc; @@ -132,15 +154,15 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) { } //Clears the current move so a new move can be proposed -void clear_move_blocks(t_pl_blocks_to_be_moved& blocks_affected) { +void t_pl_blocks_to_be_moved::clear_move_blocks() { //Reset moved flags - blocks_affected.moved_to.clear(); - blocks_affected.moved_from.clear(); + moved_to.clear(); + moved_from.clear(); //For run-time, we just reset size of blocks_affected.moved_blocks to zero, but do not free the blocks_affected //array to avoid memory allocation - blocks_affected.moved_blocks.resize(0); + moved_blocks.resize(0); - blocks_affected.affected_pins.clear(); + affected_pins.clear(); } diff --git a/vpr/src/place/move_transactions.h b/vpr/src/place/move_transactions.h index 05b7486cc35..65e4c89774b 100644 --- a/vpr/src/place/move_transactions.h +++ b/vpr/src/place/move_transactions.h @@ -3,6 +3,13 @@ #include "vpr_types.h" #include "clustered_netlist_utils.h" +enum class e_block_move_result { + VALID, //Move successful + ABORT, //Unable to perform move + INVERT, //Try move again but with from/to inverted + INVERT_VALID //Completed inverted move +}; + /* Stores the information of the move for a block that is * * moved during placement * * block_num: the index of the moved block * @@ -33,23 +40,32 @@ struct t_pl_moved_block { * graph. */ struct t_pl_blocks_to_be_moved { explicit t_pl_blocks_to_be_moved(size_t max_blocks); + t_pl_blocks_to_be_moved() = delete; + t_pl_blocks_to_be_moved(const t_pl_blocks_to_be_moved&) = delete; + t_pl_blocks_to_be_moved(t_pl_blocks_to_be_moved&&) = delete; + +/** + * @brief This function increments the size of the moved_blocks vector and return the index + * of the newly added last elements. + */ + size_t get_size_and_increment(); + +/** + * @brief This function clears all data structures of this struct. + */ + void clear_move_blocks(); + + e_block_move_result record_block_move(ClusterBlockId blk, t_pl_loc to); + + std::set determine_locations_emptied_by_move(); std::vector moved_blocks; std::unordered_set moved_from; std::unordered_set moved_to; std::vector affected_pins; - size_t get_size_and_increment(); -}; - -enum class e_block_move_result { - VALID, //Move successful - ABORT, //Unable to perform move - INVERT, //Try move again but with from/to inverted - INVERT_VALID //Completed inverted move }; -e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId blk, t_pl_loc to); void apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected); @@ -57,6 +73,4 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected); void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected); -void clear_move_blocks(t_pl_blocks_to_be_moved& blocks_affected); - #endif diff --git a/vpr/src/place/move_utils.cpp b/vpr/src/place/move_utils.cpp index 143fe0fd8d8..02e20f24fd0 100644 --- a/vpr/src/place/move_utils.cpp +++ b/vpr/src/place/move_utils.cpp @@ -1,5 +1,6 @@ #include "move_utils.h" +#include "move_transactions.h" #include "place_util.h" #include "globals.h" @@ -141,7 +142,7 @@ e_block_move_result record_single_block_swap(t_pl_blocks_to_be_moved& blocks_aff // Check whether the to_location is empty if (b_to == EMPTY_BLOCK_ID) { // Sets up the blocks moved - outcome = record_block_move(blocks_affected, b_from, to); + outcome = blocks_affected.record_block_move(b_from, to); } else if (b_to != INVALID_BLOCK_ID) { // Check whether block to is compatible with from location @@ -152,14 +153,14 @@ e_block_move_result record_single_block_swap(t_pl_blocks_to_be_moved& blocks_aff } // Sets up the blocks moved - outcome = record_block_move(blocks_affected, b_from, to); + outcome = blocks_affected.record_block_move(b_from, to); if (outcome != e_block_move_result::VALID) { return outcome; } t_pl_loc from = place_ctx.block_locs[b_from].loc; - outcome = record_block_move(blocks_affected, b_to, from); + outcome = blocks_affected.record_block_move(b_to, from); } // Finish swapping the blocks and setting up blocks_affected @@ -341,7 +342,7 @@ e_block_move_result record_macro_move(t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId blk_to = place_ctx.grid_blocks.block_at_location(to); - record_block_move(blocks_affected, member.blk_index, to); + blocks_affected.record_block_move(member.blk_index, to); int imacro_to = -1; get_imacro_from_iblk(&imacro_to, blk_to, place_ctx.pl_macros); @@ -392,7 +393,7 @@ e_block_move_result record_macro_self_swaps(t_pl_blocks_to_be_moved& blocks_affe auto& place_ctx = g_vpr_ctx.placement(); //Reset any partial move - clear_move_blocks(blocks_affected); + blocks_affected.clear_move_blocks(); //Collect the macros affected std::vector affected_macros; @@ -431,14 +432,14 @@ e_block_move_result record_macro_self_swaps(t_pl_blocks_to_be_moved& blocks_affe std::copy_if(displaced_blocks.begin(), displaced_blocks.end(), std::back_inserter(non_macro_displaced_blocks), is_non_macro_block); //Based on the currently queued block moves, find the empty 'holes' left behind - auto empty_locs = determine_locations_emptied_by_move(blocks_affected); + auto empty_locs = blocks_affected.determine_locations_emptied_by_move(); VTR_ASSERT_SAFE(empty_locs.size() >= non_macro_displaced_blocks.size()); //Fit the displaced blocks into the empty locations auto loc_itr = empty_locs.begin(); for (auto blk : non_macro_displaced_blocks) { - outcome = record_block_move(blocks_affected, blk, *loc_itr); + outcome = blocks_affected.record_block_move(blk, *loc_itr); ++loc_itr; } @@ -483,27 +484,6 @@ bool is_legal_swap_to_location(ClusterBlockId blk, t_pl_loc to) { return true; } -//Examines the currently proposed move and determine any empty locations -std::set determine_locations_emptied_by_move(t_pl_blocks_to_be_moved& blocks_affected) { - std::set moved_from; - std::set moved_to; - - for (const auto& block : blocks_affected.moved_blocks) { - //When a block is moved its old location becomes free - moved_from.emplace(block.old_loc); - - //But any block later moved to a position fills it - moved_to.emplace(block.new_loc); - } - - std::set empty_locs; - std::set_difference(moved_from.begin(), moved_from.end(), - moved_to.begin(), moved_to.end(), - std::inserter(empty_locs, empty_locs.begin())); - - return empty_locs; -} - #ifdef VTR_ENABLE_DEBUG_LOGGING void enable_placer_debug(const t_placer_opts& placer_opts, ClusterBlockId blk_id) { diff --git a/vpr/src/place/move_utils.h b/vpr/src/place/move_utils.h index ce599492358..3bb70438eae 100644 --- a/vpr/src/place/move_utils.h +++ b/vpr/src/place/move_utils.h @@ -125,8 +125,6 @@ e_block_move_result record_macro_self_swaps(t_pl_blocks_to_be_moved& blocks_affe */ bool is_legal_swap_to_location(ClusterBlockId blk, t_pl_loc to); -std::set determine_locations_emptied_by_move(t_pl_blocks_to_be_moved& blocks_affected); - /** * @brief Propose block for the RL agent based on required block type. * diff --git a/vpr/src/place/net_cost_handler.cpp b/vpr/src/place/net_cost_handler.cpp index a2b027f51e6..53aed32dea1 100644 --- a/vpr/src/place/net_cost_handler.cpp +++ b/vpr/src/place/net_cost_handler.cpp @@ -125,22 +125,27 @@ struct TSInfo { vtr::Matrix ts_layer_sink_pin_count; /* [0...num_afftected_nets] -> net_id of the affected nets */ std::vector ts_nets_to_update; + // TSInfo(const TSInfo&) = delete; + // TSInfo(TSInfo&&) = delete; }; /** * @brief This class is used to hide control flows needed to distinguish 2d and 3d placement */ class BBUpdater { - bool cube_bb = false; + // BBUpdater(const BBUpdater&) = delete; + // BBUpdater(BBUpdater&&) = delete; + + private: + bool m_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); + 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); }; } // namespace @@ -213,8 +218,8 @@ static void record_affected_net(const ClusterNetId net); static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm, const PlaceDelayModel* delay_model, const PlacerCriticalities* criticalities, - const ClusterBlockId& blk_id, - const ClusterPinId& pin_id, + const ClusterBlockId blk_id, + const ClusterPinId pin_id, const t_pl_moved_block& moving_blk_inf, std::vector& affected_pins, double& timing_delta_c, @@ -477,12 +482,12 @@ static void set_bb_delta_cost(double& bb_delta_c); /******************************* End of Function definitions ************************************/ namespace { // Initialize the ts vectors -void BBUpdater::init(size_t num_nets, bool cube_bb_in) { +void BBUpdater::init(size_t num_nets, bool cube_bb) { const int num_layers = g_vpr_ctx.device().grid.get_num_layers(); - cube_bb = cube_bb_in; + m_cube_bb = cube_bb; // Either 3D BB or per layer BB data structure are used, not both. - if (cube_bb) { + if (m_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 { @@ -497,18 +502,20 @@ void BBUpdater::init(size_t num_nets, bool cube_bb_in) { } void BBUpdater::get_non_updatable_bb(const ClusterNetId& net) { - if (cube_bb) + if (m_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 + } + 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)]); + } } void BBUpdater::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) + if (m_cube_bb) { ::update_bb(net_id, ts_info.ts_bb_edge_new[net_id], ts_info.ts_bb_coord_new[net_id], @@ -516,7 +523,8 @@ void BBUpdater::update_bb(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, pin_old_loc, pin_new_loc, is_driver); - else + } + else { ::update_layer_bb(net_id, ts_info.layer_ts_bb_edge_new[net_id], ts_info.layer_ts_bb_coord_new[net_id], @@ -524,27 +532,30 @@ void BBUpdater::update_bb(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, pin_old_loc, pin_new_loc, is_driver); + } } -double BBUpdater::get_net_cost(const ClusterNetId& net_id) { - if (cube_bb) +double BBUpdater::get_net_cost(const ClusterNetId net_id) { + if (m_cube_bb) { return ::get_net_cost(net_id, ts_info.ts_bb_coord_new[net_id]); - else + } + 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 BBUpdater::set_ts_bb_coord(const ClusterNetId& net_id) { +void BBUpdater::set_ts_bb_coord(const ClusterNetId net_id) { auto& place_move_ctx = g_placer_ctx.mutable_move(); - if (cube_bb) { + if (m_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 BBUpdater::set_ts_edge(const ClusterNetId& net_id) { +void BBUpdater::set_ts_edge(const ClusterNetId net_id) { auto& place_move_ctx = g_placer_ctx.mutable_move(); - if (cube_bb) { + if (m_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]; @@ -699,10 +710,8 @@ static void record_affected_net(const ClusterNetId net) { /* Record effected nets. */ if (pl_net_cost.proposed_net_cost[net] < 0.) { /* Net not marked yet. */ - size_t last_size = ts_info.ts_nets_to_update.size(); - VTR_ASSERT(last_size < ts_info.ts_nets_to_update.capacity()); - ts_info.ts_nets_to_update.resize(last_size + 1); - ts_info.ts_nets_to_update[last_size] = net; + VTR_ASSERT_SAFE(ts_info.ts_nets_to_update.size() < ts_info.ts_nets_to_update.capacity()); + ts_info.ts_nets_to_update.push_back(net); /* Flag to say we've marked this net. */ pl_net_cost.proposed_net_cost[net] = 1.; @@ -712,8 +721,8 @@ static void record_affected_net(const ClusterNetId net) { static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm, const PlaceDelayModel* delay_model, const PlacerCriticalities* criticalities, - const ClusterBlockId& blk_id, - const ClusterPinId& pin_id, + const ClusterBlockId blk_id, + const ClusterPinId pin_id, const t_pl_moved_block& moving_blk_inf, std::vector& affected_pins, double& timing_delta_c, @@ -1892,7 +1901,7 @@ static double wirelength_crossing_count(size_t fanout) { } static void set_bb_delta_cost(double& bb_delta_c) { - for (const auto& ts_net: ts_info.ts_nets_to_update) { + for (const ClusterNetId ts_net: ts_info.ts_nets_to_update) { ClusterNetId net_id = ts_net; pl_net_cost.proposed_net_cost[net_id] = bb_updater.get_net_cost(net_id); @@ -2028,7 +2037,7 @@ void update_move_nets() { auto& cluster_ctx = g_vpr_ctx.clustering(); auto& place_move_ctx = g_placer_ctx.mutable_move(); - for (const auto& ts_net : ts_info.ts_nets_to_update) { + for (const ClusterNetId ts_net : ts_info.ts_nets_to_update) { ClusterNetId net_id = ts_net; bb_updater.set_ts_bb_coord(net_id); @@ -2051,7 +2060,7 @@ void update_move_nets() { void reset_move_nets() { /* Reset the net cost function flags first. */ - for (const auto& ts_net : ts_info.ts_nets_to_update) { + for (const ClusterNetId ts_net : ts_info.ts_nets_to_update) { ClusterNetId net_id = ts_net; pl_net_cost.proposed_net_cost[net_id] = -1; pl_net_cost.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET; diff --git a/vpr/src/place/place.cpp b/vpr/src/place/place.cpp index 31621994f92..e07fd7fa01a 100644 --- a/vpr/src/place/place.cpp +++ b/vpr/src/place/place.cpp @@ -1378,9 +1378,8 @@ static e_move_result try_swap(const t_annealing_state* state, // //Also find all the pins affected by the swap, and calculates new connection //delays and timing costs and store them in proposed_* data structures. - find_affected_nets_and_update_costs( - place_algorithm, delay_model, criticalities, blocks_affected, - bb_delta_c, timing_delta_c); + find_affected_nets_and_update_costs(place_algorithm, delay_model, criticalities, + blocks_affected, bb_delta_c, timing_delta_c); //For setup slack analysis, we first do a timing analysis to get the newest //slack values resulted from the proposed block moves. If the move turns out @@ -1567,8 +1566,6 @@ static e_move_result try_swap(const t_annealing_state* state, if (!router_block_move) { calculate_reward_and_process_outcome(placer_opts, move_outcome_stats, delta_c, timing_bb_factor, move_generator); - } else { - // std::cout << "Group move delta cost: " << delta_c << std::endl; } #ifdef VTR_ENABLE_DEBUG_LOGGING @@ -1578,7 +1575,7 @@ static e_move_result try_swap(const t_annealing_state* state, #endif /* Clear the data structure containing block move info */ - clear_move_blocks(blocks_affected); + blocks_affected.clear_move_blocks(); //VTR_ASSERT(check_macro_placement_consistency() == 0); #if 0 diff --git a/vpr/src/place/place_constraints.h b/vpr/src/place/place_constraints.h index c4695d8819e..493f378b99d 100644 --- a/vpr/src/place/place_constraints.h +++ b/vpr/src/place/place_constraints.h @@ -100,16 +100,16 @@ void print_macro_constraint_error(const t_pl_macro& pl_macro); inline bool floorplan_legal(const t_pl_blocks_to_be_moved& blocks_affected) { bool floorplan_legal; - for (const auto& block : blocks_affected.moved_blocks) { - floorplan_legal = cluster_floorplanning_legal(block.block_num, - block.new_loc); + for (const t_pl_moved_block& moved_block : blocks_affected.moved_blocks) { + floorplan_legal = cluster_floorplanning_legal(moved_block.block_num, + moved_block.new_loc); if (!floorplan_legal) { VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\tMove aborted for block %zu, location tried was x: %d, y: %d, subtile: %d \n", - size_t(block.block_num), - block.new_loc.x, - block.new_loc.y, - block.new_loc.sub_tile); + size_t(moved_block.block_num), + moved_block.new_loc.x, + moved_block.new_loc.y, + moved_block.new_loc.sub_tile); return false; } } diff --git a/vpr/src/place/placer_breakpoint.cpp b/vpr/src/place/placer_breakpoint.cpp index 4b23862daf9..b576bc64f04 100644 --- a/vpr/src/place/placer_breakpoint.cpp +++ b/vpr/src/place/placer_breakpoint.cpp @@ -8,7 +8,7 @@ std::map available_move_types = { # ifndef NO_GRAPHICS //transforms the vector moved_blocks to a vector of ints and adds it in glob_breakpoint_state -void transform_blocks_affected(t_pl_blocks_to_be_moved blocksAffected) { +void transform_blocks_affected(const t_pl_blocks_to_be_moved& blocksAffected) { get_bp_state_globals()->get_glob_breakpoint_state()->blocks_affected_by_move.clear(); for (size_t i = 0; i < blocksAffected.moved_blocks.size(); i++) { //size_t conversion is required since block_num is of type ClusterBlockId and can't be cast to an int. And this vector has to be of type int to be recognized in expr_eval class diff --git a/vpr/src/place/placer_breakpoint.h b/vpr/src/place/placer_breakpoint.h index 36f2da7ef63..c01ef77450c 100644 --- a/vpr/src/place/placer_breakpoint.h +++ b/vpr/src/place/placer_breakpoint.h @@ -10,7 +10,7 @@ #ifdef VTR_ENABLE_DEBUG_LOGGING //transforms the vector moved_blocks to a vector of ints and adds it in glob_breakpoint_state -void transform_blocks_affected(t_pl_blocks_to_be_moved blocksAffected); +void transform_blocks_affected(const t_pl_blocks_to_be_moved& blocksAffected); //checks the breakpoint and see whether one of them was reached and pause place,emt accordingly void stop_placement_and_check_breakpoints(t_pl_blocks_to_be_moved& blocks_affected, e_move_result move_outcome, double delta_c, double bb_delta_c, double timing_delta_c); diff --git a/vpr/test/test_noc_place_utils.cpp b/vpr/test/test_noc_place_utils.cpp index 8d3ba5c346f..4633996458d 100644 --- a/vpr/test/test_noc_place_utils.cpp +++ b/vpr/test/test_noc_place_utils.cpp @@ -878,7 +878,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_ commit_noc_costs(); // clear the affected blocks - clear_move_blocks(blocks_affected); + blocks_affected.clear_move_blocks(); // clear the routed traffic flows routed_traffic_flows.clear(); @@ -1026,7 +1026,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_ commit_noc_costs(); // clear the affected blocks - clear_move_blocks(blocks_affected); + blocks_affected.clear_move_blocks(); /* * Now we will run a test where one of the router clusters we will swap has no traffic flows associated with it. This will make sure whether the test @@ -1127,7 +1127,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_ commit_noc_costs(); // clear the affected blocks - clear_move_blocks(blocks_affected); + blocks_affected.clear_move_blocks(); /* * Now we will run a test where both of the router clusters being swapped @@ -1192,7 +1192,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_ commit_noc_costs(); // clear the affected blocks - clear_move_blocks(blocks_affected); + blocks_affected.clear_move_blocks(); // now verify the test function by comparing the link bandwidths in the noc model (should have been updated by the test function) to the golden set int number_of_links = golden_link_bandwidths.size();