-
Notifications
You must be signed in to change notification settings - Fork 614
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
Add Layer Colors to Probe Types #3744
Conversation
c081aff
to
87181a9
Compare
Question:
possible to be wrapped by layer? |
@sequencer wrote:
Yes, though there needs to be a way to get a reference to the port out of the layerblock so that it can be connected to. I've considered that it may make sense to allow returning any type from a layerblock to enable this. However, I'm not sure if this is entirely necessary. The following is not advised, but works: class DUT extends Module {
val a = IO(Input(UInt(32.W)))
val b = IO(Output(UInt(32.W)))
val pc = Reg(UInt(32.W))
pc :<>= a
b :<>= pc
var _trace: Vec[UInt] = null
block(Verification) {
val trace = IO(Output(Probe(Vec(4, UInt(32.W)), Verification)))
_trace = trace
val committedInstructions = Reg(Vec(4, UInt(32.W)))
committedInstructions(0) :<>= pc
committedInstructions(1) :<>= committedInstructions(0)
committedInstructions(2) :<>= committedInstructions(1)
committedInstructions(3) :<>= committedInstructions(2)
define(trace, ProbeValue(committedInstructions))
}
} |
LOL, I just exactly thought about the same thing.
What if |
@sequencer wrote:
That's the other approach. This probably makes sense to allow. There is a question of what you can return. Can you only return layer-colored ports? Can you return anything? I'd like to solve this in a follow-on PR. Any change to the return type of a |
8425259
to
bc4ee58
Compare
@@ -797,7 +797,7 @@ object Data { | |||
// Needed for the `implicit def toConnectableDefault` | |||
import scala.language.implicitConversions | |||
|
|||
private[chisel3] case class ProbeInfo(val writable: Boolean) | |||
private[chisel3] case class ProbeInfo(val writable: Boolean, color: Option[layer.Layer]) |
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.
I'm confused. Binary compatibility should be complaining about this because it isn't smart enough to filter out package private things (it looks at the Java byte code which doesn't have package private). Why are we not having to waive this? If somehow they've made MiMa support package private Scala semantics--that's great--but I'd like to understand before we merge because this is surprising me.
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.
This is still a mystery but we're just gonna leave it.
If using boring api. e.g. tapAndRead. The secret port should also be colored |
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.
Overall looks good but a couple of suggestions. Also I need to disable binary compatibility checking so this will pass CI when we switch back to case classes.
"define a = probe(in)", | ||
"define b = probe(in)" | ||
)() | ||
} |
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.
Can we have a negative test of what happens if you try to drive a layer-colored probe from the wrong layer or from no layer?
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.
There's currently no checking of this. firtool
will error about it if you do this. It's probably better to duplicate the check of FIRRTL semantics in Chisel here. I'll see about adding this.
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.
This logic was recently tweaked a bit, but here's the basic place where we check lexical scoping:
chisel/core/src/main/scala/chisel3/Data.scala
Line 585 in 4ffbd99
private[chisel3] def isVisible: Boolean = isVisibleFromModule && isVisibleFromWhen |
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.
@@ -797,7 +797,7 @@ object Data { | |||
// Needed for the `implicit def toConnectableDefault` | |||
import scala.language.implicitConversions | |||
|
|||
private[chisel3] case class ProbeInfo(val writable: Boolean) | |||
private[chisel3] case class ProbeInfo(val writable: Boolean, color: Option[layer.Layer]) |
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.
This is still a mystery but we're just gonna leave it.
3999ce1
to
f83f4b6
Compare
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, 1 minor suggestion.
Add a memoized (via a `lazy val`) member to Layer that returns the FIRRTL "full name" of that layer. This includes all the parent layers prefixed with interleaves periods. This is memoized to avoid unnecessarily recomputing the partial prefixes of parents. Signed-off-by: Schuyler Eldridge <[email protected]>
Extend the probe modifier case class, `ProbeInfo`, to include information about the optional layer color of this layer. Extend emission to properly write this out to FIRRTL text. Signed-off-by: Schuyler Eldridge <[email protected]>
Signed-off-by: Schuyler Eldridge <[email protected]>
1bc9889
to
f9d4c3b
Compare
This adds Layer Colors to Probe types.
This is an existing part of the FIRRTL 3.2.0 "groups" feature which is being expanded/clarified in FIRRTL 4.0.0. This enables a probe to be associated/colored with a layer. This enables a layerblock to define probes of the same color.
This feature is used to construct simple interfaces of probes whose defines require complicated logic that does not exist inside the interface. Consider a situation where you have a simple single-cycle microprocessor. You'd like to expose a simple commit trace that is the last four instructions. However, the microprocessor does not actually record the last four instructions. It only keeps track of the current instruction. What do you do? If you put the logic outside the microprocessor, then your interface has changed. If you put the logic inside the microprocessor, you're adding junk that shouldn't be there.
Layer colored probes provide a way to hide this logic in a layer while still keeping a clean interface.
(This example is intentionally simple---a real world example is computing an in-order commit trace for an out-of-order processor where you need to assemble all the instructions committing out-of-order.)
The example below shows a realization of the basic example above:
Using a series of patches to enable this in CIRCT (llvm/circt#6552, llvm/circt#6574, and llvm/circt#6554) based on updates to the FIRRTL spec (chipsalliance/firrtl-spec#160), this produces the following FIRRTL and Verilog:
The resulting Verilog has a clean DUT (no junk!). There is collateral in a bind file that can be used to "enable" the Verification layer. This then uses Verilog hierarchical names to pass information from the bound module in the DUT (which computes all the logic that we don't want in the DUT) to a bound module in the TestHarness (which consumes this). The circuit is valid (no illegal hierarchical names) whether or not the Verification layer is enabled.