diff --git a/rvvector/benchmark_temp/Makefile b/rvvector/benchmark_temp/Makefile new file mode 100644 index 00000000..74447af7 --- /dev/null +++ b/rvvector/benchmark_temp/Makefile @@ -0,0 +1,41 @@ +LIB_PATH = ../../runtime + +COMP = /nethome/ekim79/riscv-gnu-toolchain/drops/bin/riscv32-unknown-elf-gcc + +CC_FLAGS = -ffreestanding -O0 -Wl,--gc-sections -nostartfiles -nostdlib -nostartfiles -nodefaultlibs -Wl,-Bstatic,-T,$(LIB_PATH)/mains/vortex_link.ld -march=rv32imv -mabi=ilp32 + +DMP = /nethome/ekim79/riscv-gnu-toolchain/drops/bin/riscv32-unknown-elf-objdump +CPY = /nethome/ekim79/riscv-gnu-toolchain/drops/bin/riscv32-unknown-elf-objcopy + +# VX_STR = ../../startup/vx_start.s + +NEWLIB = $(LIB_PATH)/newlib/newlib.c +VX_STR = $(LIB_PATH)/startup/vx_start.s +VX_INT = $(LIB_PATH)/intrinsics/vx_intrinsics.s +VX_IO = $(LIB_PATH)/io/vx_io.s $(LIB_PATH)/io/vx_io.c +VX_API = $(LIB_PATH)/vx_api/vx_api.c +VX_TEST = $(LIB_PATH)/tests/tests.c +VX_FIO = $(LIB_PATH)/fileio/fileio.s +VX_VEC1 = vx_vec_vvaddint32.s +VX_VEC2 = vx_vec_saxpy.s #float --> int +VX_VEC3 = vx_vec_sgemm_float.s #float --> int +VX_VEC4 = vx_vec_vsadd.s +VX_VEC5 = vx_vec_memcpy.s +LIBS = /nethome/ekim79/riscv-gnu-toolchain/drops/riscv32-unknown-elf/lib/libc.a /nethome/ekim79/riscv-gnu-toolchain/drops/riscv32-unknown-elf/lib/libstdc++.a -static-libgcc -lgcc + +VX_MAIN = vx_vec_benchmark + +all: HEX DUMP ELF + +DUMP: ELF + $(DMP) -D $(VX_MAIN).elf > $(VX_MAIN).dump + +HEX: ELF + $(CPY) -O ihex $(VX_MAIN).elf $(VX_MAIN).hex + +ELF: + $(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC1) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_TEST) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf +# $(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC2) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_TEST) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf +# $(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC3) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_TEST) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf +# $(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC4) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_TEST) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf +# $(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC5) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_TEST) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf~ diff --git a/rvvector/benchmark_temp/TO_DO_LIST b/rvvector/benchmark_temp/TO_DO_LIST new file mode 100644 index 00000000..28a9d57b --- /dev/null +++ b/rvvector/benchmark_temp/TO_DO_LIST @@ -0,0 +1,9 @@ +1. add benchmarks under (Vortex/benchmarks/..) + 1.1 bfs --> blas spmv approach + 1.2 kmeans // stage 2 + 1.3 saxpy --> sample + 1.4 sfilter // stage 2 + 1.5 sgemm --> sample modify (float --> int) + 1.6 vecadd --> sample + + diff --git a/rvvector/benchmark_temp/vx_vec_benchmark.c b/rvvector/benchmark_temp/vx_vec_benchmark.c new file mode 100644 index 00000000..06faf2ea --- /dev/null +++ b/rvvector/benchmark_temp/vx_vec_benchmark.c @@ -0,0 +1,156 @@ +#include +#include +#include "../../runtime/intrinsics/vx_intrinsics.h" +#include "vx_vec_benchmark.h" + +int main() +{ + vx_tmc(1); + int n = 5; + int *a = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1}; + int *b = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1}; + int *c = (int*)malloc(sizeof(int) * n); //{1, 1, 1, 1, 1}; + + for (int i = 0; i < n; ++i) { a[i] = 1; b[i] = 2; c[i] = 5; } + +#if 1 +//--------------------------------------------------------------- +/* vvaddint32 + * # vector-vector add routine of 32-bit integers + * # void vvaddint32(size_t n, const int*x, const int*y, int*z) + * # { for (size_t i=0; i failed at ! \n", i); + return 1; + } + } + printf("\nPASSED.......................... \n"); +#endif +#if 0 +//--------------------------------------------------------------- +/* # vector-scalar add + # for (i=0; i failed at ! \n", i); + return 1; + } + } + printf("\nPASSED.......................... \n"); + +#endif +#if 0 +//--------------------------------------------------------------- +/* # memory copy + # void *memcpy(void* dest, const void* src, size_t n) */ + for (int i = 0; i < n; ++i) { a[i] = 1; b[i] = 2;} + printf("memcpy\na[%d]: ", n); + for(int i = 0; i < n; ++i) printf("%d \n", a[i]); + printf("\nb[%d]: ", n); + for(int i = 0; i < n; ++i) printf("%d \n", b[i]); + + vx_vec_memcpy(a, b, n); + + for(int i = 0; i < n; ++i) + { + if(a[i] != b[i]) + { + printf("\n failed at ! \n", i); + return; + } + } + printf("\nPASSED.......................... \n"); +//--------------------------------------------------------------- +/* # void saxpy(size_t n, const float a, const float *x, float *y) + # ==> convert to int!! + # void saxpy(size_t n, const int a, const int *x, int *y) + # { + # size_t i; + # for (i=0; i failed at ! \n", i); + return; + } + } + printf("\nPASSED.......................... \n"); + +//--------------------------------------------------------------- +/* # void sgemm_nn(size_t n, size_t m, size_t k, const float*a, // m * k matrix +# size_t lda, const float*b, // k * n matrix +# size_t ldb, float*c, // m * n matrix +# size_t ldc) +# c += a*b (alpha=1, no transpose on input matrices) +# matrices stored in C row-major order */ + + int m = 8; + int k = 8; + int n = 8 + int lda = 4; + int ldb = 4; + int ldc = 4; + + int* a1 = (int*)malloc(sizeof(m * k)); + int* b1 = (int*)malloc(sizeof(k * n)); + int* c1 = (int*)malloc(sizeof(m * n)); + + for(int i = 0; i < (m * k); ++i) a1[i] = 1; + for(int i = 0; i < (k * n); ++i) b1[i] = 1; + for(int i = 0; i < (m * n); ++i) c1[i] = 1; + + printf("sgemm_nn\na[%d]: ", n); + for(int i = 0; i < n; ++i) printf("%d \n", a1[i]); + printf("\nb[%d]: ", n); + for(int i = 0; i < n; ++i) printf("%d \n", b1[i]); + + vx_vec_sgemm_nn(n, m, k, a1, lda, b1, ldb, c1, ldc); + + //for(int i = 0; i < n; ++i) + //{ + // if(b[i] != ((a[i] * scalar) + c[i])) + // { + // printf("\n failed at ! \n", i); + // return; + // } + //} + printf("\nNOT TESTED.......................... \n"); +//--------------------------------------------------------------- +#endif + + vx_tmc(0); + return 0; +} diff --git a/rvvector/benchmark_temp/vx_vec_benchmark.h b/rvvector/benchmark_temp/vx_vec_benchmark.h new file mode 100644 index 00000000..e6feb741 --- /dev/null +++ b/rvvector/benchmark_temp/vx_vec_benchmark.h @@ -0,0 +1,16 @@ +#pragma once + + +#ifdef __cplusplus +extern "C" { +#endif + +void vx_vec_vvaddint32(int n, int* a, int* b, int *c); +//void vx_vec_vsadd(int n, int* a, int scalar); +//void vx_vec_memcpy(int* a, int* b, int n); +//void vx_vec_saxpy(int n, int scalar, int* a, int* b); +//void vx_vec_sgemm_nn(int n, int m, int k, int* a1, int lda, int* b1, int ldb, int* c1, int ldc); + +#ifdef __cplusplus +} +#endif diff --git a/rvvector/benchmark_temp/vx_vec_memcpy.s b/rvvector/benchmark_temp/vx_vec_memcpy.s new file mode 100644 index 00000000..8edbe844 --- /dev/null +++ b/rvvector/benchmark_temp/vx_vec_memcpy.s @@ -0,0 +1,17 @@ +.type vx_vec_memcpy, @function +.global vx_vec_memcpy +# void *memcpy(void* dest, const void* src, size_t n) +# a0=dest, a1=src, a2=n +# +vx_vec_memcpy: +# memcpy + mv a3, a0 # Copy destination + vsetvli t0, a2, e8,m8 # Vectors of 8b +loop: + vlb.v v0, (a1) # Load bytes + add a1, a1, t0 # Bump pointer + sub a2, a2, t0 # Decrement count + vsb.v v0, (a3) # Store bytes + add a3, a3, t0 # Bump pointer + bnez a2, loop # Any more? + ret # Return \ No newline at end of file diff --git a/rvvector/benchmark_temp/vx_vec_saxpy.s b/rvvector/benchmark_temp/vx_vec_saxpy.s new file mode 100644 index 00000000..bd44cd40 --- /dev/null +++ b/rvvector/benchmark_temp/vx_vec_saxpy.s @@ -0,0 +1,28 @@ +.type vx_vec_saxpy, @function +.global vx_vec_saxpy +# void +# saxpy(size_t n, const float a, const float *x, float *y) +# { +# size_t i; +# for (i=0; i results.txt + +# echo ../kernel/vortex_test.hex +make +printf "Fasten your seatbelts ladies and gentelmen!!\n\n\n\n" +cd obj_dir && ./Vcache_simX -E -a rv32i --core ../../rvvector/benchmark_temp/vx_vec_benchmark.hex -s -b 1> emulator.debug