Skip to content

Commit b855b54

Browse files
committed
fix(gen_bd): unify ddr and hbm bd and update parsers for ungrouped pipeline
1 parent 13d61f7 commit b855b54

6 files changed

+557
-496
lines changed

gen_vivado_bd.py

+99-83
Original file line numberDiff line numberDiff line change
@@ -33,78 +33,58 @@
3333
)
3434

3535

36-
def dut_mmap_tcl(
36+
def dut_hbm_mmap_tcl(
3737
mmap_ports: dict[str, dict[str, int]],
38-
hbm: bool,
3938
hbm_init_file: str,
4039
) -> list[str]:
41-
"""Adds DUT's MMAP ports related tcl commands to the block design.
40+
"""Adds DUT's HBM-MMAP related tcl commands to the block design.
4241
4342
Returns a list of tcl commands.
4443
"""
4544
tcl = []
46-
if hbm:
47-
num_hbm_nmu = sum(1 for v in mmap_ports.values() if v.get("noc") is None)
48-
tcl += [
49-
f"""
45+
num_hbm_nmu = sum(1 for v in mmap_ports.values() if v.get("noc") is None)
46+
tcl += [
47+
f"""
5048
startgroup
5149
5250
set_property -dict [list \
5351
CONFIG.NUM_HBM_BLI {{{num_hbm_nmu}}} \
54-
CONFIG.NUM_SI {{{8 + len(mmap_ports) - num_hbm_nmu}}} \
55-
CONFIG.NUM_CLKS {{9}} \
52+
CONFIG.NUM_SI {{{len(mmap_ports) - num_hbm_nmu}}} \
53+
CONFIG.NUM_CLKS {{1}} \
5654
CONFIG.HBM_MEM_BACKDOOR_WRITE {{true}} \
5755
CONFIG.HBM_MEM_INIT_FILE {{{hbm_init_file}}} \
5856
] $axi_noc_dut
5957
"""
60-
]
58+
]
6159

62-
# counters for each HBM PC to balance the usage of the HBM ports
63-
# initialize with CIPS connections
64-
def get_hbm_noc_port(bank: int) -> str:
65-
# bank 0 = HBM PC 0 port 0 = port_idx 0
66-
# bank 0 = HBM PC 0 port 1 = port_idx 1
67-
# bank 1 = HBM PC 1 port 0 = port_idx 2
68-
# bank 1 = HBM PC 1 port 1 = port_idx 3
69-
port_idx = bank % 2 * 2 + hbm_bank_cnt[bank] % 2
70-
# Note: hbm_bank_cnt is STATIC!
71-
hbm_bank_cnt[bank] += 1
72-
return f"HBM{bank // 2}_PORT{port_idx}"
73-
74-
hbm_bank_cnt = {i: 1 for i in range(32)}
75-
else:
76-
tcl += [
77-
f"""
78-
# Create mmap noc
79-
startgroup
80-
set axi_noc_dut [ create_bd_cell -type ip -vlnv xilinx.com:ip:axi_noc:1.1 axi_noc_dut ]
60+
# counters for each HBM PC to balance the usage of the HBM ports
61+
# initialize with CIPS connections
62+
def get_hbm_noc_port(bank: int) -> str:
63+
# bank 0 = HBM PC 0 port 0 = port_idx 0
64+
# bank 0 = HBM PC 0 port 1 = port_idx 1
65+
# bank 1 = HBM PC 1 port 0 = port_idx 2
66+
# bank 1 = HBM PC 1 port 1 = port_idx 3
67+
port_idx = bank % 2 * 2 + hbm_bank_cnt[bank] % 2
68+
# Note: hbm_bank_cnt is STATIC!
69+
hbm_bank_cnt[bank] += 1
70+
return f"HBM{bank // 2}_PORT{port_idx}"
8171

82-
set_property -dict [list \
83-
CONFIG.NUM_CLKS {{1}} \
84-
CONFIG.NUM_MI {{0}} \
85-
CONFIG.NUM_NMI {{1}} \
86-
CONFIG.NUM_NSI {{0}} \
87-
CONFIG.NUM_SI {{{len(mmap_ports)}}} \
88-
] $axi_noc_dut
89-
"""
90-
]
72+
hbm_bank_cnt = {i: 1 for i in range(32)}
9173

