Skip to content

Commit 5b2a7c4

Browse files
committed
[ap draw] drawing manager
now in ap, there are no NOGRAPHCIS macro
1 parent 3c0381b commit 5b2a7c4

File tree

7 files changed

+108
-29
lines changed

7 files changed

+108
-29
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @file
3+
* @author Yulang (Robert) Luo
4+
* @date October 2025
5+
* @brief The definitions of the Analytical Draw Manager class which is used
6+
* to handle graphics updates during analytical placement.
7+
*/
8+
9+
#include "analytical_draw_manager.h"
10+
#include "vpr_types.h"
11+
12+
#ifndef NO_GRAPHICS
13+
#include "draw.h"
14+
#include "draw_global.h"
15+
#include "partial_placement.h"
16+
#endif
17+
18+
AnalyticalDrawManager::AnalyticalDrawManager(const PartialPlacement& p_placement) {
19+
#ifndef NO_GRAPHICS
20+
// Set the analytical placement reference in draw state
21+
get_draw_state_vars()->set_ap_partial_placement_ref(p_placement);
22+
#else
23+
(void)p_placement;
24+
#endif
25+
}
26+
27+
AnalyticalDrawManager::~AnalyticalDrawManager() {
28+
#ifndef NO_GRAPHICS
29+
// Clear the analytical placement reference in draw state
30+
get_draw_state_vars()->clear_ap_partial_placement_ref();
31+
#endif
32+
}
33+
34+
void AnalyticalDrawManager::update_graphics(const std::string& msg) {
35+
#ifndef NO_GRAPHICS
36+
update_screen(ScreenUpdatePriority::MAJOR, msg.c_str(), ANALYTICAL_PLACEMENT, nullptr);
37+
#else
38+
(void)msg;
39+
#endif
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
/**
3+
* @file
4+
* @author Yulang (Robert) Luo
5+
* @date October 2025
6+
* @brief The decalarations of the Analytical Draw Manager class which is used
7+
* to handle graphics updates during analytical placement.
8+
*/
9+
10+
#include <string>
11+
12+
// Forward declarations
13+
class PartialPlacement;
14+
15+
/**
16+
* @class AnalyticalDrawManager
17+
* @brief Manages graphics updates during analytical placement operations.
18+
*
19+
* This class provides a clean interface for updating the screen during
20+
* analytical placement without requiring the placement code to be littered
21+
* with NO_GRAPHICS conditional compilation directives.
22+
*/
23+
class AnalyticalDrawManager {
24+
public:
25+
/**
26+
* @brief Constructor initializes the draw manager with a reference to the
27+
* current partial placement.
28+
*/
29+
explicit AnalyticalDrawManager(const PartialPlacement& p_placement);
30+
31+
/**
32+
* @brief Destructor cleans up the reference in the draw state.
33+
*/
34+
~AnalyticalDrawManager();
35+
36+
/**
37+
* @brief Update screen with current analytical placement state
38+
* @param msg A message to display with the update
39+
*/
40+
void update_graphics(const std::string& msg);
41+
};

vpr/src/analytical_place/global_placer.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <limits>
1212
#include <memory>
1313
#include <vector>
14+
#include "analytical_draw_manager.h"
1415
#include "PreClusterTimingManager.h"
1516
#include "analytical_solver.h"
1617
#include "ap_flow_enums.h"
@@ -356,10 +357,10 @@ PartialPlacement SimPLGlobalPlacer::place() {
356357
PartialPlacement best_p_placement(ap_netlist_);
357358
double best_ub_hpwl = std::numeric_limits<double>::max();
358359

359-
#ifndef NO_GRAPHICS
360-
get_draw_state_vars()->set_ap_partial_placement_ref(p_placement);
361-
update_screen(ScreenUpdatePriority::MAJOR, "AP starts", ANALYTICAL_PLACEMENT, nullptr);
362-
#endif
360+
// Initialize graphics for analytical placement, setting the reference in
361+
// the draw state.
362+
AnalyticalDrawManager draw_manager(p_placement);
363+
363364
// Run the global placer.
364365
for (size_t i = 0; i < max_num_iterations_; i++) {
365366
float iter_start_time = runtime_timer.elapsed_sec();
@@ -369,22 +370,18 @@ PartialPlacement SimPLGlobalPlacer::place() {
369370
solver_->solve(i, p_placement);
370371
float solver_end_time = runtime_timer.elapsed_sec();
371372
double lb_hpwl = p_placement.get_hpwl(ap_netlist_);
372-
#ifndef NO_GRAPHICS
373-
// Per iteration analytical solve display
374-
std::string iter_msg = vtr::string_fmt("AP Iteration %zu after analytical solve", i);
375-
update_screen(ScreenUpdatePriority::MAJOR, iter_msg.c_str(), ANALYTICAL_PLACEMENT, nullptr);
376-
#endif
373+
374+
// Update graphics after analytical solver
375+
draw_manager.update_graphics("Iteration " + std::to_string(i) + " After Solver");
377376

378377
// Run the legalizer.
379378
float legalizer_start_time = runtime_timer.elapsed_sec();
380379
partial_legalizer_->legalize(p_placement);
381380
float legalizer_end_time = runtime_timer.elapsed_sec();
382381
double ub_hpwl = p_placement.get_hpwl(ap_netlist_);
383-
#ifndef NO_GRAPHICS
384-
// Per iteration legalized display
385-
iter_msg = vtr::string_fmt("AP Iteration %zu after partial legalization", i);
386-
update_screen(ScreenUpdatePriority::MAJOR, iter_msg.c_str(), ANALYTICAL_PLACEMENT, nullptr);
387-
#endif
382+
383+
// Update graphics after legalizer
384+
draw_manager.update_graphics("Iteration " + std::to_string(i) + " After Legalizer");
388385

389386
// Perform a timing update
390387
float timing_update_start_time = runtime_timer.elapsed_sec();
@@ -440,8 +437,6 @@ PartialPlacement SimPLGlobalPlacer::place() {
440437

441438
if (hpwl_relative_gap < target_hpwl_relative_gap_)
442439
break;
443-
444-
445440
}
446441

447442
// Update the setup slacks. This is performed down here (as well as being
@@ -470,13 +465,7 @@ PartialPlacement SimPLGlobalPlacer::place() {
470465
*density_manager_,
471466
pre_cluster_timing_manager_);
472467

473-
474-
#ifndef NO_GRAPHICS
475-
// Final display of the last iteration's placement
476-
get_draw_state_vars()->set_ap_partial_placement_ref(p_placement);
477-
update_screen(ScreenUpdatePriority::MAJOR, "Global Placement Complete", ANALYTICAL_PLACEMENT, nullptr);
478-
get_draw_state_vars()->clear_ap_partial_placement_ref();
479-
#endif
468+
480469
// Return the placement from the final iteration.
481470
return best_p_placement;
482471
}

vpr/src/draw/draw.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ void update_screen(ScreenUpdatePriority priority, const char* msg, enum pic_type
324324
draw_state->pic_on_screen = pic_on_screen_val;
325325
}
326326

327-
// What is this? Always true!
328327
bool should_pause = int(priority) >= draw_state->gr_automode;
329328

330329
//If there was a state change, we must call ezgl::application::run() to update the buttons.

vpr/src/draw/draw.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,18 @@ void update_screen(ScreenUpdatePriority priority, const char* msg, enum pic_type
5252
*/
5353
void init_draw_coords(float clb_width, const BlkLocRegistry& blk_loc_registry);
5454

55+
/**
56+
* @brief Set the intial_world ezgl::rectangle for analytical placement
57+
*
58+
* This function sets graphic initial dimensions so there are no gaps between blocks
59+
*/
5560
void set_initial_world_ap();
61+
62+
/**
63+
* @brief Set the intial_world ezgl::rectangle for default
64+
*
65+
* This function sets graphic initial dimensions so there are gaps between blocks
66+
*/
5667
void set_initial_world();
5768

5869
/* Sets the static show_graphics and gr_automode variables to the *

vpr/src/draw/draw_basic.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,7 @@ void draw_analytical_place(ezgl::renderer* g) {
205205

206206
for (int x = 0; x < (int)device_ctx.grid.width(); ++x) {
207207
for (int y = 0; y < (int)device_ctx.grid.height(); ++y) {
208-
// Only draw at the root of a non-unit tile
209-
int w_off = device_ctx.grid.get_width_offset({x, y, layer});
210-
int h_off = device_ctx.grid.get_height_offset({x, y, layer});
211-
if (w_off > 0 || h_off > 0) continue;
212-
208+
if (device_ctx.grid.is_root_location({x, y, layer}) == false) continue;
213209
t_physical_tile_type_ptr type = device_ctx.grid.get_physical_type({x, y, layer});
214210
if (type->capacity == 0) continue;
215211

vpr/src/draw/draw_basic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
* Blocks are drawn in layer order (so that semi-transparent blocks/grids render well)*/
3030
void drawplace(ezgl::renderer* g);
3131

32+
/** This function draws the analytical placement from the PartialPlacement object, it
33+
* also draws the architecture grid and the blocks from device_ctx.
34+
*/
3235
void draw_analytical_place(ezgl::renderer* g);
3336

3437
/** This routine draws the nets on the placement. The nets have not

0 commit comments

Comments
 (0)