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

fud2 support for FIRRTL #1

Merged
merged 6 commits into from
Jan 11, 2024
Merged

fud2 support for FIRRTL #1

merged 6 commits into from
Jan 11, 2024

Conversation

ayakayorihiro
Copy link
Contributor

@ayakayorihiro ayakayorihiro commented Jan 10, 2024

Edit: I also added support for running the generated System-Verilog via Verilator!

This is a first pass at supporting the Calyx-FIRRTL backend in fud2! As a point of note, we can remove the $extra_primitives argument and the primitives-for-firrtl.sv file once I support primitives in FIRRTL.

Please let me know if there's anything I can improve/should fix here! I also included Setup and Usage notes below, but I can put them elsewhere as needed.

Setup

To generate and run System-Verilog from Calyx-translated FIRRTL, we need the FIRRTL compiler. <ROOT> is the full path to the parent directory of where your repos live (most likely the parent directory of fake and calyx?).
Verilator, yosys, and sbt are also needed.

cd <ROOT>
git clone git@github.com:chipsalliance/firrtl.git
(
                cd firrtl
                sbt compile
                sbt test
                sbt assembly
) 

Then, edit the configuration file (~/.config/fud2.toml) to include the below:

[firrtl]
exe = "<ROOT>/firrtl/utils/bin/firrtl"

Usage

In the below pseudo-commands, <IN_FILE> is the input Calyx file, and <DATA_FILE> is the JSON file containing data.

To generate FIRRTL from Calyx:

fud2 <IN_FILE> --to firrtl

To generate System-Verilog from Calyx-translated FIRRTL:

fud2 <IN_FILE> --to verilog --through firrtl

To run System-Verilog from Calyx-translated FIRRTL using Icarus-Verilog:

fud2 <IN_FILE> --to dat --through icarus-firrtl -s sim.data=<DATA_FILE>

To run System-Verilog from Calyx-translated FIRRTL using Verilator:

fud2 <IN_FILE> --to dat --through verilator-firrtl -s sim.data=<DATA_FILE>

Copy link
Owner

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

AMAZING!!! I'm so glad this was comparatively straightforward to do; everything looks ship shape. I don't really have any comments on the current implementation (except for one super minor one) and think this is good to go!

At some point, when we have a different approach to the primitives, it seems like it could be possible to avoid having separate icarus-firrtl and verilator-firrtl ops, and just rely on the plain ol' icarus and verilator ops. (That is, if I can figure out how to decouple Calyx compilation and Icarus simulation.)

As for the documentation: this is already great!! I have really not written any fud2 docs yet, so I suppose whenever we do that, we should put this stuff there. I'll try to remember to move forward the project of merging fud2 into the Calyx repo, I suppose, so we have a good place to do this!

&format!("{}/primitives-for-firrtl.sv", e.config_val("data")?),
)?;
} else {
e.arg("extra_primitives", "")?;
Copy link
Owner

Choose a reason for hiding this comment

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

FWIW, you can probably leave off these "empty" assignments; in Ninja, variables that are unassigned are just empty by default.

Copy link
Contributor Author

@ayakayorihiro ayakayorihiro Jan 11, 2024

Choose a reason for hiding this comment

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

Ah I see! Thanks for letting me know :) (This will all be gone soon so I'll keep things as is for now but will keep this in mind for the future!)

@sampsyo sampsyo merged commit d4c81ed into sampsyo:main Jan 11, 2024
@sampsyo
Copy link
Owner

sampsyo commented Jan 12, 2024

FWIW, I was finally able to install FIRRTL and gave this a try all the way through! It works great!!

In recent commits, I also succeeded in simplifying the rules a bit, so now the simulation stages get to start from FIRRTL instead of from Calyx code. That makes them a little smaller and more reusable. The state diagram now looks like this:
graph

Hypothetically, "all we'd need to do" to eliminate the verilator-firrtl and icarus-firrtl stages would be to merge the extra primitives and the compiled Calyx code into one Verilog file. That way, we could feed this merged Verilog directly into the existing verilator and icarus stages. Not sure if that's as simple as just cating them, but maybe!

@ayakayorihiro
Copy link
Contributor Author

Awesome!! Thank you for trying everything out and fixing things up :)
I think when I get the primitives implemented in Chisel we should be able to get rid of the verilator-firrtl and icarus-firrtl stages simply by getting the FIRRTL versions of the primitives and compiling everything into one Verilog file...? But even with the current setup of things I think a cat would work too!

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.

2 participants