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

[Support/ESI] Add generic port conversion utility #5533

Merged
merged 10 commits into from
Jul 11, 2023

Conversation

mortbopet
Copy link
Contributor

@mortbopet mortbopet commented Jul 3, 2023

This commit takes the ESI ChannelRewriter and generalizes it to provide a generic utility for performing port conversions on a hw::HWMutableModuleLike op.

It is intended to be a generic utility that can facilitate replacement of a given module in- or output to an arbitrary set of new inputs and outputs (i.e. 1 port -> N in, M out ports). The typical usecase would be where an input (/output) of a module represent some higher-level type that will be implemented by a set of lower-level typed in- and outputs ports alongside supporting operations in the module-under-modifications and at instantiation sites. This capability can be leveraged by a bunch of other future tools, such as instance-hierarchy-boring capabilities.

It also attempts to do so in an optimal way by being able to collect multiple port modifications of a module and perform them all at once.

A change wrt. the ChannelRewriter is that struct flattening has been removed. This is both to make the lowering more generic/less monolothic (hard to support the notion of "if this ESI channel type contains a struct, and we need to flatten the struct, ...", and is redundant, due to the hw-flatten-io pass.

This first PR is used to rewrite the ESI ChannelRewriter. The first immediate use-case afterwards is to reimplement #5390 which fits perfectly under this paradigm.

Note: still a draft due to a bug in hw-flatten-io which is needed for the tests.

@mortbopet mortbopet requested a review from mikeurbach July 3, 2023 13:37
@teqdruid
Copy link
Contributor

teqdruid commented Jul 3, 2023

Thanks for doing this. Do you think it'll work for your other PR?

@mortbopet
Copy link
Contributor Author

Thanks for doing this. Do you think it'll work for your other PR?

oh, definitely! As i wrote, #5390 fits perfectly into this paradigme.

@mortbopet mortbopet force-pushed the dev/mpetersen/input_rewriter branch from 471b8d0 to 715adb0 Compare July 5, 2023 07:59
@mortbopet mortbopet changed the base branch from main to dev/mpetersen/flatten_io_fix_instance July 5, 2023 08:46
@mortbopet mortbopet force-pushed the dev/mpetersen/input_rewriter branch from ecb5a56 to 8cebf71 Compare July 5, 2023 09:31
@mortbopet mortbopet marked this pull request as ready for review July 5, 2023 13:27
@mortbopet mortbopet requested a review from teqdruid as a code owner July 5, 2023 13:27
Copy link
Contributor

@teqdruid teqdruid left a comment

Choose a reason for hiding this comment

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

Schweeeet! Thanks again for doing this.

You should probably change all verbage around "signaling standard" to something more generic. (Given that this is intended to be more generic than different signaling protocols. Yes, I do get that pretty much every wire is a ad-hoc signaling protocol if you squint hard, but most people wouldn't call it that.)

The problem with replacing 'esi.portFlattenStructswithhw-flatten-io` is that the latter flattens every module in the design. The former attribute allows you to select each module individually. Which is kinda important when you're trying to glue together a bunch of external modules with the 'flatten' signaling standard.

include/circt/Dialect/HW/PortConverter.h Outdated Show resolved Hide resolved
@@ -32,7 +33,7 @@ add_circt_dialect_library(CIRCTHW
LINK_COMPONENTS
Support

LINK_LIBS PUBLIC
Copy link
Contributor

Choose a reason for hiding this comment

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

uber-nit: unnecessary whitespace creates inconsistency within this file.

lib/Dialect/HW/PortConverter.cpp Outdated Show resolved Hide resolved
lib/Dialect/HW/PortConverter.cpp Outdated Show resolved Hide resolved
lib/Dialect/HW/PortConverter.cpp Outdated Show resolved Hide resolved
lib/Dialect/HW/PortConverter.cpp Outdated Show resolved Hide resolved
lib/Dialect/HW/PortConverter.cpp Outdated Show resolved Hide resolved
lib/Dialect/ESI/Passes/ESILowerPorts.cpp Outdated Show resolved Hide resolved
Value SignalingStandard::mapOutputDataPorts(OpBuilder &b,
ArrayRef<Backedge> newResults) {
auto chanTy = origPort.type.dyn_cast<ChannelType>();
Type dataPortType = chanTy ? chanTy.getInner() : origPort.type;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mind if we get rid of this functionality short term, but I suspect we're going to need it.

@mortbopet
Copy link
Contributor Author

You should probably change all verbage around "signaling standard" to something more generic

I thought about this but didn't come up with a good name. Should we just do SignalingStandard -> PortConversion?

The problem with replacing 'esi.portFlattenStructswithhw-flatten-io` is that the latter flattens every module in the design. The former attribute allows you to select each module individually. Which is kinda important when you're trying to glue together a bunch of external modules with the 'flatten' signaling standard.

Can just add that as an argument to the pass or tag on attributes to the modules to be flattened.

@teqdruid
Copy link
Contributor

teqdruid commented Jul 6, 2023

Yeah, port portconversion works.

I'd prefer a tag on each module rather than a list of module symbols to the pass. Does flatten-io flatten embedded structs as well? We don't want that behavior.

@mortbopet
Copy link
Contributor Author

mortbopet commented Jul 7, 2023

I'd prefer a tag on each module rather than a list of module symbols to the pass. Does flatten-io flatten embedded structs as well? We don't want that behavior.

Nope, strictly structs in module in/outputs.

This commit takes the ESI `ChannelRewriter` and generalizes it to provide a generic utility for performing port conversions on a `hw::HWMutableModuleLike` op.

It is intended to be a generic utility that can facilitate replacement of a given module in- or output to an arbitrary set of new inputs and outputs (i.e. 1 port -> N in, M out ports). Typical usecase is where an input (/output) of a module represents has some higher-level type that will be implemented by a set of lower-level typed in- and outputs ports + supporting operations within a module.

It also attempts to do so in an optimal way, by e.g. being able to collect multiple port modifications of a module, and perform them all at once.

A change wrt. the `ChannelRewriter` is that struct flattening has been removed. This is both to make the lowering more generic (hard to support the notion of "if this ESI channel type contains a struct, and we need to flatten the struct, ...", and is redundant, due to the `hw-flatten-io` pass.
@mortbopet mortbopet force-pushed the dev/mpetersen/input_rewriter branch from 5e32408 to 51c958b Compare July 7, 2023 08:08
@mortbopet mortbopet changed the base branch from dev/mpetersen/flatten_io_fix_instance to main July 7, 2023 08:08
@mortbopet mortbopet removed the request for review from fabianschuiki July 7, 2023 08:09
@mortbopet mortbopet merged commit ba7c4f2 into main Jul 11, 2023
5 checks passed
calebmkim pushed a commit to andrewb1999/circt that referenced this pull request Jul 12, 2023
This commit takes the ESI `ChannelRewriter` and generalizes it to provide a generic utility for performing port conversions on a `hw::HWMutableModuleLike` op.

It is intended to be a generic utility that can facilitate replacement of a given module in- or output to an arbitrary set of new inputs and outputs (i.e. 1 port -> N in, M out ports). Typical usecase is where an input (/output) of a module represents has some higher-level type that will be implemented by a set of lower-level typed in- and outputs ports + supporting operations within a module.

It also attempts to do so in an optimal way, by e.g. being able to collect multiple port modifications of a module, and perform them all at once.

A change wrt. the `ChannelRewriter` is that struct flattening has been removed. This is both to make the lowering more generic (hard to support the notion of "if this ESI channel type contains a struct, and we need to flatten the struct, ...", and is redundant, due to the `hw-flatten-io` pass.
@darthscsi darthscsi deleted the dev/mpetersen/input_rewriter branch June 4, 2024 14:48
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

Successfully merging this pull request may close these issues.

2 participants