-
Notifications
You must be signed in to change notification settings - Fork 592
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
[RFC] Provide mechanism to load memories directly in simulation #835
Comments
@jchang0 FYI |
I had some thoughts about this a while ago in chipsalliance/firrtl#510. Also, there was a small discussion on the chisel-users mailing list. I'm in agreement with your first two bullet points in other considerations. Annotation for a file that gets loaded during FIRRTL compilation makes sense, but you will likely want to change this file at run time (motivating examples: a neural network accelerator with pre-loaded weights, immediately loading a microprocessor's simulated memory with a test program). I had considered doing this with exposed VPI/DPI hooks when emitting memory structures that would allow you to, optionally, preload the memories. This only, however, aligns with a testing model using simulated/compiled Verilog. This brings up an additional consideration:
I had to look up bind files... I think @jackkoenig has a point here in that any auxiliary stuff should be moved over there. This brings up a tangential point of moving all the assertions (and possibly anything in an |
@seldridge I think this should work for other backends where possible, this should be relatively simple to implement in the interpreter and treadle. I am less clear on what the larger playing field is like FPGA's etc. I'll update the other considerations to list this. |
@chick: It helps when I fully read the bullet... We're thinking the same thing here. |
@jackkoenig I'm interested in feedback on this implementation. I have the initial work done. I've created a LoadMemoryAnnotation and a Transform/Pass that finds these annotated memories. It seems like a reasonable solution would be to extend the BlackBox system to be able to mark BlackBoxInLine annotations as Bound. The firrtl verilog emitter would find these annotations and would emit the bound modules along with the bind statements necessary to link them to the original module. This extra logic would include parameter and input handling. Does this seem like a reasonable approach. Or do you have some other idea on how to proceed here. |
@chick Overall I think the implementation sounds good, just a few questions. By extending the BlackBox system, do you mean the BlackBoxInline, etc. pass or do you mean the IR nodes? What changes are needed in the VerilogEmitter? Just the ability to mark a module with the name of a Verilog module that should be bound to it? What does the proposed solution do if a signal that we are trying to bind to (or rather, use as an input or output to the bound module) gets optimized away? Annotations and renaming are supposed to give us sufficient flexibility to do this linking, but it's tricky when things get optimized. For something like this I think dontTouching the requisite signals in the design is sensible so it's probably okay. I'm wondering if we shouldn't have some way to provide post-Verilog emission hooks for information in Annotations to be used to emit stuff. In fact, an artifact system as you have proposed could perhaps ask all annotations if they want to "emit" or something like that which would allow them to emit a file and/or be deleted before we emit the remaining/resulting annotations in an anno file. This would have the added benefit of solving chipsalliance/firrtl#793. I don't think this is necessary for this PR, but they are complementary. |
@jackkoenig My initial thought was that when I would create an external module with the $readmem directive in it and a bind statement. I'm concerned that the approach is not very general, if assertions were to be added with this method I don't think this would scale well if every assertion required a separate BlackBoxInline. |
Have you prototyped the external module with the $readmem directive? I don't think you can have vectors as ports in Verilog, although it is supported in SystemVerilog so perhaps Verilator supports it. The external module also could use a cross-module reference to refer to the mem so I'm just curious how you have/will get this to work! I agree that we should think about the possibility of this pattern leading to tons of external modules being included via bind. For something like assertions, I think the onus would be on the assertion library to aggregate them before emitting external modules. I think for the purposes of this you shouldn't worry about it though and just try to build a robust system that could be an example of this pattern that we can examine to see how it could be replicated/scaled. |
It looks like this cannot be done without some supporting changes in Firrtl.
|
Issues that I could use feedback on.
|
Motivation
For certain classes of large Chisel designs loading memories takes a very long time.
Provide annotations to load a memory from a file
Verilog has methods
$readmemb
and$readmemh
See hereto do this operation but there currently is no simple way to specify this in Chisel.
Strategy
Using
$readmemb
and$readmemh
could be done directly in the emitted verilog but @jackkoenig points out that it would be better to keep direct verilog emission free of these construct and instead use verilog's bind mechanism.Other considerations
The text was updated successfully, but these errors were encountered: