Skip to content

Commit 2d1de0c

Browse files
draw floorplan regions for 3d architectures
1 parent 3d6941f commit 2d1de0c

File tree

5 files changed

+79
-48
lines changed

5 files changed

+79
-48
lines changed

vpr/src/base/partition_region.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,17 @@ void print_partition_region(FILE* fp, const PartitionRegion& pr) {
8686
}
8787

8888
const PartitionRegion& get_device_partition_region() {
89-
// the device partition region is constructed
89+
// the device partition region is initialized the first time this function is called
9090
static PartitionRegion device_pr;
9191

92-
const auto& grid_ctx = g_vpr_ctx.device().grid;
92+
const auto& grid = g_vpr_ctx.device().grid;
9393

94-
if (grid_ctx.grid_size() == 0) {
95-
// TODO: error message
96-
}
94+
// this function is supposed to be called when the grid is constructed
95+
VTR_ASSERT_SAFE(grid.grid_size() != 0);
9796

98-
const int n_layers = grid_ctx.get_num_layers();
99-
const int width = (int)grid_ctx.width();
100-
const int height = (int)grid_ctx.height();
97+
const int n_layers = grid.get_num_layers();
98+
const int width = static_cast<int>(grid.width());
99+
const int height = static_cast<int>(grid.height());
101100

102101
if (device_pr.empty()) {
103102
Region device_region(0, 0, width - 1, height - 1, 0, n_layers - 1);

vpr/src/base/vpr_context.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,20 @@ struct FloorplanningContext : public Context {
523523
/**
524524
* @brief Floorplanning constraints in the compressed grid coordinate system.
525525
*
526+
* Indexing --> [0..grid.num_layers-1][0..numClusters-1]
527+
*
526528
* Each clustered block has a logical type with a corresponding compressed grid.
527529
* Compressed floorplanning constraints are calculated by translating the grid locations
528530
* of floorplanning regions to compressed grid locations. To ensure regions do not enlarge:
529531
* - The bottom left corner is rounded up to the nearest compressed location.
530532
* - The top right corner is rounded down to the nearest compressed location.
533+
*
534+
* When the floorplanning constraint spans across multiple layers, a compressed
535+
* constraints is created for each a layer that the original constraint includes.
536+
* This is because blocks of the same type might have different (x, y) locations
537+
* in different layers, and as result, their compressed locations in each layer
538+
* may correspond to a different physical (x, y) location.
539+
*
531540
*/
532541
std::vector<vtr::vector<ClusterBlockId, PartitionRegion>> compressed_cluster_constraints;
533542

vpr/src/draw/draw_floorplanning.cpp

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
# include <X11/keysym.h>
4646
# endif
4747

48-
static void draw_internal_pb(const ClusterBlockId clb_index, t_pb* current_pb, const t_pb* pb_to_draw, const ezgl::rectangle& parent_bbox, const t_logical_block_type_ptr type, ezgl::color color, ezgl::renderer* g);
48+
static void draw_internal_pb(const ClusterBlockId clb_index, t_pb* current_pb,
49+
const t_pb* pb_to_draw, const ezgl::rectangle& parent_bbox,
50+
const t_logical_block_type_ptr type, ezgl::color color,
51+
ezgl::renderer* g);
4952

5053
const std::vector<ezgl::color> kelly_max_contrast_colors_no_black = {
5154
//ezgl::color(242, 243, 244), //white: skip white since it doesn't contrast well with VPR's light background
@@ -83,63 +86,65 @@ static void highlight_partition(ezgl::renderer* g, int partitionID, int alpha) {
8386
auto& floorplanning_ctx = g_vpr_ctx.floorplanning();
8487
auto constraints = floorplanning_ctx.constraints;
8588
t_draw_coords* draw_coords = get_draw_coords_vars();
89+
t_draw_state* draw_state = get_draw_state_vars();
8690

8791
const auto& partition = constraints.get_partition((PartitionId)partitionID);
8892
const auto& partition_region = partition.get_part_region();
8993
const auto& regions = partition_region.get_regions();
9094

9195
bool name_drawn = false;
9296
ezgl::color partition_color = kelly_max_contrast_colors_no_black[partitionID % (kelly_max_contrast_colors_no_black.size())];
93-
g->set_color(partition_color, alpha);
9497

95-
// The units of space in the constraints xml file will be refered to as "tile units"
96-
// The units of space that'll be used by ezgl to draw will be refered to as "on screen units"
98+
// The units of space in the constraints xml file will be referred to as "tile units"
99+
// The units of space that'll be used by ezgl to draw will be referred to as "on screen units"
97100

98101
// Find the coordinates of the region by retrieving from the xml file
99102
// which tiles are at the corner of the region, then translate that to on
100103
// the on screen units for ezgl to use.
101104

102105
for (int region = 0; (size_t)region < regions.size(); region++) {
103106
const vtr::Rect<int>& reg_coord = regions[region].get_rect();
104-
const auto [layer_begin, layer_end] = regions[region].get_layer_range();
107+
const auto [layer_low, layer_high] = regions[region].get_layer_range();
105108

106-
//TODO: 0 should be replaced with the actual z value of the region when graph is 3D
107-
ezgl::rectangle top_right = draw_coords->get_absolute_clb_bbox(layer_begin,
108-
reg_coord.xmax(),
109-
reg_coord.ymax(),
110-
0);
111-
ezgl::rectangle bottom_left = draw_coords->get_absolute_clb_bbox(layer_end,
112-
reg_coord.xmin(),
113-
reg_coord.ymin(),
114-
0);
109+
for (int layer = layer_low; layer <= layer_high; layer++) {
110+
if (!draw_state->draw_layer_display[layer].visible) {
111+
continue;
112+
}
115113

116-
ezgl::rectangle on_screen_rect(bottom_left.bottom_left(), top_right.top_right());
114+
int alpha_layer_part = alpha * draw_state->draw_layer_display[layer].alpha / 255;
115+
g->set_color(partition_color, alpha_layer_part);
117116

118-
if (!name_drawn) {
119-
g->set_font_size(10);
120-
const std::string& partition_name = partition.get_name();
117+
ezgl::rectangle top_right = draw_coords->get_absolute_clb_bbox(layer, reg_coord.xmax(), reg_coord.ymax(), 0);
118+
ezgl::rectangle bottom_left = draw_coords->get_absolute_clb_bbox(layer, reg_coord.xmin(), reg_coord.ymin(), 0);
121119

122-
g->set_color(partition_color, 230);
120+
ezgl::rectangle on_screen_rect(bottom_left.bottom_left(), top_right.top_right());
123121

124-
g->draw_text(
125-
on_screen_rect.center(),
126-
partition_name,
127-
on_screen_rect.width() - 10,
128-
on_screen_rect.height() - 10);
122+
if (!name_drawn) {
123+
g->set_font_size(10);
124+
const std::string& partition_name = partition.get_name();
129125

130-
name_drawn = true;
126+
g->set_color(partition_color, 230);
131127

132-
g->set_color(partition_color, alpha);
133-
}
128+
g->draw_text(
129+
on_screen_rect.center(),
130+
partition_name,
131+
on_screen_rect.width() - 10,
132+
on_screen_rect.height() - 10);
134133

135-
g->fill_rectangle(on_screen_rect);
134+
name_drawn = true;
135+
136+
g->set_color(partition_color, alpha);
137+
}
138+
139+
g->fill_rectangle(on_screen_rect);
140+
}
136141
}
137142
}
138143

139144
//Iterates through all partitions and draws each region of each partition
140145
void highlight_all_regions(ezgl::renderer* g) {
141146
auto& floorplanning_ctx = g_vpr_ctx.floorplanning();
142-
auto constraints = floorplanning_ctx.constraints;
147+
const auto& constraints = floorplanning_ctx.constraints;
143148
auto num_partitions = constraints.get_num_partitions();
144149

145150
//keeps track of what alpha level each partition is
@@ -155,18 +160,18 @@ void highlight_all_regions(ezgl::renderer* g) {
155160
}
156161
}
157162

158-
// Draws atoms that're constrained to a partition in the colour of their respective partition.
163+
// Draws atoms that are constrained to a partition in the colour of their respective partition.
159164
void draw_constrained_atoms(ezgl::renderer* g) {
160165
auto& floorplanning_ctx = g_vpr_ctx.floorplanning();
161-
auto constraints = floorplanning_ctx.constraints;
162-
auto num_partitions = constraints.get_num_partitions();
166+
const auto& constraints = floorplanning_ctx.constraints;
167+
int num_partitions = constraints.get_num_partitions();
163168
auto& atom_ctx = g_vpr_ctx.atom();
164169
auto& cluster_ctx = g_vpr_ctx.clustering();
165170

166171
for (int partitionID = 0; partitionID < num_partitions; partitionID++) {
167172
auto atoms = constraints.get_part_atoms((PartitionId)partitionID);
168173

169-
for (const auto atom_id : atoms) {
174+
for (const AtomBlockId atom_id : atoms) {
170175
if (atom_ctx.lookup.atom_pb(atom_id) != nullptr) {
171176
const t_pb* pb = atom_ctx.lookup.atom_pb(atom_id);
172177
auto color = kelly_max_contrast_colors_no_black[partitionID % (kelly_max_contrast_colors_no_black.size())];
@@ -180,7 +185,12 @@ void draw_constrained_atoms(ezgl::renderer* g) {
180185
}
181186

182187
//Recursive function to find where the constrained atom is and draws it
183-
static void draw_internal_pb(const ClusterBlockId clb_index, t_pb* current_pb, const t_pb* pb_to_draw, const ezgl::rectangle& parent_bbox, const t_logical_block_type_ptr type, ezgl::color color, ezgl::renderer* g) {
188+
static void draw_internal_pb(const ClusterBlockId clb_index,
189+
t_pb* current_pb,
190+
const t_pb* pb_to_draw,
191+
const ezgl::rectangle& parent_bbox,
192+
const t_logical_block_type_ptr type,
193+
ezgl::color color, ezgl::renderer* g) {
184194
t_draw_coords* draw_coords = get_draw_coords_vars();
185195
t_draw_state* draw_state = get_draw_state_vars();
186196

@@ -300,8 +310,8 @@ void highlight_selected_partition(GtkWidget* widget) {
300310
static GtkTreeModel* create_and_fill_model() {
301311
auto& atom_ctx = g_vpr_ctx.atom();
302312
auto& floorplanning_ctx = g_vpr_ctx.floorplanning();
303-
auto constraints = floorplanning_ctx.constraints;
304-
auto num_partitions = constraints.get_num_partitions();
313+
const auto& constraints = floorplanning_ctx.constraints;
314+
int num_partitions = constraints.get_num_partitions();
305315

306316
GtkTreeStore* store = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING);
307317

@@ -318,7 +328,7 @@ static GtkTreeModel* create_and_fill_model() {
318328
COL_NAME, partition_name.c_str(),
319329
-1);
320330

321-
for (auto const_atom : atoms) {
331+
for (AtomBlockId const_atom : atoms) {
322332
std::string atom_name = (atom_ctx.lookup.atom_pb(const_atom))->name;
323333
gtk_tree_store_append(store, &child_iter, &iter);
324334
gtk_tree_store_set(store, &child_iter,

vpr/src/draw/draw_noc.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ void draw_noc_connection_marker(ezgl::renderer* g, const vtr::vector<NocRouterId
201201
/*
202202
* This function draws the links within the noc. So based on a given noc topology, this function draws the links that connect the routers in the noc together.
203203
*/
204-
void draw_noc_links(ezgl::renderer* g, t_logical_block_type_ptr noc_router_logical_block_type, vtr::vector<NocLinkId, ezgl::color>& noc_link_colors, ezgl::rectangle noc_connection_marker_bbox, const vtr::vector<NocLinkId, NocLinkShift>& list_of_noc_link_shift_directions) {
204+
void draw_noc_links(ezgl::renderer* g,
205+
t_logical_block_type_ptr noc_router_logical_block_type,
206+
vtr::vector<NocLinkId, ezgl::color>& noc_link_colors,
207+
ezgl::rectangle noc_connection_marker_bbox,
208+
const vtr::vector<NocLinkId, NocLinkShift>& list_of_noc_link_shift_directions) {
205209
t_draw_coords* draw_coords = get_draw_coords_vars();
206210
auto& noc_ctx = g_vpr_ctx.noc();
207211

vpr/src/draw/draw_noc.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ enum NocLinkType {
6161
};
6262

6363
/*
64-
* Since the noc links run in both directions between any two routers, we want to draw them parallel to each other instead of ovrelapping them. So the idea is to shift one link in one direction and shift the other link in the opposite direction. THe enum below defines the direction a link was shifted, so for example if we had a vertical line, top would be mean shift left and Bottom would mean shift right. SImilarily, if we had a horizontal line, top would mean shift up and bottom would mean shift down.
64+
* Since the noc links run in both directions between any two routers,
65+
* we want to draw them parallel to each other instead of overlapping them.
66+
* So the idea is to shift one link in one direction and shift the other link
67+
* in the opposite direction. The enum below defines the direction a link was shifted,
68+
* so for example if we had a vertical line, top would be mean shift left and Bottom would mean shift right.
69+
* Similarly, if we had a horizontal line, top would mean shift up and bottom would mean shift down.
6570
*/
6671
enum NocLinkShift {
6772
NO_SHIFT, // initially there is no shift
@@ -173,7 +178,11 @@ void draw_noc_connection_marker(ezgl::renderer* g, const vtr::vector<NocRouterId
173178
* will overlap. This vector describes how the two links should be moved
174179
* so that they do not overlap.
175180
*/
176-
void draw_noc_links(ezgl::renderer* g, t_logical_block_type_ptr noc_router_logical_block_type, vtr::vector<NocLinkId, ezgl::color>& noc_link_colors, ezgl::rectangle noc_connection_marker_bbox, const vtr::vector<NocLinkId, NocLinkShift>& list_of_noc_link_shift_directions);
181+
void draw_noc_links(ezgl::renderer* g,
182+
t_logical_block_type_ptr noc_router_logical_block_type,
183+
vtr::vector<NocLinkId, ezgl::color>& noc_link_colors,
184+
ezgl::rectangle noc_connection_marker_bbox,
185+
const vtr::vector<NocLinkId, NocLinkShift>& list_of_noc_link_shift_directions);
177186

178187
/**
179188
* @brief Goes through all the links within the NoC and updates the color that

0 commit comments

Comments
 (0)