Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spike-dasm: Add Snitch ISA aware riscv-isa-sim as submodule #32

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jobs:
working-directory: target/snitch_cluster
run: |
./run.py sw/run.yaml --simulator verilator -j
- name: Annotate traces
working-directory: target/snitch_cluster
run: |
make SIM_DIR=./runs/simple annotate -j

# Tests requiring hardware FDIV unit
sw-snitch-cluster-fdiv-vlt:
Expand Down
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ Bender.lock
.vscode/
__pycache__

// Modelsim Fiels
# Modelsim Files
*.wlf
modelsim.ini
*stacktrace*
transcript

gmon.out

// Docs
# Docs
/site/
/docs/generated/
/docs/generated/

# Installation directories
/.venv/
/tools/
19 changes: 2 additions & 17 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,12 @@ variables:
TERM: ansi
FORCE_COLOR: 1
# Configure environment
PYTHON: /usr/local/anaconda3-2022.05/bin/python3
BENDER: bender-0.27.1
CC: gcc-9.2.0
CXX: g++-9.2.0
VCS_SEPP: vcs-2020.12
VERILATOR_SEPP: verilator-4.110
QUESTA_SEPP: questa-2022.3
LLVM_BINROOT: /usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0/bin
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: /usr/pack/gcc-9.2.0-af/linux-x64/bin/gcc
LLVM_SYS_120_PREFIX: /usr/pack/llvm-12.0.1-af
CMAKE: cmake-3.18.1

before_script:
- $PYTHON -m venv .venv
- source .venv/bin/activate
# Unpack packages in a local temporary directory which can be safely cleaned
# after installation. Also protects against "No space left on device" errors
# occurring when the /tmp folder is filled by other processes.
- mkdir tmp
- TMPDIR=tmp pip install -r python-requirements.txt
- rm -rf tmp
- $BENDER vendor init
source iis-setup.sh

##############
# Build docs #
Expand Down Expand Up @@ -118,6 +102,7 @@ snitch-cluster-vsim:
- cd target/snitch_cluster
- make bin/snitch_cluster.vsim
- ./run.py sw/run.yaml --simulator vsim -j --run-dir runs/vsim
- make SIM_DIR=./runs/vsim/simple annotate -j

# Banshee
snitch-cluster-banshee:
Expand Down
34 changes: 4 additions & 30 deletions docs/ug/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ git clone https://github.com/pulp-platform/{{ repo }}.git --recurse-submodules

If you had already cloned the repository without the `--recurse-submodules` flag, clone its submodules:
```shell
git submodule init --recursive
git submodule update --init --recursive
```

