CIRCT 23.0.0git
Loading...
Searching...
No Matches
esi_advanced.py
Go to the documentation of this file.
1# REQUIRES: esi-runtime, esi-cosim, rtl-sim
2# RUN: rm -rf %t
3# RUN: mkdir %t && cd %t
4# RUN: %PYTHON% %s %t 2>&1
5# RUN: esi-cosim.py -- %PYTHON% %S/test_software/esi_advanced.py cosim env
6
7import sys
8
9from pycde import generator, Clock, Module, Reset, System
10from pycde.bsp import get_bsp
11from pycde.common import InputChannel, OutputChannel, Output
12from pycde.types import Bits, UInt
13from pycde import esi
14
15
16class Merge(Module):
17 clk = Clock()
18 rst = Reset()
19 a = InputChannel(UInt(8))
20 b = InputChannel(UInt(8))
21
22 x = OutputChannel(UInt(8))
23
24 @generator
25 def build(ports):
26 chan = ports.a.type.merge(ports.a, ports.b)
27 ports.x = chan
28
29
30class Join(Module):
31 clk = Clock()
32 rst = Reset()
33 a = InputChannel(UInt(8))
34 b = InputChannel(UInt(8))
35
36 x = OutputChannel(UInt(9))
37
38 @generator
39 def build(ports):
40 joined = ports.a.type.join(ports.a, ports.b)
41 ports.x = joined.transform(lambda x: x.a + x.b)
42
43
44class Fork(Module):
45 clk = Clock()
46 rst = Reset()
47 a = InputChannel(UInt(8))
48
49 x = OutputChannel(UInt(8))
50 y = OutputChannel(UInt(8))
51
52 @generator
53 def build(ports):
54 x, y = ports.a.fork(ports.clk, ports.rst)
55 ports.x = x
56 ports.y = y
57
58
59class Top(Module):
60 clk = Clock()
61 rst = Reset()
62
63 @generator
64 def build(ports):
65 clk = ports.clk
66 rst = ports.rst
67 merge_a = esi.ChannelService.from_host(esi.AppID("merge_a"),
68 UInt(8)).buffer(clk, rst, 1)
69 merge_b = esi.ChannelService.from_host(esi.AppID("merge_b"),
70 UInt(8)).buffer(clk, rst, 1)
71 merge = Merge("merge_i8",
72 clk=ports.clk,
73 rst=ports.rst,
74 a=merge_a,
75 b=merge_b)
76 esi.ChannelService.to_host(esi.AppID("merge_x"),
77 merge.x.buffer(clk, rst, 1))
78
79 join_a = esi.ChannelService.from_host(esi.AppID("join_a"),
80 UInt(8)).buffer(clk, rst, 1)
81 join_b = esi.ChannelService.from_host(esi.AppID("join_b"),
82 UInt(8)).buffer(clk, rst, 1)
83 join = Join("join_i8", clk=ports.clk, rst=ports.rst, a=join_a, b=join_b)
84 esi.ChannelService.to_host(
85 esi.AppID("join_x"),
86 join.x.buffer(clk, rst, 1).transform(lambda x: x.as_uint(16)))
87
88 fork_a = esi.ChannelService.from_host(esi.AppID("fork_a"),
89 UInt(8)).buffer(clk, rst, 1)
90 fork = Fork("fork_i8", clk=ports.clk, rst=ports.rst, a=fork_a)
91 esi.ChannelService.to_host(esi.AppID("fork_x"), fork.x.buffer(clk, rst, 1))
92 esi.ChannelService.to_host(esi.AppID("fork_y"), fork.y.buffer(clk, rst, 1))
93
94
95if __name__ == "__main__":
96 bsp = get_bsp(sys.argv[2] if len(sys.argv) > 2 else None)
97 s = System(bsp(Top), name="ESIAdvanced", output_directory=sys.argv[1])
98 s.generate()
99 s.run_passes()
100 s.compile()
101 s.package()