9274
# Configure and connect mmap noc
9375
all_busif_ports = []
9476
nmu_port_cnt = {"reg": 0, "hbm": 0}
9577
for i, (port, attr) in enumerate(mmap_ports.items()):
96-
if not hbm:
97-
noc_s_port = f"S{i:02d}_AXI" # DDR
9878
# for HBM, mmap ports use dedicated HBM NMU nodes if attr["noc"] is not set
9979
# else, use regular NMU nodes
100-
elif attr.get("noc") is None:
80+
if attr.get("noc") is None:
10181
noc_s_port = f"HBM{nmu_port_cnt['hbm']:02d}_AXI" # HBM NMU
10282
nmu_port_cnt["hbm"] += 1
10383
else:
10484
noc_s_port = f"S{(nmu_port_cnt['reg'] + 8):02d}_AXI" # regular NMU
10585
nmu_port_cnt["reg"] += 1
10686

107-
noc_m_port = get_hbm_noc_port(attr["bank"]) if hbm else "M00_INI"
87+
noc_m_port = get_hbm_noc_port(attr["bank"])
10888

10989
tcl += [
11090
f"""
@@ -114,7 +94,7 @@ def get_hbm_noc_port(bank: int) -> str:
11494
read_avg_burst {{8}} \
11595
write_avg_burst {{8}} \\
11696
# excl_group {{{'' if attr.get("noc") is None else i}}} \\
117-
sep_rt_group {{{i}}} \\
97+
sep_rt_group {{{i}}} \
11898
}}}}] [get_bd_intf_pins /axi_noc_dut/{noc_s_port}]
11999
connect_bd_intf_net [get_bd_intf_pins $dut/{port}] \
120100
[get_bd_intf_pins /axi_noc_dut/{noc_s_port}]
@@ -124,15 +104,71 @@ def get_hbm_noc_port(bank: int) -> str:
124104

125105
s_busif_ports = ":".join(all_busif_ports)
126106

127-
if hbm:
107+
tcl += [
108+
f"set_property -dict [list CONFIG.ASSOCIATED_BUSIF {{{s_busif_ports}}}] \
109+
[get_bd_pins /axi_noc_dut/aclk0]"
110+
]
111+
112+
tcl += ["endgroup"]
113+
return tcl
114+
115+
116+
def dut_ddr_mmap_tcl(mmap_ports: dict[str, dict[str, int]]) -> list[str]:
117+
"""Adds DUT's MMAP-DDR related tcl commands to the block design.
118+
119+
Returns a list of tcl commands.
120+
"""
121+
tcl = []
122+
123+
ddr_mc_cnt = [0, 0, 0]
124+
for attr in mmap_ports.values():
125+
mc = attr["bank"] // 4
126+
ddr_mc_cnt[mc] += 1
127+
128+
for i, cnt in enumerate(ddr_mc_cnt):
128129
tcl += [
129-
f"set_property -dict [list CONFIG.ASSOCIATED_BUSIF {{{s_busif_ports}}}] \
130-
[get_bd_pins /axi_noc_dut/aclk8]"
130+
f"""
131+
# Create mmap noc
132+
startgroup
133+
set_property -dict [list \
134+
CONFIG.NUM_SI {{{cnt}}} \
135+
] $axi_noc_dut_{i + 1}
136+
"""
131137
]
132-
else:
138+
139+
# Configure and connect mmap noc
140+
all_busif_ports: list[list[str]] = [[], [], []]
141+
ddr_mc_cnt = [0, 0, 0]
142+
for i, (port, attr) in enumerate(mmap_ports.items()):
143+
mc = attr["bank"] // 4
144+
noc_s_port = f"S{ddr_mc_cnt[mc]:02d}_AXI" # DDR
145+
noc_m_port = f"MC_{attr['bank'] % 4}"
146+
ddr_mc_cnt[mc] += 1
147+
148+
tcl += [
149+
f"""
150+
set_property -dict [list CONFIG.CONNECTIONS {{{noc_m_port} {{ \
151+
read_bw {{{attr['read_bw'] - 100}}} \
152+
write_bw {{{attr['write_bw'] - 100}}} \
153+
read_avg_burst {{8}} \
154+
write_avg_burst {{8}} \\
155+
# excl_group {{{'' if attr.get("noc") is None else i}}} \\
156+
sep_rt_group {{{i}}} \\
157+
}}}}] [get_bd_intf_pins /axi_noc_dut_{mc + 1}/{noc_s_port}]
158+
connect_bd_intf_net [get_bd_intf_pins $dut/{port}] \
159+
[get_bd_intf_pins /axi_noc_dut_{mc + 1}/{noc_s_port}]
160+
"""
161+
]
162+
all_busif_ports[mc].append(noc_s_port)
163+
164+
for i, busif in enumerate(all_busif_ports):
165+
if not busif:
166+
continue
167+
s_busif_ports = ":".join(busif)
168+
133169
tcl += [
134170
f"set_property -dict [list CONFIG.ASSOCIATED_BUSIF {{{s_busif_ports}}}] \
135-
[get_bd_pins /axi_noc_dut/aclk0]"
171+
[get_bd_pins /axi_noc_dut_{i + 1}/aclk0]"
136172
]
137173

138174
tcl += ["endgroup"]
@@ -259,54 +295,36 @@ def dut_tcl(
259295
"""
260296
]
261297

