From 55e2cb4a76c9f8f940031b41cb3358a0dcfa9860 Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Mon, 16 Mar 2020 17:49:24 -0400 Subject: [PATCH] driver test kernel --- driver/kernel/Makefile | 37 ++++++++++++++++++++++++ driver/kernel/main.c | 65 ++++++++++++++++++++++++++++++++++++++++++ driver/sim/Makefile | 4 +-- driver/sw/test.cpp | 12 ++++++++ driver/sw/utils.cpp | 2 -- simX/mem.cpp | 2 +- 6 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 driver/kernel/Makefile create mode 100644 driver/kernel/main.c diff --git a/driver/kernel/Makefile b/driver/kernel/Makefile new file mode 100644 index 00000000..0ac1368a --- /dev/null +++ b/driver/kernel/Makefile @@ -0,0 +1,37 @@ +RISCV_TOOL_PATH ?= $(wildcard ~/dev/riscv-gnu-toolchain/drops) +VX_RT_PATH ?= $(wildcard ../../runtime) + +CC = $(RISCV_TOOL_PATH)/bin/riscv32-unknown-elf-gcc +CXX = $(RISCV_TOOL_PATH)/bin/riscv32-unknown-elf-g++ +DMP = $(RISCV_TOOL_PATH)/bin/riscv32-unknown-elf-objdump +HEX = $(RISCV_TOOL_PATH)/bin/riscv32-unknown-elf-objcopy +GDB = $(RISCV_TOOL_PATH)/bin/riscv32-unknown-elf-gdb + +NEWLIB = $(VX_RT_PATH)/newlib/newlib.c +VX_STR = $(VX_RT_PATH)/startup/vx_start.s +VX_INT = $(VX_RT_PATH)/intrinsics/vx_intrinsics.s +VX_IO = $(VX_RT_PATH)/io/vx_io.s $(VX_RT_PATH)/io/vx_io.c +VX_API = $(VX_RT_PATH)/vx_api/vx_api.c +VX_FIO = $(VX_RT_PATH)/fileio/fileio.s + +CFLAGS = -march=rv32im -mabi=ilp32 -O0 -Wl,-Bstatic,-T,$(VX_RT_PATH)/mains/vortex_link.ld -ffreestanding -nostdlib + +LIBS = $(RISCV_TOOL_PATH)/riscv32-unknown-elf/lib/libc.a $(RISCV_TOOL_PATH)/riscv32-unknown-elf/lib/libstdc++.a -static-libgcc -lgcc + +PROJECT = demo + +SRCS = main.c + +all: $(PROJECT).dump $(PROJECT).hex + +$(PROJECT).dump: $(PROJECT).elf + $(DMP) -D $(PROJECT).elf > $(PROJECT).dump + +$(PROJECT).hex: $(PROJECT).elf + $(HEX) -O ihex $(PROJECT).elf $(PROJECT).hex + +$(PROJECT).elf: $(SRCS) + $(CC) $(CFLAGS) $(VX_STR) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(SRCS) $(LIBS) -I$(VX_RT_PATH) -o $(PROJECT).elf + +clean: + rm -rf *.o *.elf *.dump *.hex *.qemu *.log *.debug diff --git a/driver/kernel/main.c b/driver/kernel/main.c new file mode 100644 index 00000000..6171408f --- /dev/null +++ b/driver/kernel/main.c @@ -0,0 +1,65 @@ +#include "intrinsics/vx_intrinsics.h" +#include "io/vx_io.h" +#include "vx_api/vx_api.h" + +typedef struct +{ + unsigned * x; + unsigned * y; + unsigned * z; + unsigned numColums; + unsigned numRows; +} mat_add_args_t; + +unsigned x[] = {5, 5, 5, 5, + 6, 6, 6, 6, + 7, 7, 7, 7, + 8, 8, 8, 8}; + +unsigned y[] = {1, 1, 1, 1, + 1, 1, 1, 1, + 1, 1, 1, 1, + 1, 1, 1, 1}; + +unsigned z[] = {0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0}; + +void mat_add_kernel(void * void_arguments) +{ + mat_add_args_t * arguments = (mat_add_args_t *) void_arguments; + + unsigned wid = vx_warpID(); + unsigned tid = vx_threadID(); + + bool valid = (wid < arguments->numRows) && (tid < arguments->numColums); + + __if (valid) + { + unsigned index = (wid * arguments->numColums) + tid; + arguments->z[index] = arguments->x[index] + arguments->y[index]; + } + __endif +} + +int main() +{ + // Main is called with all threads active of warp 0 + vx_tmc(1); + + vx_print_str("Demo kernel\n"); + + mat_add_args_t arguments; + arguments.x = x; + arguments.y = y; + arguments.z = z; + arguments.numColums = 4; + arguments.numRows = 4; + + vx_spawnWarps(4, 4, mat_add_kernel, &arguments); + + vx_print_str("done."); + + return 0; +} \ No newline at end of file diff --git a/driver/sim/Makefile b/driver/sim/Makefile index c6351c41..1f5c05be 100644 --- a/driver/sim/Makefile +++ b/driver/sim/Makefile @@ -1,11 +1,11 @@ -CXXFLAGS += -O2 -g -Wall -Wextra -pedantic -Wfatal-errors +CXXFLAGS += -O0 -g -Wall -Wextra -pedantic -Wfatal-errors CXXFLAGS += -I../sw LDFLAGS += -L./obj_dir -DRV_CFLAGS += -O2 -g -Wall -Wextra -pedantic -Wfatal-errors +DRV_CFLAGS += -O0 -g -Wall -Wextra -pedantic -Wfatal-errors DRV_CFLAGS += -I../../sw diff --git a/driver/sw/test.cpp b/driver/sw/test.cpp index 97a690a2..42df93f2 100644 --- a/driver/sw/test.cpp +++ b/driver/sw/test.cpp @@ -52,6 +52,18 @@ static int upload_program(vx_device_h device, const char* filename, uint32_t tra // get buffer address auto buf_ptr = (uint8_t*)vs_buf_ptr(buffer); + + // + // copy initialization routine + // + + ((uint32_t*)buf_ptr)[0] = 0xf1401073; + ((uint32_t*)buf_ptr)[1] = 0xf1401073; + ((uint32_t*)buf_ptr)[2] = 0x30101073; + ((uint32_t*)buf_ptr)[3] = 0x800000b7; + ((uint32_t*)buf_ptr)[4] = 0x000080e7; + + vx_copy_to_fpga(buffer, 0, 5 * 4, 0); // // copy hex program diff --git a/driver/sw/utils.cpp b/driver/sw/utils.cpp index 262c6ee1..5f73eefd 100644 --- a/driver/sw/utils.cpp +++ b/driver/sw/utils.cpp @@ -1,5 +1,3 @@ - - #include #include "utils.h" diff --git a/simX/mem.cpp b/simX/mem.cpp index 0b826ac5..870f9946 100644 --- a/simX/mem.cpp +++ b/simX/mem.cpp @@ -340,7 +340,7 @@ void RAM::loadHexImpl(std::string path) { uint32_t new_addr = init_addr+off; ((uint32_t*)this->get(new_addr))[0] = 0x00000000; } - } + } fseek(fp, 0, SEEK_END); uint32_t size = ftell(fp);