Skip to content
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

[FIRRTL][Dedup] Rework hashing for perf and bug fixes. #7420

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

dtzSiFive
Copy link
Contributor

@dtzSiFive dtzSiFive commented Jul 31, 2024

Primary change is to only generate and populate mappings for sources of values, and not each value themselves.

Values are identified using these base numberings plus an appropriate offset.

The main benefit of this is to greatly reduce the number of entries in the indices map.
When handling operations with many block arguments (module-like's with many ports) or with many results (instances of those module-like's) this greatly reduces the pressure on the indices map. For these designs, dedup now runs dramatically faster and uses significantly less memory.

Also separates location of the value impl, such that if a Value's impl is storage inline into an Operation or Block such that there is aliasing, the two are given different numbers (and especially the numbering isn't changed).

On a synthetic design containing a module with 2^20 ports and 256 instances of that module, this is the difference between completing in 20s and OOM'ing on my machine after running for 30 minutes.

Functional changes:

Fixes #7415.
Fixes #7416.
Also fixes deduping if block arg types are different (but unused).

This is done by hashing block count, and each block's numbering between as well as the types of its arguments before that block's operations.

Additionally fixes use of numberings (indices) before it was populated where attribute processing for inner symbol ports hashed using the block argument's numbering before it was populated.

@dtzSiFive dtzSiFive requested review from rwy7 and youngar July 31, 2024 21:41
Copy link
Contributor

@mikeurbach mikeurbach left a comment

Choose a reason for hiding this comment

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

This is great. You've clearly put a lot more thought into this than I, but after reviewing it no major concerns from me.

Primary change is to only generate and populate mappings for
sources of values, and not each value themselves.

Values are identified using these base numberings plus an appropriate
offset.

The main benefit of this is to greatly reduce the number of entries in the
`indices` map.
When handling operations with many block arguments (module-like's with many
ports) or with many results (instances of those module-like's) this greatly
reduces the pressure on the `indices` map.  For these designs, dedup now runs
dramatically faster and uses significantly less memory.

Also separates location of the value impl, such that if a Value's impl is storage
inline into an Operation or Block such that there is aliasing, the two
are given different numbers (and especially the numbering isn't changed).

On a synthetic design containing a module with 2^20 ports and 256 instances of
that module, this is the difference between completing in 20s and OOM'ing on my
machine after running for 30 minutes.

Functional changes:

Fixes llvm#7415.
Fixes llvm#7416.
Also fixes deduping if block arg types are different (but unused).

This is done by hashing block count, and each block's numbering between
as well as the types of its arguments before that block's operations.

Additionally fixes use of numberings (indices) before it was
populated where attribute processing for inner symbol ports
hashed using the block argument's numbering before it was populated.
@dtzSiFive dtzSiFive force-pushed the fix/dedup-blocks-and-perf branch from 64f0f1c to 6d08991 Compare August 1, 2024 00:48
Copy link
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

Awesome!

@dtzSiFive dtzSiFive merged commit 20cb546 into llvm:main Aug 1, 2024
4 checks passed
@dtzSiFive dtzSiFive deleted the fix/dedup-blocks-and-perf branch August 1, 2024 12:02
@dtzSiFive
Copy link
Contributor Author

Landing, thanks for reviews folks!

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