diff --git a/examples/add/Makefile b/examples/add/Makefile new file mode 100644 index 0000000..1cdf2cd --- /dev/null +++ b/examples/add/Makefile @@ -0,0 +1,24 @@ +# Makefile for RISC-V add example + +CC = gcc +CFLAGS = -O3 +CFLAGS_VEC = -O3 -march=rv64gcv + +# Default target with -O3 +all: add_riscv add_riscv_vec + +# Build with -O3 optimization +add_riscv: add_riscv.c + $(CC) $(CFLAGS) -o add_riscv add_riscv.c + $(CC) $(CFLAGS) -S -o add_riscv.s add_riscv.c + +# Build with vector extensions +add_riscv_vec: add_riscv.c + $(CC) $(CFLAGS_VEC) -o add_riscv_vec add_riscv.c + $(CC) $(CFLAGS_VEC) -S -o add_riscv_vec.s add_riscv.c + +# Clean up +clean: + rm -f add_riscv add_riscv_vec add_riscv.s add_riscv_vec.s + +.PHONY: all clean \ No newline at end of file diff --git a/examples/add/add_riscv.c b/examples/add/add_riscv.c new file mode 100644 index 0000000..e584767 --- /dev/null +++ b/examples/add/add_riscv.c @@ -0,0 +1,54 @@ +// Vector add benchmark for RISC-V testing +// a[i] = b[i] + c[i] + +#include +#include + +#define DTYPE double + +void kernel(DTYPE* a, DTYPE* b, DTYPE* c, const int size) +{ + // OSACA start marker will be added around this loop + for(int i=0; i 1) { + size = atoi(argv[1]); + } + + printf("RISC-V Vector add: a[i] = b[i] + c[i], size=%d\n", size); + + // Allocate memory + DTYPE* a = (DTYPE*)malloc(size * sizeof(DTYPE)); + DTYPE* b = (DTYPE*)malloc(size * sizeof(DTYPE)); + DTYPE* c = (DTYPE*)malloc(size * sizeof(DTYPE)); + + // Initialize arrays + for(int i=0; i +#include + +#define DTYPE double + +void kernel(DTYPE* a, DTYPE* b, DTYPE* c, const DTYPE s, const int size) +{ + // OSACA start marker will be added around this loop + for(int i=0; i 1) { + size = atoi(argv[1]); + } + + printf("RISC-V STREAM triad: a[i] = b[i] + s * c[i], size=%d\n", size); + + // Allocate memory + DTYPE* a = (DTYPE*)malloc(size * sizeof(DTYPE)); + DTYPE* b = (DTYPE*)malloc(size * sizeof(DTYPE)); + DTYPE* c = (DTYPE*)malloc(size * sizeof(DTYPE)); + + // Initialize arrays + for(int i=0; i