-
Notifications
You must be signed in to change notification settings - Fork 415
Refactor the placer debug code #1522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
vpr/src/draw/draw.cpp
Outdated
@@ -998,16 +998,16 @@ static void drawplace(ezgl::renderer* g) { | |||
ezgl::color block_color; | |||
t_logical_block_type_ptr logical_block_type = nullptr; | |||
# ifdef VTR_ENABLE_DEBUG_LOGGING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this guard? Does it only control the breakpoint functionality or something else? Does compiling in breakpoints slow the tool down?
If not, we can just eliminate this #ifdef throughout the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd factor this into a subroutine; shorter routines with meaningful names are easier to understand and change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once in a subroutine, you should comment the function (above the function header) about exactly what it does. Add inline comments for anything tricky or non-obvious if necessary.
@@ -998,16 +998,16 @@ static void drawplace(ezgl::renderer* g) { | |||
ezgl::color block_color; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the continue for if (bnum == ...) on a separate, indented line.
vpr/src/draw/draw.cpp
Outdated
t_pl_loc curr_loc; | ||
curr_loc.x = i; | ||
curr_loc.y = j; | ||
auto it = std::find_if(draw_state->colored_blocks.begin(), draw_state->colored_blocks.end(), [&curr_loc](const std::pair<t_pl_loc, ezgl::color>& a) { return (a.first.x == curr_loc.x && a.first.y == curr_loc.y); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a better name than a.
colored_blocks should really be called colored_locations (I think).
vpr/src/draw/draw.cpp
Outdated
curr_loc.x = i; | ||
curr_loc.y = j; | ||
auto it = std::find_if(draw_state->colored_blocks.begin(), draw_state->colored_blocks.end(), [&curr_loc](const std::pair<t_pl_loc, ezgl::color>& a) { return (a.first.x == curr_loc.x && a.first.y == curr_loc.y); }); | ||
if (placer_debug_enabled() && it != draw_state->colored_blocks.end()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is placer_debug_enabled() the right name? Does this really mean we are in a breakpoint? If so worth renaming.
vpr/src/draw/draw.cpp
Outdated
curr_loc.x = i; | ||
curr_loc.y = j; | ||
auto it = std::find_if(draw_state->colored_blocks.begin(), draw_state->colored_blocks.end(), [&curr_loc](const std::pair<t_pl_loc, ezgl::color>& a) { return (a.first.x == curr_loc.x && a.first.y == curr_loc.y); }); | ||
if (placer_debug_enabled() && it != draw_state->colored_blocks.end()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: found a colored location at the spot I am drawing (currently used for drawing the current move). This overrides any block color.
vpr/src/draw/draw.cpp
Outdated
curr_loc.x = i; | ||
curr_loc.y = j; | ||
auto it = std::find_if(draw_state->colored_blocks.begin(), draw_state->colored_blocks.end(), [&curr_loc](const std::pair<t_pl_loc, ezgl::color>& a) { return (a.first.x == curr_loc.x && a.first.y == curr_loc.y); }); | ||
if (placer_debug_enabled() && it != draw_state->colored_blocks.end()) { | ||
block_color = it->second; | ||
auto tile_type = device_ctx.grid[i][j].type; | ||
logical_block_type = pick_best_logical_type(tile_type); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No color specified at this location; use the block color.
vpr/src/draw/draw.cpp
Outdated
// location highlighting functions | ||
void set_draw_loc_color(t_pl_loc loc, ezgl::color clr){ | ||
t_draw_state* draw_state = get_draw_state_vars(); | ||
draw_state->colored_blocks.push_back(std::make_pair(loc,clr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change variable name to colored_locs
vpr/src/draw/draw.cpp
Outdated
@@ -4157,4 +4135,16 @@ static void run_graphics_commands(std::string commands) { | |||
++draw_state->sequence_number; | |||
} | |||
|
|||
#ifdef VTR_ENABLE_DEBUG_LOGGING | |||
// location highlighting functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand this: pass in an (x,y,subtile) location and the color in which it should be drawn. This overrides the color of any block placed in that location, and also applies if the location is empty.
vpr/src/draw/draw.cpp
Outdated
t_draw_state* draw_state = get_draw_state_vars(); | ||
draw_state->colored_blocks.push_back(std::make_pair(loc,clr)); | ||
} | ||
void clear_colored_blocks(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a blank line (vertical spacing).
Add a function level comment.
vpr/src/draw/draw.h
Outdated
@@ -84,6 +84,12 @@ float get_net_alpha(); | |||
|
|||
ezgl::color get_block_type_color(t_physical_tile_type_ptr type); | |||
|
|||
#ifdef VTR_ENABLE_DEBUG_LOGGING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the #ifdef (unless you show a slowdown).
vpr/src/draw/draw.h
Outdated
@@ -84,6 +84,12 @@ float get_net_alpha(); | |||
|
|||
ezgl::color get_block_type_color(t_physical_tile_type_ptr type); | |||
|
|||
#ifdef VTR_ENABLE_DEBUG_LOGGING | |||
// location highlighting functions | |||
void set_draw_loc_color(t_pl_loc , ezgl::color ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the function level comments (or duplicate them) here.
vpr/src/place/move_utils.cpp
Outdated
@@ -8,9 +8,8 @@ | |||
//Run-time flag to control when placer debug information is printed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First two lines of this comment can probably be deleted. (get rid of #ifdef and second line seems less detailed / accurate than the rest of the comment).
vpr/src/place/move_utils.h
Outdated
@@ -57,4 +51,8 @@ bool find_to_loc_uniform(t_logical_block_type_ptr type, | |||
float rlim, | |||
const t_pl_loc from, | |||
t_pl_loc& to); | |||
|
|||
//Accessor and setter for f_placer_debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain what setting this to true or false means. (idea: person who wants to call these should only have to read the .h file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is placer_debug_enabled the right name? Or should it be placer_breakpoint_reached? (or something like that).
vpr/src/place/place.cpp
Outdated
@@ -45,13 +45,17 @@ | |||
#include "tatum/TimingReporter.hpp" | |||
|
|||
#ifdef VTR_ENABLE_DEBUG_LOGGING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of ifdef if possible.
vpr/src/place/place.cpp
Outdated
# include "draw_types.h" | ||
# include "draw_global.h" | ||
# include "draw_color.h" | ||
# include "breakpoint.h" | ||
//map of the available move types and their corresponding type number | ||
std::map<int, std::string> available_move_types = { | ||
{0, "Uniform"}}; | ||
|
||
#define OLD_BLK_LOC_COLOR blk_GOLD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these colors be defined in a draw routine?
vpr/src/place/place.cpp
Outdated
@@ -3046,13 +3050,13 @@ void stop_placement_and_check_breakopints(t_pl_blocks_to_be_moved& blocks_affect | |||
get_bp_state_globals()->get_glob_breakpoint_state()->from_block = size_t(blocks_affected.moved_blocks[0].block_num); | |||
|
|||
//check for breakpoints | |||
f_place_debug = check_for_breakpoints(true); | |||
if (f_place_debug) | |||
set_placer_debug(check_for_breakpoints(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you should do something like:
if (check_for_breakpoints (true)) { // What does the true flag passed in mean? Comment this.
set_placer_debug (true);
....
else {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reviewing the code, I found that the true flag means that the function is called from placer. I added a comment by this meaning.
vpr/src/place/place.cpp
Outdated
@@ -3037,7 +3041,7 @@ void transform_blocks_affected(t_pl_blocks_to_be_moved blocksAffected) { | |||
} | |||
|
|||
#ifdef VTR_ENABLE_DEBUG_LOGGING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimize added code in try_swap (already a critical routine and overly long). Create high-level functions, if possible in a new place_debug.cpp (or some such) file and call them from here. Should only see a few calls / condition checks in try_swap for breakpoints and they should be well commented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking closer, I think Mahshad already did this.
vpr/src/place/place.cpp
Outdated
@@ -3067,6 +3071,10 @@ void stop_placement_and_check_breakopints(t_pl_blocks_to_be_moved& blocks_affect | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider if this routine should be moved to another file, in /draw or in a placer breakpoints .cpp file (can't recall the exact names).
Various inline comments above ... please take a crack at them and let me know when it's ready for merging. |
- all the drawing code is moved to draw.cpp - the breakpoint algorithm is moved from place.cpp to a new file - the compilation debugging guard is only used when needed - Using more meaningful names - Added high level comments for all placer debugging functions
@vaughnbetz , I have pushed a new commit that addresses all your comments. please let me know if there are any further comments. |
…n VPR_USE_EZGL is disabled
Looks good. The QoR failure was just a golden result that needed updating. Merging. |
Description
This PR follows #1287 . In this PR, some code refactoring was done while preserving the same functionality.
Related Issue
Motivation and Context
Taking into consideration some code review comments on #1287
How Has This Been Tested?
test that the UI is working for multiple VPR benchmarks
test that the feature is disabled if the compilation or the code flag is disabled
Types of changes
Checklist: