Skip to content

Commit c0b916e

Browse files
MSPDUTTAPriyanka Dutta
andauthored
FST generation (#19)
* Added support to generate fst for ESSENT which gives 2x speedup and reduces waveform size by 135x * Update README.md How to compile and run ESSENT with VCD or FST * Update README.md --------- Co-authored-by: Priyanka Dutta <[email protected]>
1 parent 299b185 commit c0b916e

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Essent is written in Scala, which runs on the JVM. To run essent, it's easiest t
1818
+ `O2` - Muxes are represented with `if/else` blocks instead of ternary statements `?`. As many signals as possible are pulled into the if or else blocks. If both the if and else blocks will be trivially one statement, the optimization will not be performed.
1919
+ `O3` - Attempts to exploit low activity factors by reusing results from the previous cycle. The design will be partitioned, and each partition will get its own eval function. If none of the inputs to a partition change, its outputs will be reused. These partitions can include state elements.
2020

21+
2122
Example invocations:
2223

2324
$ ./essent --help
@@ -55,7 +56,6 @@ int main() {
5556
}
5657
```
5758

58-
5959
Compiling everything
6060
--------------------------------------------------------------------------------
6161

@@ -64,9 +64,49 @@ Since essent emits a single header file for a firrtl circuit, the entire simulat
6464
An example compile command:
6565

6666
$ g++ -O3 -std=c++11 -I./firrtl-sig design-harness.cc -o simulator
67-
67+
6868
On macOS, when using clang, we also found `-fno-slp-vectorize` to improve compile time for large designs, and `-fbracket-depth=1024` allows it to handle designs with deeply nested muxes.
6969

70+
Running with waveform
71+
--------------------------------------------------------------------------------
72+
To generate waveform with ESSENT you can choose either format , VCD or FST and then you can view using gtkwave waveform viewer.
73+
74+
```
75+
Install gtkwave by entering the following commands in the terminal:
76+
77+
sudo apt update
78+
sudo apt install gtkwave
79+
```
80+
Compile:
81+
+ `withVCD` - This flag enabled generates waveform in VCD format , which can be viewed using gtkwave; disabled by default
82+
+ `withFST` - This flag enabled generates waveform in FST format , which can be viewed using gtkwave; disabled by default
83+
84+
Example invocations:
85+
86+
```
87+
$ ./essent -O3 -withVCD my_design.fir
88+
```
89+
90+
Requitered update in Harness file:
91+
92+
Before we start the simulation , we need to add the below to the testbench file, which generates the header part of the VCD or FST.
93+
94+
top->genWaveHeader();
95+
96+
Running:
97+
We do not need any extra argument to run with VCD , it is same as running essent without VCD.
98+
99+
with FST:
100+
Please install vcd2fst before we run with FST.
101+
Instead of going into generating FST from scratch, we are using vcd2fst tool to convert our VCD related data into streams and compress parallely to generate
102+
in a form of FST format, which is 135x smaller than VCD file.
103+
```
104+
105+
clang++ -O3 -std=c++11 -fno-slp-vectorize -fbracket-depth=1024 -Iriscv/include -I../firrtl-sig emulator.cc -o emulator_fst -Lriscv/lib -Wl,-rpath,riscv/lib -lfesvr -lpthread
106+
107+
./emulator_fst dhrystone.riscv | **vcd2fst -p -v /dev/stdin -f** dump_mydesign.fst"
108+
```
109+
70110

71111
Examples
72112
--------------------------------------------------------------------------------

src/main/scala/ArgsParser.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ case class OptFlags(
1919
partStats: Boolean = false,
2020
partCutoff: Int = 8,
2121
withVCD: Boolean = false,
22+
withFST: Boolean = false,
2223
essentLogLevel: String = "warn",
2324
firrtlLogLevel: String = "warn") {
2425
def inputFileDir() = firInputFile.getParent
@@ -111,6 +112,12 @@ class ArgsParser {
111112
removeFlatConnects = false,
112113
withVCD = true)
113114
).text("parameter used for vcd generation")
115+
116+
opt[Unit]("withFST").abbr("withFST").action( (_, c) => c.copy(
117+
removeFlatConnects = false,
118+
withVCD = true,
119+
withFST = true)
120+
).text("parameter used for vcd generation")
114121
}
115122

116123
def getConfig(args: Seq[String]): Option[OptFlags] = parser.parse(args, OptFlags())

src/main/scala/Vcd.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ class Vcd(circuit: Circuit, initopt: OptFlags, w: Writer, rn: Renamer) {
240240
def genWaveHeader(): Unit = {
241241
w.writeLines(1, "void genWaveHeader() {")
242242
w.writeLines(0, "")
243-
w.writeLines(1,s"""outfile = fopen("dump_$topName.vcd","w+");""")
243+
if(opt.withFST)
244+
w.writeLines(1,s"""outfile = fopen("/dev/stdout","w+");""")
245+
else
246+
w.writeLines(1,s"""outfile = fopen("dump_$topName.vcd","w+");""")
244247
w.writeLines(2, "time_t timetoday;")
245248
w.writeLines(2, "time (&timetoday);")
246249
writeFprintf(""" "%s","$version Essent version 1 $end\n");""")
@@ -312,7 +315,8 @@ class Vcd(circuit: Circuit, initopt: OptFlags, w: Writer, rn: Renamer) {
312315
val cleanName = rn.removeDots(name)
313316
if(rn.nameToMeta(name).decType != ExtIO && rn.nameToMeta(name).decType != RegSet) {
314317
if(!cleanName.contains("$_") && !cleanName.contains("$next") && !cleanName.startsWith("_")) {
315-
compSig(cleanName,rn.vcdOldValue(cleanName))
318+
val temp_str = compSig(cleanName,rn.vcdOldValue(cleanName))
319+
w.writeLines(indentLevel, temp_str)
316320
w.writeLines(indentLevel, s""" ${rn.vcdOldValue(cleanName)} = $cleanName;""")
317321
}
318322
}

0 commit comments

Comments
 (0)