Merge remote-tracking branch 'origin/main' into tcdtm

This commit is contained in:
Jerry Zhao
2023-05-01 10:47:57 -07:00
20 changed files with 1385 additions and 946 deletions

View File

@@ -231,7 +231,7 @@ $(SFC_MFC_TARGETS) &: $(FIRRTL_FILE) $(FINAL_ANNO_FILE) $(SFC_LEVEL) $(EXTRA_FIR
$(SED) -i 's/.*/& /' $(MFC_SMEMS_CONF) # need trailing space for SFC macrocompiler
# DOC include end: FirrtlCompiler
$(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(ALL_MODS_FILELIST) $(BB_MODS_FILELIST) &: $(MFC_MODEL_HRCHY_JSON) $(MFC_FILELIST) $(MFC_BB_MODS_FILELIST)
$(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(ALL_MODS_FILELIST) $(BB_MODS_FILELIST) $(MFC_MODEL_HRCHY_JSON_UNIQUIFIED) &: $(MFC_MODEL_HRCHY_JSON) $(MFC_FILELIST) $(MFC_BB_MODS_FILELIST)
$(base_dir)/scripts/split-module-files.py \
--model-hier-json $(MFC_MODEL_HRCHY_JSON) \
--dut $(TOP) \
@@ -243,6 +243,14 @@ $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(ALL_MODS_FILELIST) $(BB_MODS_FILEL
$(SED) -i 's/\.\///' $(TOP_MODS_FILELIST)
$(SED) -i 's/\.\///' $(MODEL_MODS_FILELIST)
$(SED) -i 's/\.\///' $(BB_MODS_FILELIST)
$(base_dir)/scripts/uniqify-module-names.py \
--top-filelist $(TOP_MODS_FILELIST) \
--mod-filelist $(MODEL_MODS_FILELIST) \
--gen-collateral-path $(GEN_COLLATERAL_DIR) \
--model-hier-json $(MFC_MODEL_HRCHY_JSON) \
--out-model-hier-json $(MFC_MODEL_HRCHY_JSON_UNIQUIFIED) \
--dut $(TOP) \
--model $(MODEL)
sort -u $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(BB_MODS_FILELIST) > $(ALL_MODS_FILELIST)
$(TOP_BB_MODS_FILELIST) $(MODEL_BB_MODS_FILELIST) &: $(BB_MODS_FILELIST) $(MFC_TOP_HRCHY_JSON) $(FINAL_ANNO_FILE)
@@ -253,10 +261,10 @@ $(TOP_BB_MODS_FILELIST) $(MODEL_BB_MODS_FILELIST) &: $(BB_MODS_FILELIST) $(MFC_T
--out-top-bb-f $(TOP_BB_MODS_FILELIST) \
--out-model-bb-f $(MODEL_BB_MODS_FILELIST)
$(TOP_SMEMS_CONF) $(MODEL_SMEMS_CONF) &: $(MFC_SMEMS_CONF) $(MFC_MODEL_HRCHY_JSON)
$(TOP_SMEMS_CONF) $(MODEL_SMEMS_CONF) &: $(MFC_SMEMS_CONF) $(MFC_MODEL_HRCHY_JSON_UNIQUIFIED)
$(base_dir)/scripts/split-mems-conf.py \
--in-smems-conf $(MFC_SMEMS_CONF) \
--in-model-hrchy-json $(MFC_MODEL_HRCHY_JSON) \
--in-model-hrchy-json $(MFC_MODEL_HRCHY_JSON_UNIQUIFIED) \
--dut-module-name $(TOP) \
--model-module-name $(MODEL) \
--out-dut-smems-conf $(TOP_SMEMS_CONF) \

View File

@@ -103,7 +103,7 @@ dependencies:
- sty
- open_pdks.sky130a
- pip:
- hammer-vlsi[asap7]==1.1.0
- hammer-vlsi[asap7]==1.1.1
# doc requirements
- sphinx

View File

@@ -91,6 +91,7 @@ run_step() {
# Check for this, since many users will be attempting to use this with gemmini
if [ $TOOLCHAIN_TYPE == "esp-tools" ]; then
while true; do
printf '\033[2J'
read -p "WARNING: You are trying to install the esp-tools toolchain."$'\n'"This should ONLY be used for Hwacha development."$'\n'"Gemmini should be used with riscv-tools."$'\n'"Type \"y\" to continue if this is intended, or \"n\" if not: " validate
case "$validate" in
y | Y)

View File

@@ -65,6 +65,7 @@ restore_bash_options
if [ "$git_tag_rc" -ne 0 ]; then
if [ "$FORCE" == false ]; then
while true; do
printf '\033[2J'
read -p "WARNING: You are not on an official release of Chipyard."$'\n'"Type \"y\" to continue if this is intended or \"n\" if not: " validate
case "$validate" in
y | Y)

100
scripts/uniqify-module-names.py Executable file
View File

@@ -0,0 +1,100 @@
#!/usr/bin/env python3
import json
import argparse
import shutil
import os
import datetime
parser = argparse.ArgumentParser(description="")
parser.add_argument("--top-filelist", type=str, required=True, help="Abs path to <top>.<model>.top.f")
parser.add_argument("--mod-filelist", type=str, required=True, help="Abs path to <top>.<model>.model.f")
parser.add_argument("--gen-collateral-path", dest="gcpath", type=str, required=True, help="Abs path to the gen-collateral directory")
parser.add_argument("--model-hier-json", type=str, required=True, help="Path to hierarchy JSON emitted by firtool. Must include DUT as a module.")
parser.add_argument("--out-model-hier-json", type=str, required=True, help="Path to updated hierarchy JSON emitted by this script.")
parser.add_argument("--dut", type=str, required=True, help="Name of the DUT module.")
parser.add_argument("--model", type=str, required=True, help="Name of the Model module.")
args = parser.parse_args()
MODEL_SFX=args.model + "_UNIQUIFIED"
def bash(cmd):
fail = os.system(cmd)
if fail:
print(f'[*] failed to execute {cmd}')
sys.exit(1)
else:
print(cmd)
def get_filelist(filelist):
fnames = []
with open(filelist) as f:
lines = f.readlines()
for line in lines:
try:
fname = line.split("/")[-1].strip()
fnames.append(fname)
except:
print(f"Something is wrong about this line '{line}'")
return fnames
def update_filelist(cur_file, new_file):
bash(f"echo \"{args.gcpath}/{new_file}\" >> {os.path.join(args.gcpath, args.mod_filelist)}")
def generate_copy(c, sfx):
(cur_name, ext) = os.path.splitext(c)
new_name = cur_name + "_" + sfx
new_file = new_name + ext
cur_file = os.path.join(args.gcpath, c)
new_file = os.path.join(args.gcpath, new_file)
shutil.copy(cur_file, new_file)
bash(f"sed -i s/\"module {cur_name}\"/\"module {new_name}\"/ {new_file}")
return new_file
def dfs_update_modules(tree, common_fnames, visited, top_fnames):
# List of direct submodules to update
childs_to_update = list()
for child in tree['instances']:
# We don't have to change stuff that are under the dut
if (child['module_name'] == args.dut) or (child['module_name'] in visited):
continue
if dfs_update_modules(child, common_fnames, visited, top_fnames):
childs_to_update.append(child['module_name'])
if (child['module_name'] + ".sv") in common_fnames:
child['module_name'] = child['module_name'] + "_" + MODEL_SFX
cur_module = tree['module_name']
cur_file = cur_module + ".sv"
new_file = None
# cur_file is in the common list, or is a ancestor of of them, generate a new file
if (cur_file in common_fnames) or len(childs_to_update) > 0:
new_file = generate_copy(cur_file, MODEL_SFX)
update_filelist(cur_file, os.path.basename(new_file))
for submodule_name in childs_to_update:
if (submodule_name + ".sv") in common_fnames:
bash(f"sed -i s/\"{submodule_name}\"/\"{submodule_name}_{MODEL_SFX}\"/ {new_file}")
visited.add(cur_module)
return (new_file is not None)
def main():
top_fnames = set(get_filelist(args.top_filelist))
mod_fnames = set(get_filelist(args.mod_filelist))
common_fnames = top_fnames.intersection(mod_fnames)
with open(args.model_hier_json) as imhj:
imhj_data = json.load(imhj)
with open(args.out_model_hier_json, "w+") as out_file:
visited = set()
dfs_update_modules(imhj_data, common_fnames, visited, top_fnames)
json.dump(imhj_data, out_file, indent=2)
if __name__ == "__main__":
main()

1
software/tutorial/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
overlay

21
software/tutorial/build.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
set -ex
CYDIR=$(git rev-parse --show-toplevel)
G_DIR=$CYDIR/generators/gemmini/software/gemmini-rocc-tests
O_DIR=$CYDIR/software/tutorial/overlay/root
echo "Building Gemmini RoCC tests"
cd $G_DIR
./build.sh imagenet
cd build
rm -rf $O_DIR
mkdir -p $O_DIR
cp -r imagenet/resnet50-baremetal $O_DIR/
cp -r imagenet/resnet50-linux $O_DIR/
cp -r imagenet/mobilenet-baremetal $O_DIR/
cp -r imagenet/mobilenet-linux $O_DIR/
echo "Complete!"

View File

@@ -0,0 +1,8 @@
{
"name" : "mobilenet-baremetal",
"base" : "bare-base.json",
"workdir" : "..",
"host-init" : "build.sh",
"bin" : "overlay/root/mobilenet-baremetal",
"spike-args" : "--extension=gemmini"
}

View File

@@ -0,0 +1,8 @@
{
"name" : "resnet50-baremetal",
"base" : "bare-base.json",
"workdir" : "..",
"host-init" : "build.sh",
"bin" : "overlay/root/resnet50-baremetal",
"spike-args" : "--extension=gemmini"
}

View File

@@ -0,0 +1,8 @@
{
"name" : "resnet50-linux-interactive",
"base" : "br-base.json",
"workdir" : "..",
"host-init" : "build.sh",
"overlay" : "overlay",
"spike-args" : "--extension=gemmini"
}

View File

@@ -0,0 +1,9 @@
{
"name" : "resnet50-linux",
"base" : "br-base.json",
"workdir" : "..",
"host-init" : "build.sh",
"overlay" : "overlay",
"command" : "/root/resnet50-linux",
"spike-args" : "--extension=gemmini"
}

View File

@@ -29,7 +29,7 @@ include libgloss.mk
PROGRAMS = pwm blkdev accum charcount nic-loopback big-blkdev pingd \
streaming-passthrough streaming-fir nvdla spiflashread spiflashwrite fft gcd \
hello
hello mt-hello
.DEFAULT_GOAL := default

1
tests/encoding.h Symbolic link
View File

@@ -0,0 +1 @@
../toolchains/riscv-tools/riscv-tests/env/encoding.h

View File

@@ -1,6 +1,10 @@
#include <stdio.h>
#include "encoding.h"
#include "marchid.h"
int main(void) {
printf("Hello world\n");
uint64_t marchid = read_csr(marchid);
const char* march = get_march(marchid);
printf("Hello world from core 0, a %s\n", march);
return 0;
}

17
tests/marchid.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef MARCHID_H
#define MARCHID_H
const char* get_march(size_t marchid) {
switch (marchid) {
case 1:
return "rocket";
case 2:
return "sonicboom";
case 5:
return "spike";
default:
return "unknown";
}
}
#endif

48
tests/mt-hello.c Normal file
View File

@@ -0,0 +1,48 @@
#include "encoding.h"
#include <stdio.h>
#include "marchid.h"
// EDIT THIS
static size_t n_cores = 4;
static void __attribute__((noinline)) barrier()
{
static volatile int sense;
static volatile int count;
static __thread int threadsense;
__sync_synchronize();
threadsense = !threadsense;
if (__sync_fetch_and_add(&count, 1) == n_cores-1)
{
count = 0;
sense = threadsense;
}
else while(sense != threadsense)
;
__sync_synchronize();
}
void __main(void) {
size_t mhartid = read_csr(mhartid);
if (mhartid >= n_cores) while (1);
const char* march = get_march(read_csr(marchid));
for (size_t i = 0; i < n_cores; i++) {
if (mhartid == i) {
printf("Hello world from core %lu, a %s\n", mhartid, march);
}
barrier();
}
// Spin if not core 0
if (mhartid > 0) while (1);
}
int main(void) {
__main();
return 0;
}

View File

@@ -164,6 +164,7 @@ SFC_ANNO_FILE ?= $(build_dir)/$(long_name).sfc.anno.json
# firtool compiler outputs
MFC_TOP_HRCHY_JSON ?= $(build_dir)/top_module_hierarchy.json
MFC_MODEL_HRCHY_JSON ?= $(build_dir)/model_module_hierarchy.json
MFC_MODEL_HRCHY_JSON_UNIQUIFIED ?= $(build_dir)/model_module_hierarchy.uniquified.json
MFC_SMEMS_CONF ?= $(build_dir)/$(long_name).mems.conf
# hardcoded firtool outputs
MFC_FILELIST = $(GEN_COLLATERAL_DIR)/filelist.f

View File

@@ -10,7 +10,7 @@ $(SIM_CONF): $(sim_common_files)
echo " top_module: $(VLSI_TOP)" >> $@
echo " tb_name: ''" >> $@ # don't specify -top
echo " input_files:" >> $@
for x in $$(comm -23 <(cat $(MODEL_MODS_FILELIST) $(MODEL_BB_MODS_FILELIST) | sort -u) <(sort $(VLSI_RTL))) $(MODEL_SMEMS_FILE) $(SIM_FILE_REQS); do \
for x in $$(cat $(MODEL_MODS_FILELIST) $(MODEL_BB_MODS_FILELIST) | sort -u) $(MODEL_SMEMS_FILE) $(SIM_FILE_REQS); do \
echo ' - "'$$x'"' >> $@; \
done
echo " input_files_meta: 'append'" >> $@