Skip to content

Commit

Permalink
sw: Add generic offload app
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Aug 30, 2023
1 parent 7e0e812 commit 6944f8d
Show file tree
Hide file tree
Showing 22 changed files with 288 additions and 357 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ occamy-single-cluster-vsim:
- cd target/sim
- make CFG_OVERRIDE=cfg/single-cluster.hjson rtl
- $QUESTA make bin/occamy_top.vsim
- $QUESTA ../../deps/snitch_cluster/util/sim/simulate.py sw/run.yaml
--simulator vsim --sim-bin bin/occamy_top.vsim
35 changes: 17 additions & 18 deletions target/sim/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ VLT_FLAGS += --prof-cfuncs # Enable code profiling
# C testbench #
###############

TB_CC_SOURCES = $(SNITCH_TEST_DIR)/rtl_lib.cc
TB_CC_SOURCES = $(SNITCH_TEST_DIR)/bootrom.cc
TB_CC_SOURCES += $(SNITCH_TEST_DIR)/ipc.cc
TB_CC_SOURCES += $(SNITCH_TEST_DIR)/rtl_lib.cc
TB_CC_SOURCES += $(SNITCH_TEST_DIR)/common_lib.cc
TB_CC_SOURCES += $(TARGET_TEST_DIR)/bootdata.cc
TB_CC_SOURCES += $(TARGET_TEST_DIR)/uartdpi/uartdpi.c
Expand All @@ -127,7 +129,9 @@ TB_CC_FLAGS +=-I$(SNITCH_TEST_DIR)
TB_CC_FLAGS +=-I$(TARGET_TEST_DIR)/uartdpi

# Required C sources for the verilator TB that are linked against the verilated model
VLT_COBJ = $(VLT_BUILDDIR)/tb/common_lib.o
VLT_COBJ = $(VLT_BUILDDIR)/tb/bootrom.o
VLT_COBJ += $(VLT_BUILDDIR)/tb/ipc.o
VLT_COBJ += $(VLT_BUILDDIR)/tb/common_lib.o
VLT_COBJ += $(VLT_BUILDDIR)/tb/verilator_lib.o
VLT_COBJ += $(VLT_BUILDDIR)/tb/tb_bin.o
VLT_COBJ += $(VLT_BUILDDIR)/test/uartdpi/uartdpi.o
Expand Down Expand Up @@ -450,34 +454,29 @@ $(PLATFORM_HEADERS_DIR)/occamy_base_addr.h: $(CFG)
# Traces #
##########

# CVA6 trace should use binary written in logs/.rtlbinary
# which is retrieved by the Makefrag in the BINARY variable,
# but the Snitch traces use another binary which is expected to
# be passed on the command-line, overriding the BINARY variable.
# So we define a new variable to store the CVA6 binary
CVA6_BINARY ?= $(shell cat $(LOGS_DIR)/.rtlbinary)

$(LOGS_DIR)/hart_00000_perf.json: $(LOGS_DIR)/trace_hart_00000.txt $(ROOT)/util/trace/events.py
$(PYTHON) $(ROOT)/util/trace/events.py -f cva6 $< -o $@
$(LOGS_DIR)/hart_00000_perf.json: $(LOGS_DIR)/trace_hart_00000.txt $(EVENTS_PY)
$(PYTHON) $(EVENTS_PY) -f cva6 $< -o $@

$(LOGS_DIR)/trace_hart_00000.s: $(LOGS_DIR)/trace_hart_00000.txt ${ANNOTATE}
$(PYTHON) ${ANNOTATE} ${ANNOTATE_FLAGS} -o $@ $(CVA6_BINARY) $<
$(LOGS_DIR)/trace_hart_00000.s: $(LOGS_DIR)/trace_hart_00000.txt $(ANNOTATE_PY)
$(PYTHON) $(ANNOTATE_PY) $(ANNOTATE_FLAGS) -o $@ $(CVA6_BINARY) $<

$(LOGS_DIR)/trace_hart_00000.diff: $(LOGS_DIR)/trace_hart_00000.txt ${ANNOTATE}
$(PYTHON) ${ANNOTATE} ${ANNOTATE_FLAGS} -o $@ $(CVA6_BINARY) $< -d
$(LOGS_DIR)/trace_hart_00000.diff: $(LOGS_DIR)/trace_hart_00000.txt $(ANNOTATE_PY)
$(PYTHON) $(ANNOTATE_PY) $(ANNOTATE_FLAGS) -o $@ $(CVA6_BINARY) $< -d

traces: $(LOGS_DIR)/hart_00000_perf.json

annotate: $(shell (echo $(LOGS_DIR)/trace_hart_00000.txt | sed 's/\.txt/\.s/') || echo "") \
$(shell (echo $(LOGS_DIR)/trace_hart_00000.txt | sed 's/\.txt/\.diff/') || echo "")

$(LOGS_DIR)/perf.csv: $(shell (ls $(LOGS_DIR)/trace_hart_*.dasm 2>/dev/null | sed 's/trace_hart/hart/' | sed 's/.dasm/_perf.json/')) \
$(LOGS_DIR)/hart_00000_perf.json $(ROOT)/util/trace/perf_csv.py
$(PYTHON) $(ROOT)/util/trace/perf_csv.py -o $@ -i $(LOGS_DIR)/hart_*_perf.json
$(LOGS_DIR)/hart_00000_perf.json $(PERF_CSV_PY)
$(PYTHON) $(PERF_CSV_PY) -o $@ -i $(LOGS_DIR)/hart_*_perf.json

