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

[xls][mlir] Support XLS fifo properties/config in MLIR channels. #1916

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

schilkp
Copy link
Contributor

@schilkp schilkp commented Feb 7, 2025

As discussed via email.

Support XLS fifo properties/config in MLIR channels.

This also adds support for converting these properties to/from XLS, and updates different passes (array_to_bits, index_type_conversion) to ensure these attributes are maintained when channels are modified.

Finally, these properties are also exposed for sproc channels, and the proc elaboration pass is updated to assign said properties to all eproc channels that are generated from an sproc channel.

To be discussed: Are the input/output flopping fifo configuration values required?

@ericastor
Copy link
Collaborator

ericastor commented Feb 7, 2025

FWIW, the I/O flopping configuration values are important to many FIFO libraries - they change the way the FIFOs are instantiated. You can see one example of how it's relevant here, in our own FIFO generator: https://github.com/google/xls/blob/main/xls/codegen/materialize_fifos_pass.cc#L162

They don't need to be in v1 of this, but they should probably be added at some point! (EDIT: And if they are here, they should almost certainly stay.)

@schilkp
Copy link
Contributor Author

schilkp commented Feb 8, 2025

They don't need to be in v1 of this, but they should probably be added at some point! (EDIT: And if they are here, they should almost certainly stay.)

Got it - I was not sure so I implemented them while I was at it so they are good to go :)

FWIW, the I/O flopping configuration values are important to many FIFO libraries - they change the way the FIFOs are instantiated. You can see one example of how it's relevant here, in our own FIFO generator: https://github.com/google/xls/blob/main/xls/codegen/materialize_fifos_pass.cc#L162

Just for my own understanding - I was digging around this part of codegen (also for #1896) and I still don't quite understand how input_flop_kind and output_flop_kind (the two pieces of ChannelConfig that are outside of FifoConfig) are used in the materialize FIFOs pass.

As far as I can tell only FifoConfig is used to construct the fifo because that pass does not have access to the original channel's ChannelConfig (in other words, it uses depth, bypass, register_push_outputs, and register_pop_outputs only)

Are those values somehow constructed from input_flop_kind and output_flop_kind?

The only other reference I can find to those values is during the "Convert IR to Blocks" pass, which seems to construct registers on the proc blocks the channels are attached to? 1

I am asking because I have been working on a project that relies on precisely how XLS instantiates buffers, so I am trying to make sure I really understand it :)

Footnotes

  1. https://github.com/google/xls/blob/1d94eb0a27491db56174cb40cc18fe3e5332c8dd/xls/codegen/proc_block_conversion.cc#L1324

@grebe
Copy link
Collaborator

grebe commented Feb 10, 2025

I believe ChannelConfig holds the metadata for both internal (FIFO-based) and boundary channels. It might be more accurate for its constructor arg to be a std::variant<FifoConfig, FlopKind, FlopKind>.

This is why the materialize_fifo_pass doesn't deal with FlopKinds- it only concerns itself with FIFO configurations, as FIFOs are used for internal channels, not boundary channels. The pass doesn't need access to the whole ChannelConfig b/c the FifoConfig is the only relevant portion.

@ericastor
Copy link
Collaborator

Another way to think of it - the FIFO config describes the FIFO that you'll need to instantiate if the channel is internal (between two XLS procs, or from a proc back to itself). The rest of the ChannelConfig describes how the proc will interact with the channel, regardless of what the FIFO actually is... e.g., whether to insert registers on the proc side of the I/O path, and how.

We've had a lot of confusion around channels because of this naming issue - in different contexts, "a channel" can refer to any of:

  1. the bundle of ports & protocol that a proc needs to use to talk to an external entity,
  2. the logic that actually connects one set of ports to another (usually a FIFO), and
  3. the collection of everything on the connecting path between procs (including the ports on both ends & the logic between them).

I've been starting to think we should have disambiguating names for these.

@schilkp
Copy link
Contributor Author

schilkp commented Feb 11, 2025

Thanks you two for the explaination. That really clears it up. I was very confused why the flopping was not relevant for the fifo instantiation directly.

To make sure I get this right:

For input(output) boundary channels:

  • The input(output) flopping determines if the connected proc input(output) gets a flop/buffer.
  • The fifo config is ignored.

