Skip to content

Commit 4c15ba6

Browse files
committed
[Docs]: The Yosys+Odin-II documentation
Related-issue: #1831 Signed-off-by: Seyed Alireza Damghani <[email protected]>
1 parent d735a46 commit 4c15ba6

File tree

10 files changed

+1393
-0
lines changed

10 files changed

+1393
-0
lines changed

doc/src/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ For more specific documentation about VPR see :ref:`vpr`.
3737
arch/index
3838
vpr/index
3939
odin/index
40+
yosys+odin/index
4041
abc/index
4142
tutorials/index
4243
utils/index
93.4 KB
Loading
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
Contributing
2+
============
3+
4+
The Odin-II team welcomes outside help from anyone interested.
5+
To fix issues or add a new feature submit a PR or WIP PR following the provided guidelines.
6+
7+
Creating a Pull Request (PR)
8+
----------------------------
9+
10+
**Important**
11+
12+
Before creating a Pull Request (PR), if it is a bug you have happened upon and intend to fix make sure you create an issue beforehand.
13+
14+
Pull requests are intended to correct bugs and improve Yosys+Odin-II's performance.
15+
To create a pull request, clone the `vtr-verilog-to-routing repository <https://github.com/verilog-to-routing/vtr-verilog-to-routing>`_ and branch from the master.
16+
Make changes to the branch that improve Yosys+Odin-II and correct the bug.
17+
18+
**Important**
19+
20+
In addition to correcting the bug, it is required that test cases (benchmarks) are created that reproduce the issue and are included in the regression tests.
21+
An example of a good test case could be the benchmark found in the `Issue` being addressed.
22+
The results of these new tests need to be regenerate in Yosys+Odin-II regression tests.
23+
See :ref:`regression_test` for further instruction.
24+
Push these changes to the cloned repository and create the pull request.
25+
Add a description of the changes made and reference the `Issue` that it corrects.
26+
There is a template provided on the GitHub repository.
27+
28+
Creating a "Work in Progress" (WIP) PR
29+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30+
31+
**Important**
32+
33+
Before creating a WIP PR, if it is a bug you have happened upon and intend to fix make sure you create an issue beforehand.
34+
35+
A `Work in Progress` PR is a pull request that isn't complete or ready to be merged.
36+
It is intended to demonstrate that an issue is being addressed and indicates to other developers that they don't need to fix it.
37+
Creating a WIP PR is similar to a regular PR with a few adjustments.
38+
First, clone the `vtr-verilog-to-routing repository <https://github.com/verilog-to-routing/vtr-verilog-to-routing>`_ and branch from the master.
39+
Make changes to that branch.
40+
41+
Since Yosys is added to the VTR repository as an external library, no changes are allowed to be made to its codebase.
42+
Instead, contributions concerning improving the Yosys elaboration script, Odin-II BLIF elaboration, and Odin-II partial mapping could be possible alterations for the Yosys+Odin-II synthesizer.
43+
Then, create a pull request with that branch and **include WIP in the title.**
44+
This will automatically indicate that this PR is not ready to be merged.
45+
Continue to work on the branch, pushing the commits regularly.
46+
Like a PR, test cases are also needed to be included through the use of benchmarks.
47+
See :ref:`regression_test` for further instruction.
48+
49+
Formating
50+
~~~~~~~~~
51+
52+
Odin-II shares the same contributing philosophy as `VPR <https://docs.verilogtorouting.org/en/latest/dev/contributing/contributing/>`_.
53+
Most importantly PRs will be rejected if they do not respect the coding standard: see `VPRs coding standard <https://docs.verilogtorouting.org/en/latest/dev/developing/#code-formatting>`_
54+
55+
To overcome the formatting issue, simply run ``make format`` to adapt the newly added code to VPR's coding standard.
56+
If you have made alterations to python scripts, you would probably need to run ``make format-py`` and ``./dev/pylint_check.py`` from the VTR root directory to correct the python code formatting and check for lint errors.
57+
58+
Yosys+Odin-II's Flow
59+
--------------------
60+
61+
Yosys+Odin-II functions via two CAD tools, Yosys and Odin-II, by executing a set of steps determined by the files and arguments passed in.
62+
The figure below illustrates the synthesis flow of Yosys+Odin-II and Odin-II if a Verilog file is passed, with an optional FPGA Architecture Specification File.
63+
The synthesis process includes: reading the HDL file and performing a coarse-grained synthesis by Yosys, elaborating the generated coarse-grained netlist by Odin-II, and ultimately performing partial technology mapping and unused logic removal with the FPGA architecture awareness again by Odin-II.
64+
The simulator is only activated if an input vector file is passed in which creates the output vector file.
65+
66+
Fine-grained BLIF files, usually generated by Odin-II, being passed in are only used for simulation; no partial mapping takes place.
67+
However, the partial mapping can be performed on coarse-grained BLIF netlists, specified by the ``--coarsen`` command argument.
68+
The flow is depicted in the figure below.
69+
70+
.. image:: ./YosysOdinFlow.png
71+
:width: 100%
72+
:alt: The Odin-II and Yosys+Odin-II Synthesis Flow
73+
74+
75+
**Figure 1** - The Odin-II and Yosys+Odin-II Synthesis Flow
76+
77+
78+
.. code-block:: tcl
79+
80+
# FILE: $VTR_ROOT/ODIN_II/regression_test/tools/synth.tcl #
81+
yosys -import
82+
83+
# the environment variable VTR_ROOT is set by Odin-II.
84+
# Feel free to specify file paths using "$env(VTR_ROOT)/ ..."
85+
86+
# Read the hardware decription Verilog
87+
read_verilog -nomem2reg -nolatches PATH_TO_VERILOG_FILE.v;
88+
# Check that cells match libraries and find top module
89+
hierarchy -check -auto-top;
90+
91+
# Make name convention more readable
92+
autoname;
93+
# Translate processes to entlist components such as MUXs, FFs and latches
94+
procs; opt;
95+
# Extraction and optimization of finite state machines
96+
fsm; opt;
97+
# Collects memories, their port and create multiport memory cells
98+
memory_collect; memory_dff; opt;
99+
100+
# Looking for combinatorial loops, wires with multiple drivers and used wires without any driver.
101+
check;
102+
# resolve asynchronous dffs
103+
techmap -map $VTR_ROOT/ODIN_II/techlib/adff2dff.v;
104+
techmap -map $VTR_ROOT/ODIN_II/techlib/adffe2dff.v;
105+
106+
# convert mem block to bram/rom
107+
# [NOTE]: Yosys complains about expression width more than 24 bits.
108+
# E.g. [63:0] memory [18:0] ==> ERROR: Expression width 33554432 exceeds implementation limit of 16777216!
109+
# mem will be handled using Odin-II
110+
# memory_bram -rules $VTR_ROOT/ODIN_II/techlib/mem_rules.txt
111+
# techmap -map $VTR_ROOT/ODIN_II/techlib/mem_map.v;
112+
113+
# Transform the design into a new one with single top module
114+
flatten;
115+
# Transforms pmux into trees of regular multiplexers
116+
pmuxtree;
117+
# undirven to ensure there is no wire without drive
118+
opt -undriven -full; # -noff #potential option to remove all sdff and etc. Only dff will remain
119+
# Make name convention more readable
120+
autoname;
121+
# Print statistics
122+
stat;
123+
# Output BLIF
124+
write_blif -param -impltf TCL_BLIF;
125+
126+
**Algorithm 1** - The Yosys+Odin-II Tcl Script File
127+
128+
129+
Yosys Elaboration
130+
~~~~~~~~~~~~~~~~~
131+
132+
Yosys, as an open synthesis suite, reads the input digital circuits and creates the corresponding data structures, such as netlist and Abstract Syntax Tree (AST).
133+
As shown in Algorithm 1, the Tcl script, including the step-by-step generic coarse-grained synthesis commands required to be run by Yosys, is developed at ``$VTR_ROOT/ODIN_II/regression_test/tools/synth.tcl``.
134+
Utilizing these commands for the Yosys API inside the Odin-II codebase, the Yosys synthesizer performs the elaboration of the input digital design.
135+
The generic coarse-grained synthesis commands includes:
136+
137+
1. Parsing the hardware description Verilog files. The option ``-nomem2reg`` prevents Yosys from exploding implicit memories to an array of registers. The option ``-nolatches`` is used for both VTR primitives and input circuit design to avoid Yosys generating logic loops.
138+
2. Checking that the design cells match the libraries and detecting the top module using ``hierarchy``.
139+
3. Translating the processes to netlist components such as multiplexers, flip-flops, and latches, by the ``procs`` command.
140+
4. Performing extraction and optimization of finite state machines by the ``fsm`` command.
141+
5. Collecting memories and their ports, then creating a multiport memory cell, by the ``memory_collect`` command.
142+
6. Converting asynchronous memory ports to synchronous ones by merging ports and the related DFFs at their interfaces, using the ``memory_dff`` command.
143+
7. Examining errors like combinatorial loops, wires with multiple drivers and used wires without any driver by the ``check`` command.
144+
145+
After performing basic synthesis steps, the ``techmap`` command with the input ``addf2dff`` transforms asynchronous DFFs to the synchronous form using the design provided by Yosys.
146+
The next command follows the same approach but with a modified version of ``adff2dff`` for asynchronous DFFs with the enable signal.
147+
148+
The ``flatten`` command generates an output netlist with only one module, representing the HDL circuit design's top module.
149+
The ``pmuxtree`` pass is used to transforms `pmux`, a sub-circuit representing parallel cases, into trees of regular multiplexers.
150+
In the ``autoname`` passes, Yosys generates an easy-to-read BLIF file by transforming signal names into the short format. This would help the Odin-II BLIF reader reading necessary data, regardless of additional debugging information used in the Yosys name convention.
151+
152+
Then, the optimization pass is called to make the netlist ready for output.
153+
The option ``undriven`` ensures that all nets without a driver are removed, while the ``full`` optimization option is used to remove duplicated inputs in `AND`, `OR` and `MUX` gates.
154+
Ultimately, we use the ``write_blif`` command to output the coarse-grained BLIF file.
155+
The option ``param`` prints some additional information about logic cells into the BLIF file, and the ``impltf`` option conceals the definition of primary netlist ports, i.e., VCC, GND and PAD, in the output.
156+
157+
.. note::
158+
159+
As earlier mentioned in :ref:`user_guide`, the Yosys BLIF output process, i.e., ``write_blif``, is handled by Yosys embedded API inside the Odin-II codebase. As a result, the last command is not required if a user would like to run the Yosys+Odin-II synthesizer using the Tcl script.
160+
161+
162+
BLIF Reader and Building the Netlist
163+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164+
165+
In this step, Odin-II reads the Yosys generated coarse-grained BLIF file and creates the corresponding netlist data structure.
166+
Previously, only the simulation option was available when a BLIF file was passed to Odin-II.
167+
However, the option for performing the partial mapping phase on input BLIF files have become available with the Yosys+Odin-II integration.
168+
Using the ``--elaborator yosys`` command argument, the Odin-II BLIF reader reads the Yosys generated coarse-grained BLIF file.
169+
Additionally, if a coarse-grained BLIF file is already created, the user can perform Odin-II partial mapping on that using the ``-b design.blif --coarsen`` command arguments.
170+
171+
.. note::
172+
173+
The netlist can be viewed via graphviz using the command ``-G``. The file will appear in the main directory under ``net.dot``.
174+
175+
BLIF Elaboration
176+
~~~~~~~~~~~~~~~~
177+
178+
As depicted in Yosys+Odin-II synthesis flow, the difference between fine-grained and coarse-grained netlists is the BLIF elaboration and partial mapping phases in Odin-II technology mapping flow.
179+
Technically, the infrastructure of Odin-II and Yosys differ from each other.
180+
As a result, the elaboration phase is performed on the input netlist when the input BLIF file is specified as a coarse-grained design to make it compatible with Odin-II partial mapper.
181+
As an example, Yosys generates complex DFFs, such as DFF with synchronous enable and reset, while Odin-II partial mapper only recognizes the simple DFF represented by ``.latch`` in BLIF.
182+
Therefore, these complex modules are required to be transformed into simpler designs using standard logic cells.
183+
184+
185+
186+
Partial Mapping
187+
~~~~~~~~~~~~~~~
188+
189+
During the partial mapping, Odin-II maps the logic using an architecture.
190+
If no architecture is passed in, Odin-II will create the soft logic and use LUTs for mapping.
191+
However, if an architecture is passed, Odin-II will map accordingly to the available hard blocks and LUTs.
192+
It uses a combination of soft logic and hard logic.
193+
194+
With the integration of Yosys+Odin-II, the Odin-II partial mapping features such as hard/soft logic trade-offs become available for a Yosys elaborated circuit.
195+
For instance, using optimization command arguments, a user can force the partial mapper to infer at least a user-defined percentage of multipliers in soft logic.
196+
197+
Simulator
198+
~~~~~~~~~
199+
200+
The simulator of Odin-II takes an input vector file and creates an output vector file determined by the behaviour described in the Verilog file or BLIF file.
201+
This section is comprehensivly decribed in :ref:`user_guide`.
202+
203+
Useful tools of Odin-II for Developers
204+
--------------------------------------
205+
206+
When making improvements to Yosys+Odin-II, there are some features the developer should be aware of to make their job easier.
207+
For instance, Odin-II has a ``-G`` command that prints the netlist viewable with GraphViz.
208+
These files can be found in the ODIN_II directory.
209+
This is very helpful to visualize what is being created and how everything is related to each other in the Netlist and AST.
210+
211+
Another feature to be aware of is ``make test_yosys+odin``.
212+
This build runs through all the regression tests and will list all the benchmarks that fail, using Yosys+Odin-II synthesizer.
213+
It is important to run this after every major change implemented to ensure the change only affects benchmarks it was intended to effect (if any).
214+
It sheds insight on what needs to be fixed and how close it is to being merged with the master.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. _dev_guide:
2+
3+
Developers Guide
4+
================
5+
6+
7+
.. toctree::
8+
:maxdepth: 2
9+
10+
contributing
11+
regression_test
12+
testing

0 commit comments

Comments
 (0)