$(LOGS_DIR)/event.csv: $(shell (ls $(LOGS_DIR)/trace_hart_*.dasm 2>/dev/null | sed 's/trace_hart/hart/' | sed 's/.dasm/_perf.json/')) \
$(LOGS_DIR)/hart_00000_perf.json $(ROOT)/util/trace/perf_csv.py
$(PYTHON) $(ROOT)/util/trace/perf_csv.py -o $@ -i $(LOGS_DIR)/hart_*_perf.json --filter tstart tend
$(LOGS_DIR)/hart_00000_perf.json $(PERF_CSV_PY)
$(PYTHON) $(PERF_CSV_PY) -o $@ -i $(LOGS_DIR)/hart_*_perf.json --filter tstart tend

#############
# Verilator #
Expand Down Expand Up @@ -575,7 +574,7 @@ clean-work:
rm -rf work

clean-bender:
rm -rf Bender.lock .bender/ work/
rm -rf $(ROOT)/Bender.lock $(ROOT)/.bender/ $(ROOT)/deps

clean-logs:
rm -rf $(LOGS_DIR)/
Expand Down
2 changes: 1 addition & 1 deletion target/sim/sw/device/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Luca Colagrande <colluca@iis.ee.ethz.ch>

# Add user applications to APPS variable
APPS = offload
APPS = blas/axpy

TARGET ?= all

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

APP = offload
SRCS = src/offload.c
INCDIRS = ../../../host/apps/offload/src
include ../../../../../../../deps/snitch_cluster/sw/blas/axpy/Makefile
include ../../common.mk

include ../common.mk
$(DEP): $(DATA_H)
11 changes: 7 additions & 4 deletions target/sim/sw/device/apps/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

include ../../toolchain.mk
# Usage of absolute paths is required to externally include
# this Makefile from multiple different locations
MK_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
include $(MK_DIR)/../toolchain.mk

###################
# Build variables #
###################

# Directories
BUILDDIR = $(abspath build)
APPSDIR = $(abspath ../)
RUNTIME_DIR = $(abspath ../../runtime)
APPSDIR = $(abspath $(MK_DIR))
RUNTIME_DIR = $(abspath $(MK_DIR)/../runtime)
SNRT_DIR = $(shell bender path snitch_cluster)/sw/snRuntime
SW_DIR = $(abspath ../../../)
SW_DIR = $(abspath $(MK_DIR)/../../)

# Dependencies
INCDIRS += $(RUNTIME_DIR)/src
Expand Down
205 changes: 0 additions & 205 deletions target/sim/sw/device/apps/offload/src/offload.c

This file was deleted.

2 changes: 2 additions & 0 deletions target/sim/sw/device/runtime/src/occamy_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ extern volatile uint32_t* snrt_cluster_clint_set_ptr();
extern volatile uint32_t* snrt_cluster_clint_clr_ptr();

extern uint32_t snrt_cluster_hw_barrier_addr();

extern volatile uint32_t* snrt_zero_memory_ptr();
4 changes: 4 additions & 0 deletions target/sim/sw/device/runtime/src/occamy_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ inline volatile uint32_t* __attribute__((const)) snrt_cluster_clint_clr_ptr() {
inline uint32_t __attribute__((const)) snrt_cluster_hw_barrier_addr() {
return _snrt_cluster_hw_barrier;
}

inline volatile uint32_t* __attribute__((const)) snrt_zero_memory_ptr() {
return cluster_zero_memory_ptr(snrt_cluster_idx());
}
3 changes: 3 additions & 0 deletions target/sim/sw/device/runtime/src/occamy_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
#define SNRT_CRT0_PRE_BARRIER
#define SNRT_INVOKE_MAIN
#define SNRT_CRT0_POST_BARRIER
#define SNRT_CRT0_CALLBACK7

static inline void snrt_crt0_callback3() {
_snrt_cluster_hw_barrier = cluster_hw_barrier_addr(snrt_cluster_idx());
}

static inline void snrt_crt0_callback7() { return_to_cva6(SYNC_CLUSTERS); }

#include "start.c"
1 change: 1 addition & 0 deletions target/sim/sw/device/runtime/src/snrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
#include "occamy_memory.c"
#include "occamy_start.c"
#include "sync.c"
#include "sys_dma.c"
#include "team.c"
6 changes: 6 additions & 0 deletions target/sim/sw/device/runtime/src/snrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#ifndef SNRT_H
#define SNRT_H

#include <stddef.h>
#include <stdint.h>

// Occamy specific definitions
#include "occamy_defs.h"
#include "occamy_memory_map.h"
#include "sys_dma.h"

// Forward declarations
#include "alloc_decls.h"
Expand All @@ -30,3 +34,5 @@
#include "ssr.h"
#include "sync.h"
#include "team.h"

#endif // SNRT_H
Loading

0 comments on commit 6944f8d

Please sign in to comment.