262-
tcl += dut_mmap_tcl(mmap_ports, hbm, hbm_init_file)
298+
if hbm:
299+
tcl += dut_hbm_mmap_tcl(mmap_ports, hbm_init_file)
300+
else:
301+
tcl += dut_ddr_mmap_tcl(mmap_ports)
263302

264303
if stream_attr:
265304
tcl += dut_stream_noc_tcl(stream_attr)
266305

267306
return tcl
268307

269308

270-
def connect_dut_mb_tcl(stream_attr: dict[str, dict[str, str]]) -> list[str]:
271-
"""Connects dut in the Microblaze block design.
272-
273-
Returns a list of tcl commands.
274-
"""
275-
tcl = [
276-
"""
277-
connect_bd_net [get_bd_pins sim_clk_gen_1/clk] [get_bd_clk_pins $dut]
278-
connect_bd_net [get_bd_pins rst_clk_wiz_100M/peripheral_aresetn] [get_bd_rst_pins $dut]
279-
connect_bd_intf_net [get_bd_intf_pins smartconnect_0/M01_AXI] \
280-
[get_bd_intf_pins dut_0/s_axi_control]
281-
connect_bd_net [get_bd_pins axi_noc_dut/aclk0] [get_bd_pins sim_clk_gen_1/clk]
282-
connect_bd_intf_net [get_bd_intf_pins axi_noc_dut/M00_INI] \
283-
[get_bd_intf_pins axi_noc_0/S00_INI]
284-
"""
285-
]
286-
if stream_attr:
287-
tcl += [
288-
"connect_bd_net [get_bd_pins axis_noc_dut/aclk0] \
289-
[get_bd_pins sim_clk_gen_1/clk]"
290-
]
291-
return tcl
292-
293-
294309
def connect_dut_arm_ddr_tcl(stream_attr: dict[str, dict[str, str]]) -> list[str]:
295310
"""Connects dut in the ARM-DDR block design.
296311
297312
Returns a list of tcl commands.
298313
"""
299314
tcl = [
300315
"""
316+
# Create external clk port for simulation
317+
set pl0_ref_clk_0 [ create_bd_port -dir O -type clk pl0_ref_clk_0 ]
318+
connect_bd_net [get_bd_pins CIPS_0/pl0_ref_clk] [get_bd_ports pl0_ref_clk_0]
319+
301320
# connect_bd_net [get_bd_pins clk_wizard_0/clk_out1] [get_bd_clk_pins $dut] \
302321
# [get_bd_pins axi_noc_dut/aclk0]
303322
connect_bd_net [get_bd_pins CIPS_0/pl0_ref_clk] [get_bd_clk_pins $dut] \
304-
[get_bd_pins axi_noc_dut/aclk0]
323+
[get_bd_pins axi_noc_dut_1/aclk0] [get_bd_pins axi_noc_dut_2/aclk0] \
324+
[get_bd_pins axi_noc_dut_3/aclk0]
305325
connect_bd_net [get_bd_pins proc_sys_reset_0/peripheral_aresetn] [get_bd_rst_pins $dut]
306326
connect_bd_intf_net [get_bd_intf_pins icn_ctrl/M01_AXI] \
307327
[get_bd_intf_pins dut_0/s_axi_control]
308-
connect_bd_intf_net [get_bd_intf_pins axi_noc_dut/M00_INI] \
309-
[get_bd_intf_pins noc_lpddr4_1/S01_INI]
310328
connect_bd_net [get_bd_pins dut_0/interrupt] [get_bd_pins axi_intc_0/intr]
311329
"""
312330
]
@@ -329,14 +347,12 @@ def connect_dut_arm_hbm_tcl(stream_attr: dict[str, dict[str, str]]) -> list[str]
329347
"""
330348
# Create external clk and reset ports for simulation
331349
set pl0_ref_clk_0 [ create_bd_port -dir O -type clk pl0_ref_clk_0 ]
332-
set pl0_resetn_0 [ create_bd_port -dir O -type rst pl0_resetn_0 ]
333350
connect_bd_net [get_bd_pins CIPS_0/pl0_ref_clk] [get_bd_ports pl0_ref_clk_0]
334-
connect_bd_net [get_bd_pins CIPS_0/pl0_resetn] [get_bd_ports pl0_resetn_0]
335351
336352
# connect_bd_net [get_bd_pins clk_wizard_0/clk_out1] [get_bd_clk_pins $dut] \
337-
# [get_bd_pins $axi_noc_dut/aclk8]
353+
# [get_bd_pins $axi_noc_dut/aclk0]
338354
connect_bd_net [get_bd_pins CIPS_0/pl0_ref_clk] [get_bd_clk_pins $dut] \
339-
[get_bd_pins $axi_noc_dut/aclk8]
355+
[get_bd_pins $axi_noc_dut/aclk0]
340356
connect_bd_net [get_bd_pins proc_sys_reset_0/peripheral_aresetn] [get_bd_rst_pins $dut]
341357
connect_bd_intf_net [get_bd_intf_pins icn_ctrl/M01_AXI] \
342358
[get_bd_intf_pins dut_0/s_axi_control]
@@ -388,7 +404,7 @@ def gen_arm_bd_ddr(
388404
bd_attr["hbm_init_file"],
389405
)
390406
tcl += connect_dut_arm_ddr_tcl(stream_attr)
391-
tcl += assign_arm_bd_address()
407+
tcl += assign_arm_bd_address(False)
392408
return tcl
393409

394410

@@ -428,15 +444,15 @@ def gen_arm_bd_hbm(
428444
bd_attr["hbm_init_file"],
429445
)
430446
tcl += connect_dut_arm_hbm_tcl(stream_attr)
431-
tcl += assign_arm_bd_address()
447+
tcl += assign_arm_bd_address(True)
432448
return tcl
433449

434450

435451
if __name__ == "__main__":
436452
import json
437453

438454
# manually set the following
439-
TEST_DIR = "/home/jakeke/rapidstream-noc/test/serpens32_mmap"
455+
TEST_DIR = "/home/jakeke/rapidstream-noc/test/tmp2"
440456
TOP_MOD_NAME = "Serpens"
441457
HBM_BD = True
442458

0 commit comments

Comments
 (0)