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
Commits
169a2bbe
Commit
169a2bbe
authored
5 years ago
by
Rasmus Karlsson
Browse files
Options
Downloads
Patches
Plain Diff
Wrote hella lot of tests
parent
be79d84a
No related branches found
No related tags found
1 merge request
!34
Resolve "Operation Splitting"
Pipeline
#14095
passed
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/signal_flow_graph.py
+2
-2
2 additions, 2 deletions
b_asic/signal_flow_graph.py
test/test_signal_flow_graph.py
+194
-1
194 additions, 1 deletion
test/test_signal_flow_graph.py
with
196 additions
and
3 deletions
b_asic/signal_flow_graph.py
+
2
−
2
View file @
169a2bbe
...
@@ -242,14 +242,14 @@ class SFG(AbstractOperation):
...
@@ -242,14 +242,14 @@ class SFG(AbstractOperation):
return
ops
# Need any checking before returning?
return
ops
# Need any checking before returning?
def
replace_self
(
self
):
def
replace_self
(
self
)
->
None
:
"""
Iterates over the SFG
'
s (self) Input- and OutputSignals to reconnect them to each necessary operation inside the SFG,
"""
Iterates over the SFG
'
s (self) Input- and OutputSignals to reconnect them to each necessary operation inside the SFG,
so that the inner operations of the SFG can function on their own, effectively replacing the SFG.
"""
so that the inner operations of the SFG can function on their own, effectively replacing the SFG.
"""
assert
len
(
self
.
inputs
)
==
len
(
self
.
input_operations
),
"
Number of inputs does not match the number of input_operations in SFG.
"
assert
len
(
self
.
inputs
)
==
len
(
self
.
input_operations
),
"
Number of inputs does not match the number of input_operations in SFG.
"
assert
len
(
self
.
outputs
)
==
len
(
self
.
output_operations
),
"
Number of outputs does not match the number of output_operations SFG.
"
assert
len
(
self
.
outputs
)
==
len
(
self
.
output_operations
),
"
Number of outputs does not match the number of output_operations SFG.
"
#
Add check so it does not Split the SFG if
not a component of a
larg
er SFG
#
Does this function need a check for if the user wants call this on an SFG which is
not a component of a
noth
er SFG
# For each input_signal, connect it to the corresponding operation
# For each input_signal, connect it to the corresponding operation
for
port
,
input_operation
in
zip
(
self
.
inputs
,
self
.
input_operations
):
for
port
,
input_operation
in
zip
(
self
.
inputs
,
self
.
input_operations
):
...
...
This diff is collapsed.
Click to expand it.
test/test_signal_flow_graph.py
+
194
−
1
View file @
169a2bbe
import
pytest
import
pytest
from
b_asic
import
SFG
,
Signal
,
Input
,
Output
,
Constant
,
Addition
,
Multiplication
from
b_asic
import
SFG
,
Signal
,
Input
,
Output
,
Constant
,
Addition
,
Multiplication
,
Subtraction
class
TestConstructor
:
class
TestConstructor
:
...
@@ -147,3 +147,196 @@ class TestComponents:
...
@@ -147,3 +147,196 @@ class TestComponents:
mac_sfg
=
SFG
(
inputs
=
[
inp1
,
inp2
],
outputs
=
[
out1
],
name
=
"
mac_sfg
"
)
mac_sfg
=
SFG
(
inputs
=
[
inp1
,
inp2
],
outputs
=
[
out1
],
name
=
"
mac_sfg
"
)
assert
set
([
comp
.
name
for
comp
in
mac_sfg
.
components
])
==
{
"
INP1
"
,
"
INP2
"
,
"
INP3
"
,
"
ADD1
"
,
"
ADD2
"
,
"
MUL1
"
,
"
OUT1
"
,
"
S1
"
,
"
S2
"
,
"
S3
"
,
"
S4
"
,
"
S5
"
,
"
S6
"
,
"
S7
"
}
assert
set
([
comp
.
name
for
comp
in
mac_sfg
.
components
])
==
{
"
INP1
"
,
"
INP2
"
,
"
INP3
"
,
"
ADD1
"
,
"
ADD2
"
,
"
MUL1
"
,
"
OUT1
"
,
"
S1
"
,
"
S2
"
,
"
S3
"
,
"
S4
"
,
"
S5
"
,
"
S6
"
,
"
S7
"
}
class
TestReplaceSelfSoloComp
:
def
test_replace_self_mac
(
self
):
"""
Replace a MAC with inner components in an SFG
"""
inp1
=
Input
(
"
INP1
"
)
inp2
=
Input
(
"
INP2
"
)
inp3
=
Input
(
"
INP3
"
)
add1
=
Addition
(
None
,
None
,
"
ADD1
"
)
add2
=
Addition
(
None
,
None
,
"
ADD2
"
)
mul1
=
Multiplication
(
None
,
None
,
"
MUL1
"
)
out1
=
Output
(
None
,
"
OUT1
"
)
add1
.
input
(
0
).
connect
(
inp1
,
"
S1
"
)
add1
.
input
(
1
).
connect
(
inp2
,
"
S2
"
)
add2
.
input
(
0
).
connect
(
add1
,
"
S3
"
)
add2
.
input
(
1
).
connect
(
inp3
,
"
S4
"
)
mul1
.
input
(
0
).
connect
(
add1
,
"
S5
"
)
mul1
.
input
(
1
).
connect
(
add2
,
"
S6
"
)
out1
.
input
(
0
).
connect
(
mul1
,
"
S7
"
)
mac_sfg
=
SFG
(
inputs
=
[
inp1
,
inp2
],
outputs
=
[
out1
])
inp4
=
Input
(
"
INP4
"
)
inp5
=
Input
(
"
INP5
"
)
out2
=
Output
(
None
,
"
OUT2
"
)
mac_sfg
.
inputs
[
0
].
connect
(
inp4
,
"
S8
"
)
mac_sfg
.
inputs
[
1
].
connect
(
inp5
,
"
S9
"
)
out2
.
input
(
0
).
connect
(
mac_sfg
.
outputs
[
0
],
"
S10
"
)
test_sfg
=
SFG
(
inputs
=
[
inp4
,
inp5
],
outputs
=
[
out2
])
assert
test_sfg
.
evaluate
(
1
,
2
)
==
9
mac_sfg
.
replace_self
()
assert
test_sfg
.
evaluate
(
1
,
2
)
==
9
def
test_replace_self_operation_tree
(
self
,
operation_tree
):
"""
Replaces an SFG with only a operation_tree component with its inner components
"""
sfg1
=
SFG
(
outputs
=
[
Output
(
operation_tree
)])
out1
=
Output
(
None
,
"
OUT1
"
)
out1
.
input
(
0
).
connect
(
sfg1
.
outputs
[
0
],
"
S1
"
)
test_sfg
=
SFG
(
outputs
=
[
out1
])
assert
test_sfg
.
evaluate_output
(
0
,
[])
==
5
sfg1
.
replace_self
()
assert
test_sfg
.
evaluate_output
(
0
,
[])
==
5
def
test_replace_self_large_operation_tree
(
self
,
large_operation_tree
):
"""
Replaces an SFG with only a large_operation_tree component with its inner components
"""
sfg1
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
out1
=
Output
(
None
,
"
OUT1
"
)
out1
.
input
(
0
).
connect
(
sfg1
.
outputs
[
0
],
"
S1
"
)
test_sfg
=
SFG
(
outputs
=
[
out1
])
assert
test_sfg
.
evaluate_output
(
0
,
[])
==
14
sfg1
.
replace_self
()
assert
test_sfg
.
evaluate_output
(
0
,
[])
==
14
class
TestReplaceSelfMultipleComp
:
def
test_replace_self_operation_tree
(
self
,
operation_tree
):
"""
Replaces a operation_tree in an SFG with other components
"""
sfg1
=
SFG
(
outputs
=
[
Output
(
operation_tree
)])
inp1
=
Input
(
"
INP1
"
)
inp2
=
Input
(
"
INP2
"
)
out1
=
Output
(
None
,
"
OUT1
"
)
add1
=
Addition
(
None
,
None
,
"
ADD1
"
)
add2
=
Addition
(
None
,
None
,
"
ADD2
"
)
add1
.
input
(
0
).
connect
(
inp1
,
"
S1
"
)
add1
.
input
(
1
).
connect
(
inp2
,
"
S2
"
)
add2
.
input
(
0
).
connect
(
add1
,
"
S3
"
)
add2
.
input
(
1
).
connect
(
sfg1
.
outputs
[
0
],
"
S4
"
)
out1
.
input
(
0
).
connect
(
add2
,
"
S5
"
)
test_sfg
=
SFG
(
inputs
=
[
inp1
,
inp2
],
outputs
=
[
out1
])
assert
test_sfg
.
evaluate
(
1
,
2
)
==
8
sfg1
.
replace_self
()
assert
test_sfg
.
evaluate
(
1
,
2
)
==
8
def
test_replace_self_large_operation_tree
(
self
,
large_operation_tree
):
"""
Replaces a large_operation_tree in an SFG with other components
"""
sfg1
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
inp1
=
Input
(
"
INP1
"
)
inp2
=
Input
(
"
INP2
"
)
out1
=
Output
(
None
,
"
OUT1
"
)
add1
=
Addition
(
None
,
None
,
"
ADD1
"
)
add2
=
Addition
(
None
,
None
,
"
ADD2
"
)
add1
.
input
(
0
).
connect
(
inp1
,
"
S1
"
)
add1
.
input
(
1
).
connect
(
inp2
,
"
S2
"
)
add2
.
input
(
0
).
connect
(
add1
,
"
S3
"
)
add2
.
input
(
1
).
connect
(
sfg1
.
outputs
[
0
],
"
S4
"
)
out1
.
input
(
0
).
connect
(
add2
,
"
S5
"
)
test_sfg
=
SFG
(
inputs
=
[
inp1
,
inp2
],
outputs
=
[
out1
])
assert
test_sfg
.
evaluate
(
1
,
2
)
==
17
sfg1
.
replace_self
()
assert
test_sfg
.
evaluate
(
1
,
2
)
==
17
def
create_sfg
(
self
,
op_tree
):
"""
Create a simple SFG with either operation_tree or large_operation_tree
"""
sfg1
=
SFG
(
outputs
=
[
Output
(
op_tree
)])
inp1
=
Input
(
"
INP1
"
)
inp2
=
Input
(
"
INP2
"
)
out1
=
Output
(
None
,
"
OUT1
"
)
add1
=
Addition
(
None
,
None
,
"
ADD1
"
)
add2
=
Addition
(
None
,
None
,
"
ADD2
"
)
add1
.
input
(
0
).
connect
(
inp1
,
"
S1
"
)
add1
.
input
(
1
).
connect
(
inp2
,
"
S2
"
)
add2
.
input
(
0
).
connect
(
add1
,
"
S3
"
)
add2
.
input
(
1
).
connect
(
sfg1
.
outputs
[
0
],
"
S4
"
)
out1
.
input
(
0
).
connect
(
add2
,
"
S5
"
)
return
SFG
(
inputs
=
[
inp1
,
inp2
],
outputs
=
[
out1
])
def
test_replace_self_many_op
(
self
,
large_operation_tree
):
"""
Replaces an sfg component in a larger SFG with several component operations
"""
inp1
=
Input
(
"
INP1
"
)
inp2
=
Input
(
"
INP2
"
)
inp3
=
Input
(
"
INP3
"
)
inp4
=
Input
(
"
INP4
"
)
out1
=
Output
(
None
,
"
OUT1
"
)
add1
=
Addition
(
None
,
None
,
"
ADD1
"
)
sub1
=
Subtraction
(
None
,
None
,
"
SUB1
"
)
add1
.
input
(
0
).
connect
(
inp1
,
"
S1
"
)
add1
.
input
(
1
).
connect
(
inp2
,
"
S2
"
)
sfg1
=
self
.
create_sfg
(
large_operation_tree
)
sfg1
.
inputs
[
0
].
connect
(
add1
,
"
S3
"
)
sfg1
.
inputs
[
1
].
connect
(
inp3
,
"
S4
"
)
sub1
.
input
(
0
).
connect
(
sfg1
.
outputs
[
0
],
"
S5
"
)
sub1
.
input
(
1
).
connect
(
inp4
,
"
S6
"
)
out1
.
input
(
0
).
connect
(
sub1
,
"
S7
"
)
test_sfg
=
SFG
(
inputs
=
[
inp1
,
inp2
,
inp3
,
inp4
],
outputs
=
[
out1
])
assert
test_sfg
.
evaluate
(
1
,
2
,
3
,
4
)
==
16
sfg1
.
replace_self
()
assert
test_sfg
.
evaluate
(
1
,
2
,
3
,
4
)
==
16
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment