Skip to content

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

Merged
merged 10 commits into from
Sep 10, 2020
Merged

Refactor the placer debug code #1522

merged 10 commits into from
Sep 10, 2020

Conversation

MohamedElgammal
Copy link
Contributor

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

  • Bug fix (change which fixes an issue)
  • New feature (change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • [ x] All new and existing tests passed

@probot-autolabeler probot-autolabeler bot added lang-cpp C/C++ code VPR VPR FPGA Placement & Routing Tool labels Sep 2, 2020
@MohamedElgammal MohamedElgammal changed the title Place debug refactor Refactor the placer debug code Sep 2, 2020
@@ -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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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;
Copy link
Contributor

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.

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); });
Copy link
Contributor

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).

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()) {
Copy link
Contributor

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.

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()) {
Copy link
Contributor

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.

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 {
Copy link
Contributor

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.

// 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));
Copy link
Contributor

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

@@ -4157,4 +4135,16 @@ static void run_graphics_commands(std::string commands) {
++draw_state->sequence_number;
}

#ifdef VTR_ENABLE_DEBUG_LOGGING
// location highlighting functions
Copy link
Contributor

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.

t_draw_state* draw_state = get_draw_state_vars();
draw_state->colored_blocks.push_back(std::make_pair(loc,clr));
}
void clear_colored_blocks(){
Copy link
Contributor

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.

@@ -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
Copy link
Contributor

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).

@@ -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 );
Copy link
Contributor

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.

@@ -8,9 +8,8 @@
//Run-time flag to control when placer debug information is printed
Copy link
Contributor

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).

@@ -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
Copy link
Contributor

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.

Copy link
Contributor

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).

@@ -45,13 +45,17 @@
#include "tatum/TimingReporter.hpp"

#ifdef VTR_ENABLE_DEBUG_LOGGING
Copy link
Contributor

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.

# 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
Copy link
Contributor

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?

@@ -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));
Copy link
Contributor

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 {

Copy link
Contributor Author

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.

@@ -3037,7 +3041,7 @@ void transform_blocks_affected(t_pl_blocks_to_be_moved blocksAffected) {
}

#ifdef VTR_ENABLE_DEBUG_LOGGING
Copy link
Contributor

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.

Copy link
Contributor

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.

@@ -3067,6 +3071,10 @@ void stop_placement_and_check_breakopints(t_pl_blocks_to_be_moved& blocks_affect

Copy link
Contributor

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).

@vaughnbetz
Copy link
Contributor

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
@MohamedElgammal
Copy link
Contributor Author

@vaughnbetz , I have pushed a new commit that addresses all your comments. please let me know if there are any further comments.

@probot-autolabeler probot-autolabeler bot added the infra Project Infrastructure label Sep 6, 2020
@vaughnbetz
Copy link
Contributor

Looks good. The QoR failure was just a golden result that needed updating. Merging.

@vaughnbetz vaughnbetz merged commit 1478410 into master Sep 10, 2020
@vaughnbetz vaughnbetz deleted the place_debug_refactor branch September 10, 2020 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infra Project Infrastructure lang-cpp C/C++ code VPR VPR FPGA Placement & Routing Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants