Skip to content

Implementation Methods for RRGraphView API #1740

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

Closed
ethanroj23 opened this issue May 25, 2021 · 5 comments
Closed

Implementation Methods for RRGraphView API #1740

ethanroj23 opened this issue May 25, 2021 · 5 comments

Comments

@ethanroj23
Copy link
Contributor

Overview

In my implementation of API function calls for the RRGraphView class, I have come up with several methods that could be used. Before adding several hundreds of function calls, I figured it would be good to have some input. The three methods are included below. I am currently leaning towards method 2 or 3. Soon after Xifan's PR (#1693) is merged, I will make a PR which will add these calls to RRGraphView::node_type(RRNodeId node).

@vaughnbetz, @hzeller, @tangxifan, @nelsobe, which of these methods do you think is best? Or is there another method that is better?

API Implementation Variations (check_route.cpp starting at line 200)

1. Single Line Replacement

static void check_source(int inode, ClusterNetId net_id) {
    auto& device_ctx = g_vpr_ctx.device();
    auto& cluster_ctx = g_vpr_ctx.clustering();
    auto& place_ctx = g_vpr_ctx.placement();

-   t_rr_type rr_type = device_ctx.rr_nodes[inode].type();
+   t_rr_type rr_type = device_ctx.rr_graph.node_type(RRNodeId(inode));
    if (rr_type != SOURCE) {
        VPR_FATAL_ERROR(VPR_ERROR_ROUTE,
                        "in check_source: net %d begins with a node of type %d.\n", size_t(net_id), rr_type);
    }

2. Addition of const auto& rr_graph

static void check_source(int inode, ClusterNetId net_id) {
    auto& device_ctx = g_vpr_ctx.device();
+   const auto& rr_graph = device_ctx.rr_graph;
    auto& cluster_ctx = g_vpr_ctx.clustering();
    auto& place_ctx = g_vpr_ctx.placement();

-   t_rr_type rr_type = device_ctx.rr_nodes[inode].type();
+   t_rr_type rr_type = rr_graph.node_type(RRNodeId(inode));
    if (rr_type != SOURCE) {
        VPR_FATAL_ERROR(VPR_ERROR_ROUTE,
                        "in check_source: net %d begins with a node of type %d.\n", size_t(net_id), rr_type);
    }

3. Addition of const auto& rr_graph and an additional variable for the RRNodeId

static void check_source(int inode, ClusterNetId net_id) {
    auto& device_ctx = g_vpr_ctx.device();
+   const auto& rr_graph = device_ctx.rr_graph;
    auto& cluster_ctx = g_vpr_ctx.clustering();
    auto& place_ctx = g_vpr_ctx.placement();

+   RRNodeId inode_i = RRNodeId(inode);

-   t_rr_type rr_type = device_ctx.rr_nodes[inode].type();
+   t_rr_type rr_type = rr_graph.node_type(inode_i);
    if (rr_type != SOURCE) {
        VPR_FATAL_ERROR(VPR_ERROR_ROUTE,
                        "in check_source: net %d begins with a node of type %d.\n", size_t(net_id), rr_type);
    }
@vaughnbetz
Copy link
Contributor

I'd go for 1 or 2 (no strong preference between them on my part). I don't like #3 as the cast to RRNodeId is pretty mechanical and adding a temporary for it just creates additional names to keep track of.

In some cases you may be able to pass in an RRNodeId (change the type of the input parameter) to avoid the conversion to RRNodeId. If that can be done without undue effort it is better, as it expands the type-checking back to the caller, where it is more useful.

@tangxifan
Copy link
Contributor

I agree with @vaughnbetz that 1 and 2 are better than 3.
Between 1 and 2, I prefer 2 because it is easier for future refactoring (in my opinion).
2 allows us to easily add RRGraphView as an input argument of the function when we plan to get rid of global variable usage in these functions.

@nelsobe
Copy link

nelsobe commented May 25, 2021

I agree with both of the above in terms of #1 or #2 being preferable to #3. I would vote for #2 given a choice but it is not super strong.

@vaughnbetz
Copy link
Contributor

I say we go for #2 then to make future refactoring easier, and since you find it more readable Ethan.

@ethanroj23
Copy link
Contributor Author

We have decided on method #2 for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants