Skip to content

Commit

Permalink
New Python script to generate bender target (#25)
Browse files Browse the repository at this point in the history
* Initial Commit

* Bug Fix
  • Loading branch information
IveanEx committed Aug 31, 2024
1 parent 65bdf05 commit f216583
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 44 deletions.
20 changes: 1 addition & 19 deletions target/rtl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ TARGET_RTL ?= $(ROOT)/target/rtl

BENDER ?= bender
#VERIBLE_FMT ?= verible-verilog-format
BENDER_TARGETS ?= -t cv64a6_imafdc_sv39 -t occamy

OCCAMYGEN ?= $(ROOT)/util/occamygen/occamygen.py
REGGEN ?= $(shell $(BENDER) path register_interface)/vendor/lowrisc_opentitan/util/regtool.py
PLICGEN = $(SOURCE_PLIC_DIR)/util/reg_rv_plic.py
Expand Down Expand Up @@ -298,21 +296,5 @@ $(TARGET_CLINT_DIR)/clint.%: $(SOURCE_CLINT_DIR)/data/clint.%.tpl $(CFG) | $(TAR
#############################
# Step 3: Bender Target Gen #
#############################
SNAX_CFGS = $(shell python3 $(HEMAIA_UTIL) --cfg_path $(CFG) --print_clusters)
src/bender_targets.tmp: $(CFG) # Generate bender_targets.tmp file
if echo "$(SNAX_CFGS)" | grep -q "snax_xdma_cluster"; then \
$(eval BENDER_TARGETS += -t snax_xdma -t snax_xdma_cluster): ; \
fi
if echo "$(SNAX_CFGS)" | grep -q "snax_KUL_cluster"; then \
$(eval BENDER_TARGETS+= -t snax_gemmX -t snax_data_reshuffler -t snax_KUL_cluster): ;\
fi
if echo "$(SNAX_CFGS)" | grep -q "snax_KUL_xdma_cluster"; then \
$(eval BENDER_TARGETS+= -t snax_gemmX -t snax_KUL_xdma_cluster_xdma -t snax_KUL_xdma_cluster): ;\
fi
if echo "$(SNAX_CFGS)" | grep -q "snax_alu_cluster"; then \
$(eval BENDER_TARGETS += -t snax_alu -t snax_alu_cluster): ; \
fi
if echo "$(SNAX_CFGS)" | grep -q "snax_hypercorex_cluster"; then \
$(eval BENDER_TARGETS += -t hypercorex -t snax_hypercorex_cluster): ; \
fi
echo $(BENDER_TARGETS) > src/bender_targets.tmp
echo $(shell $(HEMAIA_UTIL) --cfg_path $(CFG) --get_bender_targets) > src/bender_targets.tmp
3 changes: 3 additions & 0 deletions target/rtl/cfg/cluster_cfg/snax_KUL_cluster.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

cluster: {
name: "snax_KUL_cluster",
bender_target: ["snax_KUL_cluster"],
boot_addr: 4096, // 0x1000
cluster_base_addr: 268435456, // 0x1000_0000
cluster_base_offset: 1048576, // 256KB -> 1MB
Expand Down Expand Up @@ -118,6 +119,7 @@
xfvec: false,
snax_acc_cfg: {
snax_acc_name: "snax_streamer_gemmX",
bender_target: ["snax_gemmX"],
snax_narrow_tcdm_ports: 8,
snax_wide_tcdm_ports: 48,
snax_num_rw_csr: 10,
Expand Down Expand Up @@ -147,6 +149,7 @@
xfvec: false,
snax_acc_cfg: {
snax_acc_name: "snax_data_reshuffler",
bender_target: ["snax_data_reshuffler"],
snax_narrow_tcdm_ports: 16,
snax_num_rw_csr: 2,
snax_num_ro_csr: 2,
Expand Down
3 changes: 3 additions & 0 deletions target/rtl/cfg/cluster_cfg/snax_KUL_xdma_cluster.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

cluster: {
name: "snax_KUL_xdma_cluster",
bender_target: ["snax_KUL_xdma_cluster"],
boot_addr: 4096, // 0x1000
cluster_base_addr: 268435456, // 0x1000_0000
cluster_base_offset: 1048576, // 256KB -> 1MB
Expand Down Expand Up @@ -117,6 +118,7 @@
xfvec: false,
snax_acc_cfg: {
snax_acc_name: "snax_streamer_gemmX",
bender_target: ["snax_gemmX"],
snax_narrow_tcdm_ports: 8,
snax_wide_tcdm_ports: 48,
snax_num_rw_csr: 10,
Expand All @@ -136,6 +138,7 @@
dma_core_template: {
isa: "rv32ima",
snax_xdma_cfg: {
bender_target: ["snax_KUL_xdma_cluster_xdma"],
reader_buffer: 4,
writer_buffer: 4,
reader_agu_dimension: 7,
Expand Down
4 changes: 3 additions & 1 deletion target/rtl/cfg/cluster_cfg/snax_alu_cluster.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

cluster: {
name: "snax_alu_cluster",
bender_target: ["snax_alu_cluster"],
boot_addr: 4096, // 0x1000
cluster_base_addr: 268435456, // 0x1000_0000
cluster_base_offset: 1048576, // 256KB -> 1MB
Expand Down Expand Up @@ -109,7 +110,8 @@
xfdotp: false,
xfvec: false,
snax_acc_cfg: {
snax_acc_name: "snax_alu"
snax_acc_name: "snax_alu",
bender_target: ["snax_alu"],
snax_narrow_tcdm_ports: 12,
snax_num_rw_csr: 3,
snax_num_ro_csr: 2,
Expand Down
4 changes: 3 additions & 1 deletion target/rtl/cfg/cluster_cfg/snax_hypercorex_cluster.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

cluster: {
name: "snax_hypercorex_cluster",
bender_target: ["snax_hypercorex_cluster"],
boot_addr: 4096, // 0x1000
cluster_base_addr: 268435456, // 0x1000_0000
cluster_base_offset: 1048576, // 256KB -> 1MB
Expand Down Expand Up @@ -117,7 +118,8 @@
xfdotp: false,
xfvec: false,
snax_acc_cfg: {
snax_acc_name: "snax_hypercorex"
snax_acc_name: "snax_hypercorex",
bender_target: ["hypercorex"],
snax_narrow_tcdm_ports: 3,
snax_wide_tcdm_ports: 32,
snax_disable_csr_manager: true,
Expand Down
1 change: 1 addition & 0 deletions target/rtl/cfg/cluster_cfg/snax_minimal_cluster.hjson
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
cluster: {
name: "snax_minimal_cluster"
bender_target: ["snax_minimal_cluster"],
boot_addr: 4096, // 0x1000
cluster_base_addr: 268435456, // 0x10000000
cluster_base_offset: 262144 // 0x40000
Expand Down
5 changes: 3 additions & 2 deletions target/rtl/cfg/cluster_cfg/snax_xdma_cluster.hjson
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
cluster: {
name: "snax_xdma_cluster"
name: "snax_xdma_cluster",
bender_target: ["snax_xdma_cluster"],
boot_addr: 4096, // 0x1000
cluster_base_addr: 268435456, // 0x10000000
cluster_base_offset: 262144, // 256KB
Expand Down Expand Up @@ -86,6 +87,7 @@
dma_core_template: {
isa: "rv32ima",
snax_xdma_cfg: {
bender_target: ["snax_xdma"],
reader_buffer: 8,
writer_buffer: 8,
reader_agu_dimension: 3,
Expand All @@ -111,5 +113,4 @@
num_dtlb_entries: 1,
num_itlb_entries: 1,
},

}
2 changes: 1 addition & 1 deletion target/rtl/cfg/occamy_cfg/hemaia.hjson
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
bender_target: ["cv64a6_imafdc_sv39", "occamy"],
// Remote CFG, about to be removed

is_remote_quadrant: false,
remote_quadrants: [],
// Multi-chip configuration
Expand Down
3 changes: 2 additions & 1 deletion target/rtl/cfg/occamy_cfg/hemaia_minimal.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
// Remote CFG
bender_target: ["cv64a6_imafdc_sv39", "occamy"],
// Remote CFG, about to be removed
is_remote_quadrant: false,
remote_quadrants: [],
addr_width: 48,
Expand Down
2 changes: 1 addition & 1 deletion target/rtl/cfg/occamy_cfg/hemaia_two_clusters.hjson
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
bender_target: ["cv64a6_imafdc_sv39", "occamy"],
// Remote CFG, about to be removed

is_remote_quadrant: false,
remote_quadrants: [],
// Multi-chip configuration
Expand Down
67 changes: 49 additions & 18 deletions util/hemaia/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ def get_config(cfg_path: str):
cfg = JsonRef.replace_refs(cfg)
return cfg


# For generating cluster synthesis filelists
def generate_cluster_syn_flist(cfg, snax_path, outdir):
config_name = os.path.splitext(os.path.basename(os.path.normpath(cfg)))[0]
subprocess.call(f"make -C {snax_path}/target/snitch_cluster \
CFG_OVERRIDE={cfg} \
MEM_TYPE=exclude_tcsram \
SYN_FLIST={config_name}.tcl \
SYN_BUILDDIR={outdir} \
gen-syn", shell=True)


def hemaia_util():
# Parse all arguments
parser = argparse.ArgumentParser(
Expand All @@ -48,7 +36,7 @@ def hemaia_util():
parser.add_argument(
"--cfg_path",
type=str,
default="target/rtl/cfg/occamy_cfg/lru.hjson",
default="../../target/rtl/cfg/occamy_cfg/lru.hjson",
help="Path to the hemaia json file",
)

Expand All @@ -58,6 +46,12 @@ def hemaia_util():
help="Print out the containing cluster names",
)

parser.add_argument(
"--get_bender_targets",
action="store_true",
help="Get the bender targets for the whole system",
)

parser.add_argument("--outdir",
"-o",
type=pathlib.Path,
Expand Down Expand Up @@ -89,28 +83,65 @@ def hemaia_util():
raise Exception("No clusters found in the hemaia json file")
if cluster_cfgs.__len__() == 0:
raise Exception("The number of cluster is 0")

occamy_cfg['clusters'] = cluster_cfgs

# The remaining part is the region for the util functions
# Available variables:
# - occamy_cfg: The main configuration file
# - occamy_cfg: The main configuration file, with parsed cluster configurations
# - cluster_cfg_paths: The paths to the cluster configurations in a list
# - cluster_cfgs: The parsed cluster configurations in a list

# For printing out the cluster names and generate targets
if parsed_args.print_clusters:
for cluster_cfg in cluster_cfgs:
for cluster_cfg in occamy_cfg['clusters']:
print(cluster_cfg['cluster']['name'] + " ", end="")
print()
return

# For generating filelists for each cluster
# These filelists are specific for synthesis only
if parsed_args.cluster_flist:

def generate_cluster_syn_flist(cfg, snax_path, outdir):
config_name = os.path.splitext(os.path.basename(os.path.normpath(cfg)))[0]
subprocess.call(f"make -C {snax_path}/target/snitch_cluster \
CFG_OVERRIDE={cfg} \
MEM_TYPE=exclude_tcsram \
SYN_FLIST={config_name}.tcl \
SYN_BUILDDIR={outdir} \
gen-syn", shell=True)

print("Generate filelist for each cluster only.")
for cluster_cfg_path in cluster_cfg_paths:
generate_cluster_syn_flist(cluster_cfg_path,
parsed_args.snax_path,
parsed_args.outdir)
parsed_args.snax_path,
parsed_args.outdir)
return

# For generating all bender targets
if parsed_args.get_bender_targets:
def get_bender_targets(cfg):
targets = []
# If cfg is dictionary, then first check if it has bender_target, then iterate over the rest
if isinstance(cfg, dict):
for name,content in cfg.items():
if name == "bender_target":
targets.extend(content)
else:
targets.extend(get_bender_targets(content))
# If cfg is a list, then iterate over the list
elif isinstance(cfg, list):
for item in cfg:
targets.extend(get_bender_targets(item))
# Return the list of targets with removing duplicates
return list(set(targets))

bender_targets = get_bender_targets(occamy_cfg)
for i in bender_targets:
print(" -t "+ i,end="")
print()
return


if __name__ == "__main__":
hemaia_util()

0 comments on commit f216583

Please sign in to comment.