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