Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kestrel Collaboration
Kestrel LiteX
migen
Commits
6fac3f02
Commit
6fac3f02
authored
12 years ago
by
Sebastien Bourdeauducq
Browse files
Options
Download
Email Patches
Plain Diff
examples/dataflow: structuring test
parent
7d0e179a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
10 deletions
+46
-10
examples/dataflow/structuring.py
examples/dataflow/structuring.py
+38
-0
migen/actorlib/structuring.py
migen/actorlib/structuring.py
+8
-10
No files found.
examples/dataflow/structuring.py
0 → 100644
View file @
6fac3f02
from
migen.flow.network
import
*
from
migen.actorlib
import
structuring
from
migen.actorlib.sim
import
*
from
migen.sim.generic
import
Simulator
from
migen.sim.icarus
import
Runner
pack_factor
=
5
def
source_gen
():
for
i
in
range
(
80
):
#print("==> " + str(i))
yield
Token
(
"source"
,
{
"value"
:
i
})
def
sink_gen
():
while
True
:
t
=
Token
(
"sink"
)
yield
t
print
(
t
.
value
[
"value"
])
def
main
():
base_layout
=
[(
"value"
,
BV
(
32
))]
source
=
ActorNode
(
SimActor
(
source_gen
(),
(
"source"
,
Source
,
base_layout
)))
packer
=
ActorNode
(
structuring
.
Pack
(
base_layout
,
pack_factor
))
unpacker
=
ActorNode
(
structuring
.
Unpack
(
pack_factor
,
base_layout
))
sink
=
ActorNode
(
SimActor
(
sink_gen
(),
(
"sink"
,
Sink
,
base_layout
)))
g
=
DataFlowGraph
()
g
.
add_connection
(
source
,
packer
)
g
.
add_connection
(
packer
,
unpacker
)
g
.
add_connection
(
unpacker
,
sink
)
comp
=
CompositeActor
(
g
)
fragment
=
comp
.
get_fragment
()
sim
=
Simulator
(
fragment
,
Runner
())
sim
.
run
(
100
)
main
()
This diff is collapsed.
Click to expand it.
migen/actorlib/structuring.py
View file @
6fac3f02
...
@@ -16,13 +16,14 @@ class Cast(CombinatorialActor):
...
@@ -16,13 +16,14 @@ class Cast(CombinatorialActor):
Cat
(
*
sigs_to
).
eq
(
Cat
(
*
sigs_from
))
Cat
(
*
sigs_to
).
eq
(
Cat
(
*
sigs_from
))
])
])
class
Chop
(
Actor
):
def
pack_layout
(
l
,
n
):
return
[(
"chunk{0}"
.
format
(
i
),
l
)
for
i
in
range
(
n
)]
class
Unpack
(
Actor
):
def
__init__
(
self
,
n
,
layout_to
):
def
__init__
(
self
,
n
,
layout_to
):
self
.
n
=
n
self
.
n
=
n
layout_from
=
[(
"chunk{0}"
.
format
(
i
),
layout_to
)
for
i
in
range
(
self
.
n
)]
super
().
__init__
(
super
().
__init__
(
(
"sink"
,
Sink
,
layout_
from
),
(
"sink"
,
Sink
,
pack_layout
(
layout_
to
,
n
)
),
(
"source"
,
Source
,
layout_to
))
(
"source"
,
Source
,
layout_to
))
def
get_fragment
(
self
):
def
get_fragment
(
self
):
...
@@ -43,21 +44,18 @@ class Chop(Actor):
...
@@ -43,21 +44,18 @@ class Chop(Actor):
)
)
)
)
]
]
cases
=
[(
Constant
(
i
,
BV
(
muxbits
)),
cases
=
[(
Constant
(
i
,
BV
(
muxbits
))
if
i
else
Default
()
,
Cat
(
*
self
.
token
(
"source"
).
flatten
()).
eq
(
*
self
.
token
(
"sink"
).
subrecord
(
"chunk{0}"
.
format
(
i
)).
flatten
()))
Cat
(
*
self
.
token
(
"source"
).
flatten
()).
eq
(
*
self
.
token
(
"sink"
).
subrecord
(
"chunk{0}"
.
format
(
i
)).
flatten
()))
for
i
in
range
(
self
.
n
)]
for
i
in
range
(
self
.
n
)]
cases
[
-
1
][
0
]
=
Default
()
comb
.
append
(
Case
(
mux
,
*
cases
))
comb
.
append
(
Case
(
mux
,
*
cases
))
return
Fragment
(
comb
,
sync
)
return
Fragment
(
comb
,
sync
)
class
Pack
(
Actor
):
class
Pack
(
Actor
):
def
__init__
(
self
,
layout_from
,
n
):
def
__init__
(
self
,
layout_from
,
n
):
self
.
n
=
n
self
.
n
=
n
layout_to
=
[(
"chunk{0}"
.
format
(
i
),
layout_from
)
for
i
in
range
(
self
.
n
)]
super
().
__init__
(
super
().
__init__
(
(
"sink"
,
Sink
,
layout_from
),
(
"sink"
,
Sink
,
layout_from
),
(
"source"
,
Source
,
layout
_to
))
(
"source"
,
Source
,
pack_
layout
(
layout_from
,
n
)
))
def
get_fragment
(
self
):
def
get_fragment
(
self
):
demuxbits
=
bits_for
(
self
.
n
-
1
)
demuxbits
=
bits_for
(
self
.
n
-
1
)
...
@@ -66,7 +64,7 @@ class Pack(Actor):
...
@@ -66,7 +64,7 @@ class Pack(Actor):
load_part
=
Signal
()
load_part
=
Signal
()
strobe_all
=
Signal
()
strobe_all
=
Signal
()
cases
=
[(
Constant
(
i
,
BV
(
demuxbits
)),
cases
=
[(
Constant
(
i
,
BV
(
demuxbits
)),
Cat
(
*
self
.
token
(
"source"
).
subrecord
(
"chunk{0}"
.
format
(
i
)).
flatten
()).
eq
(
*
self
.
token
(
"sink"
).
flatten
())
Cat
(
*
self
.
token
(
"source"
).
subrecord
(
"chunk{0}"
.
format
(
i
)).
flatten
()).
eq
(
*
self
.
token
(
"sink"
).
flatten
())
)
for
i
in
range
(
self
.
n
)]
for
i
in
range
(
self
.
n
)]
comb
=
[
comb
=
[
self
.
endpoints
[
"sink"
].
ack
.
eq
(
~
strobe_all
|
self
.
endpoints
[
"source"
].
ack
),
self
.
endpoints
[
"sink"
].
ack
.
eq
(
~
strobe_all
|
self
.
endpoints
[
"source"
].
ack
),
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment