Skip to content

Commit 8de8482

Browse files
collucafischeti
andauthored
treewide: Improve integration in systems (#227)
Co-authored-by: Tim Fischer <fischeti@iis.ee.ethz.ch>
1 parent 05ed6e4 commit 8de8482

File tree

44 files changed

+580
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+580
-564
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ jobs:
124124
submodules: 'recursive'
125125
- name: Hash Verilator prerequisites
126126
id: verilator-hash
127-
uses: colluca/list-make-prerequisites@v1.0.2
127+
uses: colluca/list-make-prerequisites@v1.0.3
128128
with:
129129
working-directory: target/snitch_cluster
130-
target: bin/snitch_cluster.vlt
130+
target: verilator
131131
flags: --recursive
132132
- name: Set up cache for Verilator build
133133
id: verilator-cache
@@ -141,7 +141,7 @@ jobs:
141141
if: steps.verilator-cache.outputs.cache-hit != 'true'
142142
working-directory: target/snitch_cluster
143143
run: |
144-
make CFG_OVERRIDE=cfg/github-ci.json VLT_JOBS=1 bin/snitch_cluster.vlt
144+
make CFG_OVERRIDE=cfg/github-ci.json VLT_JOBS=1 verilator
145145
- name: Build Software
146146
working-directory: target/snitch_cluster
147147
run: |

Bender.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ sources:
188188
# target/snitch_cluster
189189
- target: snitch_cluster_wrapper
190190
files:
191-
- target/snitch_cluster/generated/snitch_cluster_pkg.sv
191+
- target/snitch_cluster/.generated/snitch_cluster_pkg.sv
192192
- target: all(snitch_cluster_wrapper, not(postlayout))
193193
files:
194-
- target/snitch_cluster/generated/snitch_cluster_wrapper.sv
194+
- target/snitch_cluster/.generated/snitch_cluster_wrapper.sv
195195
- target: all(snitch_cluster_wrapper, postlayout)
196196
files:
197197
- nonfree/gf12/fusion/runs/0/out/15/snitch_cluster_wrapper.v

docs/ug/tutorial.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ To run software on Snitch without a physical chip, you will need a simulation mo
2727

2828
=== "Verilator"
2929
```shell
30-
make bin/snitch_cluster.vlt
30+
make verilator
3131
```
3232

3333
=== "Questa"
3434
```shell
35-
make DEBUG=ON bin/snitch_cluster.vsim
35+
make DEBUG=ON vsim
3636
```
3737

3838
=== "VCS"
3939
```shell
40-
make bin/snitch_cluster.vcs
40+
make vcs
4141
```
4242

4343
These commands compile the RTL sources respectively in `work-vlt`, `work-vsim` and `work-vcs`. Additionally, common C++ testbench sources (e.g. the [frontend server (fesvr)](https://github.com/riscv-software-src/riscv-isa-sim)) are compiled under `work`. Each command will also generate a script or an executable (e.g. `bin/snitch_cluster.vsim`) which we can use to simulate software on Snitch, as we will see in section [Running a simulation](#running-a-simulation).
@@ -54,7 +54,7 @@ In the [`cfg`](https://github.com/pulp-platform/{{ repo }}/blob/{{ branch }}/tar
5454
The command you previously executed automatically generated the RTL sources from the templates, and it implicitly used the default configuration file. In this configuration the FPU is not equipped with a floating-point divide and square-root unit.
5555
To override the default configuration file, e.g. to use the omega TCDM interconnect, define the following variable when you invoke `make`:
5656
```shell
57-
make CFG_OVERRIDE=cfg/omega.json bin/snitch_cluster.vlt
57+
make CFG_OVERRIDE=cfg/omega.json verilator
5858
```
5959

6060
If you want to use a custom configuration, just point `CFG_OVERRIDE` to the path of your configuration file.
@@ -268,11 +268,11 @@ In your `tutorial` folder, create a new file named `app.mk` with the following c
268268
269269
```make
270270
APP := tutorial
271-
$(APP)_BUILD_DIR := $(ROOT)/target/snitch_cluster/sw/apps/$(APP)/build
272-
SRCS := $(ROOT)/target/snitch_cluster/sw/apps/$(APP)/src/$(APP).c
273-
$(APP)_INCDIRS := $(ROOT)/target/snitch_cluster/sw/apps/$(APP)/data
271+
$(APP)_BUILD_DIR := $(SN_ROOT)/target/snitch_cluster/sw/apps/$(APP)/build
272+
SRCS := $(SN_ROOT)/target/snitch_cluster/sw/apps/$(APP)/src/$(APP).c
273+
$(APP)_INCDIRS := $(SN_ROOT)/target/snitch_cluster/sw/apps/$(APP)/data
274274
275-
include $(ROOT)/target/snitch_cluster/sw/apps/common.mk
275+
include $(SN_ROOT)/target/snitch_cluster/sw/apps/common.mk
276276
```
277277

278278
This file will be included in the top-level Makefile, compiling your source code into an executable with the name provided in the `APP` variable.

sw/dnn/common.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
#
55
# Luca Colagrande <colluca@iis.ee.ethz.ch>
66

7-
include $(ROOT)/sw/apps/common.mk
8-
$(APP)_INCDIRS += $(ROOT)/sw/dnn/src
9-
$(APP)_INCDIRS += $(ROOT)/sw/blas
7+
include $(SN_ROOT)/sw/apps/common.mk
8+
$(APP)_INCDIRS += $(SN_ROOT)/sw/dnn/src
9+
$(APP)_INCDIRS += $(SN_ROOT)/sw/blas

target/common/common.mk

Lines changed: 40 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -8,143 +8,53 @@ PL_SIM ?= 0 # 1 for post-layout simulation
88
VCD_DUMP ?= 0 # 1 to dump VCD traces
99

1010
# Directories
11-
SIM_DIR ?= $(shell pwd)
12-
TB_DIR ?= $(SNITCH_ROOT)/target/common/test
13-
UTIL_DIR ?= $(SNITCH_ROOT)/util
14-
LOGS_DIR = $(SIM_DIR)/logs
15-
16-
# Files
17-
BENDER_LOCK = $(ROOT)/Bender.lock
18-
BENDER_YML = $(ROOT)/Bender.yml
19-
20-
# SEPP packages
21-
QUESTA_SEPP ?=
22-
VCS_SEPP ?=
23-
VERILATOR_SEPP ?=
11+
SIM_DIR ?= $(shell pwd)
12+
TB_DIR ?= $(SN_ROOT)/target/common/test
13+
UTIL_DIR ?= $(SN_ROOT)/util
14+
LOGS_DIR = $(SIM_DIR)/logs
15+
SN_PERIPH_DIR = $(SN_ROOT)/hw/snitch_cluster/src/snitch_cluster_peripheral
16+
SN_TARGET_DIR = $(SN_ROOT)/target/snitch_cluster
17+
SN_GEN_DIR ?= $(SN_TARGET_DIR)/.generated
18+
SN_HW_DIR = $(SN_ROOT)/hw
19+
SN_BIN_DIR = $(SN_TARGET_DIR)/bin
2420

2521
# External executables
26-
BENDER ?= bender
27-
VLT ?= $(VERILATOR_SEPP) verilator
28-
VCS ?= $(VCS_SEPP) vcs
22+
BENDER ?= bender
23+
REGGEN ?= $(shell $(BENDER) path register_interface)/vendor/lowrisc_opentitan/util/regtool.py
24+
VERIBLE_FMT ?= verible-verilog-format
2925
CLANG_FORMAT ?= clang-format
30-
VSIM ?= $(QUESTA_SEPP) vsim
31-
VOPT ?= $(QUESTA_SEPP) vopt
32-
VLOG ?= $(QUESTA_SEPP) vlog
33-
VLIB ?= $(QUESTA_SEPP) vlib
3426
RISCV_MC ?= $(LLVM_BINROOT)/llvm-mc
3527
ADDR2LINE ?= $(LLVM_BINROOT)/llvm-addr2line
3628
# tail is required for nonsense oseda output
3729
VLT_BIN = $(shell $(VERILATOR_SEPP) which verilator_bin | tail -n1 | $(VERILATOR_SEPP) xargs realpath | tail -n1)
3830

3931
# Internal executables
40-
GENTRACE_PY ?= $(UTIL_DIR)/trace/gen_trace.py
41-
ANNOTATE_PY ?= $(UTIL_DIR)/trace/annotate.py
42-
EVENTS_PY ?= $(UTIL_DIR)/trace/events.py
43-
JOIN_PY ?= $(UTIL_DIR)/bench/join.py
44-
ROI_PY ?= $(UTIL_DIR)/bench/roi.py
45-
VISUALIZE_PY ?= $(UTIL_DIR)/bench/visualize.py
46-
47-
VLT_JOBS ?= $(shell nproc)
48-
VLT_NUM_THREADS ?= 1
49-
50-
COMMON_BENDER_FLAGS += -t rtl -t snitch_cluster
51-
ifeq ($(PL_SIM), 1)
52-
COMMON_BENDER_FLAGS += -t postlayout
53-
endif
54-
55-
VSIM_BENDER += $(COMMON_BENDER_FLAGS) -t test -t simulation -t vsim
56-
VSIM_BUILDDIR ?= work-vsim
57-
VSIM_FLAGS += -t 1ps
58-
VOPT_FLAGS =
59-
ifeq ($(DEBUG), ON)
60-
VSIM_FLAGS += -do "log -r /*"
61-
VOPT_FLAGS += +acc
62-
endif
63-
64-
ifeq ($(PL_SIM), 1)
65-
include $(ROOT)/nonfree/gf12/modelsim/Makefrag
66-
VOPT_FLAGS += -modelsimini $(ROOT)/nonfree/gf12/modelsim/modelsim.ini
67-
VOPT_FLAGS += +nospecify
68-
VOPT_FLAGS += $(GATE_LIBS)
69-
VSIM_FLAGS += -modelsimini $(ROOT)/nonfree/gf12/modelsim/modelsim.ini
70-
VSIM_FLAGS += +nospecify
71-
endif
72-
73-
ifeq ($(VCD_DUMP), 1)
74-
VSIM_FLAGS += -do "source $(ROOT)/nonfree/gf12/modelsim/vcd.tcl"
75-
else
76-
VSIM_FLAGS += -do "run -a"
77-
endif
78-
79-
# VCS_BUILDDIR should to be the same as the `DEFAULT : ./work-vcs`
80-
# in target/snitch_cluster/synopsys_sim.setup
81-
VCS_BENDER += $(COMMON_BENDER_FLAGS) -t test -t simulation -t vcs
82-
VCS_BUILDDIR := work-vcs
32+
GENTRACE_PY ?= $(UTIL_DIR)/trace/gen_trace.py
33+
ANNOTATE_PY ?= $(UTIL_DIR)/trace/annotate.py
34+
EVENTS_PY ?= $(UTIL_DIR)/trace/events.py
35+
JOIN_PY ?= $(UTIL_DIR)/bench/join.py
36+
ROI_PY ?= $(UTIL_DIR)/bench/roi.py
37+
VISUALIZE_PY ?= $(UTIL_DIR)/bench/visualize.py
38+
SN_BOOTROM_GEN = $(SN_ROOT)/util/gen_bootrom.py
39+
SN_CLUSTER_GEN = $(SN_ROOT)/util/clustergen.py
40+
41+
# Clustergen prerequisites
42+
SN_CLUSTER_GEN_SRC = $(wildcard $(SN_ROOT)/util/clustergen/*.py)
43+
44+
# Bender prerequisites
45+
SN_BENDER_LOCK = $(SN_ROOT)/Bender.lock
46+
SN_BENDER_YML = $(SN_ROOT)/Bender.yml
8347

8448
# fesvr is being installed here
8549
FESVR ?= ${MKFILE_DIR}work
8650
FESVR_VERSION ?= 35d50bc40e59ea1d5566fbd3d9226023821b1bb6
8751

88-
VLT_BENDER += $(COMMON_BENDER_FLAGS) -t verilator -DASSERTS_OFF
89-
VLT_BUILDDIR := $(abspath work-vlt)
90-
VLT_FESVR = $(VLT_BUILDDIR)/riscv-isa-sim
91-
VLT_FLAGS += --timing
92-
VLT_FLAGS += --timescale 1ns/1ps
93-
VLT_FLAGS += --trace
94-
VLT_FLAGS += -Wno-BLKANDNBLK
95-
VLT_FLAGS += -Wno-LITENDIAN
96-
VLT_FLAGS += -Wno-CASEINCOMPLETE
97-
VLT_FLAGS += -Wno-CMPCONST
98-
VLT_FLAGS += -Wno-WIDTH
99-
VLT_FLAGS += -Wno-WIDTHCONCAT
100-
VLT_FLAGS += -Wno-UNSIGNED
101-
VLT_FLAGS += -Wno-UNOPTFLAT
102-
VLT_FLAGS += -Wno-fatal
103-
VLT_FLAGS += --unroll-count 1024
104-
VLT_FLAGS += --threads $(VLT_NUM_THREADS)
105-
106-
RISCV_MC_FLAGS ?= -disassemble -mcpu=snitch
107-
ANNOTATE_FLAGS ?= -q --keep-time --addr2line=$(ADDR2LINE)
108-
LAYOUT_EVENTS_FLAGS ?= --cfg=$(CFG)
109-
110-
# We need a recent LLVM installation (>11) to compile Verilator.
111-
# We also need to link the binaries with LLVM's libc++.
112-
# Define CLANG_PATH to be the path of your Clang installation.
113-
114-
ifneq (${CLANG_PATH},)
115-
CLANG_CC := $(CLANG_PATH)/bin/clang
116-
CLANG_CXX := $(CLANG_PATH)/bin/clang++
117-
CLANG_CXXFLAGS := -nostdinc++ -isystem $(CLANG_PATH)/include/c++/v1
118-
CLANG_LDFLAGS := -nostdlib++ -fuse-ld=lld -L ${CLANG_PATH}/lib -Wl,-rpath,${CLANG_PATH}/lib -lc++
119-
else
120-
CLANG_CC ?= clang
121-
CLANG_CXX ?= clang++
122-
CLANG_CXXFLAGS := ""
123-
CLANG_LDFLAGS := ""
124-
endif
125-
126-
# If requested, build verilator with LLVM and add llvm c/ld flags
127-
ifeq ($(VLT_USE_LLVM),ON)
128-
CC = $(CLANG_CC)
129-
CXX = $(CLANG_CXX)
130-
CFLAGS = $(CLANG_CXXFLAGS)
131-
CXXFLAGS = $(CLANG_CXXFLAGS)
132-
LDFLAGS = $(CLANG_LDFLAGS)
133-
VLT_FLAGS += --compiler clang
134-
VLT_FLAGS += -CFLAGS "${CLANG_CXXFLAGS}"
135-
VLT_FLAGS += -LDFLAGS "${CLANG_LDFLAGS}"
136-
endif
137-
138-
VLOGAN_FLAGS := -assert svaext
139-
VLOGAN_FLAGS += -assert disable_cover
140-
VLOGAN_FLAGS += -full64
141-
VLOGAN_FLAGS += -kdb
142-
VLOGAN_FLAGS += -timescale=1ns/1ps
143-
VHDLAN_FLAGS := -full64
144-
VHDLAN_FLAGS += -kdb
145-
146-
# default on target `all`
147-
all:
52+
# Flags
53+
COMMON_BENDER_FLAGS += -t rtl -t snitch_cluster
54+
COMMON_BENDER_SIM_FLAGS += -t simulation -t test
55+
RISCV_MC_FLAGS ?= -disassemble -mcpu=snitch
56+
ANNOTATE_FLAGS ?= -q --keep-time --addr2line=$(ADDR2LINE)
57+
LAYOUT_EVENTS_FLAGS ?= --cfg=$(CFG)
14858

14959
#################
15060
# Prerequisites #
@@ -162,21 +72,8 @@ work/lib/libfesvr.a: work/${FESVR_VERSION}_unzip
16272
mkdir -p $(dir $@)
16373
cp $(dir $<)libfesvr.a $@
16474

165-
# Build fesvr seperately for verilator since this might use different compilers
166-
# and libraries than modelsim/vcs and
167-
$(VLT_FESVR)/${FESVR_VERSION}_unzip:
168-
mkdir -p $(dir $@)
169-
wget -O $(dir $@)/${FESVR_VERSION} https://github.com/riscv/riscv-isa-sim/tarball/${FESVR_VERSION}
170-
tar xfm $(dir $@)${FESVR_VERSION} --strip-components=1 -C $(dir $@)
171-
patch $(VLT_FESVR)/fesvr/context.h < patches/context.h.diff
172-
touch $@
173-
174-
$(VLT_BUILDDIR)/lib/libfesvr.a: $(VLT_FESVR)/${FESVR_VERSION}_unzip
175-
cd $(dir $<)/ && ./configure --prefix `pwd` \
176-
CC=${CC} CXX=${CXX} CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" LDFLAGS="${LDFLAGS}"
177-
$(MAKE) -C $(dir $<) install-config-hdrs install-hdrs libfesvr.a
178-
mkdir -p $(dir $@)
179-
cp $(dir $<)libfesvr.a $@
75+
$(SN_GEN_DIR) $(SN_BIN_DIR):
76+
mkdir -p $@
18077

18178
########
18279
# Util #
@@ -200,10 +97,10 @@ endef
20097
# Common rule to fill a template file with clustergen
20198
# Arg 1: path for the generated file
20299
# Arg 2: path of the template file
203-
define cluster_gen_rule
204-
$(1): $(CFG) $(CLUSTER_GEN_PREREQ) $(2) | $(GENERATED_DIR)
100+
define sn_cluster_gen_rule
101+
$(1): $(SN_CFG) $(SN_CLUSTER_GEN) $(SN_CLUSTER_GEN_SRC) $(2) | $(SN_GEN_DIR)
205102
@echo "[CLUSTERGEN] Generate $$@"
206-
$(CLUSTER_GEN) -c $$< -o $$@ --template $(2)
103+
$(SN_CLUSTER_GEN) -c $$< -o $$@ --template $(2)
207104
endef
208105

209106
# Common rule to generate a Makefile with RTL source and header
@@ -216,10 +113,10 @@ endef
216113
# Arg 4: top module name
217114
# Arg 5: name of target for which prerequisites are generated
218115
define gen_rtl_prerequisites
219-
$(2)/$(4).f: $(BENDER_YML) $(BENDER_LOCK) | $(2)
116+
$(2)/$(4).f: $(SN_BENDER_YML) $(SN_BENDER_LOCK) | $(2)
220117
$(BENDER) script verilator $(3) > $$@
221118

222-
$(1): $(2)/$(4).f $(GENERATED_RTL_SOURCES) | $(2)
119+
$(1): $(2)/$(4).f $(SN_GEN_RTL_SRCS) | $(2)
223120
$(VLT) -f $$< --Mdir $(2) --MMD -E --top-module $(4) > /dev/null
224121
mv $(2)/V$(4)__ver.d $$@
225122
sed -E -i -e 's|^[^:]*:|$(5):|' \

target/common/rtl.mk

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2025 ETH Zurich and University of Bologna.
2+
# Solderpad Hardware License, Version 0.51, see LICENSE for details.
3+
# SPDX-License-Identifier: SHL-0.51
4+
5+
# Directories
6+
SN_BOOTROM_DIR ?= $(SN_TARGET_DIR)/test
7+
8+
# Templates
9+
SN_CLUSTER_WRAPPER_TPL = $(SN_HW_DIR)/snitch_cluster/src/snitch_cluster_wrapper.sv.tpl
10+
SN_CLUSTER_PKG_TPL = $(SN_HW_DIR)/snitch_cluster/src/snitch_cluster_pkg.sv.tpl
11+
12+
# Generated RTL sources
13+
SN_CLUSTER_WRAPPER = $(SN_GEN_DIR)/snitch_cluster_wrapper.sv
14+
SN_CLUSTER_PKG = $(SN_GEN_DIR)/snitch_cluster_pkg.sv
15+
SN_CLUSTER_PERIPH_TOP = $(SN_PERIPH_DIR)/snitch_cluster_peripheral_reg_top.sv
16+
SN_CLUSTER_PERIPH_PKG = $(SN_PERIPH_DIR)/snitch_cluster_peripheral_reg_pkg.sv
17+
SN_BOOTROM = $(SN_BOOTROM_DIR)/snitch_bootrom.sv
18+
19+
# All generated RTL sources
20+
SN_GEN_RTL_SRCS = $(SN_CLUSTER_WRAPPER) $(SN_CLUSTER_PKG) $(SN_CLUSTER_PERIPH_TOP) $(SN_CLUSTER_PERIPH_PKG) $(SN_BOOTROM)
21+
22+
# CLUSTERGEN rules
23+
$(eval $(call sn_cluster_gen_rule,$(SN_CLUSTER_WRAPPER),$(SN_CLUSTER_WRAPPER_TPL)))
24+
$(eval $(call sn_cluster_gen_rule,$(SN_CLUSTER_PKG),$(SN_CLUSTER_PKG_TPL)))
25+
26+
# REGGEN rules
27+
$(SN_CLUSTER_PERIPH_PKG): $(SN_CLUSTER_PERIPH_TOP)
28+
$(SN_CLUSTER_PERIPH_TOP): $(SN_PERIPH_DIR)/snitch_cluster_peripheral_reg.hjson
29+
@echo "[REGGEN] Generating peripheral regfile"
30+
$(REGGEN) -r -t $(SN_PERIPH_DIR) $<
31+
32+
# Bootrom rules
33+
$(SN_BOOTROM_DIR)/bootrom.elf $(SN_BOOTROM_DIR)/bootrom.dump $(SN_BOOTROM_DIR)/bootrom.bin $(SN_BOOTROM): $(SN_BOOTROM_DIR)/bootrom.S $(SN_BOOTROM_DIR)/bootrom.ld $(SN_BOOTROM_GEN) | $(SN_BOOTROM_DIR)
34+
$(RISCV_CC) -mabi=ilp32d -march=rv32imafd -static -nostartfiles -fuse-ld=$(RISCV_LD) -L$(SN_ROOT)/sw/runtime -T$(SN_BOOTROM_DIR)/bootrom.ld $< -o $(SN_BOOTROM_DIR)/bootrom.elf
35+
$(RISCV_OBJDUMP) -d $(SN_BOOTROM_DIR)/bootrom.elf > $(SN_BOOTROM_DIR)/bootrom.dump
36+
$(RISCV_OBJCOPY) -j .text -O binary $(SN_BOOTROM_DIR)/bootrom.elf $(SN_BOOTROM_DIR)/bootrom.bin
37+
$(SN_BOOTROM_GEN) --sv-module snitch_bootrom $(SN_BOOTROM_DIR)/bootrom.bin > $(SN_BOOTROM)
38+
39+
# General RTL targets
40+
.PHONY: sn-rtl sn-clean-rtl
41+
42+
sn-rtl: $(SN_GEN_RTL_SRCS)
43+
44+
sn-clean-rtl:
45+
rm -f $(SN_GEN_RTL_SRCS)
46+
47+
$(SN_BOOTROM_DIR):
48+
mkdir -p $@

0 commit comments

Comments
 (0)