For internal channels:

  • The input+output flopping determines if the connected proc input and output gets a flop/buffer
  • The fifo config is used to parametrize the actually FIFO that makes up the channel.

In other words - the input and output flopping is relevant for both internal and boundary channels?

@ericastor
Copy link
Collaborator

That's correct!

@jpienaar jpienaar requested review from jmolloy and jpienaar February 22, 2025 13:43
@schilkp schilkp force-pushed the schilkp/mlir_fifo_props branch from f62bc6f to f78fff6 Compare February 24, 2025 07:04
@schilkp
Copy link
Contributor Author

schilkp commented Feb 24, 2025

rebased.

schilkp added a commit to schilkp/xls that referenced this pull request Feb 25, 2025
@schilkp schilkp force-pushed the schilkp/mlir_fifo_props branch from f78fff6 to 0f4e000 Compare February 25, 2025 11:22
schilkp added a commit to schilkp/xls that referenced this pull request Feb 25, 2025
Copy link
Member

@jpienaar jpienaar left a comment

Choose a reason for hiding this comment

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

Nice, sorry got delayed with CGO/C4ML prep. Looks good and nice mapping retaining the core info. One could also do a roundtrip test (in one lit test convert back and forth and diff) to easily test both paths.

@schilkp
Copy link
Contributor Author

schilkp commented Mar 4, 2025

Thanks for the review :)Traveling today, will get to this tomorrow.

One could also do a roundtrip test (in one lit test convert back and forth and diff) to easily test both paths.

Is there a LIT-specific mechanism for this, or would you just do an // RUN: That pipes between translation tools into filecheck, with a number of // CHECK:s that validate nothing changed?

@schilkp schilkp force-pushed the schilkp/mlir_fifo_props branch 2 times, most recently from 38b7d51 to dbc4a4b Compare March 5, 2025 08:57
@schilkp schilkp requested a review from jpienaar March 5, 2025 12:38
@schilkp
Copy link
Contributor Author

schilkp commented Mar 5, 2025

@jpienaar feedback addressed except for one point I would @jmolloy's feedback on :)

Edit: Maybe you could ping him, not sure if my ping-ing gets through ;)

@jpienaar
Copy link
Member

jpienaar commented Mar 5, 2025

Is there a LIT-specific mechanism for this, or would you just do an // RUN: That pipes between translation tools into filecheck, with a number of // CHECK:s that validate nothing changed?

Pretty much the latter yes. One can diff with the output of opt tool which would strip the comments (and then you don't need explicit CHECK lines), but often just checking some local invariant is fine for the lit one (it at least verifies nothing failed and specific information retained). Having a more complete diff tool that understands what can safely be ignored is better, and then could be run uniformly over all tests even.

Copy link
Member

@jpienaar jpienaar 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 to me, thanks!

This also adds support for converting these properties to/from XLS, and
updates different passes (array_to_bits, index_type_conversion) to
ensure these attributes are maintained when channels are modified.

Finally, these properties are also exposed for sproc channels, and the
proc elaboration pass is updated to assign said properties to all
eproc channels that are generated from an sproc channel.
@schilkp schilkp force-pushed the schilkp/mlir_fifo_props branch from dbc4a4b to 7cf46ef Compare March 5, 2025 17:42
Copy link
Member

@jpienaar jpienaar left a comment

Choose a reason for hiding this comment

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

Approving again as seems workflows didn't start (else I may manually go and poke)

@schilkp
Copy link
Contributor Author

schilkp commented Mar 5, 2025

Ah I was quickly writing the round-trip test if you want to hold off for another 20min or so :)

I ping you when done.

@schilkp
Copy link
Contributor Author

schilkp commented Mar 5, 2025

Ah I was quickly writing the round-trip test if you want to hold off for another 20min or so :)

I ping you when done.

@jpienaar Actually it seems that nobody every did a MLIR -> IR -> MLIR roundtrip and this is broken because of some loc-related bugs. I have it mostly fixed but won't wrap it up today. Feel free to merge this and I open a PR for the location-based bugs and round-trip test of fifo props tomorrow, or feel free to hold off merging this :)

@jpienaar
Copy link
Member

jpienaar commented Mar 5, 2025

I'll submit this one. For locations: remember to enable printing locations, else parsing will go south/drop it :)

@copybara-service copybara-service bot merged commit 28639f9 into google:main Mar 6, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants