Skip to content

Commit f41df3b

Browse files
authored
Merge pull request #2389 from verilog-to-routing/placement_debug_tool
Placement Debug Messages
2 parents 9066310 + c16faeb commit f41df3b

18 files changed

+278
-21
lines changed

doc/src/vpr/command_line_usage.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,38 @@ Setting any of the following options selects `Dusty's annealing schedule <dusty_
879879

880880
**Default:** ``move_block_type``
881881

882+
.. option:: --placer_debug_block <int>
883+
884+
.. note:: This option is likely only of interest to developers debugging the placement algorithm
885+
886+
Controls which block the placer produces detailed debug information for.
887+
888+
If the block being moved has the same ID as the number assigned to this parameter, the placer will print debugging information about it.
889+
890+
* For values >= 0, the value is the block ID for which detailed placer debug information should be produced.
891+
* For value == -1, detailed placer debug information is produced for all blocks.
892+
* For values < -1, no placer debug output is produced.
893+
894+
.. warning:: VPR must have been compiled with `VTR_ENABLE_DEBUG_LOGGING` on to get any debug output from this option.
895+
896+
**Default:** ``-2``
897+
898+
.. option:: --placer_debug_net <int>
899+
900+
.. note:: This option is likely only of interest to developers debugging the placement algorithm
901+
902+
Controls which net the placer produces detailed debug information for.
903+
904+
If a net with the same ID assigned to this parameter is connected to the block that is being moved, the placer will print debugging information about it.
905+
906+
* For values >= 0, the value is the net ID for which detailed placer debug information should be produced.
907+
* For value == -1, detailed placer debug information is produced for all nets.
908+
* For values < -1, no placer debug output is produced.
909+
910+
.. warning:: VPR must have been compiled with `VTR_ENABLE_DEBUG_LOGGING` on to get any debug output from this option.
911+
912+
**Default:** ``-2``
913+
882914

883915
.. _timing_driven_placer_options:
884916

vpr/src/base/SetupVPR.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,9 @@ static void SetupPlacerOpts(const t_options& Options, t_placer_opts* PlacerOpts)
677677
PlacerOpts->floorplan_num_vertical_partitions = Options.floorplan_num_vertical_partitions;
678678

679679
PlacerOpts->seed = Options.Seed;
680+
681+
PlacerOpts->placer_debug_block = Options.placer_debug_block;
682+
PlacerOpts->placer_debug_net = Options.placer_debug_net;
680683
}
681684

682685
static void SetupAnalysisOpts(const t_options& Options, t_analysis_opts& analysis_opts) {

vpr/src/base/read_options.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,30 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
21222122
.choices({"move_type", "move_block_type"})
21232123
.show_in(argparse::ShowIn::HELP_ONLY);
21242124

2125+
place_grp.add_argument(args.placer_debug_block, "--placer_debug_block")
2126+
.help(
2127+
" Controls when placer debugging is enabled for blocks.\n"
2128+
" * For values >= 0, the value is taken as the block ID for\n"
2129+
" which to enable placer debug output.\n"
2130+
" * For value == -1, placer debug output is enabled for\n"
2131+
" all blocks.\n"
2132+
" * For values < -1, all block-based placer debug output is disabled.\n"
2133+
"Note if VPR as compiled without debug logging enabled this will produce only limited output.\n")
2134+
.default_value("-2")
2135+
.show_in(argparse::ShowIn::HELP_ONLY);
2136+
2137+
place_grp.add_argument(args.placer_debug_net, "--placer_debug_net")
2138+
.help(
2139+
"Controls when placer debugging is enabled for nets.\n"
2140+
" * For values >= 0, the value is taken as the net ID for\n"
2141+
" which to enable placer debug output.\n"
2142+
" * For value == -1, placer debug output is enabled for\n"
2143+
" all nets.\n"
2144+
" * For values < -1, all net-based placer debug output is disabled.\n"
2145+
"Note if VPR as compiled without debug logging enabled this will produce only limited output.\n")
2146+
.default_value("-2")
2147+
.show_in(argparse::ShowIn::HELP_ONLY);
2148+
21252149
auto& place_timing_grp = parser.add_argument_group("timing-driven placement options");
21262150

21272151
place_timing_grp.add_argument(args.PlaceTimingTradeoff, "--timing_tradeoff")

vpr/src/base/read_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ struct t_options {
143143
argparse::ArgValue<int> floorplan_num_horizontal_partitions;
144144
argparse::ArgValue<int> floorplan_num_vertical_partitions;
145145

146+
argparse::ArgValue<int> placer_debug_block;
147+
argparse::ArgValue<int> placer_debug_net;
148+
146149
/*NoC Options*/
147150
argparse::ArgValue<bool> noc;
148151
argparse::ArgValue<std::string> noc_flows_file;

vpr/src/base/vpr_context.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ struct PlacementContext : public Context {
396396
* Used for unique identification and consistency checking
397397
*/
398398
std::string placement_id;
399+
400+
/**
401+
* Use during placement to print extra debug information. It is set to true based on the number assigned to
402+
* placer_debug_net or placer_debug_block parameters in the command line.
403+
*/
404+
bool f_placer_debug = false;
399405
};
400406

401407
/**

vpr/src/base/vpr_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,9 @@ struct t_placer_opts {
11991199
int floorplan_num_horizontal_partitions;
12001200
int floorplan_num_vertical_partitions;
12011201

1202+
int placer_debug_block;
1203+
int placer_debug_net;
1204+
12021205
/**
12031206
* @brief Tile types that should be used during delay sampling.
12041207
*

vpr/src/place/centroid_move_generator.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, t_propose_action& proposed_action, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* /*criticalities*/) {
99
//Find a movable block based on blk_type
10-
ClusterBlockId b_from = propose_block_to_move(proposed_action.logical_blk_type_index, false, nullptr, nullptr);
10+
ClusterBlockId b_from = propose_block_to_move(placer_opts,
11+
proposed_action.logical_blk_type_index,
12+
false,
13+
nullptr,
14+
nullptr);
15+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "Centroid Move Choose Block %d - rlim %f\n", size_t(b_from), rlim);
1116

1217
if (!b_from) { //No movable block found
1318
return e_create_move::ABORT;

vpr/src/place/critical_uniform_move_generator.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
#include "place_constraints.h"
44
#include "move_utils.h"
55

6-
e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, t_propose_action& proposed_action, float rlim, const t_placer_opts& /*placer_opts*/, const PlacerCriticalities* /*criticalities*/) {
6+
e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, t_propose_action& proposed_action, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* /*criticalities*/) {
77
ClusterNetId net_from;
88
int pin_from;
99
//Find a movable block based on blk_type
10-
ClusterBlockId b_from = propose_block_to_move(proposed_action.logical_blk_type_index, true, &net_from, &pin_from);
10+
ClusterBlockId b_from = propose_block_to_move(placer_opts,
11+
proposed_action.logical_blk_type_index,
12+
true,
13+
&net_from,
14+
&pin_from);
15+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "Critical Uniform Move Choose Block %d - rlim %f\n", size_t(b_from), rlim);
1116

1217
auto& place_ctx = g_vpr_ctx.placement();
1318
auto& cluster_ctx = g_vpr_ctx.clustering();

vpr/src/place/feasible_region_move_generator.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ e_create_move FeasibleRegionMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
99
ClusterNetId net_from;
1010
int pin_from;
1111
//Find a movable block based on blk_type
12-
ClusterBlockId b_from = propose_block_to_move(proposed_action.logical_blk_type_index, true, &net_from, &pin_from);
12+
ClusterBlockId b_from = propose_block_to_move(placer_opts,
13+
proposed_action.logical_blk_type_index,
14+
true,
15+
&net_from,
16+
&pin_from);
17+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "Feasible Region Move Choose Block %di - rlim %f\n", size_t(b_from), rlim);
1318

1419
if (!b_from) { //No movable block found
1520
return e_create_move::ABORT;

vpr/src/place/initial_placement.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static bool try_dense_placement(t_pl_macro pl_macro, PartitionRegion& pr, t_logi
229229
* @param pad_loc_type Used to check whether an io block needs to be marked as fixed.
230230
* @param constraints_file Used to read block locations if any constraints is available.
231231
*/
232-
static void place_all_blocks(vtr::vector<ClusterBlockId, t_block_score>& block_scores, enum e_pad_loc_type pad_loc_type, const char* constraints_file);
232+
static void place_all_blocks(const t_placer_opts& placer_opts, vtr::vector<ClusterBlockId, t_block_score>& block_scores, enum e_pad_loc_type pad_loc_type, const char* constraints_file);
233233

234234
/**
235235
* @brief If any blocks remain unplaced after all initial placement iterations, this routine
@@ -780,6 +780,12 @@ static bool try_dense_placement(t_pl_macro pl_macro, PartitionRegion& pr, t_logi
780780
static bool try_place_macro(t_pl_macro pl_macro, t_pl_loc head_pos) {
781781
auto& place_ctx = g_vpr_ctx.mutable_placement();
782782

783+
VTR_LOGV_DEBUG(place_ctx.f_placer_debug, "\t\t\t\tTry to place the macro at %dx%dx%dx%d\n",
784+
head_pos.x,
785+
head_pos.y,
786+
head_pos.sub_tile,
787+
head_pos.layer);
788+
783789
bool macro_placed = false;
784790

785791
// If that location is occupied, do nothing.
@@ -792,6 +798,7 @@ static bool try_place_macro(t_pl_macro pl_macro, t_pl_loc head_pos) {
792798
if (mac_can_be_placed) {
793799
// Place down the macro
794800
macro_placed = true;
801+
VTR_LOGV_DEBUG(place_ctx.f_placer_debug, "\t\t\t\tMacro is placed at the given location\n");
795802
for (size_t imember = 0; imember < pl_macro.members.size(); imember++) {
796803
t_pl_loc member_pos = head_pos + pl_macro.members[imember].offset;
797804

@@ -808,8 +815,10 @@ static bool try_place_macro(t_pl_macro pl_macro, t_pl_loc head_pos) {
808815
static bool place_macro(int macros_max_num_tries, t_pl_macro pl_macro, enum e_pad_loc_type pad_loc_type, std::vector<t_grid_empty_locs_block_type>* blk_types_empty_locs_in_grid, vtr::vector<ClusterBlockId, t_block_score>& block_scores) {
809816
ClusterBlockId blk_id;
810817
blk_id = pl_macro.members[0].blk_index;
818+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\t\tHead of the macro is Block %d\n", size_t(blk_id));
811819

812820
if (is_block_placed(blk_id)) {
821+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\t\t\tBlock is already placed\n", size_t(blk_id));
813822
return true;
814823
}
815824

@@ -826,6 +835,7 @@ static bool place_macro(int macros_max_num_tries, t_pl_macro pl_macro, enum e_pa
826835
//Enough to check head member of macro to see if its constrained because
827836
//constraints propagation was done earlier in initial placement.
828837
if (is_cluster_constrained(blk_id)) {
838+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\t\t\tMacro's head is constrained\n");
829839
pr = floorplanning_ctx.cluster_constraints[blk_id];
830840
} else { //If the block is not constrained, assign a region the size of the grid to its PartitionRegion
831841
Region reg;
@@ -843,15 +853,18 @@ static bool place_macro(int macros_max_num_tries, t_pl_macro pl_macro, enum e_pa
843853
//If blk_types_empty_locs_in_grid is not NULL, means that initial placement has been failed in first iteration for this block type
844854
//We need to place densely in second iteration to be able to find a legal initial placement solution
845855
if (blk_types_empty_locs_in_grid != NULL && blk_types_empty_locs_in_grid->size() != 0) {
856+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\t\t\tTry dense placement\n");
846857
macro_placed = try_dense_placement(pl_macro, pr, block_type, pad_loc_type, blk_types_empty_locs_in_grid);
847858
}
848859

849860
if (!macro_placed) {
861+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\t\t\tTry centroid placement\n");
850862
macro_placed = try_centroid_placement(pl_macro, pr, block_type, pad_loc_type, block_scores);
851863
}
852-
864+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\t\t\tMacro is placed: %d\n", macro_placed);
853865
// If macro is not placed yet, try to place the macro randomly for the max number of random tries
854866
for (int itry = 0; itry < macros_max_num_tries && macro_placed == false; itry++) {
867+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\t\t\tTry random place iter: %d\n", itry);
855868
macro_placed = try_random_placement(pl_macro, pr, block_type, pad_loc_type);
856869
} // Finished all tries
857870

@@ -863,6 +876,7 @@ static bool place_macro(int macros_max_num_tries, t_pl_macro pl_macro, enum e_pa
863876
// if there are no legal positions, error out
864877

865878
// Exhaustive placement of carry macros
879+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\t\t\tTry exhaustive placement\n");
866880
macro_placed = try_exhaustive_placement(pl_macro, pr, block_type, pad_loc_type);
867881
}
868882
return macro_placed;
@@ -913,7 +927,11 @@ static vtr::vector<ClusterBlockId, t_block_score> assign_block_scores() {
913927
return block_scores;
914928
}
915929

916-
static void place_all_blocks(vtr::vector<ClusterBlockId, t_block_score>& block_scores, enum e_pad_loc_type pad_loc_type, const char* constraints_file) {
930+
#ifdef VTR_ENABLE_DEBUG_LOGGING
931+
static void place_all_blocks(const t_placer_opts& placer_opts, vtr::vector<ClusterBlockId, t_block_score>& block_scores, enum e_pad_loc_type pad_loc_type, const char* constraints_file) {
932+
#else
933+
static void place_all_blocks(const t_placer_opts& /* placer_opts */, vtr::vector<ClusterBlockId, t_block_score>& block_scores, enum e_pad_loc_type pad_loc_type, const char* constraints_file) {
934+
#endif
917935
auto& cluster_ctx = g_vpr_ctx.clustering();
918936
auto& place_ctx = g_vpr_ctx.placement();
919937
auto& device_ctx = g_vpr_ctx.device();
@@ -963,6 +981,12 @@ static void place_all_blocks(vtr::vector<ClusterBlockId, t_block_score>& block_s
963981
heap_blocks.pop_back();
964982

965983
auto blk_id_type = cluster_ctx.clb_nlist.block_type(blk_id);
984+
985+
#ifdef VTR_ENABLE_DEBUG_LOGGING
986+
enable_placer_debug(placer_opts, blk_id);
987+
#endif
988+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "Popped Block %d\n", size_t(blk_id));
989+
966990
blocks_placed_since_heap_update++;
967991

968992
bool block_placed = place_one_block(blk_id, pad_loc_type, &blk_types_empty_locs_in_grid[blk_id_type->index], &block_scores);
@@ -974,6 +998,7 @@ static void place_all_blocks(vtr::vector<ClusterBlockId, t_block_score>& block_s
974998
}
975999

9761000
if (!block_placed) {
1001+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "Didn't find a location the block\n", size_t(blk_id));
9771002
//add current block to list to ensure it will be placed sooner in the next iteration in initial placement
9781003
number_of_unplaced_blks_in_curr_itr++;
9791004
block_scores[blk_id].failed_to_place_in_prev_attempts++;
@@ -1065,6 +1090,7 @@ bool place_one_block(const ClusterBlockId& blk_id,
10651090
get_imacro_from_iblk(&imacro, blk_id, place_ctx.pl_macros);
10661091

10671092
if (imacro != -1) { //If the block belongs to a macro, pass that macro to the placement routines
1093+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\tBelongs to a macro %d\n", imacro);
10681094
pl_macro = place_ctx.pl_macros[imacro];
10691095
placed_macro = place_macro(MAX_NUM_TRIES_TO_PLACE_MACROS_RANDOMLY, pl_macro, pad_loc_type, blk_types_empty_locs_in_grid, (*block_scores));
10701096
} else {
@@ -1082,7 +1108,10 @@ bool place_one_block(const ClusterBlockId& blk_id,
10821108
return placed_macro;
10831109
}
10841110

1085-
void initial_placement(enum e_pad_loc_type pad_loc_type, const char* constraints_file, bool noc_enabled) {
1111+
void initial_placement(const t_placer_opts& placer_opts,
1112+
enum e_pad_loc_type pad_loc_type,
1113+
const char* constraints_file,
1114+
bool noc_enabled) {
10861115
vtr::ScopedStartFinishTimer timer("Initial Placement");
10871116

10881117
/* Go through cluster blocks to calculate the tightest placement
@@ -1098,7 +1127,7 @@ void initial_placement(enum e_pad_loc_type pad_loc_type, const char* constraints
10981127
vtr::vector<ClusterBlockId, t_block_score> block_scores = assign_block_scores();
10991128

11001129
//Place all blocks
1101-
place_all_blocks(block_scores, pad_loc_type, constraints_file);
1130+
place_all_blocks(placer_opts, block_scores, pad_loc_type, constraints_file);
11021131

11031132
//if any blocks remain unplaced, print an error
11041133
check_initial_placement_legality();

0 commit comments

Comments
 (0)