Skip to content

Commit

Permalink
[Profiling] Differentiating FSM tracking of groups vs ground truths (…
Browse files Browse the repository at this point in the history
…go, done) (#2277)

This PR contains bug fixes and adjustments for:
1. Register-based control flow coordination taking extra cycles
2. Stream-processing VCD files are prone to bugs

To elaborate for my own sake:
1. Any register that TDCC generates to track control flow use an extra
cycle to process. For example, a group `g`'s `go` and `done` signals may
denote that `g` takes only 2 cycles. However, if an FSM register `fsm`
uses 0 to encode **when `g` is allowed to be active**, then `fsm` would
have value 0 for **3 cycles** (2 cycles for `g` + 1 cycle for reading in
that `g` is done).
To deal with this situation, the profiler maintains two versions of
information for all FSM-managed groups: (a) the ground truth information
provided by `go` and `done` signals for the group (ex.
`TOP.toplevel.main.write` in the below screenshot), and (b) the FSM
register-based information (ex. `TOP.toplevel.main.write[FSM]` in the
below screenshot). The screenshot is the summary provided for
`tests/profiler/simple-seq.futil`)

![image](https://github.com/user-attachments/assets/2ee80aea-1ec9-4e93-b67c-d80b6ab6aa72)
Having both versions will help us understand the impacts of these extra
(phantom) cycles.

2. While working on (1), I found that my VCD parsing script didn't
capture some value changes that happened simultaneously with the clock
cycle updates. The below is a small illustrative example (denoted
`timestamp signal value`):
```
70 a 1
70 clk 1
70 b 1
```
We see that on the cycle starting at timestamp 70, both `a` and `b`
updated values. However, since my script read the VCD file through a
stream, it only noticed that `a` updated values (because it was listed
before the `clk` update).
To fix this bug, I read the value changes into a dictionary from
timestamps to value change events, so that I can process all events that
happened at the same time as a cycle update.
  • Loading branch information
ayakayorihiro authored Sep 5, 2024
1 parent 9605a8d commit e7d2d64
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 271 deletions.
13 changes: 0 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ members = [
"tools/calyx-pass-explorer",
"tools/cider-data-converter",
"tools/component_cells",
"tools/component_groups",
"tools/yxi",
"tools/calyx-writer",
]
Expand Down
2 changes: 1 addition & 1 deletion runt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,4 @@ name = "profiler"
paths = ["tests/profiler/*.futil"]
cmd = """
bash tools/profiler/get-profile-counts-info.sh {} {}.data STDOUT -d
"""
"""
39 changes: 21 additions & 18 deletions tests/profiler/par.expect
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,65 @@
Total clock cycles: 3
=====SUMMARY=====

Group TOP.toplevel.main.par0 Summary:
[FSM] Group TOP.toplevel.main.par0 Summary:
Total cycles: 3
# of times active: 1
Avg runtime: 3.0

Group TOP.toplevel.main.wr_a Summary:
[GT] Group TOP.toplevel.main.par0 Summary:
Total cycles: 2
# of times active: 1
Avg runtime: 2.0

[GT] Group TOP.toplevel.main.wr_a Summary:
Total cycles: 1
# of times active: 1
Avg runtime: 1.0

Group TOP.toplevel.main.wr_b Summary:
[GT] Group TOP.toplevel.main.wr_b Summary:
Total cycles: 1
# of times active: 1
Avg runtime: 1.0

Group TOP.toplevel.main.wr_c Summary:
[GT] Group TOP.toplevel.main.wr_c Summary:
Total cycles: 1
# of times active: 1
Avg runtime: 1.0

=====DUMP=====

Group TOP.toplevel.main.par0:
[FSM] Group TOP.toplevel.main.par0:
FSM name: TOP.toplevel.main.fsm
FSM state ids: [0]
Total cycles: 3
# of times active: 1
Segments: [0, 3)

Group TOP.toplevel.main.wr_a:
FSM name: None
FSM state ids: None
[GT] Group TOP.toplevel.main.par0:
Total cycles: 2
# of times active: 1
Segments: [0, 2)

[GT] Group TOP.toplevel.main.wr_a:
Total cycles: 1
# of times active: 1
Segments: [0, 1)

Group TOP.toplevel.main.wr_b:
FSM name: None
FSM state ids: None
[GT] Group TOP.toplevel.main.wr_b:
Total cycles: 1
# of times active: 1
Segments: [0, 1)

Group TOP.toplevel.main.wr_c:
FSM name: None
FSM state ids: None
[GT] Group TOP.toplevel.main.wr_c:
Total cycles: 1
# of times active: 1
Segments: [0, 1)

Writing dump JSON to /home/ayaka/projects/calyx/tools/profiler/data//tmp/dump.json
Writing summary to STDOUT
name,total-cycles,times-active,avg
TOP.toplevel.main.par0,3,1,3.0
TOP.toplevel.main.par0[FSM],3,1,3.0
TOP.toplevel.main.par0,2,1,2.0
TOP.toplevel.main.wr_a,1,1,1.0
TOP.toplevel.main.wr_b,1,1,1.0
TOP.toplevel.main.wr_c,1,1,1.0
TOTAL,3,-,-
[get-profile-counts-info.sh] Writing visualization to /home/ayaka/projects/calyx/tools/profiler/data//tmp/visual.json
[get-profile-counts-info.sh] Writing visualization
27 changes: 17 additions & 10 deletions tests/profiler/simple-par.expect
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,43 @@
Total clock cycles: 3
=====SUMMARY=====

Group TOP.toplevel.main.par0 Summary:
[FSM] Group TOP.toplevel.main.par0 Summary:
Total cycles: 3
# of times active: 1
Avg runtime: 3.0

Group TOP.toplevel.main.write Summary:
[GT] Group TOP.toplevel.main.par0 Summary:
Total cycles: 2
# of times active: 1
Avg runtime: 2.0

[GT] Group TOP.toplevel.main.write Summary:
Total cycles: 1
# of times active: 1
Avg runtime: 1.0

=====DUMP=====

Group TOP.toplevel.main.par0:
[FSM] Group TOP.toplevel.main.par0:
FSM name: TOP.toplevel.main.fsm
FSM state ids: [0]
Total cycles: 3
# of times active: 1
Segments: [0, 3)

Group TOP.toplevel.main.write:
FSM name: None
FSM state ids: None
[GT] Group TOP.toplevel.main.par0:
Total cycles: 2
# of times active: 1
Segments: [0, 2)

[GT] Group TOP.toplevel.main.write:
Total cycles: 1
# of times active: 1
Segments: [0, 1)

Writing dump JSON to /home/ayaka/projects/calyx/tools/profiler/data//tmp/dump.json
Writing summary to STDOUT
name,total-cycles,times-active,avg
TOP.toplevel.main.par0,3,1,3.0
TOP.toplevel.main.par0[FSM],3,1,3.0
TOP.toplevel.main.par0,2,1,2.0
TOP.toplevel.main.write,1,1,1.0
TOTAL,3,-,-
[get-profile-counts-info.sh] Writing visualization to /home/ayaka/projects/calyx/tools/profiler/data//tmp/visual.json
[get-profile-counts-info.sh] Writing visualization
21 changes: 15 additions & 6 deletions tests/profiler/simple-seq.expect
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@
Total clock cycles: 2
=====SUMMARY=====

Group TOP.toplevel.main.write Summary:
[FSM] Group TOP.toplevel.main.write Summary:
Total cycles: 2
# of times active: 1
Avg runtime: 2.0

[GT] Group TOP.toplevel.main.write Summary:
Total cycles: 1
# of times active: 1
Avg runtime: 1.0

=====DUMP=====

Group TOP.toplevel.main.write:
[FSM] Group TOP.toplevel.main.write:
FSM name: TOP.toplevel.main.fsm
FSM state ids: [0]
Total cycles: 2
# of times active: 1
Segments: [0, 2)

Writing dump JSON to /home/ayaka/projects/calyx/tools/profiler/data//tmp/dump.json
Writing summary to STDOUT
[GT] Group TOP.toplevel.main.write:
Total cycles: 1
# of times active: 1
Segments: [0, 1)

name,total-cycles,times-active,avg
TOP.toplevel.main.write,2,1,2.0
TOP.toplevel.main.write[FSM],2,1,2.0
TOP.toplevel.main.write,1,1,1.0
TOTAL,2,-,-
[get-profile-counts-info.sh] Writing visualization to /home/ayaka/projects/calyx/tools/profiler/data//tmp/visual.json
[get-profile-counts-info.sh] Writing visualization
60 changes: 60 additions & 0 deletions tests/profiler/while-never-true.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[get-profile-counts-info.sh] Obtaining FSM info from TDCC
[get-profile-counts-info.sh] Obtaining cell information from component-cells backend
[get-profile-counts-info.sh] Obtaining VCD file via simulation
[get-profile-counts-info.sh] Using FSM info and VCD file to obtain cycle level counts
Total clock cycles: 2
=====SUMMARY=====

[FSM] Group TOP.toplevel.main.cond Summary:
Total cycles: 2
# of times active: 1
Avg runtime: 2.0

[GT] Group TOP.toplevel.main.cond Summary:
Total cycles: 1
# of times active: 1
Avg runtime: 1.0

[FSM] Group TOP.toplevel.main.incr Summary:
Total cycles: 0
# of times active: 0
Avg runtime: 0

[GT] Group TOP.toplevel.main.incr Summary:
Total cycles: 0
# of times active: 0
Avg runtime: 0

=====DUMP=====

[FSM] Group TOP.toplevel.main.cond:
FSM name: TOP.toplevel.main.fsm
FSM state ids: [0, 3]
Total cycles: 2
# of times active: 1
Segments: [0, 2)

[GT] Group TOP.toplevel.main.cond:
Total cycles: 1
# of times active: 1
Segments: [0, 1)

[FSM] Group TOP.toplevel.main.incr:
FSM name: TOP.toplevel.main.fsm
FSM state ids: [2, 1]
Total cycles: 0
# of times active: 0
Segments:

[GT] Group TOP.toplevel.main.incr:
Total cycles: 0
# of times active: 0
Segments:

name,total-cycles,times-active,avg
TOP.toplevel.main.cond[FSM],2,1,2.0
TOP.toplevel.main.cond,1,1,1.0
TOP.toplevel.main.incr[FSM],0,0,0
TOP.toplevel.main.incr,0,0,0
TOTAL,2,-,-
[get-profile-counts-info.sh] Writing visualization
28 changes: 0 additions & 28 deletions tools/component_groups/Cargo.toml

This file was deleted.

Loading

0 comments on commit e7d2d64

Please sign in to comment.