Skip to content
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

[Calyx-FIRRTL] Script for generating FIRRTL primitives #1863

Closed
wants to merge 19 commits into from

Conversation

ayakayorihiro
Copy link
Contributor

@ayakayorihiro ayakayorihiro commented Jan 23, 2024

As discussed briefly in #1860 , FIRRTL modules are monomorphic; i.e. you cannot pass parameters into modules in the same fashion that you can pass parameters to Calyx primitives. Therefore, we need to generate specific FIRRTL modules that represent a Calyx primitive usage that we later instantiate in our code. The first step towards this was writing a backend (primitive-uses) that generates a JSON file that contains all of the primitive uses in a particular Calyx program (#1860).

This PR contains a Python script (generate-firrtl-primitives.py) that uses the primitive usage information (in the JSON file) to produce FIRRTL modules for all the primitives that the associated Calyx program needs. It uses templated FIRRTL primitive files (in tools/firrtl/templates) and m4 to fill in the templates.

Please let me know if there's anything in tools/firrtl/generate-firrtl-primitives.py that I can fix! (I currently have a small hack in the script that I'm not sure how to bypass...) Or if my approach of adding 20 template FIRRTL files is not ideal.

I will be testing (once I get a test harness working... still working on it) the FIRRTL primitive templates, so I expect at least some of them to need fixes later. I'm also currently working on E2E fud2 FIRRTL support that pipelines the whole process together.

Usage

First, use the primitive-uses backend to produce a JSON file.
ex)

fud2 examples/tutorial/language-tutorial-mem.futil --to primitive-uses-json -o language-tutorial-mem-primitive-uses.json

Then, run the script. It takes in a single argument (the location of the previously generated JSON file) and prints out the FIRRTL primitives:
ex (continuing from above))

python3  tools/firrtl/generate-firrtl-primitives.py 

@ayakayorihiro
Copy link
Contributor Author

I'm going to close this PR since I later realized that I should link it with #1864 ! Sorry for the confusion.

@ayakayorihiro ayakayorihiro deleted the generate-firrtl-mods branch May 6, 2024 19:11
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant