Skip to content

Commit

Permalink
fix(ir): sync with rapidstream IR and NoC mode updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-ke committed Jun 4, 2024
1 parent 2a089ad commit 2febc8c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
12 changes: 7 additions & 5 deletions ir_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class IREnum(Enum):
TAIL_REGION = "__TAIL_REGION"
DATA_WIDTH = "DATA_WIDTH"
DEPTH = "DEPTH"
PIPELINE_BODY_LEVEL = "PIPELINE_BODY_LEVEL"
BODY_LEVEL = "BODY_LEVEL"
IF_DOUT = "if_dout"
IF_EMPTY_N = "if_empty_n"
IF_READ = "if_read"
Expand Down Expand Up @@ -169,9 +169,11 @@ def parse_floorplan(ir: dict[str, Any], grouped_mod_name: str) -> dict[str, list
combined_mods = {
# top
"inst/": parse_top_mod(ir)["submodules"],
# grouped module
f"inst/{grouped_mod_name}_0/": parse_mod(ir, grouped_mod_name)["submodules"],
}
if grouped_mod_ir := parse_mod(ir, grouped_mod_name):
print("No constraints from the grouped module.")
# grouped module
combined_mods[f"inst/{grouped_mod_name}_0/"] = grouped_mod_ir["submodules"]

insts = {}
for parent, mods in combined_mods.items():
Expand Down Expand Up @@ -363,7 +365,7 @@ def create_nmu_fifo_ir(
if p["name"] == IREnum.DEPTH.value:
p["expr"] = create_id_expr(fifo_params["depth"] // 2)
# remove the body level pipelines
elif p["name"] == IREnum.PIPELINE_BODY_LEVEL.value:
elif p["name"] == IREnum.BODY_LEVEL.value:
p["expr"] = create_id_expr(0)
# assign NMU fifo regions to head region
elif IREnum.REGION.value in p["name"]:
Expand Down Expand Up @@ -395,7 +397,7 @@ def create_nsu_fifo_ir(
if p["name"] == IREnum.DEPTH.value:
p["expr"] = create_id_expr(fifo_params["depth"] // 2)
# remove the body level pipelines
elif p["name"] == IREnum.PIPELINE_BODY_LEVEL.value:
elif p["name"] == IREnum.BODY_LEVEL.value:
p["expr"] = create_id_expr(0)
# assign NSU fifo regions to tail region
elif IREnum.REGION.value in p["name"]:
Expand Down
47 changes: 29 additions & 18 deletions run_noc_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class SelectorEnum(Enum):
nmu_per_slot=[], # generated
nsu_per_slot=[], # generated
cr_mapping=[
["CLOCKREGION_X0Y0:CLOCKREGION_X4Y4", "CLOCKREGION_X0Y5:CLOCKREGION_X4Y7"],
["CLOCKREGION_X5Y0:CLOCKREGION_X9Y4", "CLOCKREGION_X5Y5:CLOCKREGION_X9Y7"],
["CLOCKREGION_X0Y1:CLOCKREGION_X4Y4", "CLOCKREGION_X0Y5:CLOCKREGION_X4Y7"],
["CLOCKREGION_X5Y1:CLOCKREGION_X9Y4", "CLOCKREGION_X5Y5:CLOCKREGION_X9Y7"],
],
)

Expand Down Expand Up @@ -179,29 +179,37 @@ class SelectorEnum(Enum):
with open(f"{build_dir}/{NOC_CONSTRAINT_TCL}", "w", encoding="utf-8") as file:
file.write("\n".join(tcl))

# generate grouped ir and rtl
zsh_cmds = f"""
if selector in (SelectorEnum.NONE.name, SelectorEnum.EMPTY.name):
# skip generating grouped ir and wrapper
zsh_cmds = f"""
rapidstream-exporter -i {rapidstream_json} -f {build_dir}/rtl
"""
else:
# generate grouped ir with the selected streams
zsh_cmds = f"""
source ~/.zshrc && amd
rapidstream-optimizer -i {rapidstream_json} -o {build_dir}/{NOC_PASS_JSON} \
create-group-wrapper --group-name-to-insts-json={build_dir}/{SELECTED_STREAMS_JSON}
"""
print(zsh_cmds)
subprocess.run(["zsh", "-c", zsh_cmds], check=True)
print(zsh_cmds)
subprocess.run(["zsh", "-c", zsh_cmds], check=True)

# generate new rtl wrapper
with open(f"{build_dir}/{NOC_PASS_JSON}", "r", encoding="utf-8") as file:
noc_pass_ir = json.load(file)
# generate new rtl wrapper
with open(f"{build_dir}/{NOC_PASS_JSON}", "r", encoding="utf-8") as file:
noc_pass_ir = json.load(file)

noc_pass_wrapper_ir = noc_rtl_wrapper(noc_pass_ir, GROUPED_MOD_NAME)
noc_pass_wrapper_ir = noc_rtl_wrapper(noc_pass_ir, GROUPED_MOD_NAME)

with open(
f"{build_dir}/{NOC_PASS_WRAPPER_JSON}", "w", encoding="utf-8"
) as file:
json.dump(noc_pass_wrapper_ir, file, indent=4)
with open(
f"{build_dir}/{NOC_PASS_WRAPPER_JSON}", "w", encoding="utf-8"
) as file:
json.dump(noc_pass_wrapper_ir, file, indent=4)

zsh_cmds = f"""
zsh_cmds = f"""
rapidstream-exporter -i {build_dir}/{NOC_PASS_WRAPPER_JSON} -f {build_dir}/rtl
"""

# generate rtl folder
print(zsh_cmds)
subprocess.run(["zsh", "-c", zsh_cmds], check=True)

Expand Down Expand Up @@ -233,9 +241,12 @@ class SelectorEnum(Enum):
if selector == SelectorEnum.NONE.name:
tcl = []
else:
with open(
f"{build_dir}/{NOC_PASS_WRAPPER_JSON}", "r", encoding="utf-8"
) as file:
final_ir = (
rapidstream_json
if selector == SelectorEnum.EMPTY.name
else f"{build_dir}/{NOC_PASS_WRAPPER_JSON}"
)
with open(final_ir, "r", encoding="utf-8") as file:
noc_pass_wrapper_ir = json.load(file)

floorplan = parse_floorplan(noc_pass_wrapper_ir, GROUPED_MOD_NAME)
Expand Down

0 comments on commit 2febc8c

Please sign in to comment.