Skip to content

Flat Routing Visualization #3159

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Flat Routing Visualization #3159

wants to merge 15 commits into from

Conversation

SamuelHo10
Copy link
Contributor

Several changes were made for flat routing visualization.

Firstly, I modified the draw intra-logic block code so that the margins between blocks are absolute and not based on relative size. The intra-logic blocks are also now drawn to be not long and skinny, and instead must have a reasonable width-to-height ratio. Furthermore, the intra-logic blocks of maximum depth were previously not drawn. That has also been fixed.

To get the pin locations of intracluster RRNodeId, I made helper functions to convert RRNodeId into cluster_blk_id and pb_graph_pin. I also separated the code which draws edges and pins, primarily for readability and also to avoid repetition. The loops with clusternets were replaced with atomnets when flat routing is enabled. Lastly, for testing and debugging purposes, the ability to click on intracluster pins to highlight the net was added.

@github-actions github-actions bot added VPR VPR FPGA Placement & Routing Tool lang-cpp C/C++ code docs Documentation infra Project Infrastructure build Build system lang-python Python code lang-make CMake/Make code libvtrutil labels Jun 22, 2025
@SamuelHo10 SamuelHo10 force-pushed the visualize_flat_routing branch from 4410643 to 571e50d Compare June 22, 2025 00:18
@amin1377
Copy link
Contributor

@SamuelHo10:

Thank you for your changes! Could you please share some screenshots showing how the intra-logic connections are drawn? Also, it would be helpful if you could include a screenshot for the case when the flat-router is not enabled, just to ensure the default flow remains intact.

I’m currently testing this PR locally, but having the screenshots here would be useful for future reference.

@SamuelHo10
Copy link
Contributor Author

For Future Reference,

Flat Routing Enabled:
flat_route1
flat_route2
flat_route3

Flat Routing Disabled
no_flat

Copy link
Contributor

@vaughnbetz vaughnbetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; some changes requested though.
As we discussed in the meeting, you should:

@@ -27,6 +27,7 @@ void draw_rr_edges(RRNodeId from_node, ezgl::renderer* g);

void draw_rr_chan(RRNodeId inode, const ezgl::color color, ezgl::renderer* g);

void draw_rr_intrapin(RRNodeId inode, const ezgl::color& color, ezgl::renderer* g);
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 comment describing what the function does. I think it would be best to make it a Doxygen comment so we can choose to build Doxygen comments for more drawing code in the future.

General principle: comment what a function does in the .h file, or (if it is a static function) in its declaration in the .cpp file. Use Doxygen formatting in either case.

int height = (int)device_ctx.grid.height();
if (chanx_track.empty()) {
chanx_track = vtr::OffsetMatrix<int>({{{1, width - 1}, {0, height - 1}}});
// Draw Pins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this drawing rr nodes (not just pins)? Suggest changing the comment.

for (int i = 1; i < width - 1; i++)
for (int j = 0; j < height - 1; j++)
chanx_track[i][j] = (-1);
// Draw IO Pins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Draw cluster-level IO pins

continue;
}

auto iedge = find_edge(prev_node, inode);
auto switch_type = rr_graph.edge_switch(RRNodeId(prev_node), iedge);
// Skip drawing sources and sinks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip drawing edges to or from sources and sinks

} else {
draw_pin_to_chan_edge(inode, prev_node, g);
}
if (rr_graph.node_type(prev_node) == e_rr_type::OPIN) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match the structure of the rest of the code and shorten this routine I think this switch statement should be moved into a helper router (maybe called draw_inter_cluster_rr_edge )

@@ -400,7 +416,7 @@ static void draw_internal_pb(const ClusterBlockId clb_index, t_pb* pb, const ezg
if (draw_state->draw_block_text) {
g->draw_text(
ezgl::point2d(abs_bbox.center_x(),
abs_bbox.top() - (abs_bbox.height()) / 15.0),
abs_bbox.top() - draw_coords->get_tile_height() * 0.01),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest tying this 0.01 to one of the const drawing values above, or making a new one. It'll be hard to find and update/align this 0.01 with other drawing offsets in future changes if you don't give it a name (or even better, compute it from the constants already present).

@@ -858,13 +858,13 @@ t_pb_graph_pin* get_pb_graph_node_pin_from_model_port_pin(const t_model_ports* m
}

//Retrieves the atom pin associated with a specific CLB and pb_graph_pin
// Warning: Not all pb_graph_pins are associated with an atom pin!
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 expand on this. Some represents nodes/pins within the pb_graph hierarchy, but not on a primitive.


VTR_ASSERT(pb_graph_pin);

return {blk_id, pb_graph_pin};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to very clearly comment this return type in the Doxygen comment in the .h file (use @return). Consider using a named structure. A pair could be OK with enough commenting. If you stick with a pair, callers should extract the data into named variables for clarity, or (even better) use something like:

auto [blk_id, pb_graph_pin] = get_rr_node_cluster_blk_id_pb_graph_pin ( ...)

/**
* @brief Returns the atom pin ID for the given RR node ID.
* **Warning**: This function should be called only if flat-router is enabled,
* since, otherwise, the routing resources inside clusters are not added to the RR graph. Also, not all RRNodes have an AtomPinId associated with them.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you do if the rr_node_id does not correspond to an atom pin? Return an invalid ID? assert? (Bad: silently corrupt memory or you don't know!).
Comment this ... OK to either return the invalid ID if this isn't an atom_pin, or OK to assert but you need to comment which. I lean toward returning the invalid id in that case since it might be useful for some if statements in the future, but your call.

ClusterBlockId blk_id;
t_pb_graph_pin* pb_graph_pin;
std::tie(blk_id, pb_graph_pin) = get_rr_node_cluster_blk_id_pb_graph_pin(rr_node_id);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have some VTR_ASSERT_SAFE calls here to verify that this rr_node_id does in fact correspond to an atom pin.
VTR_ASSERT_SAFE is turned off in release build; you could also use VTR_ASSERT if this code isn't very hot and you always want it checked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build system docs Documentation infra Project Infrastructure lang-cpp C/C++ code lang-make CMake/Make code lang-python Python code libvtrutil VPR VPR FPGA Placement & Routing Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants