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

Gvsoc ci #142

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@ jobs:
run: |
make SIM_DIR=./runs/simple annotate -j

##############################################
# Simulate SW on Snitch Cluster w/ GVSOC #
##############################################

sw-snitch-cluster-gvsoc:
name: Simulate SW on Snitch Cluster w/ GVSOC
runs-on: ubuntu-22.04
needs: build-docker
if: >
github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name != github.repository
container:
image: ghcr.io/pulp-platform/snitch_cluster:${{ github.ref_name }}
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Build Software
working-directory: target/snitch_cluster
run: |
make CFG_OVERRIDE=cfg/github-ci.hjson OPENOCD_SEMIHOSTING=ON sw
- name: Run Tests
working-directory: target/snitch_cluster
run: |
GVSOC_TARGET=pulp.snitch.snitch_cluster_single && ./util/run.py sw/run.yaml --simulator gvsoc -j

# #########################################
# # Build SW on Snitch Cluster w/ Banshee #
# #########################################
Expand Down
2 changes: 2 additions & 0 deletions target/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ SED_SRCS := sed -e ${MATCH_END} -e ${MATCH_BGN} -e ${MATCH_DEF}

COMMON_BENDER_FLAGS += -t rtl

GVSOC_BUILDDIR ?= work-gvsoc

VSIM_BENDER += $(COMMON_BENDER_FLAGS) -t test -t simulation -t vsim
VSIM_SOURCES = $(shell ${BENDER} script flist-plus ${VSIM_BENDER} | ${SED_SRCS})
VSIM_BUILDDIR ?= work-vsim
Expand Down
21 changes: 21 additions & 0 deletions target/common/gvsoc.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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

$(BIN_DIR)/$(TARGET).gvsoc:
@echo "#!/bin/bash" > $@
@echo 'binary=$$(realpath $$1)' >> $@
@echo 'echo $$binary > .rtlbinary' >> $@
@echo 'path="$$(dirname "$$(dirname "$$(readlink -f "$${BASH_SOURCE[0]}")")")"' >> $@
@echo 'if [ -z "$$GVSOC_TARGET" ]; then' >> $@
@echo ' GVSOC_TARGET=snitch' >> $@
@echo 'fi' >> $@
@echo 'gvsoc --target=$${GVSOC_TARGET} --binary $$binary \
--control-script=$${path}/${GVSOC_BUILDDIR}/pulp/pulp/snitch/utils/gvcontrol.py $$2 run' >> $@
@chmod +x $@

.PHONY: clean-gvsoc
clean-gvsoc:
rm -rf $(BIN_DIR)/$(TARGET).gvsoc $(GVSOC_BUILDDIR)

