-
Notifications
You must be signed in to change notification settings - Fork 383
[Datapath] Create Datapath to Comb Pass #8736
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
|
Initially created this in review because think we need to discuss where some of the shared infrastructure should live. @uenoku - you'll notice that I've currently duplicated your wallace tree and full adder code for example - since this is common infrastructure - where do you think this should best reside? |
|
Super cool!
Could you add function declarations to https://github.com/llvm/circt/blob/main/include/circt/Dialect/Comb/CombOps.h and define in CombOps.cpp? |
|
@uenoku - have now moved these over to comb ops as suggested - think this is now ready for a full review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Could you add a test for option, and also translation validation LEC tests under integration_test for both lowerAndArray and lowerBoothArray lowering paths?
| @@ -0,0 +1,47 @@ | |||
| // RUN: circt-opt %s --convert-datapath-to-comb | FileCheck %s | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test lower-compress-to-add as well.
include/circt/Dialect/Comb/CombOps.h
Outdated
|
|
||
| /// Perform Wallace tree reduction on partial products. | ||
| /// See https://en.wikipedia.org/wiki/Wallace_tree | ||
| SmallVector<Value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add documents for targetAddends and partialProducts?
include/circt/Dialect/Comb/CombOps.h
Outdated
| wallaceReduction(Value falseValue, size_t width, size_t targetAddends, | ||
| ConversionPatternRewriter &rewriter, Location loc, | ||
| SmallVector<SmallVector<Value>> &partialProducts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could you refactor the signature a bit since it's exposed as a library? Specifically could you remove falseValue and use OpBuilder instead of ConversionRewriter, reorder to look like more a builder function.
| wallaceReduction(Value falseValue, size_t width, size_t targetAddends, | |
| ConversionPatternRewriter &rewriter, Location loc, | |
| SmallVector<SmallVector<Value>> &partialProducts); | |
| wallaceReduction(OpBuilder &builder, Location loc, size_t width, | |
| size_t targetAddends, | |
| SmallVector<SmallVector<Value>>& partialProducts); |
include/circt/Dialect/Comb/CombOps.h
Outdated
| unsigned offset, Value replacement); | ||
|
|
||
| /// Construct a full adder for three 1-bit inputs. | ||
| std::pair<Value, Value> fullAdder(ConversionPatternRewriter &rewriter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConversionPatternRewriter is sub-class of OpBuilder so OpBuilder would be appropriate (I defined this function in this so sorry).
| std::pair<Value, Value> fullAdder(ConversionPatternRewriter &rewriter, | |
| std::pair<Value, Value> fullAdder(OpBuilder &builder, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this pointer - wasn't sure on the appropriate signature for these functions!
| for (unsigned i = 0; i < width; i += 2) { | ||
| // Get Booth bits: b[i+1], b[i], b[i-1] (b[-1] = 0) | ||
| Value bim1 = (i == 0) ? zeroFalse : bBits[i - 1]; | ||
| Value bi = (i < width) ? bBits[i] : zeroFalse; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| Value bi = (i < width) ? bBits[i] : zeroFalse; | |
| Value bi = bBits[i]; |
| ConversionPatternRewriter &rewriter) const override { | ||
|
|
||
| auto inputs = op.getOperands(); | ||
| Value a = inputs[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| Value a = inputs[0]; | |
| Value a = op.getLhs(); | |
| Value b = op.getRhs(); |
lib/Dialect/Comb/CombOps.cpp
Outdated
|
|
||
| assert(addends.size() <= targetAddends); | ||
| SmallVector<Value> carrySave; | ||
| for (auto addend : addends) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| for (auto addend : addends) { | |
| for (auto& addend : addends) { |
| // CHECK-NEXT: %[[PP2:.+]] = comb.and %[[B2R]], %a : i3 | ||
| // CHECK-NEXT: %c2_i3 = hw.constant 2 : i3 | ||
| // CHECK-NEXT: comb.shl %[[PP2]], %c2_i3 : i3 | ||
| %0:3 = datapath.partial_product %a, %b : (i3, i3) -> (i3, i3, i3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test for booth as well (at least it compiles)?
…sing lec. Add a forceBooth option largely for testing purposes
|
@uenoku - have moved everything over to CombOps to provide shared infrastructure - added tests to circt-synth integration tests - since this is largely about lowering? Although open to suggestions to move? - have added an option to forceBooth array lowering so that we can check equivalence in a resonable runtime. Let me know if you've got any other concerns or queries! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing comments, one question for pattern population helper but LGTM!i
- added tests to circt-synth integration tests - since this is largely about lowering
I think that makes sense. Eventually we might want to clean up that directory as currently there are tons of translation validation are added altogether but we can do that later.
|
Will merge tomorrow unless anyone has any final comments :) |
A pass lowering datapath operators to a subset of the comb dialect, typically gate-level comb operators. The pass is for usage in the circt-synth pipeline, where we create datapath operators, perform datapath optimisations and then lower back to comb for further processing in the AIG generation pipeline.
The compress operator can be lowered to a Wallace tree and also to a variadic add. The lower-compress-to-add option is used for comparing compressor tree synthesis against other tools (e.g. Yosys). The partial product operator can be lowered to alternative multiplier array implementations depending on the bitwidth. Currently the pass supports lowering to a simple AND array and a Radix-4 Booth multiplier.
A subsequent PR will incorporate the datapath dialect into circt-synth tool flow.