From b13814b509c8d5bb0ce9ef10585a44412bcc4341 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 7 Apr 2021 19:35:04 -0400 Subject: [PATCH 01/19] Added floorplan constraint checks to the placement move generators --- vpr/src/place/centroid_move_generator.cpp | 17 ++++++++++++++++- .../place/critical_uniform_move_generator.cpp | 17 ++++++++++++++++- .../place/feasible_region_move_generator.cpp | 17 ++++++++++++++++- vpr/src/place/median_move_generator.cpp | 18 ++++++++++++++++-- vpr/src/place/place_constraints.cpp | 3 +++ vpr/src/place/static_move_generator.cpp | 2 +- vpr/src/place/uniform_move_generator.cpp | 17 ++++++++++++++++- .../weighted_centroid_move_generator.cpp | 17 ++++++++++++++++- .../place/weighted_median_move_generator.cpp | 19 ++++++++++++++++++- 9 files changed, 118 insertions(+), 9 deletions(-) diff --git a/vpr/src/place/centroid_move_generator.cpp b/vpr/src/place/centroid_move_generator.cpp index 623fe71d4c3..165becacb29 100644 --- a/vpr/src/place/centroid_move_generator.cpp +++ b/vpr/src/place/centroid_move_generator.cpp @@ -2,6 +2,7 @@ #include "vpr_types.h" #include "globals.h" #include "directed_moves_util.h" +#include "place_constraints.h" e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, e_move_type& /*move_type*/, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* /*criticalities*/) { /* Pick a random block to be swapped with another random block. */ @@ -35,5 +36,19 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block return e_create_move::ABORT; } - return ::create_move(blocks_affected, b_from, to); + e_create_move create_move; + create_move = ::create_move(blocks_affected, b_from, to); + + //Check if the move is legal from a floorplan perspective + //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap + bool floorplan_legal = true; + for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + if (!floorplan_legal) { + VTR_LOG("Move 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); + return e_create_move::ABORT; + } + } + + return create_move; } diff --git a/vpr/src/place/critical_uniform_move_generator.cpp b/vpr/src/place/critical_uniform_move_generator.cpp index 733354649b1..394e68f1618 100644 --- a/vpr/src/place/critical_uniform_move_generator.cpp +++ b/vpr/src/place/critical_uniform_move_generator.cpp @@ -1,5 +1,6 @@ #include "critical_uniform_move_generator.h" #include "globals.h" +#include "place_constraints.h" e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, e_move_type& /*move_type*/, float rlim, const t_placer_opts& /*placer_opts*/, const PlacerCriticalities* /*criticalities*/) { auto& place_ctx = g_vpr_ctx.placement(); @@ -33,5 +34,19 @@ e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved return e_create_move::ABORT; } - return ::create_move(blocks_affected, b_from, to); + e_create_move create_move; + create_move = ::create_move(blocks_affected, b_from, to); + + //Check if the move is legal from a floorplan perspective + //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap + bool floorplan_legal = true; + for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + if (!floorplan_legal) { + VTR_LOG("Move 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); + return e_create_move::ABORT; + } + } + + return create_move; } diff --git a/vpr/src/place/feasible_region_move_generator.cpp b/vpr/src/place/feasible_region_move_generator.cpp index 1ab6e8770aa..bea8e3dab7b 100644 --- a/vpr/src/place/feasible_region_move_generator.cpp +++ b/vpr/src/place/feasible_region_move_generator.cpp @@ -2,6 +2,7 @@ #include "globals.h" #include #include "math.h" +#include "place_constraints.h" e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, e_move_type& /*move_type*/, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* criticalities) { auto& place_ctx = g_vpr_ctx.placement(); @@ -122,5 +123,19 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& return e_create_move::ABORT; } - return ::create_move(blocks_affected, b_from, to); + e_create_move create_move; + create_move = ::create_move(blocks_affected, b_from, to); + + //Check if the move is legal from a floorplan perspective + //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap + bool floorplan_legal = true; + for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + if (!floorplan_legal) { + VTR_LOG("Move 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); + return e_create_move::ABORT; + } + } + + return create_move; } diff --git a/vpr/src/place/median_move_generator.cpp b/vpr/src/place/median_move_generator.cpp index fb7a0a2589e..adf4505fedb 100644 --- a/vpr/src/place/median_move_generator.cpp +++ b/vpr/src/place/median_move_generator.cpp @@ -1,7 +1,7 @@ #include "median_move_generator.h" #include "globals.h" #include - +#include "place_constraints.h" #include "placer_globals.h" static bool get_bb_incrementally(ClusterNetId net_id, t_bb* bb_coord_new, int xold, int yold, int xnew, int ynew); @@ -122,7 +122,21 @@ e_create_move MedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_ if (!find_to_loc_centroid(cluster_from_type, from, median_point, range_limiters, to)) return e_create_move::ABORT; - return ::create_move(blocks_affected, b_from, to); + e_create_move create_move; + create_move = ::create_move(blocks_affected, b_from, to); + + //Check if the move is legal from a floorplan perspective + //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap + bool floorplan_legal = true; + for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + if (!floorplan_legal) { + VTR_LOG("Move 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); + return e_create_move::ABORT; + } + } + + return create_move; } /* Finds the bounding box of a net and stores its coordinates in the * diff --git a/vpr/src/place/place_constraints.cpp b/vpr/src/place/place_constraints.cpp index 27c83b20009..cff83ba9f24 100644 --- a/vpr/src/place/place_constraints.cpp +++ b/vpr/src/place/place_constraints.cpp @@ -123,8 +123,10 @@ bool cluster_floorplanning_check(ClusterBlockId blk_id, t_pl_loc loc) { if (!cluster_constrained) { //not constrained so will not have floorplanning issues + //VTR_LOG("Cluster not constrained \n"); floorplanning_good = true; } else { + //VTR_LOG("Cluster is constrained \n"); PartitionRegion pr; pr = floorplanning_ctx.cluster_constraints[blk_id]; bool in_pr = pr.is_loc_in_part_reg(loc); @@ -132,6 +134,7 @@ bool cluster_floorplanning_check(ClusterBlockId blk_id, t_pl_loc loc) { //if location is in partitionregion, floorplanning is respected //if not it is not if (in_pr) { + //VTR_LOG("Block %zu passed floorplan check \n", size_t(blk_id)); floorplanning_good = true; } else { VTR_LOG("Block %zu did not pass cluster_floorplanning_check \n", size_t(blk_id)); diff --git a/vpr/src/place/static_move_generator.cpp b/vpr/src/place/static_move_generator.cpp index 8e946965b4d..3eefce43ed6 100644 --- a/vpr/src/place/static_move_generator.cpp +++ b/vpr/src/place/static_move_generator.cpp @@ -27,7 +27,7 @@ void StaticMoveGenerator::initialize_move_prob(const std::vector& prob) { } e_create_move StaticMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, e_move_type& move_type, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* criticalities) { - float rand_num = vtr::frand() * total_prob; + float rand_num = vtr::frand() * total_prob; for (size_t i = 0; i < cumm_move_probs.size(); i++) { if (rand_num <= cumm_move_probs[i]) { move_type = (e_move_type)i; diff --git a/vpr/src/place/uniform_move_generator.cpp b/vpr/src/place/uniform_move_generator.cpp index cda816e3a2b..2cbf6ed7c83 100644 --- a/vpr/src/place/uniform_move_generator.cpp +++ b/vpr/src/place/uniform_move_generator.cpp @@ -1,5 +1,6 @@ #include "uniform_move_generator.h" #include "globals.h" +#include "place_constraints.h" e_create_move UniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, e_move_type& /*move_type*/, float rlim, const t_placer_opts& /*placer_opts*/, const PlacerCriticalities* /*criticalities*/) { /* Pick a random block to be swapped with another random block. */ @@ -34,5 +35,19 @@ e_create_move UniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks VTR_LOG("\n"); #endif - return ::create_move(blocks_affected, b_from, to); + e_create_move create_move; + create_move = ::create_move(blocks_affected, b_from, to); + + //Check if the move is legal from a floorplan perspective + //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap + bool floorplan_legal = true; + for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + if (!floorplan_legal) { + VTR_LOG("Move 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); + return e_create_move::ABORT; + } + } + + return create_move; } diff --git a/vpr/src/place/weighted_centroid_move_generator.cpp b/vpr/src/place/weighted_centroid_move_generator.cpp index 0a3ae5f6245..70626b5d272 100644 --- a/vpr/src/place/weighted_centroid_move_generator.cpp +++ b/vpr/src/place/weighted_centroid_move_generator.cpp @@ -2,6 +2,7 @@ #include "globals.h" #include #include "directed_moves_util.h" +#include "place_constraints.h" e_create_move WeightedCentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, e_move_type& /*move_type*/, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* criticalities) { /* Pick a random block to be swapped with another random block. */ @@ -35,5 +36,19 @@ e_create_move WeightedCentroidMoveGenerator::propose_move(t_pl_blocks_to_be_move return e_create_move::ABORT; } - return ::create_move(blocks_affected, b_from, to); + e_create_move create_move; + create_move = ::create_move(blocks_affected, b_from, to); + + //Check if the move is legal from a floorplan perspective + //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap + bool floorplan_legal = true; + for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + if (!floorplan_legal) { + VTR_LOG("Move 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); + return e_create_move::ABORT; + } + } + + return create_move; } diff --git a/vpr/src/place/weighted_median_move_generator.cpp b/vpr/src/place/weighted_median_move_generator.cpp index 5f4baded879..2905e696b77 100644 --- a/vpr/src/place/weighted_median_move_generator.cpp +++ b/vpr/src/place/weighted_median_move_generator.cpp @@ -2,6 +2,7 @@ #include "globals.h" #include #include "math.h" +#include "place_constraints.h" #define CRIT_MULT_FOR_W_MEDIAN 10 @@ -101,7 +102,23 @@ e_create_move WeightedMedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& if (!find_to_loc_centroid(cluster_from_type, from, w_median_point, range_limiters, to)) { return e_create_move::ABORT; } - return ::create_move(blocks_affected, b_from, to); + //return ::create_move(blocks_affected, b_from, to); + + e_create_move create_move; + create_move = ::create_move(blocks_affected, b_from, to); + + //Check if the move is legal from a floorplan perspective + //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap + bool floorplan_legal = true; + for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + if (!floorplan_legal) { + VTR_LOG("Move 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); + return e_create_move::ABORT; + } + } + + return create_move; } /** From 1c4d515b1d098e02837758262034d8a96a3c8f08 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Thu, 8 Apr 2021 09:55:49 -0400 Subject: [PATCH 02/19] added comments and changed cluster_floorplanning_check -> cluster_floorplanning_legal --- vpr/src/place/centroid_move_generator.cpp | 6 +++--- vpr/src/place/critical_uniform_move_generator.cpp | 6 +++--- vpr/src/place/feasible_region_move_generator.cpp | 6 +++--- vpr/src/place/initial_placement.cpp | 2 +- vpr/src/place/median_move_generator.cpp | 6 +++--- vpr/src/place/move_transactions.h | 8 +++----- vpr/src/place/place_constraints.cpp | 12 ++++++------ vpr/src/place/place_constraints.h | 2 +- vpr/src/place/static_move_generator.cpp | 2 +- vpr/src/place/uniform_move_generator.cpp | 6 +++--- vpr/src/place/weighted_centroid_move_generator.cpp | 6 +++--- vpr/src/place/weighted_median_move_generator.cpp | 6 +++--- 12 files changed, 33 insertions(+), 35 deletions(-) diff --git a/vpr/src/place/centroid_move_generator.cpp b/vpr/src/place/centroid_move_generator.cpp index 165becacb29..19d1925bf4b 100644 --- a/vpr/src/place/centroid_move_generator.cpp +++ b/vpr/src/place/centroid_move_generator.cpp @@ -43,10 +43,10 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap bool floorplan_legal = true; for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; + VTR_LOG("Move 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); + return e_create_move::ABORT; } } diff --git a/vpr/src/place/critical_uniform_move_generator.cpp b/vpr/src/place/critical_uniform_move_generator.cpp index 394e68f1618..49ac19be5b2 100644 --- a/vpr/src/place/critical_uniform_move_generator.cpp +++ b/vpr/src/place/critical_uniform_move_generator.cpp @@ -41,10 +41,10 @@ e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap bool floorplan_legal = true; for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; + VTR_LOG("Move 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); + return e_create_move::ABORT; } } diff --git a/vpr/src/place/feasible_region_move_generator.cpp b/vpr/src/place/feasible_region_move_generator.cpp index bea8e3dab7b..0f43d1fea94 100644 --- a/vpr/src/place/feasible_region_move_generator.cpp +++ b/vpr/src/place/feasible_region_move_generator.cpp @@ -130,10 +130,10 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap bool floorplan_legal = true; for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; + VTR_LOG("Move 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); + return e_create_move::ABORT; } } diff --git a/vpr/src/place/initial_placement.cpp b/vpr/src/place/initial_placement.cpp index 4538dcb6604..da069e572cb 100644 --- a/vpr/src/place/initial_placement.cpp +++ b/vpr/src/place/initial_placement.cpp @@ -304,7 +304,7 @@ static void initial_placement_blocks(std::vector>& free_locatio // Make sure that the position is EMPTY_BLOCK before placing the block down VTR_ASSERT(place_ctx.grid_blocks[to.x][to.y].blocks[to.sub_tile] == EMPTY_BLOCK_ID); - bool floorplan_good = cluster_floorplanning_check(blk_id, to); + bool floorplan_good = cluster_floorplanning_legal(blk_id, to); if (floorplan_good) { place_ctx.grid_blocks[to.x][to.y].blocks[to.sub_tile] = blk_id; diff --git a/vpr/src/place/median_move_generator.cpp b/vpr/src/place/median_move_generator.cpp index adf4505fedb..e94dc06167f 100644 --- a/vpr/src/place/median_move_generator.cpp +++ b/vpr/src/place/median_move_generator.cpp @@ -129,10 +129,10 @@ e_create_move MedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_ //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap bool floorplan_legal = true; for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; + VTR_LOG("Move 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); + return e_create_move::ABORT; } } diff --git a/vpr/src/place/move_transactions.h b/vpr/src/place/move_transactions.h index 0856aea97a0..47e06ba808a 100644 --- a/vpr/src/place/move_transactions.h +++ b/vpr/src/place/move_transactions.h @@ -6,10 +6,8 @@ /* Stores the information of the move for a block that is * * moved during placement * * block_num: the index of the moved block * - * xold: the x_coord that the block is moved from * - * xnew: the x_coord that the block is moved to * - * yold: the y_coord that the block is moved from * - * xnew: the x_coord that the block is moved to */ + * old_loc: the location the block is moved from * + * new_loc: the location the block is moved to */ struct t_pl_moved_block { ClusterBlockId block_num; t_pl_loc old_loc; @@ -26,7 +24,7 @@ struct t_pl_moved_block { * swapping two blocks. * * moved blocks: a list of moved blocks data structure with * * information on the move. * - * [0...num_moved_blocks-1] * + * [0...max_blocks-1] * * affected_pins: pins affected by this move (used to * * incrementally invalidate parts of the timing * * graph. */ diff --git a/vpr/src/place/place_constraints.cpp b/vpr/src/place/place_constraints.cpp index cff83ba9f24..9aa2e9120d6 100644 --- a/vpr/src/place/place_constraints.cpp +++ b/vpr/src/place/place_constraints.cpp @@ -18,8 +18,8 @@ int check_placement_floorplanning() { auto& place_ctx = g_vpr_ctx.placement(); for (auto blk_id : cluster_ctx.clb_nlist.blocks()) { - auto& loc = place_ctx.block_locs[blk_id].loc; - if (!cluster_floorplanning_check(blk_id, loc)) { + auto loc = place_ctx.block_locs[blk_id].loc; + if (!cluster_floorplanning_legal(blk_id, loc)) { error++; VTR_LOG_ERROR("Block %zu is not in correct floorplanning region.\n", size_t(blk_id)); } @@ -114,7 +114,7 @@ PartitionRegion constrained_macro_locs(t_pl_macro pl_macro) { } /*returns true if location is compatible with floorplanning constraints, false if not*/ -bool cluster_floorplanning_check(ClusterBlockId blk_id, t_pl_loc loc) { +bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc) { auto& floorplanning_ctx = g_vpr_ctx.floorplanning(); bool floorplanning_good = false; @@ -123,10 +123,10 @@ bool cluster_floorplanning_check(ClusterBlockId blk_id, t_pl_loc loc) { if (!cluster_constrained) { //not constrained so will not have floorplanning issues - //VTR_LOG("Cluster not constrained \n"); + //VTR_LOG("Cluster not constrained \n"); floorplanning_good = true; } else { - //VTR_LOG("Cluster is constrained \n"); + //VTR_LOG("Cluster is constrained \n"); PartitionRegion pr; pr = floorplanning_ctx.cluster_constraints[blk_id]; bool in_pr = pr.is_loc_in_part_reg(loc); @@ -134,7 +134,7 @@ bool cluster_floorplanning_check(ClusterBlockId blk_id, t_pl_loc loc) { //if location is in partitionregion, floorplanning is respected //if not it is not if (in_pr) { - //VTR_LOG("Block %zu passed floorplan check \n", size_t(blk_id)); + //VTR_LOG("Block %zu passed floorplan check \n", size_t(blk_id)); floorplanning_good = true; } else { VTR_LOG("Block %zu did not pass cluster_floorplanning_check \n", size_t(blk_id)); diff --git a/vpr/src/place/place_constraints.h b/vpr/src/place/place_constraints.h index f0beff837bf..058ea9623c2 100644 --- a/vpr/src/place/place_constraints.h +++ b/vpr/src/place/place_constraints.h @@ -23,7 +23,7 @@ bool is_cluster_constrained(ClusterBlockId blk_id); /* * Check if the placement location would respect floorplan constraints of the block, if it has any */ -bool cluster_floorplanning_check(ClusterBlockId blk_id, t_pl_loc loc); +bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc); /* * Check whether any member of the macro has floorplan constraints diff --git a/vpr/src/place/static_move_generator.cpp b/vpr/src/place/static_move_generator.cpp index 3eefce43ed6..8e946965b4d 100644 --- a/vpr/src/place/static_move_generator.cpp +++ b/vpr/src/place/static_move_generator.cpp @@ -27,7 +27,7 @@ void StaticMoveGenerator::initialize_move_prob(const std::vector& prob) { } e_create_move StaticMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, e_move_type& move_type, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* criticalities) { - float rand_num = vtr::frand() * total_prob; + float rand_num = vtr::frand() * total_prob; for (size_t i = 0; i < cumm_move_probs.size(); i++) { if (rand_num <= cumm_move_probs[i]) { move_type = (e_move_type)i; diff --git a/vpr/src/place/uniform_move_generator.cpp b/vpr/src/place/uniform_move_generator.cpp index 2cbf6ed7c83..5a15ae6fca4 100644 --- a/vpr/src/place/uniform_move_generator.cpp +++ b/vpr/src/place/uniform_move_generator.cpp @@ -42,10 +42,10 @@ e_create_move UniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap bool floorplan_legal = true; for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; + VTR_LOG("Move 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); + return e_create_move::ABORT; } } diff --git a/vpr/src/place/weighted_centroid_move_generator.cpp b/vpr/src/place/weighted_centroid_move_generator.cpp index 70626b5d272..910b83f84e6 100644 --- a/vpr/src/place/weighted_centroid_move_generator.cpp +++ b/vpr/src/place/weighted_centroid_move_generator.cpp @@ -43,10 +43,10 @@ e_create_move WeightedCentroidMoveGenerator::propose_move(t_pl_blocks_to_be_move //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap bool floorplan_legal = true; for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; + VTR_LOG("Move 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); + return e_create_move::ABORT; } } diff --git a/vpr/src/place/weighted_median_move_generator.cpp b/vpr/src/place/weighted_median_move_generator.cpp index 2905e696b77..ae188d81604 100644 --- a/vpr/src/place/weighted_median_move_generator.cpp +++ b/vpr/src/place/weighted_median_move_generator.cpp @@ -111,10 +111,10 @@ e_create_move WeightedMedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap bool floorplan_legal = true; for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_check(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; + VTR_LOG("Move 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); + return e_create_move::ABORT; } } From 88bc674712c7ccf4aa9ae6a8ce581890e7d51ed7 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Thu, 8 Apr 2021 10:12:36 -0400 Subject: [PATCH 03/19] Took out commented code --- vpr/src/place/place_constraints.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/vpr/src/place/place_constraints.cpp b/vpr/src/place/place_constraints.cpp index 9aa2e9120d6..09212fccdae 100644 --- a/vpr/src/place/place_constraints.cpp +++ b/vpr/src/place/place_constraints.cpp @@ -123,10 +123,8 @@ bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc) { if (!cluster_constrained) { //not constrained so will not have floorplanning issues - //VTR_LOG("Cluster not constrained \n"); floorplanning_good = true; } else { - //VTR_LOG("Cluster is constrained \n"); PartitionRegion pr; pr = floorplanning_ctx.cluster_constraints[blk_id]; bool in_pr = pr.is_loc_in_part_reg(loc); @@ -134,7 +132,6 @@ bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc) { //if location is in partitionregion, floorplanning is respected //if not it is not if (in_pr) { - //VTR_LOG("Block %zu passed floorplan check \n", size_t(blk_id)); floorplanning_good = true; } else { VTR_LOG("Block %zu did not pass cluster_floorplanning_check \n", size_t(blk_id)); From 9e843426e627cc9a657d7e4eba6ea33ee4a9c464 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 14 Apr 2021 12:51:31 -0400 Subject: [PATCH 04/19] Created a helper function (floorplan_legal) to check the floorplanning legality during placement moves --- vpr/src/place/centroid_move_generator.cpp | 13 +++--------- .../place/critical_uniform_move_generator.cpp | 13 +++--------- .../place/feasible_region_move_generator.cpp | 12 ++++++++++- vpr/src/place/initial_placement.cpp | 2 -- vpr/src/place/median_move_generator.cpp | 13 +++--------- vpr/src/place/place_constraints.cpp | 9 +++++---- vpr/src/place/place_constraints.h | 20 +++++++++++++++++-- vpr/src/place/uniform_move_generator.cpp | 13 +++--------- .../weighted_centroid_move_generator.cpp | 13 +++--------- .../place/weighted_median_move_generator.cpp | 13 +++--------- 10 files changed, 52 insertions(+), 69 deletions(-) diff --git a/vpr/src/place/centroid_move_generator.cpp b/vpr/src/place/centroid_move_generator.cpp index 19d1925bf4b..32bb6515dc5 100644 --- a/vpr/src/place/centroid_move_generator.cpp +++ b/vpr/src/place/centroid_move_generator.cpp @@ -36,18 +36,11 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block return e_create_move::ABORT; } - e_create_move create_move; - create_move = ::create_move(blocks_affected, b_from, to); + e_create_move create_move = ::create_move(blocks_affected, b_from, to); - //Check if the move is legal from a floorplan perspective //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap - bool floorplan_legal = true; - for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); - if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; - } + if (!floorplan_legal(blocks_affected)) { + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/critical_uniform_move_generator.cpp b/vpr/src/place/critical_uniform_move_generator.cpp index 49ac19be5b2..c970a62a5ee 100644 --- a/vpr/src/place/critical_uniform_move_generator.cpp +++ b/vpr/src/place/critical_uniform_move_generator.cpp @@ -34,18 +34,11 @@ e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved return e_create_move::ABORT; } - e_create_move create_move; - create_move = ::create_move(blocks_affected, b_from, to); + e_create_move create_move = ::create_move(blocks_affected, b_from, to); - //Check if the move is legal from a floorplan perspective //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap - bool floorplan_legal = true; - for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); - if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; - } + if (!floorplan_legal(blocks_affected)) { + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/feasible_region_move_generator.cpp b/vpr/src/place/feasible_region_move_generator.cpp index 0f43d1fea94..35bad5309b7 100644 --- a/vpr/src/place/feasible_region_move_generator.cpp +++ b/vpr/src/place/feasible_region_move_generator.cpp @@ -123,7 +123,7 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& return e_create_move::ABORT; } - e_create_move create_move; + /*e_create_move create_move; create_move = ::create_move(blocks_affected, b_from, to); //Check if the move is legal from a floorplan perspective @@ -137,5 +137,15 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& } } + return create_move;*/ + + e_create_move create_move = ::create_move(blocks_affected, b_from, to); + + //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap + if (!floorplan_legal(blocks_affected)) { + return e_create_move::ABORT; + } + return create_move; + } diff --git a/vpr/src/place/initial_placement.cpp b/vpr/src/place/initial_placement.cpp index da069e572cb..45784d6e698 100644 --- a/vpr/src/place/initial_placement.cpp +++ b/vpr/src/place/initial_placement.cpp @@ -98,10 +98,8 @@ static int check_macro_can_be_placed(t_pl_macro pl_macro, int itype, t_pl_loc he bool member_loc_good = macro_pr.is_loc_in_part_reg(member_pos); if (!member_loc_good) { macro_can_be_placed = false; - VTR_LOG("Block member %zu did not pass the macro constraints check with location x: %d y: %d subtile %d\n", pl_macro.members[imember].blk_index, member_pos.x, member_pos.y, member_pos.sub_tile); break; } - VTR_LOG("Block member %zu passed the macro constraints check with location x: %d y: %d subtile %d\n", pl_macro.members[imember].blk_index, member_pos.x, member_pos.y, member_pos.sub_tile); } // Check whether the location could accept block of this type diff --git a/vpr/src/place/median_move_generator.cpp b/vpr/src/place/median_move_generator.cpp index e94dc06167f..05c46d1efb5 100644 --- a/vpr/src/place/median_move_generator.cpp +++ b/vpr/src/place/median_move_generator.cpp @@ -122,18 +122,11 @@ e_create_move MedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_ if (!find_to_loc_centroid(cluster_from_type, from, median_point, range_limiters, to)) return e_create_move::ABORT; - e_create_move create_move; - create_move = ::create_move(blocks_affected, b_from, to); + e_create_move create_move = ::create_move(blocks_affected, b_from, to); - //Check if the move is legal from a floorplan perspective //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap - bool floorplan_legal = true; - for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); - if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; - } + if (!floorplan_legal(blocks_affected)) { + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/place_constraints.cpp b/vpr/src/place/place_constraints.cpp index 09212fccdae..2222f95bba1 100644 --- a/vpr/src/place/place_constraints.cpp +++ b/vpr/src/place/place_constraints.cpp @@ -36,7 +36,7 @@ bool is_cluster_constrained(ClusterBlockId blk_id) { return (!pr.empty()); } -bool is_macro_constrained(t_pl_macro pl_macro) { +bool is_macro_constrained(t_pl_macro& pl_macro) { bool is_macro_constrained = false; bool is_member_constrained = false; @@ -54,7 +54,7 @@ bool is_macro_constrained(t_pl_macro pl_macro) { } /*Returns PartitionRegion of where the head of the macro could go*/ -PartitionRegion constrained_macro_locs(t_pl_macro pl_macro) { +PartitionRegion constrained_macro_locs(t_pl_macro& pl_macro) { PartitionRegion macro_pr; bool is_member_constrained = false; int num_constrained_members = 0; @@ -125,8 +125,7 @@ bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc) { //not constrained so will not have floorplanning issues floorplanning_good = true; } else { - PartitionRegion pr; - pr = floorplanning_ctx.cluster_constraints[blk_id]; + PartitionRegion pr = floorplanning_ctx.cluster_constraints[blk_id]; bool in_pr = pr.is_loc_in_part_reg(loc); //if location is in partitionregion, floorplanning is respected @@ -134,8 +133,10 @@ bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc) { if (in_pr) { floorplanning_good = true; } else { + #ifdef VERBOSE VTR_LOG("Block %zu did not pass cluster_floorplanning_check \n", size_t(blk_id)); VTR_LOG("Loc is x: %d, y: %d, subtile: %d \n", loc.x, loc.y, loc.sub_tile); + #endif } } diff --git a/vpr/src/place/place_constraints.h b/vpr/src/place/place_constraints.h index 058ea9623c2..f81366ea626 100644 --- a/vpr/src/place/place_constraints.h +++ b/vpr/src/place/place_constraints.h @@ -5,6 +5,7 @@ * Created on: Mar. 1, 2021 * Author: khalid88 */ +#include "move_transactions.h" #ifndef VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_ #define VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_ @@ -28,11 +29,26 @@ bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc); /* * Check whether any member of the macro has floorplan constraints */ -bool is_macro_constrained(t_pl_macro pl_macro); +bool is_macro_constrained(t_pl_macro& pl_macro); /* * Returns region of valid locations for the head of the macro based on floorplan constraints */ -PartitionRegion constrained_macro_locs(t_pl_macro pl_macro); +PartitionRegion constrained_macro_locs(t_pl_macro& pl_macro); + +inline bool floorplan_legal(t_pl_blocks_to_be_moved& blocks_affected) { + bool floorplan_legal = true; + + for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + if (!floorplan_legal) { +#ifdef VERBOSE + VTR_LOG("Move 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); +#endif + return false; + } + } + return true; +} #endif /* VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_ */ diff --git a/vpr/src/place/uniform_move_generator.cpp b/vpr/src/place/uniform_move_generator.cpp index 5a15ae6fca4..1a37e28f1da 100644 --- a/vpr/src/place/uniform_move_generator.cpp +++ b/vpr/src/place/uniform_move_generator.cpp @@ -35,18 +35,11 @@ e_create_move UniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks VTR_LOG("\n"); #endif - e_create_move create_move; - create_move = ::create_move(blocks_affected, b_from, to); + e_create_move create_move = ::create_move(blocks_affected, b_from, to); - //Check if the move is legal from a floorplan perspective //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap - bool floorplan_legal = true; - for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); - if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; - } + if (!floorplan_legal(blocks_affected)) { + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/weighted_centroid_move_generator.cpp b/vpr/src/place/weighted_centroid_move_generator.cpp index 910b83f84e6..5902f09e701 100644 --- a/vpr/src/place/weighted_centroid_move_generator.cpp +++ b/vpr/src/place/weighted_centroid_move_generator.cpp @@ -36,18 +36,11 @@ e_create_move WeightedCentroidMoveGenerator::propose_move(t_pl_blocks_to_be_move return e_create_move::ABORT; } - e_create_move create_move; - create_move = ::create_move(blocks_affected, b_from, to); + e_create_move create_move = ::create_move(blocks_affected, b_from, to); - //Check if the move is legal from a floorplan perspective //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap - bool floorplan_legal = true; - for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); - if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; - } + if (!floorplan_legal(blocks_affected)) { + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/weighted_median_move_generator.cpp b/vpr/src/place/weighted_median_move_generator.cpp index ae188d81604..cc6f526a87d 100644 --- a/vpr/src/place/weighted_median_move_generator.cpp +++ b/vpr/src/place/weighted_median_move_generator.cpp @@ -104,18 +104,11 @@ e_create_move WeightedMedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& } //return ::create_move(blocks_affected, b_from, to); - e_create_move create_move; - create_move = ::create_move(blocks_affected, b_from, to); + e_create_move create_move = ::create_move(blocks_affected, b_from, to); - //Check if the move is legal from a floorplan perspective //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap - bool floorplan_legal = true; - for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); - if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; - } + if (!floorplan_legal(blocks_affected)) { + return e_create_move::ABORT; } return create_move; From 2c12618b18b7ed435877b4008a0b31dab7e6782b Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 14 Apr 2021 12:53:26 -0400 Subject: [PATCH 05/19] Ran make format --- vpr/src/place/centroid_move_generator.cpp | 2 +- .../place/critical_uniform_move_generator.cpp | 2 +- .../place/feasible_region_move_generator.cpp | 31 +++++++++---------- vpr/src/place/median_move_generator.cpp | 2 +- vpr/src/place/place_constraints.cpp | 4 +-- vpr/src/place/place_constraints.h | 6 ++-- vpr/src/place/uniform_move_generator.cpp | 2 +- .../weighted_centroid_move_generator.cpp | 2 +- .../place/weighted_median_move_generator.cpp | 2 +- 9 files changed, 26 insertions(+), 27 deletions(-) diff --git a/vpr/src/place/centroid_move_generator.cpp b/vpr/src/place/centroid_move_generator.cpp index 32bb6515dc5..9a1b665941f 100644 --- a/vpr/src/place/centroid_move_generator.cpp +++ b/vpr/src/place/centroid_move_generator.cpp @@ -40,7 +40,7 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap if (!floorplan_legal(blocks_affected)) { - return e_create_move::ABORT; + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/critical_uniform_move_generator.cpp b/vpr/src/place/critical_uniform_move_generator.cpp index c970a62a5ee..15d7867c6bb 100644 --- a/vpr/src/place/critical_uniform_move_generator.cpp +++ b/vpr/src/place/critical_uniform_move_generator.cpp @@ -38,7 +38,7 @@ e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap if (!floorplan_legal(blocks_affected)) { - return e_create_move::ABORT; + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/feasible_region_move_generator.cpp b/vpr/src/place/feasible_region_move_generator.cpp index 35bad5309b7..51df356740c 100644 --- a/vpr/src/place/feasible_region_move_generator.cpp +++ b/vpr/src/place/feasible_region_move_generator.cpp @@ -124,28 +124,27 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& } /*e_create_move create_move; - create_move = ::create_move(blocks_affected, b_from, to); - - //Check if the move is legal from a floorplan perspective - //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap - bool floorplan_legal = true; - for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); - if (!floorplan_legal) { - VTR_LOG("Move 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); - return e_create_move::ABORT; - } - } - - return create_move;*/ + * create_move = ::create_move(blocks_affected, b_from, to); + * + * //Check if the move is legal from a floorplan perspective + * //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap + * bool floorplan_legal = true; + * for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { + * floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); + * if (!floorplan_legal) { + * VTR_LOG("Move 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); + * return e_create_move::ABORT; + * } + * } + * + * return create_move;*/ e_create_move create_move = ::create_move(blocks_affected, b_from, to); //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap if (!floorplan_legal(blocks_affected)) { - return e_create_move::ABORT; + return e_create_move::ABORT; } return create_move; - } diff --git a/vpr/src/place/median_move_generator.cpp b/vpr/src/place/median_move_generator.cpp index 05c46d1efb5..1d1f3335268 100644 --- a/vpr/src/place/median_move_generator.cpp +++ b/vpr/src/place/median_move_generator.cpp @@ -126,7 +126,7 @@ e_create_move MedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_ //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap if (!floorplan_legal(blocks_affected)) { - return e_create_move::ABORT; + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/place_constraints.cpp b/vpr/src/place/place_constraints.cpp index 2222f95bba1..4dd79958aa2 100644 --- a/vpr/src/place/place_constraints.cpp +++ b/vpr/src/place/place_constraints.cpp @@ -133,10 +133,10 @@ bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc) { if (in_pr) { floorplanning_good = true; } else { - #ifdef VERBOSE +#ifdef VERBOSE VTR_LOG("Block %zu did not pass cluster_floorplanning_check \n", size_t(blk_id)); VTR_LOG("Loc is x: %d, y: %d, subtile: %d \n", loc.x, loc.y, loc.sub_tile); - #endif +#endif } } diff --git a/vpr/src/place/place_constraints.h b/vpr/src/place/place_constraints.h index f81366ea626..d556b6138b4 100644 --- a/vpr/src/place/place_constraints.h +++ b/vpr/src/place/place_constraints.h @@ -8,7 +8,7 @@ #include "move_transactions.h" #ifndef VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_ -#define VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_ +# define VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_ /* * Check that placement of each block is within the floorplan constraint region of that block (if the block has any constraints). @@ -42,9 +42,9 @@ inline bool floorplan_legal(t_pl_blocks_to_be_moved& blocks_affected) { for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); if (!floorplan_legal) { -#ifdef VERBOSE +# ifdef VERBOSE VTR_LOG("Move 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); -#endif +# endif return false; } } diff --git a/vpr/src/place/uniform_move_generator.cpp b/vpr/src/place/uniform_move_generator.cpp index 1a37e28f1da..cbb0d2c2401 100644 --- a/vpr/src/place/uniform_move_generator.cpp +++ b/vpr/src/place/uniform_move_generator.cpp @@ -39,7 +39,7 @@ e_create_move UniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap if (!floorplan_legal(blocks_affected)) { - return e_create_move::ABORT; + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/weighted_centroid_move_generator.cpp b/vpr/src/place/weighted_centroid_move_generator.cpp index 5902f09e701..34060f56a5d 100644 --- a/vpr/src/place/weighted_centroid_move_generator.cpp +++ b/vpr/src/place/weighted_centroid_move_generator.cpp @@ -40,7 +40,7 @@ e_create_move WeightedCentroidMoveGenerator::propose_move(t_pl_blocks_to_be_move //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap if (!floorplan_legal(blocks_affected)) { - return e_create_move::ABORT; + return e_create_move::ABORT; } return create_move; diff --git a/vpr/src/place/weighted_median_move_generator.cpp b/vpr/src/place/weighted_median_move_generator.cpp index cc6f526a87d..8a208639f2b 100644 --- a/vpr/src/place/weighted_median_move_generator.cpp +++ b/vpr/src/place/weighted_median_move_generator.cpp @@ -108,7 +108,7 @@ e_create_move WeightedMedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap if (!floorplan_legal(blocks_affected)) { - return e_create_move::ABORT; + return e_create_move::ABORT; } return create_move; From 79378a4f06271778ac1751c648e5373d3b15e458 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 21 Apr 2021 23:55:55 -0400 Subject: [PATCH 06/19] Added ability to write our constraints XML files after placement --- vpr/src/base/vpr_constraints_reader.cpp | 4 +- vpr/src/base/vpr_constraints_serializer.h | 73 ++++++++++++++++------- vpr/src/base/vpr_constraints_writer.cpp | 60 +++++++++++++++++++ vpr/src/base/vpr_constraints_writer.h | 14 +++++ vpr/src/place/place.cpp | 6 ++ 5 files changed, 135 insertions(+), 22 deletions(-) create mode 100644 vpr/src/base/vpr_constraints_writer.cpp create mode 100644 vpr/src/base/vpr_constraints_writer.h diff --git a/vpr/src/base/vpr_constraints_reader.cpp b/vpr/src/base/vpr_constraints_reader.cpp index 8e69b7b42b4..c43a953f6f9 100644 --- a/vpr/src/base/vpr_constraints_reader.cpp +++ b/vpr/src/base/vpr_constraints_reader.cpp @@ -14,7 +14,8 @@ void load_vpr_constraints_file(const char* read_vpr_constraints_name) { vtr::ScopedStartFinishTimer timer("Loading VPR constraints file"); - VprConstraintsSerializer reader; + test_partition part; + VprConstraintsSerializer reader(part); if (vtr::check_file_name_extension(read_vpr_constraints_name, ".xml")) { try { @@ -41,3 +42,4 @@ void load_vpr_constraints_file(const char* read_vpr_constraints_name) { echo_constraints(getEchoFileName(E_ECHO_VPR_CONSTRAINTS), ctx_constraints); } } + diff --git a/vpr/src/base/vpr_constraints_serializer.h b/vpr/src/base/vpr_constraints_serializer.h index c87449f4db7..7c0b5237286 100644 --- a/vpr/src/base/vpr_constraints_serializer.h +++ b/vpr/src/base/vpr_constraints_serializer.h @@ -49,9 +49,34 @@ * * For more detail on how the load and write interfaces work with uxsdcxx, refer to 'vpr/src/route/SCHEMA_GENERATOR.md' */ +struct test_partition { + std::vector atom_names; + + int x_low = 0; + + int y_low = 0; + + int x_high; + + int y_high; + + int subtile = 0; + + std::string part_name = ""; + + int num_part; + + int num_atom; + + int num_region; + + int chip_size_x; + + int chip_size_y; +}; struct VprConstraintsContextTypes : public uxsd::DefaultVprConstraintsContextTypes { - using AddAtomReadContext = void*; + using AddAtomReadContext = int; using AddRegionReadContext = void*; using PartitionReadContext = void*; using PartitionListReadContext = void*; @@ -64,7 +89,14 @@ struct VprConstraintsContextTypes : public uxsd::DefaultVprConstraintsContextTyp }; class VprConstraintsSerializer final : public uxsd::VprConstraintsBase { + + public: + + + //VprConstraintsSerializer() : report_error_(nullptr) {} + VprConstraintsSerializer (test_partition part) : part_(part), report_error_(nullptr) {} + void start_load(const std::function* report_error_in) final { // report_error_in should be invoked if VprConstraintsSerializer encounters // an error during the read. @@ -89,8 +121,11 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase * */ - virtual inline const char* get_add_atom_name_pattern(void*& /*ctx*/) final { - return temp_.c_str(); + virtual inline const char* get_add_atom_name_pattern(int& n) final { + //std::string atom_name = "[327]"; + //return atom_name.c_str(); + + return part_.atom_names[n].c_str(); } virtual inline void set_add_atom_name_pattern(const char* name_pattern, void*& /*ctx*/) final { @@ -151,23 +186,19 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase */ virtual inline const char* get_partition_name(void*& /*ctx*/) final { - return temp_.c_str(); + return part_.part_name.c_str(); } virtual inline void set_partition_name(const char* name, void*& /*ctx*/) final { loaded_partition.set_name(name); @@ -201,11 +232,10 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase atoms_; + + //constant data for writes + test_partition part_; }; #endif /* VPR_CONSTRAINTS_SERIALIZER_H_ */ diff --git a/vpr/src/base/vpr_constraints_writer.cpp b/vpr/src/base/vpr_constraints_writer.cpp new file mode 100644 index 00000000000..761e599d0f2 --- /dev/null +++ b/vpr/src/base/vpr_constraints_writer.cpp @@ -0,0 +1,60 @@ +/* + * vpr_constraints_writer.cpp + * + * Author: khalid88 + */ + +#include "vpr_constraints_serializer.h" +#include "vpr_constraints_uxsdcxx.h" + +#include "vtr_time.h" + +#include "globals.h" +#include "pugixml.hpp" +#include "pugixml_util.hpp" +#include "echo_files.h" + +#include +#include "vpr_constraints_writer.h" + +void write_place_constraints(const char* file_name) { + auto& place_ctx = g_vpr_ctx.placement(); + auto& atom_ctx = g_vpr_ctx.atom(); + auto& device_ctx = g_vpr_ctx.device(); + + //Fill in all the information needed for putting all atoms in one big partition + + test_partition part; + + part.atom_names = {"[327]", "n_n1240", "o_7_"}; + + for (auto blk_id : atom_ctx.nlist.blocks()) { + part.atom_names.push_back(atom_ctx.nlist.block_name(blk_id)); + } + + part.x_high = device_ctx.grid.width() - 1; + part.y_high = device_ctx.grid.height() - 1; + + part.part_name = "my_part"; + + part.num_part = 1; + + part.num_atom = atom_ctx.nlist.blocks().size(); + + part.num_region = 1; + + VprConstraintsSerializer reader(part); + + if (vtr::check_file_name_extension(file_name, ".xml")) { + std::fstream fp; + fp.open(file_name, std::fstream::out | std::fstream::trunc); + fp.precision(std::numeric_limits::max_digits10); + void* context; + uxsd::write_vpr_constraints_xml(reader, context, fp); + } else { + VPR_FATAL_ERROR(VPR_ERROR_ROUTE, + "Unknown extension on output %s", + file_name); + } +} + diff --git a/vpr/src/base/vpr_constraints_writer.h b/vpr/src/base/vpr_constraints_writer.h new file mode 100644 index 00000000000..e362fae54e1 --- /dev/null +++ b/vpr/src/base/vpr_constraints_writer.h @@ -0,0 +1,14 @@ +/* + * vpr_constraints_writer.h + * + * Author: khalid88 + */ + +#ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ +#define VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ + +void write_place_constraints(const char* file_name); + + + +#endif /* VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ */ diff --git a/vpr/src/place/place.cpp b/vpr/src/place/place.cpp index aabd02c95a9..43d86a8730c 100644 --- a/vpr/src/place/place.cpp +++ b/vpr/src/place/place.cpp @@ -54,6 +54,8 @@ #include "RL_agent_util.h" #include "place_checkpoint.h" +#include "vpr_constraints_writer.cpp" + /* define the RL agent's reward function factor constant. This factor controls the weight of bb cost * * compared to the timing cost in the agent's reward function. The reward is calculated as * * -1*(1.5-REWARD_BB_TIMING_RELATIVE_WEIGHT)*timing_cost + (1+REWARD_BB_TIMING_RELATIVE_WEIGHT)*bb_cost) @@ -879,6 +881,10 @@ void try_place(const t_placer_opts& placer_opts, check_place(costs, place_delay_model.get(), placer_criticalities.get(), placer_opts.place_algorithm); + //Write out XML placement constraints file + std::string write_file = "test_write_xml.xml"; + write_place_constraints(write_file.c_str()); + //Some stats VTR_LOG("\n"); VTR_LOG("Swaps called: %d\n", num_ts_called); From 77d32e7e7b63648f2db778a32aca023d6523ae27 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Tue, 27 Apr 2021 10:17:55 -0400 Subject: [PATCH 07/19] removed extra code in write_place_constraints --- vpr/src/base/vpr_constraints_writer.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/vpr/src/base/vpr_constraints_writer.cpp b/vpr/src/base/vpr_constraints_writer.cpp index 761e599d0f2..7d3974cf851 100644 --- a/vpr/src/base/vpr_constraints_writer.cpp +++ b/vpr/src/base/vpr_constraints_writer.cpp @@ -26,8 +26,6 @@ void write_place_constraints(const char* file_name) { test_partition part; - part.atom_names = {"[327]", "n_n1240", "o_7_"}; - for (auto blk_id : atom_ctx.nlist.blocks()) { part.atom_names.push_back(atom_ctx.nlist.block_name(blk_id)); } From 5efca5a03c852abd01c969fba5ae3fce45156f89 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 28 Apr 2021 16:19:01 -0400 Subject: [PATCH 08/19] Changed serializer file to write using contexts --- vpr/src/base/read_options.h | 1 + vpr/src/base/vpr_constraints_reader.cpp | 4 +- vpr/src/base/vpr_constraints_serializer.h | 120 +++++++++++----------- vpr/src/base/vpr_constraints_writer.cpp | 44 +++++++- 4 files changed, 105 insertions(+), 64 deletions(-) diff --git a/vpr/src/base/read_options.h b/vpr/src/base/read_options.h index aa4e30377f1..932dbdb24d0 100644 --- a/vpr/src/base/read_options.h +++ b/vpr/src/base/read_options.h @@ -27,6 +27,7 @@ struct t_options { argparse::ArgValue write_rr_graph_file; argparse::ArgValue read_rr_graph_file; argparse::ArgValue read_vpr_constraints_file; + argparse::ArgValue write_vpr_constraints_file; argparse::ArgValue write_placement_delay_lookup; argparse::ArgValue read_placement_delay_lookup; diff --git a/vpr/src/base/vpr_constraints_reader.cpp b/vpr/src/base/vpr_constraints_reader.cpp index c43a953f6f9..d3567dcb5af 100644 --- a/vpr/src/base/vpr_constraints_reader.cpp +++ b/vpr/src/base/vpr_constraints_reader.cpp @@ -14,8 +14,8 @@ void load_vpr_constraints_file(const char* read_vpr_constraints_name) { vtr::ScopedStartFinishTimer timer("Loading VPR constraints file"); - test_partition part; - VprConstraintsSerializer reader(part); + VprConstraints constraints; + VprConstraintsSerializer reader(constraints); if (vtr::check_file_name_extension(read_vpr_constraints_name, ".xml")) { try { diff --git a/vpr/src/base/vpr_constraints_serializer.h b/vpr/src/base/vpr_constraints_serializer.h index 7c0b5237286..d78f32f2e51 100644 --- a/vpr/src/base/vpr_constraints_serializer.h +++ b/vpr/src/base/vpr_constraints_serializer.h @@ -49,36 +49,16 @@ * * For more detail on how the load and write interfaces work with uxsdcxx, refer to 'vpr/src/route/SCHEMA_GENERATOR.md' */ -struct test_partition { - std::vector atom_names; - - int x_low = 0; - - int y_low = 0; - - int x_high; - - int y_high; - - int subtile = 0; - - std::string part_name = ""; - - int num_part; - - int num_atom; - - int num_region; - - int chip_size_x; - - int chip_size_y; +struct partition_info { + Partition part; + std::vector atoms; + PartitionId part_id; }; struct VprConstraintsContextTypes : public uxsd::DefaultVprConstraintsContextTypes { - using AddAtomReadContext = int; - using AddRegionReadContext = void*; - using PartitionReadContext = void*; + using AddAtomReadContext = AtomBlockId; + using AddRegionReadContext = Region; + using PartitionReadContext = partition_info; using PartitionListReadContext = void*; using VprConstraintsReadContext = void*; using AddAtomWriteContext = void*; @@ -95,7 +75,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase* report_error_in) final { // report_error_in should be invoked if VprConstraintsSerializer encounters @@ -121,11 +101,10 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase * */ - virtual inline const char* get_add_atom_name_pattern(int& n) final { - //std::string atom_name = "[327]"; - //return atom_name.c_str(); - - return part_.atom_names[n].c_str(); + virtual inline const char* get_add_atom_name_pattern(AtomBlockId& blk_id) final { + auto& atom_ctx = g_vpr_ctx.atom(); + auto atom_name = atom_ctx.nlist.block_name(blk_id); + return atom_name.c_str(); } virtual inline void set_add_atom_name_pattern(const char* name_pattern, void*& /*ctx*/) final { @@ -176,29 +155,33 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase * */ - virtual inline int get_add_region_subtile(void*& /*ctx*/) final { - int i = 0; - return i; + virtual inline int get_add_region_subtile(Region& r) final { + return r.get_sub_tile(); } virtual inline void set_add_region_subtile(int subtile, void*& /*ctx*/) final { loaded_region.set_sub_tile(subtile); } - virtual inline int get_add_region_x_high(void*& /*ctx*/) final { - return part_.x_high; + virtual inline int get_add_region_x_high(Region& r) final { + + vtr::Rect rect = r.get_region_rect(); + return rect.xmax(); } - virtual inline int get_add_region_x_low(void*& /*ctx*/) final { - return part_.x_low; + virtual inline int get_add_region_x_low(Region& r) final { + vtr::Rect rect = r.get_region_rect(); + return rect.xmin(); } - virtual inline int get_add_region_y_high(void*& /*ctx*/) final { - return part_.y_high; + virtual inline int get_add_region_y_high(Region& r) final { + vtr::Rect rect = r.get_region_rect(); + return rect.ymax(); } - virtual inline int get_add_region_y_low(void*& /*ctx*/) final { - return part_.y_low; + virtual inline int get_add_region_y_low(Region& r) final { + vtr::Rect rect = r.get_region_rect(); + return rect.ymin(); } /** Generated for complex type "partition": @@ -210,8 +193,10 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase * */ - virtual inline const char* get_partition_name(void*& /*ctx*/) final { - return part_.part_name.c_str(); + virtual inline const char* get_partition_name(partition_info& part_info) final { + + return part_info.part.get_name().c_str(); + } virtual inline void set_partition_name(const char* name, void*& /*ctx*/) final { loaded_partition.set_name(name); @@ -231,11 +216,13 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase regions = pr.get_partition_region(); + return regions.size(); } - virtual inline void* get_partition_add_region(int /*n*/, void*& /*ctx*/) final { - return nullptr; + virtual inline Region get_partition_add_region(int n, partition_info& part_info) final { + PartitionRegion pr = part_info.part.get_part_region(); + std::vector regions = pr.get_partition_region(); + return regions[n]; } /** Generated for complex type "partition_list": @@ -285,11 +277,20 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase atoms = constraints_.get_part_atoms(partid); + + partition_info part_info; + part_info.part = part; + part_info.part_id = partid; + part_info.atoms = atoms; + + return part_info; } /** Generated for complex type "vpr_constraints": @@ -344,8 +345,9 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase atoms_; - //constant data for writes - test_partition part_; + //for writing + //partition_info part_info_; + }; #endif /* VPR_CONSTRAINTS_SERIALIZER_H_ */ diff --git a/vpr/src/base/vpr_constraints_writer.cpp b/vpr/src/base/vpr_constraints_writer.cpp index 7d3974cf851..13a8b35ce83 100644 --- a/vpr/src/base/vpr_constraints_writer.cpp +++ b/vpr/src/base/vpr_constraints_writer.cpp @@ -24,7 +24,7 @@ void write_place_constraints(const char* file_name) { //Fill in all the information needed for putting all atoms in one big partition - test_partition part; + /*test_partition part; for (auto blk_id : atom_ctx.nlist.blocks()) { part.atom_names.push_back(atom_ctx.nlist.block_name(blk_id)); @@ -39,9 +39,47 @@ void write_place_constraints(const char* file_name) { part.num_atom = atom_ctx.nlist.blocks().size(); - part.num_region = 1; + part.num_region = 1;*/ - VprConstraintsSerializer reader(part); + //Fill in all the info needed for locking atoms to their locations + VprConstraints constraints; + Partition part1; + part1.set_name("mypart1"); + Partition part2; + part2.set_name("mypart2"); + + Region reg1; + reg1.set_region_rect(0,0,18,18); + PartitionRegion pr1; + pr1.add_to_part_region(reg1); + part1.set_part_region(pr1); + + Region reg2; + reg2.set_region_rect(0,0,18,18); + PartitionRegion pr2; + pr2.add_to_part_region(reg2); + part2.set_part_region(pr2); + + constraints.add_partition(part1); + constraints.add_partition(part2); + + PartitionId pid1(0); + PartitionId pid2(1); + + AtomBlockId id0(0); + AtomBlockId id1(1); + AtomBlockId id2(2); + constraints.add_constrained_atom(id0,pid1); + constraints.add_constrained_atom(id1,pid1); + constraints.add_constrained_atom(id2,pid1); + + AtomBlockId id3(3); + AtomBlockId id4(4); + constraints.add_constrained_atom(id3,pid2); + constraints.add_constrained_atom(id4,pid2); + + + VprConstraintsSerializer reader(constraints); if (vtr::check_file_name_extension(file_name, ".xml")) { std::fstream fp; From fbe99b50d239c054c82ff2b364e5720897bce8f9 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 28 Apr 2021 21:55:59 -0400 Subject: [PATCH 09/19] Locking down blocks to each place --- vpr/src/base/SetupVPR.cpp | 1 + vpr/src/base/read_options.cpp | 6 +- vpr/src/base/vpr_api.cpp | 15 ++++- vpr/src/base/vpr_constraints_writer.cpp | 88 +++++++++++-------------- vpr/src/base/vpr_constraints_writer.h | 2 +- vpr/src/base/vpr_types.h | 1 + vpr/src/place/place.cpp | 6 +- 7 files changed, 62 insertions(+), 57 deletions(-) diff --git a/vpr/src/base/SetupVPR.cpp b/vpr/src/base/SetupVPR.cpp index 717ba35ed90..3fa6825fd58 100644 --- a/vpr/src/base/SetupVPR.cpp +++ b/vpr/src/base/SetupVPR.cpp @@ -94,6 +94,7 @@ void SetupVPR(const t_options* Options, FileNameOpts->CmosTechFile = Options->CmosTechFile; FileNameOpts->out_file_prefix = Options->out_file_prefix; FileNameOpts->read_vpr_constraints_file = Options->read_vpr_constraints_file; + FileNameOpts->write_vpr_constraints_file = Options->write_vpr_constraints_file; FileNameOpts->verify_file_digests = Options->verify_file_digests; diff --git a/vpr/src/base/read_options.cpp b/vpr/src/base/read_options.cpp index 9043762aa06..25fc46328c8 100644 --- a/vpr/src/base/read_options.cpp +++ b/vpr/src/base/read_options.cpp @@ -1413,9 +1413,13 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg .show_in(argparse::ShowIn::HELP_ONLY); file_grp.add_argument(args.read_vpr_constraints_file, "--read_vpr_constraints") - .help("Reads the floorplanning constraints from the specified XML file.") + .help("Writes the floorplanning constraints from placement to the specified XML file.") .show_in(argparse::ShowIn::HELP_ONLY); + file_grp.add_argument(args.write_vpr_constraints_file, "--write_vpr_constraints") + .help("Reads the floorplanning constraints from the specified XML file.") + .show_in(argparse::ShowIn::HELP_ONLY); + file_grp.add_argument(args.read_router_lookahead, "--read_router_lookahead") .help( "Reads the lookahead data from the specified file instead of computing it.") diff --git a/vpr/src/base/vpr_api.cpp b/vpr/src/base/vpr_api.cpp index 7b4f2df1c24..430572c8c4b 100644 --- a/vpr/src/base/vpr_api.cpp +++ b/vpr/src/base/vpr_api.cpp @@ -69,7 +69,7 @@ #include "cluster.h" #include "output_clustering.h" #include "vpr_constraints_reader.h" - +#include "vpr_constraints_writer.h" #include "pack_report.h" #include "overuse_report.h" @@ -635,6 +635,13 @@ bool vpr_place_flow(t_vpr_setup& vpr_setup, const t_arch& arch) { post_place_sync(); } + //Write out a vpr floorplanning constraints file if the option is specified + /*auto& filename_opts = vpr_setup.FileNameOpts; + if (!filename_opts.write_vpr_constraints_file.empty()) { + std::string write_file = "test_write_xml.xml"; + write_vpr_floorplan_constraints(write_file.c_str()); + }*/ + return true; } @@ -665,6 +672,12 @@ void vpr_place(t_vpr_setup& vpr_setup, const t_arch& arch) { print_place(filename_opts.NetFile.c_str(), cluster_ctx.clb_nlist.netlist_id().c_str(), filename_opts.PlaceFile.c_str()); + + //Write out a vpr floorplanning constraints file if the option is specified + if (!filename_opts.write_vpr_constraints_file.empty()) { + std::string write_file = "test_write_xml.xml"; + write_vpr_floorplan_constraints(write_file.c_str()); + } } void vpr_load_placement(t_vpr_setup& vpr_setup, const t_arch& arch) { diff --git a/vpr/src/base/vpr_constraints_writer.cpp b/vpr/src/base/vpr_constraints_writer.cpp index 13a8b35ce83..26b2815bde5 100644 --- a/vpr/src/base/vpr_constraints_writer.cpp +++ b/vpr/src/base/vpr_constraints_writer.cpp @@ -17,66 +17,56 @@ #include #include "vpr_constraints_writer.h" -void write_place_constraints(const char* file_name) { +void write_vpr_floorplan_constraints(const char* file_name) { auto& place_ctx = g_vpr_ctx.placement(); auto& atom_ctx = g_vpr_ctx.atom(); - auto& device_ctx = g_vpr_ctx.device(); + auto& cluster_ctx = g_vpr_ctx.clustering(); - //Fill in all the information needed for putting all atoms in one big partition + //Fill in all the info needed for locking atoms to their locations + VprConstraints constraints; - /*test_partition part; + std::map> cluster_atoms; - for (auto blk_id : atom_ctx.nlist.blocks()) { - part.atom_names.push_back(atom_ctx.nlist.block_name(blk_id)); - } + for (auto blk_id : cluster_ctx.clb_nlist.blocks()) { + cluster_atoms.insert({blk_id, std::vector()}); + } - part.x_high = device_ctx.grid.width() - 1; - part.y_high = device_ctx.grid.height() - 1; + for (auto atom_blk_id : atom_ctx.nlist.blocks()) { + ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(atom_blk_id); - part.part_name = "my_part"; + cluster_atoms[clb_index].push_back(atom_blk_id); + } - part.num_part = 1; + int part_id = 0; + for (auto i = cluster_atoms.begin(); i != cluster_atoms.end(); i++) { + std::string part_name; + part_name = cluster_ctx.clb_nlist.block_name(i->first); - part.num_atom = atom_ctx.nlist.blocks().size(); + PartitionId partid(part_id); - part.num_region = 1;*/ + Partition part; + part.set_name(part_name); - //Fill in all the info needed for locking atoms to their locations - VprConstraints constraints; - Partition part1; - part1.set_name("mypart1"); - Partition part2; - part2.set_name("mypart2"); - - Region reg1; - reg1.set_region_rect(0,0,18,18); - PartitionRegion pr1; - pr1.add_to_part_region(reg1); - part1.set_part_region(pr1); - - Region reg2; - reg2.set_region_rect(0,0,18,18); - PartitionRegion pr2; - pr2.add_to_part_region(reg2); - part2.set_part_region(pr2); - - constraints.add_partition(part1); - constraints.add_partition(part2); - - PartitionId pid1(0); - PartitionId pid2(1); - - AtomBlockId id0(0); - AtomBlockId id1(1); - AtomBlockId id2(2); - constraints.add_constrained_atom(id0,pid1); - constraints.add_constrained_atom(id1,pid1); - constraints.add_constrained_atom(id2,pid1); - - AtomBlockId id3(3); - AtomBlockId id4(4); - constraints.add_constrained_atom(id3,pid2); - constraints.add_constrained_atom(id4,pid2); + PartitionRegion pr; + Region reg; + + auto loc = place_ctx.block_locs[i->first].loc; + + reg.set_region_rect(loc.x, loc.y, loc.x, loc.y); + //reg.set_region_rect(loc.x - exp, loc.y - exp, loc.x + exp, loc.y + exp); + + pr.add_to_part_region(reg); + part.set_part_region(pr); + constraints.add_partition(part); + + int num_atoms = i->second.size(); + + for (auto j = 0; j < num_atoms; j++) { + AtomBlockId atom_id = i->second[j]; + constraints.add_constrained_atom(atom_id, partid); + } + part_id++; + } VprConstraintsSerializer reader(constraints); diff --git a/vpr/src/base/vpr_constraints_writer.h b/vpr/src/base/vpr_constraints_writer.h index e362fae54e1..9f2d9bd1aa9 100644 --- a/vpr/src/base/vpr_constraints_writer.h +++ b/vpr/src/base/vpr_constraints_writer.h @@ -7,7 +7,7 @@ #ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ #define VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ -void write_place_constraints(const char* file_name); +void write_vpr_floorplan_constraints(const char* file_name); diff --git a/vpr/src/base/vpr_types.h b/vpr/src/base/vpr_types.h index b09a0de34e7..df461582d68 100644 --- a/vpr/src/base/vpr_types.h +++ b/vpr/src/base/vpr_types.h @@ -753,6 +753,7 @@ struct t_file_name_opts { std::string CmosTechFile; std::string out_file_prefix; std::string read_vpr_constraints_file; + std::string write_vpr_constraints_file; bool verify_file_digests; }; diff --git a/vpr/src/place/place.cpp b/vpr/src/place/place.cpp index 43d86a8730c..e360a5d4b9d 100644 --- a/vpr/src/place/place.cpp +++ b/vpr/src/place/place.cpp @@ -54,7 +54,7 @@ #include "RL_agent_util.h" #include "place_checkpoint.h" -#include "vpr_constraints_writer.cpp" + /* define the RL agent's reward function factor constant. This factor controls the weight of bb cost * * compared to the timing cost in the agent's reward function. The reward is calculated as * @@ -881,10 +881,6 @@ void try_place(const t_placer_opts& placer_opts, check_place(costs, place_delay_model.get(), placer_criticalities.get(), placer_opts.place_algorithm); - //Write out XML placement constraints file - std::string write_file = "test_write_xml.xml"; - write_place_constraints(write_file.c_str()); - //Some stats VTR_LOG("\n"); VTR_LOG("Swaps called: %d\n", num_ts_called); From ebfbc75710e6ea487abddd5615e14f9441cc783e Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 28 Apr 2021 23:10:48 -0400 Subject: [PATCH 10/19] Added expand and subtile options --- vpr/src/base/SetupVPR.cpp | 2 + vpr/src/base/read_options.cpp | 19 ++++++++- vpr/src/base/read_options.h | 2 + vpr/src/base/vpr_api.cpp | 11 +---- vpr/src/base/vpr_constraints_reader.cpp | 1 - vpr/src/base/vpr_constraints_serializer.h | 50 +++++++++-------------- vpr/src/base/vpr_constraints_writer.cpp | 24 +++++------ vpr/src/base/vpr_constraints_writer.h | 4 +- vpr/src/base/vpr_types.h | 2 + vpr/src/place/place.cpp | 2 - 10 files changed, 56 insertions(+), 61 deletions(-) diff --git a/vpr/src/base/SetupVPR.cpp b/vpr/src/base/SetupVPR.cpp index 3fa6825fd58..a05c525ec01 100644 --- a/vpr/src/base/SetupVPR.cpp +++ b/vpr/src/base/SetupVPR.cpp @@ -586,6 +586,8 @@ static void SetupPlacerOpts(const t_options& Options, t_placer_opts* PlacerOpts) PlacerOpts->place_reward_fun = Options.place_reward_fun; PlacerOpts->place_crit_limit = Options.place_crit_limit; PlacerOpts->place_agent_algorithm = Options.place_agent_algorithm; + PlacerOpts->place_constraint_expand = Options.place_constraint_expand; + PlacerOpts->place_constraint_subtile = Options.place_constraint_subtile; } static void SetupAnalysisOpts(const t_options& Options, t_analysis_opts& analysis_opts) { diff --git a/vpr/src/base/read_options.cpp b/vpr/src/base/read_options.cpp index 25fc46328c8..59981c60c9d 100644 --- a/vpr/src/base/read_options.cpp +++ b/vpr/src/base/read_options.cpp @@ -1417,8 +1417,8 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg .show_in(argparse::ShowIn::HELP_ONLY); file_grp.add_argument(args.write_vpr_constraints_file, "--write_vpr_constraints") - .help("Reads the floorplanning constraints from the specified XML file.") - .show_in(argparse::ShowIn::HELP_ONLY); + .help("Reads the floorplanning constraints from the specified XML file.") + .show_in(argparse::ShowIn::HELP_ONLY); file_grp.add_argument(args.read_router_lookahead, "--read_router_lookahead") .help( @@ -1877,6 +1877,21 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg "Its range equals to [0., 1.].") .default_value("0.7") .show_in(argparse::ShowIn::HELP_ONLY); + + place_grp.add_argument(args.place_constraint_expand, "--place_constraint_expand") + .help( + "The value used to decide how much to expand the floorplan constraint region when writing" + "a floorplan constraint XML file. If it is zero, the block stays locked in its place. If it is" + "greater than zero the constraint region expands by the specified value in each direction.") + .default_value("0") + .show_in(argparse::ShowIn::HELP_ONLY); + + place_grp.add_argument(args.place_constraint_subtile, "--place_constraint_subtile") + .help( + "The value used to specify a subtile constraints when writing a floorplan constraints XML file.") + .default_value("-1") + .show_in(argparse::ShowIn::HELP_ONLY); + /* * place_grp.add_argument(args.place_timing_cost_func, "--place_timing_cost_func") * .help( diff --git a/vpr/src/base/read_options.h b/vpr/src/base/read_options.h index 932dbdb24d0..f903b768976 100644 --- a/vpr/src/base/read_options.h +++ b/vpr/src/base/read_options.h @@ -129,6 +129,8 @@ struct t_options { argparse::ArgValue place_reward_fun; //argparse::ArgValue place_timing_cost_func; argparse::ArgValue place_crit_limit; + argparse::ArgValue place_constraint_expand; + argparse::ArgValue place_constraint_subtile; /* Timing-driven placement options only */ argparse::ArgValue PlaceTimingTradeoff; diff --git a/vpr/src/base/vpr_api.cpp b/vpr/src/base/vpr_api.cpp index 430572c8c4b..b34f5611d92 100644 --- a/vpr/src/base/vpr_api.cpp +++ b/vpr/src/base/vpr_api.cpp @@ -635,13 +635,6 @@ bool vpr_place_flow(t_vpr_setup& vpr_setup, const t_arch& arch) { post_place_sync(); } - //Write out a vpr floorplanning constraints file if the option is specified - /*auto& filename_opts = vpr_setup.FileNameOpts; - if (!filename_opts.write_vpr_constraints_file.empty()) { - std::string write_file = "test_write_xml.xml"; - write_vpr_floorplan_constraints(write_file.c_str()); - }*/ - return true; } @@ -667,6 +660,7 @@ void vpr_place(t_vpr_setup& vpr_setup, const t_arch& arch) { arch.num_directs); auto& filename_opts = vpr_setup.FileNameOpts; + auto& placer_opts = vpr_setup.PlacerOpts; auto& cluster_ctx = g_vpr_ctx.clustering(); print_place(filename_opts.NetFile.c_str(), @@ -675,8 +669,7 @@ void vpr_place(t_vpr_setup& vpr_setup, const t_arch& arch) { //Write out a vpr floorplanning constraints file if the option is specified if (!filename_opts.write_vpr_constraints_file.empty()) { - std::string write_file = "test_write_xml.xml"; - write_vpr_floorplan_constraints(write_file.c_str()); + write_vpr_floorplan_constraints(filename_opts.write_vpr_constraints_file.c_str(), placer_opts.place_constraint_expand, placer_opts.place_constraint_subtile); } } diff --git a/vpr/src/base/vpr_constraints_reader.cpp b/vpr/src/base/vpr_constraints_reader.cpp index d3567dcb5af..ed975d99f1b 100644 --- a/vpr/src/base/vpr_constraints_reader.cpp +++ b/vpr/src/base/vpr_constraints_reader.cpp @@ -42,4 +42,3 @@ void load_vpr_constraints_file(const char* read_vpr_constraints_name) { echo_constraints(getEchoFileName(E_ECHO_VPR_CONSTRAINTS), ctx_constraints); } } - diff --git a/vpr/src/base/vpr_constraints_serializer.h b/vpr/src/base/vpr_constraints_serializer.h index d78f32f2e51..11d4ba9426b 100644 --- a/vpr/src/base/vpr_constraints_serializer.h +++ b/vpr/src/base/vpr_constraints_serializer.h @@ -69,13 +69,11 @@ struct VprConstraintsContextTypes : public uxsd::DefaultVprConstraintsContextTyp }; class VprConstraintsSerializer final : public uxsd::VprConstraintsBase { - - public: - - - //VprConstraintsSerializer() : report_error_(nullptr) {} - VprConstraintsSerializer (VprConstraints constraints) : constraints_(constraints), report_error_(nullptr) {} + //VprConstraintsSerializer() : report_error_(nullptr) {} + VprConstraintsSerializer(VprConstraints constraints) + : constraints_(constraints) + , report_error_(nullptr) {} void start_load(const std::function* report_error_in) final { // report_error_in should be invoked if VprConstraintsSerializer encounters @@ -102,9 +100,9 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase */ virtual inline const char* get_add_atom_name_pattern(AtomBlockId& blk_id) final { - auto& atom_ctx = g_vpr_ctx.atom(); - auto atom_name = atom_ctx.nlist.block_name(blk_id); - return atom_name.c_str(); + auto& atom_ctx = g_vpr_ctx.atom(); + auto atom_name = atom_ctx.nlist.block_name(blk_id); + return atom_name.c_str(); } virtual inline void set_add_atom_name_pattern(const char* name_pattern, void*& /*ctx*/) final { @@ -164,24 +162,23 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase rect = r.get_region_rect(); + vtr::Rect rect = r.get_region_rect(); return rect.xmax(); } virtual inline int get_add_region_x_low(Region& r) final { - vtr::Rect rect = r.get_region_rect(); - return rect.xmin(); + vtr::Rect rect = r.get_region_rect(); + return rect.xmin(); } virtual inline int get_add_region_y_high(Region& r) final { - vtr::Rect rect = r.get_region_rect(); - return rect.ymax(); + vtr::Rect rect = r.get_region_rect(); + return rect.ymax(); } virtual inline int get_add_region_y_low(Region& r) final { - vtr::Rect rect = r.get_region_rect(); - return rect.ymin(); + vtr::Rect rect = r.get_region_rect(); + return rect.ymin(); } /** Generated for complex type "partition": @@ -194,9 +191,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase */ virtual inline const char* get_partition_name(partition_info& part_info) final { - - return part_info.part.get_name().c_str(); - + return part_info.part.get_name().c_str(); } virtual inline void set_partition_name(const char* name, void*& /*ctx*/) final { loaded_partition.set_name(name); @@ -217,8 +212,6 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase regions = pr.get_partition_region(); return regions.size(); } virtual inline Region get_partition_add_region(int n, partition_info& part_info) final { - PartitionRegion pr = part_info.part.get_part_region(); - std::vector regions = pr.get_partition_region(); - return regions[n]; + PartitionRegion pr = part_info.part.get_part_region(); + std::vector regions = pr.get_partition_region(); + return regions[n]; } /** Generated for complex type "partition_list": @@ -281,7 +273,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase atoms = constraints_.get_part_atoms(partid); @@ -344,10 +336,6 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase atoms_; - - //for writing - //partition_info part_info_; - }; #endif /* VPR_CONSTRAINTS_SERIALIZER_H_ */ diff --git a/vpr/src/base/vpr_constraints_writer.cpp b/vpr/src/base/vpr_constraints_writer.cpp index 26b2815bde5..6c23d4e8fbc 100644 --- a/vpr/src/base/vpr_constraints_writer.cpp +++ b/vpr/src/base/vpr_constraints_writer.cpp @@ -17,7 +17,7 @@ #include #include "vpr_constraints_writer.h" -void write_vpr_floorplan_constraints(const char* file_name) { +void write_vpr_floorplan_constraints(const char* file_name, int expand, int subtile) { auto& place_ctx = g_vpr_ctx.placement(); auto& atom_ctx = g_vpr_ctx.atom(); auto& cluster_ctx = g_vpr_ctx.clustering(); @@ -27,17 +27,17 @@ void write_vpr_floorplan_constraints(const char* file_name) { std::map> cluster_atoms; - for (auto blk_id : cluster_ctx.clb_nlist.blocks()) { - cluster_atoms.insert({blk_id, std::vector()}); - } + for (auto blk_id : cluster_ctx.clb_nlist.blocks()) { + cluster_atoms.insert({blk_id, std::vector()}); + } - for (auto atom_blk_id : atom_ctx.nlist.blocks()) { - ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(atom_blk_id); + for (auto atom_blk_id : atom_ctx.nlist.blocks()) { + ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(atom_blk_id); - cluster_atoms[clb_index].push_back(atom_blk_id); - } + cluster_atoms[clb_index].push_back(atom_blk_id); + } - int part_id = 0; + int part_id = 0; for (auto i = cluster_atoms.begin(); i != cluster_atoms.end(); i++) { std::string part_name; part_name = cluster_ctx.clb_nlist.block_name(i->first); @@ -52,8 +52,8 @@ void write_vpr_floorplan_constraints(const char* file_name) { auto loc = place_ctx.block_locs[i->first].loc; - reg.set_region_rect(loc.x, loc.y, loc.x, loc.y); - //reg.set_region_rect(loc.x - exp, loc.y - exp, loc.x + exp, loc.y + exp); + reg.set_region_rect(loc.x - expand, loc.y - expand, loc.x + expand, loc.y + expand); + reg.set_sub_tile(subtile); pr.add_to_part_region(reg); part.set_part_region(pr); @@ -68,7 +68,6 @@ void write_vpr_floorplan_constraints(const char* file_name) { part_id++; } - VprConstraintsSerializer reader(constraints); if (vtr::check_file_name_extension(file_name, ".xml")) { @@ -83,4 +82,3 @@ void write_vpr_floorplan_constraints(const char* file_name) { file_name); } } - diff --git a/vpr/src/base/vpr_constraints_writer.h b/vpr/src/base/vpr_constraints_writer.h index 9f2d9bd1aa9..4254ac17fdf 100644 --- a/vpr/src/base/vpr_constraints_writer.h +++ b/vpr/src/base/vpr_constraints_writer.h @@ -7,8 +7,6 @@ #ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ #define VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ -void write_vpr_floorplan_constraints(const char* file_name); - - +void write_vpr_floorplan_constraints(const char* file_name, int expand, int subtile); #endif /* VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ */ diff --git a/vpr/src/base/vpr_types.h b/vpr/src/base/vpr_types.h index df461582d68..26c0b3d2207 100644 --- a/vpr/src/base/vpr_types.h +++ b/vpr/src/base/vpr_types.h @@ -1065,6 +1065,8 @@ struct t_placer_opts { //int place_timing_cost_func; std::string place_reward_fun; float place_crit_limit; + int place_constraint_expand; + int place_constraint_subtile; /** * @brief Tile types that should be used during delay sampling. diff --git a/vpr/src/place/place.cpp b/vpr/src/place/place.cpp index e360a5d4b9d..aabd02c95a9 100644 --- a/vpr/src/place/place.cpp +++ b/vpr/src/place/place.cpp @@ -54,8 +54,6 @@ #include "RL_agent_util.h" #include "place_checkpoint.h" - - /* define the RL agent's reward function factor constant. This factor controls the weight of bb cost * * compared to the timing cost in the agent's reward function. The reward is calculated as * * -1*(1.5-REWARD_BB_TIMING_RELATIVE_WEIGHT)*timing_cost + (1+REWARD_BB_TIMING_RELATIVE_WEIGHT)*bb_cost) From 0f910b801a7f4ac9d9410b5bdad79bce32624aa1 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 28 Apr 2021 23:30:29 -0400 Subject: [PATCH 11/19] Made minor change to serializer file to get rid of compiler warnings --- vpr/src/base/vpr_constraints_serializer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/base/vpr_constraints_serializer.h b/vpr/src/base/vpr_constraints_serializer.h index 11d4ba9426b..77ea356cd6e 100644 --- a/vpr/src/base/vpr_constraints_serializer.h +++ b/vpr/src/base/vpr_constraints_serializer.h @@ -319,13 +319,13 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase* report_error_; //temp data structures to be loaded during file reading Region loaded_region; Partition loaded_partition; PartitionRegion loaded_part_region; - VprConstraints constraints_; //temp string used when a method must return a const char* std::string temp_ = "test"; From c8fef8ef14422ea14d2e29de8fd84ea8d86a4048 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Thu, 29 Apr 2021 15:46:01 -0400 Subject: [PATCH 12/19] Made subtile option a bool --- vpr/src/base/read_options.cpp | 4 ++-- vpr/src/base/read_options.h | 2 +- vpr/src/base/vpr_constraints_writer.cpp | 7 +++++-- vpr/src/base/vpr_constraints_writer.h | 2 +- vpr/src/base/vpr_types.h | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/vpr/src/base/read_options.cpp b/vpr/src/base/read_options.cpp index 59981c60c9d..474844d52f4 100644 --- a/vpr/src/base/read_options.cpp +++ b/vpr/src/base/read_options.cpp @@ -1886,10 +1886,10 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg .default_value("0") .show_in(argparse::ShowIn::HELP_ONLY); - place_grp.add_argument(args.place_constraint_subtile, "--place_constraint_subtile") + place_grp.add_argument(args.place_constraint_subtile, "--place_constraint_subtile") .help( "The value used to specify a subtile constraints when writing a floorplan constraints XML file.") - .default_value("-1") + .default_value("off") .show_in(argparse::ShowIn::HELP_ONLY); /* diff --git a/vpr/src/base/read_options.h b/vpr/src/base/read_options.h index f903b768976..c8144b81ea2 100644 --- a/vpr/src/base/read_options.h +++ b/vpr/src/base/read_options.h @@ -130,7 +130,7 @@ struct t_options { //argparse::ArgValue place_timing_cost_func; argparse::ArgValue place_crit_limit; argparse::ArgValue place_constraint_expand; - argparse::ArgValue place_constraint_subtile; + argparse::ArgValue place_constraint_subtile; /* Timing-driven placement options only */ argparse::ArgValue PlaceTimingTradeoff; diff --git a/vpr/src/base/vpr_constraints_writer.cpp b/vpr/src/base/vpr_constraints_writer.cpp index 6c23d4e8fbc..3d7ef42ece5 100644 --- a/vpr/src/base/vpr_constraints_writer.cpp +++ b/vpr/src/base/vpr_constraints_writer.cpp @@ -17,7 +17,7 @@ #include #include "vpr_constraints_writer.h" -void write_vpr_floorplan_constraints(const char* file_name, int expand, int subtile) { +void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile) { auto& place_ctx = g_vpr_ctx.placement(); auto& atom_ctx = g_vpr_ctx.atom(); auto& cluster_ctx = g_vpr_ctx.clustering(); @@ -53,7 +53,10 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, int subt auto loc = place_ctx.block_locs[i->first].loc; reg.set_region_rect(loc.x - expand, loc.y - expand, loc.x + expand, loc.y + expand); - reg.set_sub_tile(subtile); + if (subtile) { + int st = loc.sub_tile; + reg.set_sub_tile(st); + } pr.add_to_part_region(reg); part.set_part_region(pr); diff --git a/vpr/src/base/vpr_constraints_writer.h b/vpr/src/base/vpr_constraints_writer.h index 4254ac17fdf..02ed1419f51 100644 --- a/vpr/src/base/vpr_constraints_writer.h +++ b/vpr/src/base/vpr_constraints_writer.h @@ -7,6 +7,6 @@ #ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ #define VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ -void write_vpr_floorplan_constraints(const char* file_name, int expand, int subtile); +void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile); #endif /* VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ */ diff --git a/vpr/src/base/vpr_types.h b/vpr/src/base/vpr_types.h index 26c0b3d2207..b9251d6dbbf 100644 --- a/vpr/src/base/vpr_types.h +++ b/vpr/src/base/vpr_types.h @@ -1066,7 +1066,7 @@ struct t_placer_opts { std::string place_reward_fun; float place_crit_limit; int place_constraint_expand; - int place_constraint_subtile; + bool place_constraint_subtile; /** * @brief Tile types that should be used during delay sampling. From 26ba44fd9e4490cd7696cda1094fc99a2f0d7788 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Tue, 4 May 2021 17:26:01 -0400 Subject: [PATCH 13/19] Fixed issue where long atom and partition names were not being printed properly --- vpr/src/base/vpr_constraints_serializer.h | 11 ++++++++--- vpr/src/base/vpr_constraints_writer.cpp | 5 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/vpr/src/base/vpr_constraints_serializer.h b/vpr/src/base/vpr_constraints_serializer.h index 77ea356cd6e..a89c48d6c17 100644 --- a/vpr/src/base/vpr_constraints_serializer.h +++ b/vpr/src/base/vpr_constraints_serializer.h @@ -101,8 +101,8 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase */ virtual inline const char* get_partition_name(partition_info& part_info) final { - return part_info.part.get_name().c_str(); + temp_part_string_ = part_info.part.get_name(); + return temp_part_string_.c_str(); } virtual inline void set_partition_name(const char* name, void*& /*ctx*/) final { loaded_partition.set_name(name); @@ -318,6 +319,10 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase* report_error_; diff --git a/vpr/src/base/vpr_constraints_writer.cpp b/vpr/src/base/vpr_constraints_writer.cpp index 3d7ef42ece5..0fdb4d1a12f 100644 --- a/vpr/src/base/vpr_constraints_writer.cpp +++ b/vpr/src/base/vpr_constraints_writer.cpp @@ -41,7 +41,6 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub for (auto i = cluster_atoms.begin(); i != cluster_atoms.end(); i++) { std::string part_name; part_name = cluster_ctx.clb_nlist.block_name(i->first); - PartitionId partid(part_id); Partition part; @@ -54,8 +53,8 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub reg.set_region_rect(loc.x - expand, loc.y - expand, loc.x + expand, loc.y + expand); if (subtile) { - int st = loc.sub_tile; - reg.set_sub_tile(st); + int st = loc.sub_tile; + reg.set_sub_tile(st); } pr.add_to_part_region(reg); From c8b2a6b935e04e4fb6b09ac35c69da832ea63294 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 5 May 2021 12:26:19 -0400 Subject: [PATCH 14/19] Fixed issue where subtile value would not be printed if it was zero --- vpr/src/base/gen/vpr_constraints_uxsdcxx.h | 6 +++++- vpr/src/base/vpr_constraints_serializer.h | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/vpr/src/base/gen/vpr_constraints_uxsdcxx.h b/vpr/src/base/gen/vpr_constraints_uxsdcxx.h index 86786e69584..f2cd1bf64c4 100644 --- a/vpr/src/base/gen/vpr_constraints_uxsdcxx.h +++ b/vpr/src/base/gen/vpr_constraints_uxsdcxx.h @@ -25,6 +25,10 @@ #include "pugixml.hpp" #include "vpr_constraints_uxsdcxx_interface.h" + +//sentinel value for indicating that a subtile has not been specified +constexpr int NO_SUBTILE = -1; + /* All uxsdcxx functions and structs live in this namespace. */ namespace uxsd { @@ -730,7 +734,7 @@ inline void write_partition(T& in, std::ostream& os, Context& context) { for (size_t i = 0, n = in.num_partition_add_region(context); i < n; i++) { auto child_context = in.get_partition_add_region(i, context); os << " */ virtual inline int get_add_region_subtile(Region& r) final { - return r.get_sub_tile(); + return r.get_sub_tile(); } virtual inline void set_add_region_subtile(int subtile, void*& /*ctx*/) final { @@ -322,7 +322,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase* report_error_; From 7b2674d064c5b5e48a3ac25b2257da16185185f6 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 5 May 2021 17:14:56 -0400 Subject: [PATCH 15/19] Added comments and did minor function refactoring to routines related to writing out or reading in constraints XML files --- vpr/src/base/read_options.cpp | 15 ++++++--- vpr/src/base/vpr_api.cpp | 12 +++---- vpr/src/base/vpr_constraints_reader.cpp | 3 +- vpr/src/base/vpr_constraints_serializer.h | 31 ++++++++++++++---- vpr/src/base/vpr_constraints_writer.cpp | 38 +++++++++++++---------- vpr/src/base/vpr_constraints_writer.h | 17 ++++++++-- vpr/src/base/vpr_types.h | 7 +++++ 7 files changed, 84 insertions(+), 39 deletions(-) diff --git a/vpr/src/base/read_options.cpp b/vpr/src/base/read_options.cpp index 474844d52f4..a1d727ff522 100644 --- a/vpr/src/base/read_options.cpp +++ b/vpr/src/base/read_options.cpp @@ -1413,11 +1413,11 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg .show_in(argparse::ShowIn::HELP_ONLY); file_grp.add_argument(args.read_vpr_constraints_file, "--read_vpr_constraints") - .help("Writes the floorplanning constraints from placement to the specified XML file.") + .help("Reads the floorplanning constraints that packing and placement must respect from the specified XML file.") .show_in(argparse::ShowIn::HELP_ONLY); file_grp.add_argument(args.write_vpr_constraints_file, "--write_vpr_constraints") - .help("Reads the floorplanning constraints from the specified XML file.") + .help("Writes out new floorplanning constraints based on current placement to the specified XML file.") .show_in(argparse::ShowIn::HELP_ONLY); file_grp.add_argument(args.read_router_lookahead, "--read_router_lookahead") @@ -1881,14 +1881,19 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg place_grp.add_argument(args.place_constraint_expand, "--place_constraint_expand") .help( "The value used to decide how much to expand the floorplan constraint region when writing" - "a floorplan constraint XML file. If it is zero, the block stays locked in its place. If it is" - "greater than zero the constraint region expands by the specified value in each direction.") + "a floorplan constraint XML file. Takes in an integer value from zero to infinity." + "If the value is zero, the block stays at the same x, y location. If it is" + "greater than zero the constraint region expands by the specified value in each direction." + "For example, if 1 was specified, a block at the x, y location (1, 1) would have a constraint region" + "of 2x2 centered around (1, 1), from (0, 0) to (2, 2).") .default_value("0") .show_in(argparse::ShowIn::HELP_ONLY); place_grp.add_argument(args.place_constraint_subtile, "--place_constraint_subtile") .help( - "The value used to specify a subtile constraints when writing a floorplan constraints XML file.") + "The bool used to say whether to print subtile constraints when printing a floorplan constraints XML file." + "If it is off, no subtile locations are specified when printing the floorplan constraints." + "If it is on, the floorplan constraints are printed with the subtiles from current placement.") .default_value("off") .show_in(argparse::ShowIn::HELP_ONLY); diff --git a/vpr/src/base/vpr_api.cpp b/vpr/src/base/vpr_api.cpp index b34f5611d92..ea5bd64e689 100644 --- a/vpr/src/base/vpr_api.cpp +++ b/vpr/src/base/vpr_api.cpp @@ -617,6 +617,7 @@ void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) { bool vpr_place_flow(t_vpr_setup& vpr_setup, const t_arch& arch) { VTR_LOG("\n"); const auto& placer_opts = vpr_setup.PlacerOpts; + const auto& filename_opts = vpr_setup.FileNameOpts; if (placer_opts.doPlacement == STAGE_SKIP) { //pass } else { @@ -635,6 +636,11 @@ bool vpr_place_flow(t_vpr_setup& vpr_setup, const t_arch& arch) { post_place_sync(); } + //Write out a vpr floorplanning constraints file if the option is specified + if (!filename_opts.write_vpr_constraints_file.empty()) { + write_vpr_floorplan_constraints(filename_opts.write_vpr_constraints_file.c_str(), placer_opts.place_constraint_expand, placer_opts.place_constraint_subtile); + } + return true; } @@ -660,17 +666,11 @@ void vpr_place(t_vpr_setup& vpr_setup, const t_arch& arch) { arch.num_directs); auto& filename_opts = vpr_setup.FileNameOpts; - auto& placer_opts = vpr_setup.PlacerOpts; auto& cluster_ctx = g_vpr_ctx.clustering(); print_place(filename_opts.NetFile.c_str(), cluster_ctx.clb_nlist.netlist_id().c_str(), filename_opts.PlaceFile.c_str()); - - //Write out a vpr floorplanning constraints file if the option is specified - if (!filename_opts.write_vpr_constraints_file.empty()) { - write_vpr_floorplan_constraints(filename_opts.write_vpr_constraints_file.c_str(), placer_opts.place_constraint_expand, placer_opts.place_constraint_subtile); - } } void vpr_load_placement(t_vpr_setup& vpr_setup, const t_arch& arch) { diff --git a/vpr/src/base/vpr_constraints_reader.cpp b/vpr/src/base/vpr_constraints_reader.cpp index ed975d99f1b..8e69b7b42b4 100644 --- a/vpr/src/base/vpr_constraints_reader.cpp +++ b/vpr/src/base/vpr_constraints_reader.cpp @@ -14,8 +14,7 @@ void load_vpr_constraints_file(const char* read_vpr_constraints_name) { vtr::ScopedStartFinishTimer timer("Loading VPR constraints file"); - VprConstraints constraints; - VprConstraintsSerializer reader(constraints); + VprConstraintsSerializer reader; if (vtr::check_file_name_extension(read_vpr_constraints_name, ".xml")) { try { diff --git a/vpr/src/base/vpr_constraints_serializer.h b/vpr/src/base/vpr_constraints_serializer.h index ebdc8447c01..4007b7c5c3b 100644 --- a/vpr/src/base/vpr_constraints_serializer.h +++ b/vpr/src/base/vpr_constraints_serializer.h @@ -49,12 +49,21 @@ * * For more detail on how the load and write interfaces work with uxsdcxx, refer to 'vpr/src/route/SCHEMA_GENERATOR.md' */ + +/* + * Used for the PartitionReadContext, which is used when writing out a constraints XML file. + * Groups together the information needed when printing a partition. + */ struct partition_info { Partition part; std::vector atoms; PartitionId part_id; }; +/* + * The contexts that end with "ReadContext" are used when writing out the XML file. + * The contexts that end with "WriteContext" are used when reading in the XML file. + */ struct VprConstraintsContextTypes : public uxsd::DefaultVprConstraintsContextTypes { using AddAtomReadContext = AtomBlockId; using AddRegionReadContext = Region; @@ -70,7 +79,8 @@ struct VprConstraintsContextTypes : public uxsd::DefaultVprConstraintsContextTyp class VprConstraintsSerializer final : public uxsd::VprConstraintsBase { public: - //VprConstraintsSerializer() : report_error_(nullptr) {} + VprConstraintsSerializer() + : report_error_(nullptr) {} VprConstraintsSerializer(VprConstraints constraints) : constraints_(constraints) , report_error_(nullptr) {} @@ -154,7 +164,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase */ virtual inline int get_add_region_subtile(Region& r) final { - return r.get_sub_tile(); + return r.get_sub_tile(); } virtual inline void set_add_region_subtile(int subtile, void*& /*ctx*/) final { @@ -273,6 +283,10 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase* report_error_; @@ -333,7 +352,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase::max_digits10); + void* context; + uxsd::write_vpr_constraints_xml(writer, context, fp); + } else { + VPR_FATAL_ERROR(VPR_ERROR_ROUTE, + "Unknown extension on output %s", + file_name); + } +} + +void setup_vpr_floorplan_constraints(VprConstraints& constraints, int expand, bool subtile) { auto& place_ctx = g_vpr_ctx.placement(); auto& atom_ctx = g_vpr_ctx.atom(); auto& cluster_ctx = g_vpr_ctx.clustering(); - //Fill in all the info needed for locking atoms to their locations - VprConstraints constraints; - std::map> cluster_atoms; for (auto blk_id : cluster_ctx.clb_nlist.blocks()) { @@ -69,18 +87,4 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub } part_id++; } - - VprConstraintsSerializer reader(constraints); - - if (vtr::check_file_name_extension(file_name, ".xml")) { - std::fstream fp; - fp.open(file_name, std::fstream::out | std::fstream::trunc); - fp.precision(std::numeric_limits::max_digits10); - void* context; - uxsd::write_vpr_constraints_xml(reader, context, fp); - } else { - VPR_FATAL_ERROR(VPR_ERROR_ROUTE, - "Unknown extension on output %s", - file_name); - } } diff --git a/vpr/src/base/vpr_constraints_writer.h b/vpr/src/base/vpr_constraints_writer.h index 02ed1419f51..496f815476e 100644 --- a/vpr/src/base/vpr_constraints_writer.h +++ b/vpr/src/base/vpr_constraints_writer.h @@ -1,7 +1,16 @@ -/* - * vpr_constraints_writer.h +/** + * @file + * @brief This file contains functions related to writing out a vpr constraints XML file. + * + * Overview + * ======== + * VPR floorplan constraints consist of region constraints specified for primitives that must be respected during packing and placement. + * The constraints XML file is printed using the XML schema vpr/src/base/vpr_constraints.xsd + * + * Routines related to writing out the file are in vpr/src/base/vpr_constraints_serializer.h. For more information on how + * the writing interface works, refer to vpr/src/route/SCHEMA_GENERATOR.md + * * - * Author: khalid88 */ #ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ @@ -9,4 +18,6 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile); +void setup_vpr_floorplan_constraints(VprConstraints& constraints, int expand, bool subtile); + #endif /* VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ */ diff --git a/vpr/src/base/vpr_types.h b/vpr/src/base/vpr_types.h index b9251d6dbbf..38313431d49 100644 --- a/vpr/src/base/vpr_types.h +++ b/vpr/src/base/vpr_types.h @@ -1014,6 +1014,13 @@ enum class e_place_delta_delay_algorithm { * @param doPlacement * True if placement is supposed to be done in the CAD flow. * False if otherwise. + * @param place_constraint_expand + * Integer value that specifies how far to expand the floorplan + * region when printing out floorplan constraints based on + * current placement. + * @param place_constraint_subtile + * True if subtiles should be specified when printing floorplan + * constraints. False if not. */ struct t_placer_opts { t_place_algorithm place_algorithm; From f3d08c483f882617053b4635a2e975e97a294f55 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Wed, 5 May 2021 17:28:44 -0400 Subject: [PATCH 16/19] Removed some unneeded code and changed some function parameters to const references --- vpr/src/place/feasible_region_move_generator.cpp | 16 ---------------- vpr/src/place/place_constraints.cpp | 6 +++--- vpr/src/place/place_constraints.h | 10 +++++----- vpr/src/place/weighted_median_move_generator.cpp | 1 - 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/vpr/src/place/feasible_region_move_generator.cpp b/vpr/src/place/feasible_region_move_generator.cpp index 51df356740c..2d075b9a4e2 100644 --- a/vpr/src/place/feasible_region_move_generator.cpp +++ b/vpr/src/place/feasible_region_move_generator.cpp @@ -123,22 +123,6 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved& return e_create_move::ABORT; } - /*e_create_move create_move; - * create_move = ::create_move(blocks_affected, b_from, to); - * - * //Check if the move is legal from a floorplan perspective - * //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap - * bool floorplan_legal = true; - * for (int i = 0; i < blocks_affected.num_moved_blocks; i++) { - * floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); - * if (!floorplan_legal) { - * VTR_LOG("Move 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); - * return e_create_move::ABORT; - * } - * } - * - * return create_move;*/ - e_create_move create_move = ::create_move(blocks_affected, b_from, to); //Check that all of the blocks affected by the move would still be in a legal floorplan region after the swap diff --git a/vpr/src/place/place_constraints.cpp b/vpr/src/place/place_constraints.cpp index 4dd79958aa2..0b4da8eb26c 100644 --- a/vpr/src/place/place_constraints.cpp +++ b/vpr/src/place/place_constraints.cpp @@ -36,7 +36,7 @@ bool is_cluster_constrained(ClusterBlockId blk_id) { return (!pr.empty()); } -bool is_macro_constrained(t_pl_macro& pl_macro) { +bool is_macro_constrained(const t_pl_macro& pl_macro) { bool is_macro_constrained = false; bool is_member_constrained = false; @@ -54,7 +54,7 @@ bool is_macro_constrained(t_pl_macro& pl_macro) { } /*Returns PartitionRegion of where the head of the macro could go*/ -PartitionRegion constrained_macro_locs(t_pl_macro& pl_macro) { +PartitionRegion constrained_macro_locs(const t_pl_macro& pl_macro) { PartitionRegion macro_pr; bool is_member_constrained = false; int num_constrained_members = 0; @@ -114,7 +114,7 @@ PartitionRegion constrained_macro_locs(t_pl_macro& pl_macro) { } /*returns true if location is compatible with floorplanning constraints, false if not*/ -bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc) { +bool cluster_floorplanning_legal(ClusterBlockId blk_id, const t_pl_loc& loc) { auto& floorplanning_ctx = g_vpr_ctx.floorplanning(); bool floorplanning_good = false; diff --git a/vpr/src/place/place_constraints.h b/vpr/src/place/place_constraints.h index d556b6138b4..90ea1e03be1 100644 --- a/vpr/src/place/place_constraints.h +++ b/vpr/src/place/place_constraints.h @@ -24,20 +24,20 @@ bool is_cluster_constrained(ClusterBlockId blk_id); /* * Check if the placement location would respect floorplan constraints of the block, if it has any */ -bool cluster_floorplanning_legal(ClusterBlockId blk_id, t_pl_loc& loc); +bool cluster_floorplanning_legal(ClusterBlockId blk_id, const t_pl_loc& loc); /* * Check whether any member of the macro has floorplan constraints */ -bool is_macro_constrained(t_pl_macro& pl_macro); +bool is_macro_constrained(const t_pl_macro& pl_macro); /* * Returns region of valid locations for the head of the macro based on floorplan constraints */ -PartitionRegion constrained_macro_locs(t_pl_macro& pl_macro); +PartitionRegion constrained_macro_locs(const t_pl_macro& pl_macro); -inline bool floorplan_legal(t_pl_blocks_to_be_moved& blocks_affected) { - bool floorplan_legal = true; +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++) { floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc); diff --git a/vpr/src/place/weighted_median_move_generator.cpp b/vpr/src/place/weighted_median_move_generator.cpp index 8a208639f2b..761c9b30c5a 100644 --- a/vpr/src/place/weighted_median_move_generator.cpp +++ b/vpr/src/place/weighted_median_move_generator.cpp @@ -102,7 +102,6 @@ e_create_move WeightedMedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& if (!find_to_loc_centroid(cluster_from_type, from, w_median_point, range_limiters, to)) { return e_create_move::ABORT; } - //return ::create_move(blocks_affected, b_from, to); e_create_move create_move = ::create_move(blocks_affected, b_from, to); From 2e7b05d70ff3d452448b41d37a45f2755e9b83a0 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Thu, 6 May 2021 10:24:12 -0400 Subject: [PATCH 17/19] Added a lookup for which atoms are in a cluster in clustered_netlist_utils. Use this lookup when writing out constraints XML --- vpr/src/base/clustered_netlist_utils.cpp | 23 ++++++++++++++++++ vpr/src/base/clustered_netlist_utils.h | 11 +++++++++ vpr/src/base/vpr_constraints_writer.cpp | 30 ++++++++---------------- vpr/src/base/vpr_constraints_writer.h | 10 ++++++++ 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/vpr/src/base/clustered_netlist_utils.cpp b/vpr/src/base/clustered_netlist_utils.cpp index dc70316cad2..a7488d9ba89 100644 --- a/vpr/src/base/clustered_netlist_utils.cpp +++ b/vpr/src/base/clustered_netlist_utils.cpp @@ -1,4 +1,5 @@ #include "clustered_netlist_utils.h" +#include "globals.h" ClusteredPinAtomPinsLookup::ClusteredPinAtomPinsLookup(const ClusteredNetlist& clustered_netlist, const AtomNetlist& atom_netlist, const IntraLbPbPinLookup& pb_gpin_lookup) { init_lookup(clustered_netlist, atom_netlist, pb_gpin_lookup); } @@ -33,3 +34,25 @@ void ClusteredPinAtomPinsLookup::init_lookup(const ClusteredNetlist& clustered_n } } } + +ClusterAtomsLookup::ClusterAtomsLookup() { + init_lookup(); +} + +void ClusterAtomsLookup::init_lookup() { + auto& atom_ctx = g_vpr_ctx.atom(); + auto& cluster_ctx = g_vpr_ctx.clustering(); + + cluster_atoms.resize(cluster_ctx.clb_nlist.blocks().size()); + + for (auto atom_blk_id : atom_ctx.nlist.blocks()) { + ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(atom_blk_id); + + cluster_atoms[clb_index].push_back(atom_blk_id); + } +} + +std::vector ClusterAtomsLookup::atoms_in_cluster(ClusterBlockId blk_id) { + std::vector atoms = cluster_atoms[blk_id]; + return atoms; +} diff --git a/vpr/src/base/clustered_netlist_utils.h b/vpr/src/base/clustered_netlist_utils.h index fcb1ddb1115..f93a06d9418 100644 --- a/vpr/src/base/clustered_netlist_utils.h +++ b/vpr/src/base/clustered_netlist_utils.h @@ -27,4 +27,15 @@ class ClusteredPinAtomPinsLookup { vtr::vector atom_pin_connected_cluster_pin_; }; +class ClusterAtomsLookup { + public: + ClusterAtomsLookup(); + std::vector atoms_in_cluster(ClusterBlockId blk_id); + + private: + void init_lookup(); + + private: + vtr::vector> cluster_atoms; +}; #endif diff --git a/vpr/src/base/vpr_constraints_writer.cpp b/vpr/src/base/vpr_constraints_writer.cpp index 8598d60bc70..e09693ae23a 100644 --- a/vpr/src/base/vpr_constraints_writer.cpp +++ b/vpr/src/base/vpr_constraints_writer.cpp @@ -13,6 +13,7 @@ #include "pugixml.hpp" #include "pugixml_util.hpp" #include "echo_files.h" +#include "clustered_netlist_utils.h" #include #include "vpr_constraints_writer.h" @@ -39,26 +40,14 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub } void setup_vpr_floorplan_constraints(VprConstraints& constraints, int expand, bool subtile) { - auto& place_ctx = g_vpr_ctx.placement(); - auto& atom_ctx = g_vpr_ctx.atom(); auto& cluster_ctx = g_vpr_ctx.clustering(); - - std::map> cluster_atoms; - - for (auto blk_id : cluster_ctx.clb_nlist.blocks()) { - cluster_atoms.insert({blk_id, std::vector()}); - } - - for (auto atom_blk_id : atom_ctx.nlist.blocks()) { - ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(atom_blk_id); - - cluster_atoms[clb_index].push_back(atom_blk_id); - } + auto& place_ctx = g_vpr_ctx.placement(); + ClusterAtomsLookup atoms_lookup; int part_id = 0; - for (auto i = cluster_atoms.begin(); i != cluster_atoms.end(); i++) { + for (auto blk_id : cluster_ctx.clb_nlist.blocks()) { std::string part_name; - part_name = cluster_ctx.clb_nlist.block_name(i->first); + part_name = cluster_ctx.clb_nlist.block_name(blk_id); PartitionId partid(part_id); Partition part; @@ -67,7 +56,7 @@ void setup_vpr_floorplan_constraints(VprConstraints& constraints, int expand, bo PartitionRegion pr; Region reg; - auto loc = place_ctx.block_locs[i->first].loc; + auto loc = place_ctx.block_locs[blk_id].loc; reg.set_region_rect(loc.x - expand, loc.y - expand, loc.x + expand, loc.y + expand); if (subtile) { @@ -79,10 +68,11 @@ void setup_vpr_floorplan_constraints(VprConstraints& constraints, int expand, bo part.set_part_region(pr); constraints.add_partition(part); - int num_atoms = i->second.size(); + std::vector atoms = atoms_lookup.atoms_in_cluster(blk_id); + int num_atoms = atoms.size(); - for (auto j = 0; j < num_atoms; j++) { - AtomBlockId atom_id = i->second[j]; + for (auto atm = 0; atm < num_atoms; atm++) { + AtomBlockId atom_id = atoms[atm]; constraints.add_constrained_atom(atom_id, partid); } part_id++; diff --git a/vpr/src/base/vpr_constraints_writer.h b/vpr/src/base/vpr_constraints_writer.h index 496f815476e..8b56ee041ef 100644 --- a/vpr/src/base/vpr_constraints_writer.h +++ b/vpr/src/base/vpr_constraints_writer.h @@ -16,6 +16,16 @@ #ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ #define VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ +/** + * @brief Write out floorplan constraints to an XML file based on current placement + * + * @param file_name The name of the file that the constraints will be written to + * @param expand The amount the floorplan region will be expanded around the current + * x, y location of the block. Ex. if location is (1, 1) and expand = 1, + * the floorplan region will be from (0, 0) to (2, 2). + * @param subtile Specifies whether to write out the constraint regions with or without + * subtile values. + */ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile); void setup_vpr_floorplan_constraints(VprConstraints& constraints, int expand, bool subtile); From 4c50e8b5bcf021adadfaa4ad7f1cba4ab299e2d0 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Thu, 6 May 2021 10:28:46 -0400 Subject: [PATCH 18/19] Add comment to describe loop that fills in constraints object for writing out XML --- vpr/src/base/vpr_constraints_writer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vpr/src/base/vpr_constraints_writer.cpp b/vpr/src/base/vpr_constraints_writer.cpp index e09693ae23a..acfc281786f 100644 --- a/vpr/src/base/vpr_constraints_writer.cpp +++ b/vpr/src/base/vpr_constraints_writer.cpp @@ -45,6 +45,11 @@ void setup_vpr_floorplan_constraints(VprConstraints& constraints, int expand, bo ClusterAtomsLookup atoms_lookup; int part_id = 0; + /* + * For each cluster block, create a partition filled with the atoms that are currently in the cluster. + * The PartitionRegion will be the location of the block in current placement, modified by the expansion factor. + * The subtile can also optionally be set in the PartitionRegion, based on the value passed in by the user. + */ for (auto blk_id : cluster_ctx.clb_nlist.blocks()) { std::string part_name; part_name = cluster_ctx.clb_nlist.block_name(blk_id); From 7df3f456b34f4f54d7d79ce3ff39c08bf38dd319 Mon Sep 17 00:00:00 2001 From: Sarah Khalid Date: Mon, 10 May 2021 16:58:09 -0400 Subject: [PATCH 19/19] Commented ClusterAtomsLookup class --- vpr/src/base/clustered_netlist_utils.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vpr/src/base/clustered_netlist_utils.h b/vpr/src/base/clustered_netlist_utils.h index f93a06d9418..3568120e2fc 100644 --- a/vpr/src/base/clustered_netlist_utils.h +++ b/vpr/src/base/clustered_netlist_utils.h @@ -27,6 +27,12 @@ class ClusteredPinAtomPinsLookup { vtr::vector atom_pin_connected_cluster_pin_; }; +/* + * This lookup is used to see which atoms are in each cluster block. + * Getting the atoms inside of a cluster is an order k lookup. + * The data is initialized automatically upon creation of the object. + * The class should only be used after the clustered netlist is created. + */ class ClusterAtomsLookup { public: ClusterAtomsLookup(); @@ -36,6 +42,7 @@ class ClusterAtomsLookup { void init_lookup(); private: + //Store the atom ids of the atoms inside each cluster vtr::vector> cluster_atoms; }; #endif