## Tools and environment
Expand Down Expand Up @@ -46,38 +46,12 @@ The following instructions are extracted from the Docker container [README.md](h

## IIS environment setup

To make sure the right versions of each tool are picked up, set the following environment variables, e.g. in a bash shell:
To make sure the right versions of each tool are picked up on your IIS machine and install additional tools, run:

```bash
export PYTHON="/usr/local/anaconda3-2022.05/bin/python3"
export BENDER="bender-0.27.1"
export CC="gcc-9.2.0"
export CXX="g++-9.2.0"
export LLVM_BINROOT="/usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0/bin"
# As a temporary workaround (until correct tool versions are installed system-wide):
export PATH=/home/colluca/snitch/bin:$PATH
export PATH=/usr/scratch/dachstein/colluca/opt/verible/bin:$PATH
source iis-setup.sh
```

Add these commands to your shell startup file (e.g. `~/.bashrc` if you use bash as the default shell) to ensure that the environment is set up correctly every time you open a new shell.
Have a look inside the script. You will want to add some of the steps contained therein to your shell startup file, e.g. exporting environment variables and activating the Python virtual environment. This way, every time you open a new shell, your environment will be ready for developing on Snitch, and you won't have to repeat the installation steps.

Create a Python virtual environment:

```shell
$PYTHON -m venv ~/.venvs/snitch_cluster
```

Activate your environment, e.g. in a bash shell:

```bash
source ~/.venvs/snitch_cluster/bin/activate
```

You may want to add the last command to your shell startup file to ensure that the virtual environment is activated on every new shell you open.

Install the required packages in the currently active virtual environment:

```shell
pip install -r python-requirements.txt
```
<!--end-section-2-->
36 changes: 36 additions & 0 deletions iis-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Define environment variables
export PYTHON=/usr/local/anaconda3-2022.05/bin/python3
export BENDER=bender-0.27.1
export CC=gcc-9.2.0
export CXX=g++-9.2.0
export VCS_SEPP=vcs-2020.12
export VERILATOR_SEPP=verilator-4.110
export QUESTA_SEPP=questa-2022.3
export LLVM_BINROOT=/usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0/bin

# Create Python virtual environment with required packages
$PYTHON -m venv .venv
source .venv/bin/activate
# Unpack packages in a local temporary directory which can be safely cleaned
# after installation. Also protects against "No space left on device" errors
# occurring when the /tmp folder is filled by other processes.
mkdir tmp
TMPDIR=tmp pip install -r python-requirements.txt
rm -rf tmp

# Bender initialization
$BENDER vendor init

# Install spike-dasm
mkdir tools/
cd tools/
wget https://github.com/pulp-platform/riscv-isa-sim/releases/download/snitch-v0.1.0/snitch-spike-dasm-0.1.0-x86_64-linux-gnu-almalinux8.7.tar.gz
tar xzf snitch-spike-dasm-0.1.0-x86_64-linux-gnu-almalinux8.7.tar.gz
cd -
echo $PATH
export PATH=$(pwd)/tools:$PATH
11 changes: 5 additions & 6 deletions target/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
DEBUG ?= OFF # ON to turn on wave logging

# Directories
LOGS_DIR ?= logs
SIM_DIR ?= $(shell pwd)
TB_DIR ?= $(SNITCH_ROOT)/target/common/test
UTIL_DIR ?= $(SNITCH_ROOT)/util
LOGS_DIR = $(SIM_DIR)/logs

# SEPP packages
QUESTA_SEPP ?=
Expand Down Expand Up @@ -184,16 +185,14 @@ define QUESTASIM
@mkdir -p $(dir $@)
@echo "#!/bin/bash" > $@
@echo 'binary=$$(realpath $$1)' >> $@
@echo 'mkdir -p $(LOGS_DIR)' >> $@
@echo 'echo $$binary > $(LOGS_DIR)/.rtlbinary' >> $@
@echo 'echo $$binary > .rtlbinary' >> $@
@echo '${VSIM} +permissive ${VSIM_FLAGS} $$3 -work ${MKFILE_DIR}/${VSIM_BUILDDIR} -c \
-ldflags "-Wl,-rpath,${FESVR}/lib -L${FESVR}/lib -lfesvr -lutil" \
$(1)_opt +permissive-off ++$$binary ++$$2' >> $@
@chmod +x $@
@echo "#!/bin/bash" > [email protected]
@echo 'binary=$$(realpath $$1)' >> [email protected]
@echo 'mkdir -p $(LOGS_DIR)' >> [email protected]
@echo 'echo $$binary > $(LOGS_DIR)/.rtlbinary' >> [email protected]
@echo 'echo $$binary > .rtlbinary' >> [email protected]
@echo '${VSIM} +permissive ${VSIM_FLAGS} -work ${MKFILE_DIR}/${VSIM_BUILDDIR} \
-ldflags "-Wl,-rpath,${FESVR}/lib -L${FESVR}/lib -lfesvr -lutil" \
$(1)_opt +permissive-off ++$$binary ++$$2' >> [email protected]
Expand Down Expand Up @@ -257,7 +256,7 @@ $(LOGS_DIR)/trace_hart_%.txt $(LOGS_DIR)/hart_%_perf.json: $(LOGS_DIR)/trace_har

# Generate source-code interleaved traces for all harts. Reads the binary from
# the logs/.rtlbinary file that is written at start of simulation in the vsim script
BINARY ?= $(shell cat $(LOGS_DIR)/.rtlbinary)
BINARY ?= $(shell cat $(SIM_DIR)/.rtlbinary)
$(LOGS_DIR)/trace_hart_%.s: $(LOGS_DIR)/trace_hart_%.txt ${ANNOTATE_PY}
$(PYTHON) ${ANNOTATE_PY} ${ANNOTATE_FLAGS} -o $@ $(BINARY) $<
$(LOGS_DIR)/trace_hart_%.diff: $(LOGS_DIR)/trace_hart_%.txt ${ANNOTATE_PY}
Expand Down
10 changes: 9 additions & 1 deletion target/snitch_cluster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,18 @@ $(VLT_BUILDDIR)/generated/%.o: $(GENERATED_DIR)/%.cc ${VLT_BUILDDIR}/lib/libfesv

# Build compilation script and compile all sources for Verilator simulation
# Link verilated archive with $(VLT_COBJ)
bin/snitch_cluster.vlt: $(VLT_AR) $(VLT_COBJ) ${VLT_BUILDDIR}/lib/libfesvr.a
bin/.snitch_cluster.vlt.elf: $(VLT_AR) $(VLT_COBJ) ${VLT_BUILDDIR}/lib/libfesvr.a
mkdir -p $(dir $@)
$(CXX) $(LDFLAGS) -std=c++14 -L ${VLT_BUILDDIR}/lib -o $@ $(VLT_COBJ) $(VLT_AR) -lfesvr -lpthread

# Build wrapper around Verilator binary, needed to create .rtlbinary
bin/snitch_cluster.vlt: bin/.snitch_cluster.vlt.elf
@echo "#!/bin/bash" > $@
@echo 'binary=$$(realpath $$1)' >> $@
@echo 'echo $$binary > .rtlbinary' >> $@
@echo '$(abspath $<) $$binary $$2' >> $@
@chmod +x $@

############
# Modelsim #
############
Expand Down
5 changes: 5 additions & 0 deletions util/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FROM ubuntu:18.04 AS builder
ARG CMAKE_VERSION=3.19.4
ARG PYTHON_VERSION=3.9.12
ARG BENDER_VERSION=0.27.1
ARG SPIKE_DASM_VERSION=0.1.0
# Run dpkg without interactive dialogue
ARG DEBIAN_FRONTEND=noninteractive

Expand Down Expand Up @@ -76,6 +77,9 @@ RUN cargo install --path /tmp/banshee
RUN wget https://github.com/pulp-platform/bender/releases/download/v${BENDER_VERSION}/bender-${BENDER_VERSION}-x86_64-linux-gnu-ubuntu18.04.tar.gz
RUN tar xzf bender-${BENDER_VERSION}-x86_64-linux-gnu-ubuntu18.04.tar.gz

# Install spike-dasm
RUN wget https://github.com/pulp-platform/riscv-isa-sim/releases/download/snitch-v${SPIKE_DASM_VERSION}/snitch-spike-dasm-${SPIKE_DASM_VERSION}-x86_64-linux-gnu-ubuntu18.04.tar.gz
RUN tar xzf snitch-spike-dasm-${SPIKE_DASM_VERSION}-x86_64-linux-gnu-ubuntu18.04.tar.gz

# 2. Stage
FROM ubuntu:18.04 AS snitch_cluster
Expand Down Expand Up @@ -141,6 +145,7 @@ RUN apt-get update && apt-get install software-properties-common -y && \

# Copy artifacts from stage 1.
COPY --from=builder /tools/bender bin/
COPY --from=builder /tools/spike-dasm bin/
COPY --from=builder /root/.cargo/bin/banshee bin/
COPY --from=builder /opt/python /opt/python

Expand Down
2 changes: 1 addition & 1 deletion util/sim/Simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_retcode(self):
if self.dry_run:
return 0
else:
if self.process:
if self.completed():
return int(self.process.returncode)

def successful(self):
Expand Down
Loading