clean: clean-gvsoc
6 changes: 6 additions & 0 deletions target/snitch_cluster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ $(BIN_DIR)/$(TARGET).vcs: ${VCS_SOURCES} ${TB_SRCS} $(TB_CC_SOURCES) $(RTL_CC_SO
-assert disable_cover -override_timescale=1ns/1ps -full64 tb_bin $(TB_CC_SOURCES) $(RTL_CC_SOURCES) \
-CFLAGS "$(TB_CC_FLAGS)" -LDFLAGS "-L${FESVR}/lib" -lfesvr

#########
# GVSOC #
#########

include $(ROOT)/target/common/gvsoc.mk

########
# Util #
########
Expand Down
41 changes: 21 additions & 20 deletions target/snitch_cluster/sw/run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,53 @@ runs:
- elf: tests/build/alias.elf
simulators: [vsim, vcs, verilator] # banshee does not model alias regions
- elf: tests/build/atomics.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x4
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x4
- elf: tests/build/barrier.elf
- elf: tests/build/data_mover.elf
- elf: tests/build/dma_empty_transfer.elf
- elf: tests/build/dma_simple.elf
- elf: tests/build/event_unit.elf
- elf: tests/build/fence_i.elf
- elf: tests/build/fp8_comparison_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with segfault
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with segfault
- elf: tests/build/fp8_comparison_vector.elf
simulators: [vsim, vcs, verilator] # banshee fails with segfault
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with segfault
- elf: tests/build/fp8_computation_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with JIT issue
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with JIT issue
- elf: tests/build/fp8_computation_vector.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x6
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x6
- elf: tests/build/fp8alt_comparison_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with segfault
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with segfault
- elf: tests/build/fp8alt_comparison_vector.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x10
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x10
- elf: tests/build/fp8alt_computation_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with JIT issue
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with JIT issue
- elf: tests/build/fp8alt_computation_vector.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x12
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x12
- elf: tests/build/fp16_comparison_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x10
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x10
- elf: tests/build/fp16_comparison_vector.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x10
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x10
- elf: tests/build/fp16_computation_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with JIT issue
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with JIT issue
- elf: tests/build/fp16_computation_vector.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x6
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x6
- elf: tests/build/fp16alt_comparison_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x10
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x10
- elf: tests/build/fp16alt_comparison_vector.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x10
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x10
- elf: tests/build/fp16alt_computation_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with JIT issue
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with JIT issue
- elf: tests/build/fp16alt_computation_vector.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x16
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x16
- elf: tests/build/fp32_comparison_scalar.elf
- elf: tests/build/fp32_comparison_vector.elf
- elf: tests/build/fp32_computation_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x2
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x2
- elf: tests/build/fp32_computation_vector.elf
simulators: [vsim, vcs, verilator] # banshee fails with exit code 0x2
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with exit code 0x2
- elf: tests/build/fp32_conversions_scalar.elf
simulators: [vsim, vcs, verilator] # banshee fails with illegal instruction
simulators: [vsim, vcs, verilator, gvsoc] # banshee fails with illegal instruction
# - elf: tests/build/fp64_conversions_scalar.elf
# simulators: [vsim, vcs, verilator]
- elf: tests/build/interrupt_local.elf
Expand All @@ -72,6 +72,7 @@ runs:
- elf: tests/build/non_null_exitcode.elf
retcode: 56
- elf: tests/build/caq.elf
simulators: [vsim, vcs, verilator, banshee] # GVSOC does not model caq
- elf: tests/build/caq_frep.elf
simulators: [vsim, vcs, verilator] # banshee does not model FREP timing
- elf: apps/blas/axpy/build/axpy.elf
Expand Down
5 changes: 3 additions & 2 deletions target/snitch_cluster/util/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

sys.path.append(str(Path(__file__).parent / '../../../util/sim'))
import sim_utils # noqa: E402
from Simulator import QuestaSimulator, VCSSimulator, VerilatorSimulator, \
from Simulator import QuestaSimulator, VCSSimulator, VerilatorSimulator, GvsocSimulator, \
BansheeSimulator # noqa: E402


SIMULATORS = {
'vsim': QuestaSimulator(Path(__file__).parent.resolve() / '../bin/snitch_cluster.vsim'),
'vcs': VCSSimulator(Path(__file__).parent.resolve() / '../bin/snitch_cluster.vcs'),
'verilator': VerilatorSimulator(Path(__file__).parent.resolve() / '../bin/snitch_cluster.vlt'),
'banshee': BansheeSimulator(Path(__file__).parent.resolve() / '../src/banshee.yaml')
'banshee': BansheeSimulator(Path(__file__).parent.resolve() / '../src/banshee.yaml'),
'gvsoc': GvsocSimulator(Path(__file__).parent.resolve() / '../bin/snitch_cluster.gvsoc')
}


Expand Down
30 changes: 30 additions & 0 deletions util/sim/Simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,36 @@ def get_cpu_time(self):
return hours*3600 + minutes*60 + seconds


class GvsocSimulation(Simulation):
"""A functional simulation running on GVSOC."""

def __init__(self, sim_bin=None, cmd=None, **kwargs):
super().__init__(**kwargs)

if cmd is None:
self.cmd = ['gvsoc', '--target', os.environ.get('GVSOC_TARGET'), '--binary',
str(self.elf), 'run']
else:
self.dynamic_args = {
'sim_bin': str(sim_bin),
'elf': str(self.elf),
'run_dir': str(self.run_dir)
}
self.cmd = [Template(arg).render(**self.dynamic_args) for arg in cmd]
self.cmd.append('--simulator=gvsoc')

def successful(self):
"""Return whether the simulation was successful."""
# On GVSOC, OpenOCD semi-hosting is used which can just report 0 or 1
actual_retcode = self.get_retcode()
if actual_retcode is not None:
if self.expected_retcode != 0:
return int(actual_retcode) != 0
else:
return int(actual_retcode) == 0
else:
return False

class VCSSimulation(QuestaVCSSimulation):
"""An RTL simulation running on VCS."""

Expand Down
19 changes: 18 additions & 1 deletion util/sim/Simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Luca Colagrande <[email protected]>

from Simulation import QuestaSimulation, VCSSimulation, VerilatorSimulation, BansheeSimulation
from Simulation import QuestaSimulation, VCSSimulation, VerilatorSimulation, BansheeSimulation, GvsocSimulation


class Simulator(object):
Expand Down Expand Up @@ -96,6 +96,23 @@ def get_simulation(self, test):
cmd=cmd
)

