CIRCT 23.0.0git
Loading...
Searching...
No Matches
esi_ram.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 pycde
6from pycde import (AppID, Clock, Input, Module, generator)
7from pycde.esi import DeclareRandomAccessMemory, ServiceDecl
8from esiaccel.bsp import get_bsp
9from pycde.module import Metadata
10from pycde.types import Bits
11
12import sys
13
14RamI64x8 = DeclareRandomAccessMemory(Bits(64), 256)
15WriteType = RamI64x8.write.type.req
16
17
18@ServiceDecl
20 write = RamI64x8.write.type.inverted()
21 read = RamI64x8.read.type.inverted()
22
23
24class Dummy(Module):
25 """To test completely automated metadata collection."""
26
27 @generator
28 def construct(ports):
29 pass
30
31
32class MemWriter(Module):
33 """Write to address 3 the contents of address 2."""
34
35 metadata = Metadata(version="0.1", misc={"numWriters": 1, "style": "stupid"})
36
37 clk = Clock()
38 rst = Input(Bits(1))
39
40 @generator
41 def construct(ports):
42 read_bundle_type = RamI64x8.read.type
43 address = 2
44 (address_chan, ready) = read_bundle_type.address.wrap(address, True)
45 read_bundle = RamI64x8.read(AppID("int_reader"))
46 bundled_channels = read_bundle.unpack(address=address_chan)
47 data_chan = bundled_channels["data"]
48 read_data, read_valid = data_chan.unwrap(True)
49
50 write_bundle_type = RamI64x8.write.type
51 write_data, _ = write_bundle_type.req.wrap({
52 'data': read_data,
53 'address': 3
54 }, read_valid)
55 write_bundle = RamI64x8.write(appid=AppID("int_writer"))
56 write_bundle.unpack(req=write_data)
57
58
59def Top(xrt: bool):
60
61 class Top(Module):
62 clk = Clock()
63 rst = Input(Bits(1))
64
65 @generator
66 def construct(ports):
67 Dummy(appid=AppID("dummy"))
68 MemWriter(clk=ports.clk, rst=ports.rst, appid=AppID("mem_writer"))
69
70 # We don't have support for host--device channel communication on XRT yet.
71 if not xrt:
72 # Pass through reads and writes from the host.
73 ram_write_host = MemComms.write(AppID("write"))
74 ram_write = RamI64x8.write(AppID("ram_write"))
75 ram_write.connect(ram_write_host)
76
77 ram_read_host = MemComms.read(AppID("read"))
78 ram_read = RamI64x8.read(AppID("ram_read"))
79 ram_read.connect(ram_read_host)
80
81 # Instantiate the RAM.
82 RamI64x8.instantiate_builtin(appid=AppID("mem"),
83 builtin="sv_mem",
84 result_types=[],
85 inputs=[ports.clk, ports.rst])
86
87 return Top
88
89
90if __name__ == "__main__":
91 is_xrt = len(sys.argv) > 2 and sys.argv[2].startswith("xrt")
92 bsp = get_bsp(sys.argv[2] if len(sys.argv) > 2 else None)
93 s = pycde.System(bsp(Top(is_xrt)),
94 name="ESIMem",
95 output_directory=sys.argv[1])
96 s.compile()
97 s.package()
construct(ports)
Definition esi_ram.py:28
construct(ports)
Definition esi_ram.py:41
Top(bool xrt)
Definition esi_ram.py:59