Skip to content

[VTR][Util] Added Prefix Sum Class #2914

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

Conversation

AlexandreSinger
Copy link
Contributor

A prefix sum is a classic data structure for quickly finding the sum of any sub-region of fixed N-Dimensional array of values. It pre-computes the partial sums of regions within an array and uses that information later to save time.

This is currently used in the net_cost_handler to pre-compute number of inter-die connections.

This class can be useful in other algorithms. For example, in a Partial Legalizer in an AP flow, it can allow for quick lookups into the capacity and utilization of regions on the FPGA.

Moved the Prefix Sum class from the net_cost_handler into the VTR Util.

@github-actions github-actions bot added VPR VPR FPGA Placement & Routing Tool lang-cpp C/C++ code libvtrutil labels Feb 26, 2025
@AlexandreSinger
Copy link
Contributor Author

@vaughnbetz I needed to use a Prefix Sum in the new Partial Legalizer I am working on. Instead of writing a custom one for my use-case, I made a general class which can be found in the vtr_util library. I found that a Prefix Sum was already being used for 3D connections, I think written by @amin1377; so I wrapped that into this class. All tests are passing. Please review when you have a moment.

Copy link

@vaughnb-cerebras vaughnb-cerebras left a comment

Choose a reason for hiding this comment

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

Nice change! A couple of thoughts embedded.
I believe also use 1D prefix sums in the placer in case you want to also pull those out. See

void NetCostHandler::alloc_and_load_chan_w_factors_for_place_cost_() {

@AlexandreSinger AlexandreSinger force-pushed the feature-lib-vtr-prefix-sum branch 3 times, most recently from 6752031 to bea6a90 Compare February 27, 2025 21:22
@AlexandreSinger
Copy link
Contributor Author

@vaughnbetz Thank you for your feedback on this! I did not realize that those were 1D Prefix Sums; I have created a class for PrefixSum1D and have converted them into using this class. I found that the original code was a little confusing with how it handled 0 channel widths, so I rewrote it slightly to make this more obvious. This does not change the functionality at all, just makes it more explicit that we assume the channel widths are at least 1.

A prefix sum is a classic data structure for quickly finding the sum of
any sub-region of fixed N-Dimensional array of values. It pre-computes
the partial sums of regions within an array and uses that information
later to save time.

This is currently used in the net_cost_handler to pre-compute number of
inter-die connections.

This class can be useful in other algorithms. For example, in a Partial
Legalizer in an AP flow, it can allow for quick lookups into the
capacity and utilization of regions on the FPGA.

Moved the Prefix Sum class from the net_cost_handler into the VTR Util.
@AlexandreSinger AlexandreSinger force-pushed the feature-lib-vtr-prefix-sum branch from bea6a90 to 2fd0bdc Compare February 27, 2025 21:28
Copy link

@vaughnb-cerebras vaughnb-cerebras left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

@AlexandreSinger
Copy link
Contributor Author

Cool! Ill merge when it passes CI.

@AlexandreSinger AlexandreSinger merged commit ef945a7 into verilog-to-routing:master Feb 27, 2025
36 checks passed
@AlexandreSinger AlexandreSinger deleted the feature-lib-vtr-prefix-sum branch February 27, 2025 22: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 libvtrutil VPR VPR FPGA Placement & Routing Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants