22def _run(conn: AcceleratorConnection, bus_width: int):
24 hostmem = conn.get_service_hostmem()
26 acc = conn.build_accelerator()
29 for width
in [13, bus_width, bus_width + 24, bus_width * 2 + 24, 16384]:
30 dut = acc.children[esiaccel.AppID(
"wr", width)]
32 dut.ports[esiaccel.AppID(name)]
for name
in (
"req",
"ack",
"gate")
34 for port
in (req, ack, gate):
36 size = (width + 7) // 8
39 mem = hostmem.allocate(size + 16)
40 allocations.append(mem)
41 ctypes.memset(mem.ptr, 0xA5, size + 16)
42 data = bytes((j * 37 + 11 + i) & 0xFF
for j
in range(size))
43 value = int.from_bytes(data,
"little") & ((1 << width) - 1)
44 data = value.to_bytes(size,
"little")
45 req.write({
"address": mem.ptr + 3,
"tag": 0,
"data": data})
46 expected.append((mem, data))
47 writers.append((ack, gate, expected))
52 for _, gate, _
in writers:
54 for ack, _, expected
in writers:
55 for mem, data
in expected:
56 ack.read().result(timeout=30)
57 assert ctypes.string_at(mem.ptr,
58 len(data) + 16) == (b
"\xA5" * 3 + data +
61 req = acc.ports[esiaccel.AppID(
"list_req")]
62 ack = acc.ports[esiaccel.AppID(
"list_ack")]
65 for count
in [1, 7, 100]:
66 mem = hostmem.allocate(count * 3 + 16)
67 allocations.append(mem)
68 ctypes.memset(mem.ptr, 0xA5, count * 3 + 16)
69 data = bytes((i * 29 + 7) & 0xFF
for i
in range(count * 3))
70 for i
in range(count):
72 "address": mem.ptr + 3,
73 "data": data[i * 3:i * 3 + 3],
74 "last": int(i == count - 1),
76 for _
in range(count):
77 ack.read().result(timeout=30)
78 assert ctypes.string_at(mem.ptr, count * 3 + 16) == (b
"\xA5" * 3 + data +
81 req = acc.ports[esiaccel.AppID(
"probe_req")]
82 resp = acc.ports[esiaccel.AppID(
"probe_resp")]
85 data = bytes((i * 13 + 3) & 0xFF
for i
in range(2048))
86 req.write({
"address": 19,
"tag": 17,
"data": data})
87 beat_bytes = bus_width // 8
88 cap = max(256, beat_bytes)
89 for offset
in range(0, len(data), beat_bytes):
90 beat = resp.read().result(timeout=30)
91 assert _int(beat[
"address"]) == 19 + offset
92 assert _int(beat[
"tag"]) == 17
93 assert _int(beat[
"valid_bytes"]) == beat_bytes
94 assert _int(beat[
"data"]) == int.from_bytes(
95 data[offset:offset + beat_bytes],
"little")
96 assert _int(beat[
"last"]) == int((offset + beat_bytes) % cap == 0)
99@cosim_test(HW_DIR / "hostmem_write.py", args=("{tmp_dir}",))