-
Notifications
You must be signed in to change notification settings - Fork 616
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Implement DataViews for Seq and Tuple #2277
Conversation
Implemented in new chisel3.experimental.conversions package. Includes: * Implementations of DataProduct * Implementations of DataView from Seq to Vec and Tuple to HWTuple * Implicit conversions from Seq to Vec and Tuple to HWTuple
I'm curious what users think @mwachs5, @aswaterman, @carlosedp, @ingallsj, @schoeberl, @sequencer, @hcook |
One of my biggest user issues with the implicit conversions is its hard to understand why my code doesn't work when your code does. If there is a function it's easy to figure out in IDE how to include the function, but if an implicit conversion is missing, it's hard to discover. What is the advantage of the example:
Is it just saving the few characters of writing The
|
Yeah it's a fair concern. I should revise my proposal a bit, I think we should definitely have
In this case, it's true that // This would work
Seq(a, b, c, d).asData := out
// This would just connect to an intermediate Wire and thus be dropped
VecInit(a, b, c, d) := out // bad! don't do this!
I had it above but it would look like this: class MyModule extends Module {
val a, b, c, d = IO(Input(UInt(8.W)))
val sel = IO(Input(Bool()))
val y, z = IO(Output(UInt(8.W)))
(y, z).asData := Mux(sel, (a, b).asData, (c, d).asData)
} This is actually the case that made me add the implicit conversion in the first place. The nice thing about the implicit conversion is that any place a user writes code that accepts object Mux {
// Simplified since we also have SourceInfo and CompileOptions implicits here, and a do_ macro
def apply[T <: Data](cond: Bool, con: T, alt: T): T = ???
} One could add the following additional methods so that it will do the conversion rather than requiring an implicit: def apply[A : DataProduct, T <: Data](cond: Bool, con: T, alt: T)(implicit ev: DataView[A, T]) : T =
apply(cond, con.viewAs[T], alt.viewAs[T]) I think this is fine to do inside of Chisel itself, but I'm not super keen to suggest users do the same. Thus in practice, most user-defined APIs would require explicit |
It's occurred to me that class MyModule extends Module {
val a, b, c, d = IO(Input(UInt(8.W)))
val sel = IO(Input(Bool()))
val y, z = IO(Output(UInt(8.W)))
(y, z).viewAs := Mux(sel, (a, b).viewAs, (c, d).viewAs)
} |
I agree I really like the implicit conversion in the Mux case I think you should include your Seq/Vec example from below it is also nice and compelling.
|
Alright, after further thought, I'm going to move all of the |
394252d
to
4cec342
Compare
This makes them available by default in the implicit scope.
4cec342
to
a4305cb
Compare
I checkout and tried this feature, I really like this conversation! I think implicitly conversion will be more friendly to most of newbies to Chisel.
By default, I forcing users from our lab using IntelliJ IDEA, and think they are supported by Jetbrains by default(I think it really can teach them Scala, haha). |
I'm all for the implicit conversions from a user perspective. Other than that, I like the implementation making very straightforward to assign tuples/hwtuples too. |
Okay I think this is ready. I've made a few minor changes but I think there's wide agreement on the approach here. Interestingly, while the implicit conversions seem to work fantastically for Tuples, they seem to work less well for Seq, as evidenced by this test: class MyModule extends Module {
val a, b, c, d = IO(Input(UInt(8.W)))
val sel = IO(Input(Bool()))
val y, z = IO(Output(UInt(8.W)))
// Unclear why the implicit conversion does not work in this case for Seq
// That being said, it's easy enough to cast via `.viewAs` with or without
Seq(y, z) := Mux(sel, Seq(a, b).viewAs, Seq(c, d).viewAs[Vec[UInt]])
} I do not know why this is, but I wrote this test to capture something interesting. The implicit conversion does work for the LHS, ie. I'm wondering if we should add |
@jackkoenig it would be great to grab those nice examples and put them into the cookbook |
Agreed, will do in follow on PR. |
Fixes #864 (at long last!)
Implemented in new chisel3.experimental.conversions package. Includes:
Examples are buried in the tests, but this makes it possible to write stuff like:
and
I still haven't implemented more than just Tuple2, I intend to do several, maybe up to like Tuple7 or something.
Opening this before finishing it because I'd like feedback on the approach.
Questions
Do we like the implicit conversions?
They feel natural but I know folks are generally skeptical of implicit conversions.
An alternative is to provide
.asData
as an extension method, something like:This would change the above examples slightly:
and
You can see the total impact of this change on existing tests in this diff: https://gist.github.com/jackkoenig/ae5d20b18b4df2871aa174f0a38551a0
There is at least one other example where the implicit conversion doesn't work great but
.asData
does:vs.
As alluded to in the comment though,
VecInit
actually becomes obsolete if we have the implicit conversion, so perhaps this example isn't particularly useful.Do we like the package?
They could live directly
chisel3.experimental.dataview
, or it could be a subpackage ofdataview
. I think theDataProducts
and theDataViews
should live together but it's not clear if the implicit conversions (assuming we keep them) should live in the same package.Contributor Checklist
docs/src
?Type of Improvement
API Impact
Backend Code Generation Impact
Desired Merge Strategy
Release Notes
Reviewer Checklist (only modified by reviewer)
3.3.x
, [small] API extension:3.4.x
, API modification or big change:3.5.0
)?Please Merge
?