class GvsocSimulator(RTLSimulator):
"""Gvsoc simulator

An [RTL simulator][Simulator.RTLSimulator], identified by the name
`vsim`, tailored to the creation of
[Gvsoc simulations][Simulation.GvsocSimulation].
"""

def __init__(self, binary):
"""Constructor for the GvsocSimulator class.

Arguments:
binary: The Gvsoc simulation binary.
"""
super().__init__(binary, name='gvsoc', simulation_cls=GvsocSimulation)
Comment on lines +99 to +113
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it inherit from the RTLSimulator class?




class VCSSimulator(RTLSimulator):
"""VCS simulator
Expand Down
10 changes: 8 additions & 2 deletions util/sim/SnitchSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

class SnitchSim:

def __init__(self, sim_bin: str, snitch_bin: str, log: str = None):
def __init__(self, sim_bin: str, snitch_bin: str, simulator: str = None, log: str = None):
self.sim_bin = sim_bin
self.snitch_bin = snitch_bin
self.sim = None
self.tmpdir = None
self.simulator = simulator
self.log = open(log, 'w+') if log else log

def start(self):
Expand All @@ -40,10 +41,15 @@ def start(self):
rx_fd = os.path.join(self.tmpdir.name, 'rx')
os.mkfifo(rx_fd)
# Start simulator process
ipc_arg = f'--ipc,{tx_fd},{rx_fd}'
if self.simulator == 'gvsoc':
ipc_arg = f'--ipc {tx_fd},{rx_fd}'
else:
ipc_arg = f'--ipc,{tx_fd},{rx_fd}'

self.sim = subprocess.Popen([self.sim_bin, self.snitch_bin, ipc_arg], stdout=self.log)
# Open FIFOs
self.tx = open(tx_fd, 'wb', buffering=0) # Unbuffered

self.rx = open(rx_fd, 'rb')
# Create thread to monitor simulation
self.stop_sim_monitor = threading.Event()
Expand Down
6 changes: 5 additions & 1 deletion util/sim/verif_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def parser(self):
parser.add_argument(
'--log',
help='Redirect simulation output to this log file')
parser.add_argument(
'--simulator',
help='Specifies simulator')
parser.add_argument(
'--dump-results',
action='store_true',
Expand Down Expand Up @@ -144,7 +147,8 @@ def simulate(self):
elf = Elf(self.args.snitch_bin)

# Start simulation
sim = SnitchSim(self.args.sim_bin, self.args.snitch_bin, log=self.args.log)
sim = SnitchSim(self.args.sim_bin, self.args.snitch_bin, simulator=self.args.simulator,
log=self.args.log)
sim.start()

# Wait for kernel execution to be over
Expand Down
Loading