Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
B-ASIC - Better ASIC Toolbox
Merge requests
!376
Add folding example
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add folding example
folding
into
master
Overview
0
Commits
1
Pipelines
1
Changes
1
Merged
Oscar Gustafsson
requested to merge
folding
into
master
2 years ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
02273d4a
1 commit,
2 years ago
1 file
+
126
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
examples/folding_example_with_architecture.py
0 → 100644
+
126
−
0
Options
"""
=======================
Comparison with folding
=======================
This is a common example when illustrating folding.
In general, the main problem with folding is to determine a suitable folding order. This
corresponds to scheduling the operations.
Here, the folding order is the same for the adders as in the standard solution to this
problem, but the order of the multipliers is different to keep each memory variable
shorter than the scheduling period.
"""
from
b_asic.architecture
import
Architecture
,
Memory
,
ProcessingElement
from
b_asic.core_operations
import
Addition
,
ConstantMultiplication
from
b_asic.schedule
import
Schedule
from
b_asic.signal_flow_graph
import
SFG
from
b_asic.special_operations
import
Delay
,
Input
,
Output
in1
=
Input
(
"
IN
"
)
T1
=
Delay
()
T2
=
Delay
(
T1
)
a
=
ConstantMultiplication
(
0.2
,
T1
,
"
a
"
)
b
=
ConstantMultiplication
(
0.3
,
T1
,
"
b
"
)
c
=
ConstantMultiplication
(
0.4
,
T2
,
"
c
"
)
d
=
ConstantMultiplication
(
0.6
,
T2
,
"
d
"
)
add2
=
a
+
c
add1
=
in1
+
add2
add3
=
b
+
d
T1
<<
add1
out1
=
Output
(
add1
+
add3
,
"
OUT
"
)
sfg
=
SFG
(
inputs
=
[
in1
],
outputs
=
[
out1
],
name
=
"
Bi-quad folding example
"
)
# %%
# Set latencies and execution times
sfg
.
set_latency_of_type
(
ConstantMultiplication
.
type_name
(),
2
)
sfg
.
set_latency_of_type
(
Addition
.
type_name
(),
1
)
sfg
.
set_execution_time_of_type
(
ConstantMultiplication
.
type_name
(),
1
)
sfg
.
set_execution_time_of_type
(
Addition
.
type_name
(),
1
)
# %%
# Create schedule
schedule
=
Schedule
(
sfg
,
cyclic
=
True
)
schedule
.
show
(
title
=
'
Original schedule
'
)
# %%
# Reschedule to only require one adder and one multiplier
schedule
.
move_operation
(
'
out1
'
,
2
)
schedule
.
move_operation
(
'
add3
'
,
2
)
schedule
.
move_operation
(
'
cmul3
'
,
-
3
)
schedule
.
move_operation
(
'
add4
'
,
3
)
schedule
.
move_operation
(
'
cmul2
'
,
-
3
)
schedule
.
set_schedule_time
(
4
)
schedule
.
move_operation
(
'
cmul2
'
,
1
)
schedule
.
move_operation
(
'
cmul1
'
,
1
)
schedule
.
move_operation
(
'
in1
'
,
3
)
schedule
.
move_operation
(
'
cmul3
'
,
-
1
)
schedule
.
move_operation
(
'
cmul1
'
,
1
)
schedule
.
show
(
title
=
'
Improved schedule
'
)
# %%
# Extract operations and create processing elements
operations
=
schedule
.
get_operations
()
adders
=
operations
.
get_by_type_name
(
'
add
'
)
adders
.
show
(
title
=
"
Adder executions
"
)
mults
=
operations
.
get_by_type_name
(
'
cmul
'
)
mults
.
show
(
title
=
"
Multiplier executions
"
)
inputs
=
operations
.
get_by_type_name
(
'
in
'
)
inputs
.
show
(
title
=
"
Input executions
"
)
outputs
=
operations
.
get_by_type_name
(
'
out
'
)
outputs
.
show
(
title
=
"
Output executions
"
)
p1
=
ProcessingElement
(
adders
,
entity_name
=
"
adder
"
)
p2
=
ProcessingElement
(
mults
,
entity_name
=
"
cmul
"
)
p_in
=
ProcessingElement
(
inputs
,
entity_name
=
'
input
'
)
p_out
=
ProcessingElement
(
outputs
,
entity_name
=
'
output
'
)
# %%
# Extract and assign memory variables
mem_vars
=
schedule
.
get_memory_variables
()
mem_vars
.
show
(
title
=
"
All memory variables
"
)
direct
,
mem_vars
=
mem_vars
.
split_on_length
()
mem_vars
.
show
(
title
=
"
Non-zero time memory variables
"
)
mem_vars_set
=
mem_vars
.
split_on_ports
(
read_ports
=
1
,
write_ports
=
1
,
total_ports
=
2
)
memories
=
[]
for
i
,
mem
in
enumerate
(
mem_vars_set
):
memory
=
Memory
(
mem
,
memory_type
=
"
RAM
"
,
entity_name
=
f
"
memory
{
i
}
"
)
memories
.
append
(
memory
)
mem
.
show
(
title
=
f
"
{
memory
.
entity_name
}
"
)
memory
.
assign
(
"
left_edge
"
)
memory
.
show_content
(
title
=
f
"
Assigned
{
memory
.
entity_name
}
"
)
direct
.
show
(
title
=
"
Direct interconnects
"
)
# %%
# Create architecture
arch
=
Architecture
({
p1
,
p2
,
p_in
,
p_out
},
memories
,
direct_interconnects
=
direct
)
# %%
# The architecture can be rendered in enriched shells.
#
# .. graphviz::
#
# digraph {
# node [shape=record]
# memory0 [label="{{<in0> in0}|memory0|{<out0> out0}}"]
# memory1 [label="{{<in0> in0}|memory1|{<out0> out0}}"]
# output [label="{{<in0> in0}|output}"]
# adder [label="{{<in0> in0|<in1> in1}|adder|{<out0> out0}}"]
# input [label="{input|{<out0> out0}}"]
# cmul [label="{{<in0> in0}|cmul|{<out0> out0}}"]
# memory1:out0 -> adder:in1 [label=2]
# cmul:out0 -> adder:in0 [label=2]
# memory0:out0 -> cmul:in0 [label=4]
# adder:out0 -> output:in0 [label=1]
# input:out0 -> adder:in0 [label=1]
# adder:out0 -> memory0:in0 [label=1]
# adder:out0 -> adder:in1 [label=2]
# memory0:out0 -> adder:in0 [label=1]
# cmul:out0 -> memory1:in0 [label=2]
# }
Loading