Skip to content

Commit

Permalink
hemaia util (#20)
Browse files Browse the repository at this point in the history
* Initial Commit

* Update CI

* Bug Fix
  • Loading branch information
IveanEx committed Aug 27, 2024
1 parent 51daea6 commit 5f0d5bb
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
echo -e "Should execute \"make sw\""
- name: Compile RTL
run: |
make rtl CFG_OVERRIDES=target/rtl/cfg/occamy_cfg/snax_two_clusters.hjson
make rtl CFG_OVERRIDE=target/rtl/cfg/occamy_cfg/snax_two_clusters.hjson
- name: Compile Verilator Binary
run: |
make occamy_system_vlt
37 changes: 15 additions & 22 deletions target/rtl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MKFILE_DIR := $(dir $(MKFILE_PATH))
ROOT := $(MKFILE_DIR)../..
TARGET_SRC_DIR ?= src
SNITCH_ROOT = $(shell $(BENDER) path snitch_cluster)
WRAPPERGEN = $(SNITCH_ROOT)/util/wrappergen/wrappergen.py
HEMAIA_UTIL = $(ROOT)/util/hemaia/util.py

SOURCE_OCCAMY_DIR ?= $(ROOT)/hw/occamy

Expand Down Expand Up @@ -87,15 +87,16 @@ clean: clean-bender clean-rtl

clean-bender:
rm -rf $(ROOT)/Bender.lock $(ROOT)/.bender/ $(ROOT)/deps
rm -rf src/bender_targets.tmp

###############
# RTL sources #
###############

.PHONY: rtl clint plic socctrl hbmctrl quadctrl snax soc tb
.PHONY: rtl clint plic socctrl hbmctrl quadctrl soc tb
.PHONY: clean-rtl clean-clint clean-plic clean-socctrl clean-hbmctrl clean-quadctrl clean-soc clean-tb

rtl: clint plic socctrl hbmctrl quadctrl snax soc tb
rtl: clint plic socctrl hbmctrl quadctrl soc tb src/bender_targets.tmp
clean-rtl: clean-clint clean-plic clean-socctrl clean-hbmctrl clean-quadctrl clean-soc clean-tb

$(TARGET_PLIC_DIR) $(TARGET_CLINT_DIR) $(TARGET_SOCCTRL_DIR) $(TARGET_HBMCTRL_DIR) $(TARGET_QUADCTRL_DIR):
Expand Down Expand Up @@ -281,9 +282,6 @@ $(TARGET_CLINT_DIR)/clint.%: $(SOURCE_CLINT_DIR)/data/clint.%.tpl $(CFG) | $(TAR
###########################################
# SNAX Accelerator + Wrapper Generations #
###########################################
# TODO: This SNAX_CFGS should not be fixed! It should be created dynamically instead.
SNAX_CFGS += cfg/cluster_cfg/snax_KUL_cluster.hjson
SNAX_CFGS += cfg/cluster_cfg/snax_KUL_xdma_cluster.hjson

#######################
# Step 1: Wrapper Gen #
Expand All @@ -300,20 +298,15 @@ SNAX_CFGS += cfg/cluster_cfg/snax_KUL_xdma_cluster.hjson
#############################
# Step 3: Bender Target Gen #
#############################

SNAX_ACC_GEN:
ifeq ($(findstring snax_xdma_cluster,$(SNAX_CFGS)),snax_xdma_cluster)
$(eval BENDER_TARGETS += -t snax_xdma -t snax_xdma_cluster)
endif

ifeq ($(findstring snax_KUL_cluster,$(SNAX_CFGS)),snax_KUL_cluster)
$(eval BENDER_TARGETS += -t snax_gemmX -t snax_data_reshuffler -t snax_KUL_cluster)
endif

ifeq ($(findstring snax_KUL_xdma_cluster,$(SNAX_CFGS)),snax_KUL_xdma_cluster)
$(eval BENDER_TARGETS += -t snax_gemmX -t snax_KUL_xdma_cluster_xdma -t snax_KUL_xdma_cluster)
endif

# Create the dependency in SNAX: when generating snax, the bender target should be stored into file, which will be used by other targets (e.g. tapeout, fpga, simulation)
snax: SNAX_ACC_GEN # SNAX_WRAPPER_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
echo $(BENDER_TARGETS) > src/bender_targets.tmp
72 changes: 72 additions & 0 deletions util/hemaia/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python3
# Copyright 2024 KU Leuven.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Yunhao Deng <[email protected]>

from mako.lookup import TemplateLookup
from mako.template import Template
from jsonref import JsonRef
import hjson
import argparse
import os


# Extract json file
def get_config(cfg_path: str):
with open(cfg_path, "r") as jsonf:
srcfull = jsonf.read()

# Format hjson file
cfg = hjson.loads(srcfull, use_decimal=True)
cfg = JsonRef.replace_refs(cfg)
return cfg

def hemaia_util():
# Parse all arguments
parser = argparse.ArgumentParser(
description="The util collection to retrieve information from the hemaia json file"
)
parser.add_argument(
"--cfg_path",
type=str,
default="target/rtl/cfg/occamy_cfg/lru.hjson",
help="Path to the hemaia json file",
)

parser.add_argument(
"--print_clusters",
action="store_true",
help="Print out the containing cluster names",
)

parsed_args = parser.parse_args()

# Parse the occamy_cfg file
occamy_cfg = get_config(parsed_args.cfg_path)
if 'clusters' in occamy_cfg:
clusters = occamy_cfg['clusters']
cluster_cfgs = []
for cluster in clusters:
cluster_cfg_path = os.path.dirname(parsed_args.cfg_path) + "/../cluster_cfg/" + cluster + ".hjson"
cluster_cfgs.append(get_config(cluster_cfg_path))
else:
raise Exception("No clusters found in the hemaia json file")

if cluster_cfgs.__len__() == 0:
raise Exception("The number of cluster is 0")

# The remaining part is related to different functions
# Available variables:
# - occamy_cfg: The main configuration file
# - cluster_cfgs: The parsed cluster configurations in a list

if parsed_args.print_clusters:
for cluster_cfg in cluster_cfgs:
print(cluster_cfg['cluster']['name'] + " ", end="")
print()
return

if __name__ == "__main__":
hemaia_util()

0 comments on commit 5f0d5bb

Please sign in to comment.