mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-24 05:47:35 -04:00
driver test kernel
This commit is contained in:
parent
8b4397f0ec
commit
55e2cb4a76
6 changed files with 117 additions and 5 deletions
37
driver/kernel/Makefile
Normal file
37
driver/kernel/Makefile
Normal file
|
@ -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
|
65
driver/kernel/main.c
Normal file
65
driver/kernel/main.c
Normal file
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
#include <iostream>
|
||||
#include "utils.h"
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue