Skip to content

Remove atom_net global context mutation from packer #2984

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

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

AmirhosseinPoolad
Copy link
Contributor

@AmirhosseinPoolad AmirhosseinPoolad commented Apr 16, 2025

While making the packer parallel, we removed these writes to the global context and nothing went wrong. This WIP PR does the same to VTR master. If these mutations are not needed, removing them will make the code cleaner (less "why is it doing this?") and could potentially make packing a bit faster.

The reason I think things should be mostly fine (other than passing the strong tests) is that atom_net lookup data is only ever changed after packing (add_atom_clb_net is only called after packing is done) and atom_clb is the same (set_atom_clb is only called after packing).

@AmirhosseinPoolad AmirhosseinPoolad marked this pull request as draft April 16, 2025 15:51
@github-actions github-actions bot added VPR VPR FPGA Placement & Routing Tool lang-cpp C/C++ code labels Apr 16, 2025
@AlexandreSinger
Copy link
Contributor

There's one big issue here, with these changes free_pb no longer cleans up the CLB lookup data. It is not an issue as free_pb is also called only during packing, with one exception*. However, this new free_pb doesn't do what it's name implies and could be confusing and also breaks the exception. I am not sure how to fix this, hence why the PR is WIP.

The intention of free_pb is to literally free the data associated with a given pb. Since there are global lookups between pbs and other pieces of code, this code also cleans up that lookup value.

The reason it was cleaning up the CLB lookup data is actually historic, and an oversite on my part. Before the Cluster Legalizer existed, the original packer literally created clusters on the spot. These clusters were ill-formed (they were missing critical data), which required them to be destroyed at the end of packing and completely regenerated which was confusing. I completely removed all updates to the CLB netlist; I guess the free_pb passed under the radar.

One note, free_pb is used after clustering; but only when a cluster is being destroyed (I think). This is because ownership of the pbs were given to the netlist after packing and its the job of the cluster netlist to clean up the data (note: I think this is not a good idea, but its just how it was implemented). TBH the update of the lookup between CLB and atoms should probably be updated in the CLB netlist itself, not in some random free method. Such as here:

void ClusteredNetlist::remove_block_impl(const ClusterBlockId blk_id) {
//Remove & invalidate pointers
free_pb(block_pbs_[blk_id], g_vpr_ctx.mutable_atom().mutable_lookup().mutable_atom_pb_bimap());
delete block_pbs_[blk_id];
block_pbs_.insert(blk_id, NULL);
block_types_.insert(blk_id, NULL);
block_logical_pins_.insert(blk_id, std::vector<ClusterPinId>());
}

If this is causing no changes to the output (which I believe it is), I completely agree with these updates. To deal with the line you commented out, you should add in the clustered_netlist.cpp file above some code to update the global lookup betwen CLBs and atoms (which is where this should have been anyways).

@AmirhosseinPoolad AmirhosseinPoolad force-pushed the wip_remove_mut_global_packer branch from 0a9608e to b46a8ed Compare April 17, 2025 15:54
@AmirhosseinPoolad AmirhosseinPoolad changed the title [WIP] Remove atom_clb and atom_net global context mutation from packer Remove atom_clb and atom_net global context mutation from packer Apr 17, 2025
@AmirhosseinPoolad AmirhosseinPoolad marked this pull request as ready for review April 17, 2025 15:55
@AmirhosseinPoolad AmirhosseinPoolad force-pushed the wip_remove_mut_global_packer branch from b46a8ed to 524e533 Compare April 17, 2025 18:14
@@ -170,8 +170,15 @@ ClusterNetId ClusteredNetlist::create_net(const std::string& name) {
}

void ClusteredNetlist::remove_block_impl(const ClusterBlockId blk_id) {
AtomPBBimap& atom_pb_bimap = g_vpr_ctx.mutable_atom().mutable_lookup().mutable_atom_pb_bimap();
AtomBlockId atom_blk_id = atom_pb_bimap.pb_atom(block_pbs_[blk_id]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not going to work how you would expect. pbs are stored as a hierarchy. The pb found in block_pbs_ is the root pb for the entire cluster. pb_atom will only return the atom_blk_id associated with a leaf pb (i.e. a primitive). Since you are passing in a root pb, this will never return an atom.

Clusters actually contain many atoms, not just one.

I would recommend iterating over the lookup for this cluster and collect all of the atom_blk_ids, then set all of the atoms to an invalid cluster. Or even better, since this is a bimap I think, you may be able to just tell the bi-map to invalidate all atoms which point to a given cluster blk id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes I forgot that free_pb is recursive. Yeah I think in that case it's worth rethinking this from a code organization stand point, since we'll be basically duplicating the tree traversal logic which I don't really feel good about. I think I'll just remove the atom_net mutation in pack.cpp for this PR and leave the free_pb changes for another PR since it'll need more extensive reworks to do properly.

AtomPBBimap& atom_pb_bimap = g_vpr_ctx.mutable_atom().mutable_lookup().mutable_atom_pb_bimap();
AtomBlockId atom_blk_id = atom_pb_bimap.pb_atom(block_pbs_[blk_id]);

// Remove the corresponding atom_clb lookup entry from global context (if exsits)
Copy link
Contributor

Choose a reason for hiding this comment

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

exists*

@AmirhosseinPoolad AmirhosseinPoolad force-pushed the wip_remove_mut_global_packer branch from 524e533 to 3c6d22b Compare April 21, 2025 21:04
@AmirhosseinPoolad AmirhosseinPoolad force-pushed the wip_remove_mut_global_packer branch from 3c6d22b to f3b166e Compare April 21, 2025 22:15
@AmirhosseinPoolad AmirhosseinPoolad changed the title Remove atom_clb and atom_net global context mutation from packer Remove atom_net global context mutation from packer Apr 21, 2025
@AmirhosseinPoolad
Copy link
Contributor Author

Hey @AlexandreSinger, I removed the free_pb changes and I think this can be merged, can you do another review? Thanks a lot!

Copy link
Contributor

@AlexandreSinger AlexandreSinger left a comment

Choose a reason for hiding this comment

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

LGTM. Can you please raise an issue regarding the other code so we can handle it in the future?

@AlexandreSinger AlexandreSinger merged commit 735448c into master Apr 22, 2025
36 checks passed
@AlexandreSinger AlexandreSinger deleted the wip_remove_mut_global_packer branch April 22, 2025 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-cpp C/C++ code VPR VPR FPGA Placement & Routing Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants