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

[DCToHW] Add DCToHW conversion pass #5298

Merged
merged 5 commits into from
Jun 20, 2023
Merged

[DCToHW] Add DCToHW conversion pass #5298

merged 5 commits into from
Jun 20, 2023

Conversation

mortbopet
Copy link
Contributor

This commit adds a lowering of DC operation to a combination of comb,seq and hw operations. The implementations are identical to those of the handshake dialect (i.e. handshake-to-hw sans the arithmetic operations).

  • ESI-typed I/O
  • DC buffers lower to ESI buffers
    • This is just a temporary solution. I anticipate more complexity here in the future when we want to do more with the FIFOs that connect DC circuits.
  • In case the IR contains DC operations that need to be clocked (fork, buffer), there must exist a clock and reset signal in the parent FunctionLike operation. These arguments are to be marked with a dc.clock and dc.reset attribute, respectively.
  • Only a single integration test for now. Will add more once [MapArith] Introduce --map-arith-to-comb pass #5297 lands (allows us to do some high-level tests through handshake).

Copy link
Contributor

@Dinistro Dinistro left a comment

Choose a reason for hiding this comment

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

I dropped a set of NIT comments. Overall it already looks very nice ;)

include/circt/Conversion/DCToHW.h Outdated Show resolved Hide resolved
integration_test/Dialect/DC/dc_cocotb.py Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
hw.module @select(%sel : !dc.value<i1>, %true : !dc.token, %false : !dc.token) -> (out0: !dc.token) {
%0 = dc.select %sel, %true, %false
hw.output %0 : !dc.token
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me.

Copy link
Contributor

@Dinistro Dinistro left a comment

Choose a reason for hiding this comment

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

LGTM, modulo some remaining NIT comments.
I'm not a big fan of having auto where it's non-trivial to derive the type manually. I'm not sure what the CIRCT policy on this is, though.

lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
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.

Since I'm only reviewing for style, I'm only commenting.

This code over-uses auto: https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable. Personally, I try to only use auto to (1) unbox, (2) auto op = b.create<comb::Addop>, and (3) iterators.

Some of my comments in RTLBuilder are geared towards moving it into a support lib.

lib/Conversion/DCToHW/CMakeLists.txt Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
Type outType =
llvm::TypeSwitch<Type, Type>(t)
.Case<ValueType>([&](auto vt) {
return esi::ChannelType::get(ctx, toHWType(vt.getInnerTypes()));
Copy link
Contributor

Choose a reason for hiding this comment

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

By default, ESI channels have ValidReady signaling. Sufficient for a first take, but very quickly we'll need to move to something more complex. May even be selecting different signaling standards based on site-specific criteria (so a pass option might not work). No changes suggested for now -- just something to bear in mind.

lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
InputHandshake hs;
auto ready = std::make_shared<Backedge>(bb.get(rtlb.b.getI1Type()));
auto [data, valid] = rtlb.unwrap(in, *ready);
hs.valid = valid;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: You're constructing a few structs like this. Visually, I prefer using a struct initializer with /*ready=*/ comments. Would allow you to condense 6 lines to one (using emplace_back).

FFS C++: WHY DID YOU NOT GET STRUCT DESIGNATED INITIALIZERS UNTIL '20?! You're only 21 years behind C, which has had this feature since C99!

/// Locate the clock and reset values from the parent operation based on
/// attributes assigned to the arguments.
static FailureOr<std::pair<Value, Value>> getClockAndReset(Operation *op) {
auto *parent = op->getParentOp();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be getParentOpOfType<FuncOpIface>? Or do you specifically want to restrict dc.clock to be in the same block args?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel either approach is somewhat vague. Choosing the parent function-like op was just the closest thing to "give me the parent op which has attributes attached to its arguments". I'm inclined to leave this as-is for now, until we know that this is not a scaleable approach.

lib/Conversion/DCToHW/DCToHW.cpp Outdated Show resolved Hide resolved
This commit adds a lowering of DC operation to a combination of
`comb,seq` and `hw` operations. The implementations are identical to
those of the `handshake` dialect (i.e. `handshake-to-hw` sans the
arithmetic operations).

- ESI-typed I/O
- DC buffers lower to ESI buffers
  - This is just a temporary solution. I anticipate more complexity here
    in the future when we want to do more with the FIFOs that connect
    DC circuits.
- In case the IR contains DC operations that need to be clocked (fork, buffer),
  there must exist a clock and reset signal in the parent `FunctionLike`
  operation. These arguments are to be marked with a `dc.clock` and `dc.reset`
  attribute, respectively.
- Only a single integration test for now. Will add more once #5297 lands
  (allows us to do some high-level tests through handshake).
@mortbopet mortbopet merged commit dcf8d1b into main Jun 20, 2023
5 checks passed
@darthscsi darthscsi deleted the dev/mpetersen/dc_to_hw branch June 4, 2024 14:50
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.

None yet

4 participants