Skip to content

Commit 56240f0

Browse files
Fix interposer wire drawing
1 parent 08f357f commit 56240f0

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

vpr/src/draw/draw.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
#include <cstdio>
1616
#include <cstring>
1717
#include <cmath>
18+
#include <vector>
1819
#include "draw.h"
1920

2021
#include "draw_interposer.h"
2122
#include "draw_types.h"
23+
#include "rr_graph_fwd.h"
24+
#include "rr_node_types.h"
2225
#include "timing_info.h"
2326
#include "physical_types.h"
2427

@@ -493,17 +496,53 @@ void init_draw_coords(float clb_width, const BlkLocRegistry& blk_loc_registry) {
493496
}
494497
}
495498

499+
std::vector<int> max_chanx_ptc_nums(grid.height() - 1);
500+
std::vector<int> max_chany_ptc_nums(grid.width() - 1);
501+
502+
// Normally you could use device_ctx.rr_chany_width to get the device's channel width but in some cases
503+
// like devices with interposer cuts, you have situations where there are 100 segments in a channel,
504+
// but the maximum ptc_num is 120. If we only reserve enough space for 100 segments, the segments with
505+
// ptc_num > 100 would be drawn over the tiles. This loop explicitly calculates the maximum ptc_num in
506+
// each routing row/column to avoid that issue.
507+
for (size_t layer = 0; layer < grid.get_num_layers(); layer++) {
508+
for (size_t x_loc = 0; x_loc < grid.width() - 1; x_loc++) {
509+
for (size_t y_loc = 0; y_loc < grid.height() - 1; y_loc++) {
510+
511+
// Get all chanx nodes at location (x_loc, y_loc), find largest ptc_num accross all nodes
512+
std::vector<RRNodeId> chanx_nodes = rr_graph.node_lookup().find_channel_nodes(layer, x_loc, y_loc, e_rr_type::CHANX);
513+
int max_chanx_ptc_num = 0;
514+
if (!chanx_nodes.empty()) {
515+
// Must explicitly check for emptiness, since std::ranges::max will crash if chanx_nodes is empty
516+
RRNodeId max_chanx_ptc_node = std::ranges::max(chanx_nodes, {}, [&rr_graph](RRNodeId node) { return rr_graph.node_ptc_num(node); });
517+
max_chanx_ptc_num = rr_graph.node_ptc_num(max_chanx_ptc_node);
518+
}
519+
520+
// Do the same for chany
521+
std::vector<RRNodeId> chany_nodes = rr_graph.node_lookup().find_channel_nodes(layer, x_loc, y_loc, e_rr_type::CHANY);
522+
int max_chany_ptc_num = 0;
523+
if (!chany_nodes.empty()) {
524+
RRNodeId max_chany_ptc_node = std::ranges::max(chany_nodes, {}, [&rr_graph](RRNodeId node) { return rr_graph.node_ptc_num(node); });
525+
max_chany_ptc_num = rr_graph.node_ptc_num(max_chany_ptc_node);
526+
}
527+
528+
// Update maximum ptc_num for each routing channel row/column
529+
max_chany_ptc_nums[x_loc] = std::max(max_chany_ptc_num, max_chany_ptc_nums[x_loc]);
530+
max_chanx_ptc_nums[y_loc] = std::max(max_chanx_ptc_num, max_chanx_ptc_nums[y_loc]);
531+
}
532+
}
533+
}
534+
496535
size_t j = 0;
497536
for (size_t i = 0; i < grid.width() - 1; i++) {
498537
draw_coords->tile_x[i] = i * draw_coords->get_tile_width() + j;
499-
j += device_ctx.rr_chany_width[i] + 1; // N wires need N+1 units of space
538+
j += max_chany_ptc_nums[i] + 1; // N wires need N+1 units of space
500539
}
501540
draw_coords->tile_x[grid.width() - 1] = (grid.width() - 1) * draw_coords->get_tile_width() + j;
502541

503542
j = 0;
504543
for (size_t i = 0; i < grid.height() - 1; ++i) {
505544
draw_coords->tile_y[i] = i * draw_coords->get_tile_width() + j;
506-
j += device_ctx.rr_chanx_width[i] + 1;
545+
j += max_chanx_ptc_nums[i] + 1;
507546
}
508547
draw_coords->tile_y[grid.height() - 1] = (grid.height() - 1) * draw_coords->get_tile_width() + j;
509548

0 commit comments

Comments
 (0)