Low FIRRTL flow working

Bump barstools to 06db605902
This commit is contained in:
joey0320
2022-12-28 23:41:25 -08:00
parent 8657b1c59b
commit 6da72d859b
4 changed files with 76 additions and 43 deletions

View File

@@ -146,11 +146,8 @@ FIRTOOL_TARGETS = \
$(FIRTOOL_FILELIST) \ $(FIRTOOL_FILELIST) \
$(FIRTOOL_BB_MODS_FILELIST) $(FIRTOOL_BB_MODS_FILELIST)
REPL_SEQ_MEM = --infer-rw --repl-seq-mem -c:$(MODEL):-o:$(FIRTOOL_SMEMS_CONF) SFC_REPL_SEQ_MEM = --infer-rw --repl-seq-mem -c:$(MODEL):-o:$(SFC_SMEMS_CONF)
ifeq (,$(ENABLE_CUSTOM_FIRRTL_PASS))
EXTRA_FIRRTL_OPTIONS += $(REPL_SEQ_MEM)
endif
# DOC include start: FirrtlCompiler # DOC include start: FirrtlCompiler
# hack: lower to low firrtl if Fixed types are found # hack: lower to low firrtl if Fixed types are found
@@ -159,8 +156,10 @@ endif
$(FIRTOOL_TARGETS) &: $(FIRRTL_FILE) $(FINAL_ANNO_FILE) $(VLOG_SOURCES) $(FIRTOOL_TARGETS) &: $(FIRRTL_FILE) $(FINAL_ANNO_FILE) $(VLOG_SOURCES)
ifeq (,$(ENABLE_CUSTOM_FIRRTL_PASS)) ifeq (,$(ENABLE_CUSTOM_FIRRTL_PASS))
$(eval SFC_LEVEL := $(if $(shell grep "Fixed<" $(FIRRTL_FILE)), low, none)) $(eval SFC_LEVEL := $(if $(shell grep "Fixed<" $(FIRRTL_FILE)), low, none))
$(eval EXTRA_FIRRTL_OPTIONS += $(if $(shell grep "Fixed<" $(FIRRTL_FILE)), $(SFC_REPL_SEQ_MEM),))
else else
$(eval SFC_LEVEL := low) $(eval SFC_LEVEL := low)
$(eval EXTRA_FIRRTL_OPTIONS += $(SFC_REPL_SEQ_MEM))
endif endif
$(call run_scala_main,tapeout,barstools.tapeout.transforms.GenerateModelStageMain,\ $(call run_scala_main,tapeout,barstools.tapeout.transforms.GenerateModelStageMain,\
--no-dedup \ --no-dedup \
@@ -174,8 +173,8 @@ endif
-X $(SFC_LEVEL) \ -X $(SFC_LEVEL) \
$(EXTRA_FIRRTL_OPTIONS)) $(EXTRA_FIRRTL_OPTIONS))
-mv $(SFC_FIRRTL_BASENAME).lo.fir $(SFC_FIRRTL_FILE) -mv $(SFC_FIRRTL_BASENAME).lo.fir $(SFC_FIRRTL_FILE)
$(if $(ENABLE_CUSTOM_FIRRTL_PASS), cat $(SFC_ANNO_FILE) | jq 'del(.[] | select(.target | test("io.cpu"))?)' > /tmp/unnec-anno-deleted.sfc.anno.json,) @if [ "$(SFC_LEVEL)" = low ]; then cat $(SFC_ANNO_FILE) | jq 'del(.[] | select(.target | test("io.cpu"))?)' > /tmp/unnec-anno-deleted.sfc.anno.json; fi
$(if $(ENABLE_CUSTOM_FIRRTL_PASS), cat /tmp/unnec-anno-deleted.sfc.anno.json > $(SFC_ANNO_FILE) && rm /tmp/unnec-anno-deleted.sfc.anno.json,) @if [ "$(SFC_LEVEL)" = low ]; then cat /tmp/unnec-anno-deleted.sfc.anno.json > $(SFC_ANNO_FILE) && rm /tmp/unnec-anno-deleted.sfc.anno.json; fi
firtool \ firtool \
--format=fir \ --format=fir \
-O=release \ -O=release \
@@ -188,12 +187,13 @@ endif
--warn-on-unprocessed-annotations \ --warn-on-unprocessed-annotations \
--lowering-options=emittedLineLength=2048,noAlwaysComb,disallowLocalVariables,explicitBitcast,verifLabels,locationInfoStyle=wrapInAtSquareBracket \ --lowering-options=emittedLineLength=2048,noAlwaysComb,disallowLocalVariables,explicitBitcast,verifLabels,locationInfoStyle=wrapInAtSquareBracket \
--repl-seq-mem \ --repl-seq-mem \
--repl-seq-mem-circuit=$(MODEL) \
--repl-seq-mem-file=$(FIRTOOL_SMEMS_CONF) \ --repl-seq-mem-file=$(FIRTOOL_SMEMS_CONF) \
--repl-seq-mem-circuit=$(MODEL) \
--annotation-file=$(SFC_ANNO_FILE) \ --annotation-file=$(SFC_ANNO_FILE) \
--split-verilog \ --split-verilog \
-o $(OUT_DIR) \ -o $(OUT_DIR) \
$(SFC_FIRRTL_FILE) $(SFC_FIRRTL_FILE)
-mv $(SFC_SMEMS_CONF) $(FIRTOOL_SMEMS_CONF)
$(SED) -i 's/.*/& /' $(FIRTOOL_SMEMS_CONF) # need trailing space for SFC macrocompiler $(SED) -i 's/.*/& /' $(FIRTOOL_SMEMS_CONF) # need trailing space for SFC macrocompiler
# DOC include end: FirrtlCompiler # DOC include end: FirrtlCompiler
@@ -214,8 +214,9 @@ $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(ALL_MODS_FILELIST) $(BB_MODS_FILEL
$(TOP_SMEMS_CONF) $(HARNESS_SMEMS_CONF) &: $(FIRTOOL_TOP_SMEMS_JSON) $(FIRTOOL_MODEL_SMEMS_JSON) $(FIRTOOL_SMEMS_CONF) $(TOP_SMEMS_CONF) $(HARNESS_SMEMS_CONF) &: $(FIRTOOL_TOP_SMEMS_JSON) $(FIRTOOL_MODEL_SMEMS_JSON) $(FIRTOOL_SMEMS_CONF)
$(base_dir)/scripts/split-mems-conf.py \ $(base_dir)/scripts/split-mems-conf.py \
--in-smems-conf $(FIRTOOL_SMEMS_CONF) \ --in-smems-conf $(FIRTOOL_SMEMS_CONF) \
--in-dut-smems-json $(FIRTOOL_TOP_SMEMS_JSON) \ --in-model-hrchy-json $(FIRTOOL_MODEL_HRCHY_JSON) \
--in-model-smems-json $(FIRTOOL_MODEL_SMEMS_JSON) \ --dut-module-name $(TOP) \
--model-module-name $(MODEL) \
--out-dut-smems-conf $(TOP_SMEMS_CONF) \ --out-dut-smems-conf $(TOP_SMEMS_CONF) \
--out-model-smems-conf $(HARNESS_SMEMS_CONF) --out-model-smems-conf $(HARNESS_SMEMS_CONF)

View File

@@ -3,6 +3,7 @@
import os import os
import json import json
import argparse import argparse
import sys
from typing import List, Optional from typing import List, Optional
# Schema of json emitted by circt # Schema of json emitted by circt
@@ -23,43 +24,73 @@ from typing import List, Optional
} }
""" """
sys.setrecursionlimit(100)
# Performing DFS recursively is not a problem here since the modules that
# we are interested in are close to the root of the module hierarchy
def dfs_find_root(tree, module_name):
if tree['module_name'] == module_name:
return tree
if len(tree['instances']) == 0:
exit(0)
for c in tree['instances']:
ret = dfs_find_root(c, module_name)
if ret is not None:
return ret
return None
def bfs_collect_module(tree):
output = set()
q = [(tree['instance_name'], tree['module_name'], tree['instances'])]
while len(q) != 0:
front = q[0]
q.pop(0)
(inst, mod, child) = front
output.add(mod)
for c in child:
q.append((c['instance_name'], c['module_name'], c['instances']))
return output
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Use CIRCT (firtool) smems JSONs to create DUT and test harness smems confs') parser = argparse.ArgumentParser(description='Use CIRCT (firtool) model-hrchy JSONs to create DUT and test harness smems confs or ')
parser.add_argument('--in-smems-conf', type=str, required=True, help='Overall smems conf file that contains all memory definitions') parser.add_argument('--in-smems-conf', type=str, required=True, help='Overall smems conf file that contains all memory definitions')
parser.add_argument('--in-dut-smems-json', type=str, required=True, help='JSON indicating which mem modules are in the DUT') parser.add_argument('--in-model-hrchy-json', type=str, required=True, help='JSON indicating which mem modules are in the DUT')
parser.add_argument('--in-model-smems-json', type=str, required=True, help='JSON indicating which mem modules are in the top-most level module (but not in the DUT)') parser.add_argument('--dut-module-name', type=str, required=True, help='Module name of the DUT')
parser.add_argument('--out-dut-smems-conf', type=str, required=True, help='Smems conf with only DUT mem module definitions') parser.add_argument('--model-module-name', type=str, required=True, help='Module name of the model')
parser.add_argument('--out-model-smems-conf', type=str, required=True, help='Smems conf with only top-most level mem module definitions (not including DUT modules)') parser.add_argument('--out-dut-smems-conf', type=str, required=True, help='Smems conf with only DUT mem module definitions')
args = parser.parse_args() parser.add_argument('--out-model-smems-conf', type=str, required=True, help='Smems conf with only top-most level mem module definitions (not including DUT modules)')
args = parser.parse_args()
with open(args.in_smems_conf) as isc, \ with open(args.in_smems_conf) as isc, \
open(args.in_dut_smems_json) as idsj, \ open(args.in_model_hrchy_json) as imhj:
open(args.in_model_smems_json) as itsj: imhj_data = json.load(imhj)
idsj_data = json.load(idsj)
itsj_data = json.load(itsj)
dut_mods = set() dut_root = dfs_find_root(imhj_data, args.dut_module_name)
for e in idsj_data: dut_submodules = bfs_collect_module(dut_root)
dut_mods.add(e['module_name'])
model_mods = set() model_root = dfs_find_root(imhj_data, args.model_module_name)
for e in itsj_data: model_submodules = bfs_collect_module(model_root)
model_mods.add(e['module_name'])
with open(args.out_dut_smems_conf, "w") as odsc, \ with open(args.out_dut_smems_conf, "w") as odsc, \
open(args.out_model_smems_conf, "w") as otsc: open(args.out_model_smems_conf, "w") as otsc:
for l in isc: for l in isc:
sl = l.split() sl = l.split()
# the line can't be split then stop immediately (normally an empty file) # the line can't be split then stop immediately (normally an empty file)
if len(sl) > 2: if len(sl) > 2:
name = sl[1] name = sl[1]
if name in dut_mods: if name in dut_submodules:
odsc.write(l) odsc.write(l)
elif name in model_mods: elif name in model_submodules:
otsc.write(l) otsc.write(l)
else: else:
assert False, "Unable to find smem CONF module in firtool emitted JSON files." assert False, "Unable to find smem CONF module in firtool emitted JSON files."
else: else:
exit(0) exit(0)

View File

@@ -167,6 +167,7 @@ FIRTOOL_TOP_SMEMS_JSON = $(OUT_DIR)/metadata/seq_mems.json
FIRTOOL_MODEL_SMEMS_JSON = $(OUT_DIR)/metadata/tb_seq_mems.json FIRTOOL_MODEL_SMEMS_JSON = $(OUT_DIR)/metadata/tb_seq_mems.json
# macrocompiler smems in/output # macrocompiler smems in/output
SFC_SMEMS_CONF ?= $(build_dir)/$(long_name).sfc.mems.conf
TOP_SMEMS_CONF ?= $(build_dir)/$(long_name).top.mems.conf TOP_SMEMS_CONF ?= $(build_dir)/$(long_name).top.mems.conf
TOP_SMEMS_FILE ?= $(OUT_DIR)/$(long_name).top.mems.v TOP_SMEMS_FILE ?= $(OUT_DIR)/$(long_name).top.mems.v
TOP_SMEMS_FIR ?= $(build_dir)/$(long_name).top.mems.fir TOP_SMEMS_FIR ?= $(build_dir)/$(long_name).top.mems.fir