From f2165834e366673b1121db8118e426525e20e0b9 Mon Sep 17 00:00:00 2001 From: Yunhao Deng Date: Sat, 31 Aug 2024 13:29:42 +0200 Subject: [PATCH] New Python script to generate bender target (#25) * Initial Commit * Bug Fix --- target/rtl/Makefile | 20 +----- .../cfg/cluster_cfg/snax_KUL_cluster.hjson | 3 + .../cluster_cfg/snax_KUL_xdma_cluster.hjson | 3 + .../cfg/cluster_cfg/snax_alu_cluster.hjson | 4 +- .../cluster_cfg/snax_hypercorex_cluster.hjson | 4 +- .../cluster_cfg/snax_minimal_cluster.hjson | 1 + .../cfg/cluster_cfg/snax_xdma_cluster.hjson | 5 +- target/rtl/cfg/occamy_cfg/hemaia.hjson | 2 +- .../rtl/cfg/occamy_cfg/hemaia_minimal.hjson | 3 +- .../cfg/occamy_cfg/hemaia_two_clusters.hjson | 2 +- util/hemaia/util.py | 67 ++++++++++++++----- 11 files changed, 70 insertions(+), 44 deletions(-) diff --git a/target/rtl/Makefile b/target/rtl/Makefile index 6acc4657d..d46ead58a 100644 --- a/target/rtl/Makefile +++ b/target/rtl/Makefile @@ -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 @@ -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 diff --git a/target/rtl/cfg/cluster_cfg/snax_KUL_cluster.hjson b/target/rtl/cfg/cluster_cfg/snax_KUL_cluster.hjson index af9bd96ec..3cf0499cb 100644 --- a/target/rtl/cfg/cluster_cfg/snax_KUL_cluster.hjson +++ b/target/rtl/cfg/cluster_cfg/snax_KUL_cluster.hjson @@ -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 @@ -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, @@ -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, diff --git a/target/rtl/cfg/cluster_cfg/snax_KUL_xdma_cluster.hjson b/target/rtl/cfg/cluster_cfg/snax_KUL_xdma_cluster.hjson index c0d630f7b..b13d266ce 100644 --- a/target/rtl/cfg/cluster_cfg/snax_KUL_xdma_cluster.hjson +++ b/target/rtl/cfg/cluster_cfg/snax_KUL_xdma_cluster.hjson @@ -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 @@ -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, @@ -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, diff --git a/target/rtl/cfg/cluster_cfg/snax_alu_cluster.hjson b/target/rtl/cfg/cluster_cfg/snax_alu_cluster.hjson index e61f4d361..c224876b0 100644 --- a/target/rtl/cfg/cluster_cfg/snax_alu_cluster.hjson +++ b/target/rtl/cfg/cluster_cfg/snax_alu_cluster.hjson @@ -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 @@ -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, diff --git a/target/rtl/cfg/cluster_cfg/snax_hypercorex_cluster.hjson b/target/rtl/cfg/cluster_cfg/snax_hypercorex_cluster.hjson index 51871450c..896e9beb9 100644 --- a/target/rtl/cfg/cluster_cfg/snax_hypercorex_cluster.hjson +++ b/target/rtl/cfg/cluster_cfg/snax_hypercorex_cluster.hjson @@ -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 @@ -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, diff --git a/target/rtl/cfg/cluster_cfg/snax_minimal_cluster.hjson b/target/rtl/cfg/cluster_cfg/snax_minimal_cluster.hjson index 940879561..a8c1a3ae4 100644 --- a/target/rtl/cfg/cluster_cfg/snax_minimal_cluster.hjson +++ b/target/rtl/cfg/cluster_cfg/snax_minimal_cluster.hjson @@ -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 diff --git a/target/rtl/cfg/cluster_cfg/snax_xdma_cluster.hjson b/target/rtl/cfg/cluster_cfg/snax_xdma_cluster.hjson index 89f3ec0a1..cbd3d47db 100644 --- a/target/rtl/cfg/cluster_cfg/snax_xdma_cluster.hjson +++ b/target/rtl/cfg/cluster_cfg/snax_xdma_cluster.hjson @@ -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 @@ -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, @@ -111,5 +113,4 @@ num_dtlb_entries: 1, num_itlb_entries: 1, }, - } diff --git a/target/rtl/cfg/occamy_cfg/hemaia.hjson b/target/rtl/cfg/occamy_cfg/hemaia.hjson index 91321bff7..5e919a6bd 100755 --- a/target/rtl/cfg/occamy_cfg/hemaia.hjson +++ b/target/rtl/cfg/occamy_cfg/hemaia.hjson @@ -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 diff --git a/target/rtl/cfg/occamy_cfg/hemaia_minimal.hjson b/target/rtl/cfg/occamy_cfg/hemaia_minimal.hjson index 2ccf7e62d..3ac9b2c6f 100755 --- a/target/rtl/cfg/occamy_cfg/hemaia_minimal.hjson +++ b/target/rtl/cfg/occamy_cfg/hemaia_minimal.hjson @@ -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, diff --git a/target/rtl/cfg/occamy_cfg/hemaia_two_clusters.hjson b/target/rtl/cfg/occamy_cfg/hemaia_two_clusters.hjson index bf004105e..256416fed 100755 --- a/target/rtl/cfg/occamy_cfg/hemaia_two_clusters.hjson +++ b/target/rtl/cfg/occamy_cfg/hemaia_two_clusters.hjson @@ -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 diff --git a/util/hemaia/util.py b/util/hemaia/util.py index e3b11cea6..3a279b1a1 100755 --- a/util/hemaia/util.py +++ b/util/hemaia/util.py @@ -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( @@ -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", ) @@ -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, @@ -89,16 +83,17 @@ 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 @@ -106,11 +101,47 @@ def hemaia_util(): # 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()