88 engines = (OneItemBuffersToHost, OneItemBuffersFromHost)
89 channel_service = ChannelEngineService(*engines)
90 with pytest.raises(ValueError, match=
"dma_engine_pair and channel_service"):
91 CosimBSP(Top, dma_engine_pair=engines, channel_service=channel_service)
95 """An engine with a `hostmem_read_list` port gets a burst-read connection
96 to HostMem: the design compiles only if the service wires that port."""
97 from pycde
import (Clock, Input, InputChannel, OutputChannel, Reset, System,
99 from pycde.types
import Bits, Bundle, BundledChannel, Channel, ChannelDirection
102 read_list_type = Bundle([
103 BundledChannel(
"req", ChannelDirection.FROM,
104 esi.HostMem.read_req_burst_type(16)),
105 BundledChannel(
"resp", ChannelDirection.TO,
106 esi.HostMem.read_window(word, 1)),
109 def to_host(client_type):
111 class ToHost(esi.EngineModule):
115 return "ReadListTestToHost"
119 input_channel = InputChannel(client_type)
127 def from_host(client_type):
129 class FromHost(esi.EngineModule):
133 return "ReadListTestFromHost"
137 hostmem_read_list =
Input(read_list_type)
138 output_channel = OutputChannel(client_type)
143 req_type = esi.HostMem.read_req_burst_type(16)
144 req, _ = Channel(req_type).
wrap(
151 resp = ports.hostmem_read_list.unpack(req=req)[
"resp"]
152 ports.output_channel = resp.transform(
153 lambda w: w.unwrap()[
"data"][0].bitcast(client_type))
163 words = esi.ChannelService.from_host(
esi.AppID(
"words"), word)
164 esi.ChannelService.to_host(
esi.AppID(
"echo"), words)
166 bsp = CosimBSP(Top, channel_service=ChannelEngineService(to_host, from_host))
167 System(bsp, output_directory=str(tmp_path)).compile()
170@pytest.mark.parametrize("max_outstanding", [1, 2, 64])
171@pytest.mark.parametrize("word_bits", [8, 64, 256, 512, 2048, 4096])
172@pytest.mark.parametrize("round_read_lengths", [False, True])
175 """Build and compile `HostMemReadReqSplitter` for a range of word widths
176 and outstanding-request limits (no simulation)."""
177 from pycde
import Clock, Input, Module, Output, Reset, System, generator
178 from pycde.types
import Bits, Channel, StructType, UInt
181 StructType([(
"address", UInt(64)), (
"length", UInt(32)),
184 StructType([(
"tag", UInt(8)), (
"data", Bits(word_bits)),
186 splitter = HostMemReadReqSplitter(req_t, resp_t, max(256, word_bits // 8),
187 max_outstanding, round_read_lengths)
192 req_in =
Input(req_t)
193 resp_in =
Input(resp_t)
195 resp_out =
Output(splitter.resp_out.type)
199 s = splitter(clk=ports.clk,
202 resp_in=ports.resp_in)
203 ports.req_out = s.req_out
204 ports.resp_out = s.resp_out
206 System(Top, output_directory=str(tmp_path)).compile()
210 from pycde.types
import Bits, Channel, StructType, UInt
212 StructType([(
"address", UInt(64)), (
"length", UInt(32)),
215 StructType([(
"tag", UInt(8)), (
"data", Bits(64)), (
"last", Bits(1))]))
216 with pytest.raises(AssertionError):
217 HostMemReadReqSplitter(req_t, resp_t, 256, 0)
220@pytest.mark.parametrize("builder", [CosimBSP, CosimBSP_DMA])
221@pytest.mark.parametrize("width", [True, 64.0, "64", 0, -8, 1, 4, 7, 24, 72])
239 channel_hostmem = cosim.ChannelHostMem
242 def capture(**kwargs):
243 configurations.append(kwargs)
244 return channel_hostmem(**kwargs)
246 monkeypatch.setattr(cosim,
"ChannelHostMem", capture)
247 builder(Top, **({
"hostmem_width": width}
if width
is not None else {}))
248 expected = width
if width
is not None else 64
249 assert configurations == [{
250 "read_width": expected,
251 "write_width": expected,
252 "max_read_request_bytes": max(256, expected // 8),
253 "max_write_payload_bytes": max(256, expected // 8),
254 "max_outstanding_reads": 4,
255 "round_read_lengths":
False,
259@pytest.mark.parametrize("width", [8, 64, 256, 512, 2048, 4096])
261 from pycde
import Clock, Input, Output, Reset, System, generator
263 gearbox = TaggedWriteGearbox(width * 3 + 13, width, max(256, width // 8))
268 req =
Input(gearbox.in_.type)
269 resp =
Output(gearbox.out.type)
273 ports.resp = gearbox(clk=ports.clk, rst=ports.rst, in_=ports.req).out
275 System(Top, output_directory=str(tmp_path)).compile()