diff --git a/cheshire/sw/Makefile b/cheshire/sw/Makefile index 56bd291cc..c76737e5d 100644 --- a/cheshire/sw/Makefile +++ b/cheshire/sw/Makefile @@ -6,22 +6,45 @@ # # Copy and compile vector software on Cheshire -CHS_ROOT ?= $(realpath ../../../../../..) -ARA_SW := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +CHS_ROOT ?= $(dir $(realpath $(firstword $(MAKEFILE_LIST))))/../../../../../.. +ARA_ROOT := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))/../.. CHS_SW := $(CHS_ROOT)/sw -SRC := $(wildcard $(ARA_SW)/*.c) $(wildcard $(ARA_SW)/*.h) +ARA_SW := $(ARA_ROOT)/cheshire/sw +ARA_APPS := $(ARA_ROOT)/apps + +APPS := $(patsubst $(ARA_APPS)/%/main.c,%,$(shell find $(ARA_APPS) -name "main.c")) +SW_C := $(wildcard $(ARA_SW)/*.c) +DEPS_H := $(wildcard $(ARA_SW)/*.h) + +ARA_CONFIGURATION ?= 2_lanes +include $(ARA_ROOT)/config/$(ARA_CONFIGURATION).mk # Get the original compiler options and add the support for vector extension CHS_SW_FLAGS ?= $(shell grep "^CHS_SW_FLAGS\s\+?=\s\+" -- $(CHS_SW)/sw.mk | sed 's/^.*?= //' | sed s/rv64gc/rv64gcv/) +# Tweak the compilation to include Cheshire-related headers and files +CHS_SW_FLAGS += -DCHESHIRE -DNR_LANES=$(nr_lanes) -DVLEN=$(vlen) -.PHONY: chs-sw-all copy_vector_sw +.PHONY: chs-sw-all copy_vector_sw copy-vector-deps # Forward build command to the main Cheshire makefile and attach the correct -march -# Rename the .c vector files not to break the cheshire vanilla flow -chs-sw-all: copy-vector-sw +chs-sw-all: copy-vector-deps make -C $(CHS_ROOT) $@ CHS_SW_FLAGS="$(CHS_SW_FLAGS)" - for f in $(filter %.c, $(SRC)); do mv $(CHS_SW)/tests/$f $(CHS_SW)/tests/$f.bkp; done -# Copy the vector programs to cheshire -copy-vector-sw: - cp $(SRC) $(CHS_SW)/tests +# Copy the dependencies from this folder to Cheshire +copy-vector-deps: $(DEPS_H) + cp $^ $(CHS_SW)/tests + +# Copy the vector programs from this folder to Cheshire +copy-vector-sw: $(SW_C) + cp $^ $(CHS_SW)/tests + +# Copy the apps from the app folder to Cheshire +define app_copy_template +.PHONY: copy-$1 + +# Create the data first and then copy everything to Cheshire +copy-$1: $(shell find $(ARA_APPS)/$(1) -name "*.c" -o -name "*.S" -o -name "*.h") + $(MAKE) -C $(ARA_APPS) $1/data.S def_args_$$1="$(def_args_$1)" + cp $$^ $(CHS_SW)/tests +endef +$(foreach app,$(APPS),$(eval $(call app_copy_template,$(app)))) diff --git a/cheshire/sw/README.md b/cheshire/sw/README.md index e4be744d2..e11e9a934 100644 --- a/cheshire/sw/README.md +++ b/cheshire/sw/README.md @@ -1,9 +1,30 @@ # Build software for Cheshire Ara -Compile the `.c` programs in this folder with: +## Copy the source files to Cheshire + +Copy the source files from this folder into Cheshire's `sw/tests` directory. + +```bash +make copy-vector-sw +``` + +## Copy an app to Cheshire + +Copy one of the app files from the `app` folder into Cheshire's `sw/tests` directory. + +Use the target `copy-$app` to move the necessary source files to Cheshire's `sw/tests`. +For example, to move the `fmatmul` app: + +```bash +make copy-fmatmul +``` + +## Compile the vector code for Cheshire + +Compile the source files with the vector extension support enable: ```bash make chs-sw-all ``` -This command will copy the necessary source files into Cheshire's `sw/tests` directory and compile them with the support for vector extension. \ No newline at end of file +This command will also copy the necessary dependencies to `sw/tests` and enable the vector extension at compile time. diff --git a/cheshire/sw/cheshire_util.h b/cheshire/sw/cheshire_util.h index ca1bd5b29..fa79709e1 100644 --- a/cheshire/sw/cheshire_util.h +++ b/cheshire/sw/cheshire_util.h @@ -18,7 +18,7 @@ inline void cheshire_start() { uart_init(&__base_uart, reset_freq, __BOOT_BAUDRATE); } -inline void cheshire_finish() { +inline void cheshire_end() { // Flush teh UART uart_write_flush(&__base_uart); } diff --git a/cheshire/sw/vector_util.h b/cheshire/sw/vector_util.h index 9526ffb66..77e032ef6 100644 --- a/cheshire/sw/vector_util.h +++ b/cheshire/sw/vector_util.h @@ -13,9 +13,31 @@ #include #include "encoding.h" +#define start_timer() +#define stop_timer() +#define get_timer() 0 + +#define FABS(x) ((x < 0) ? -x : x) + inline void enable_rvv() { asm volatile ("li t0, %0" :: "i"(MSTATUS_VS)); asm volatile ("csrs mstatus, t0" ); } +inline int similarity_check(double a, double b, double threshold) { + double diff = a - b; + if (FABS(diff) > threshold) + return 0; + else + return 1; +} + +inline int similarity_check_32b(float a, float b, float threshold) { + float diff = a - b; + if (FABS(diff) > threshold) + return 0; + else + return 1; +} + #endif