application exit error handing
This commit is contained in:
@@ -11,9 +11,9 @@ CFLAGS += -I$(VORTEX_RT_PATH)/include -I$(VORTEX_RT_PATH)/../hw
|
||||
|
||||
LDFLAGS += -Wl,-Bstatic,-T,$(VORTEX_RT_PATH)/linker/vx_link.ld -Wl,--gc-sections $(VORTEX_RT_PATH)/libvortexrt.a
|
||||
|
||||
PROJECT = vx_simple
|
||||
PROJECT = simple
|
||||
|
||||
SRCS = main.c tests.c
|
||||
SRCS = main.cpp tests.cpp
|
||||
|
||||
all: $(PROJECT).elf $(PROJECT).hex $(PROJECT).dump
|
||||
|
||||
@@ -27,7 +27,10 @@ $(PROJECT).elf: $(SRCS)
|
||||
$(CC) $(CFLAGS) $(SRCS) $(LDFLAGS) -o $(PROJECT).elf
|
||||
|
||||
run: $(PROJECT).hex
|
||||
(cd ../../../hw/simulate/obj_dir && ./VVortex ../../../tests/runtime/simple/$(PROJECT).hex)
|
||||
../../../hw/simulate/obj_dir/VVortex $(PROJECT).hex
|
||||
|
||||
run-simx: $(PROJECT).hex
|
||||
../../../simX/simX -a rv32i -i $(PROJECT).hex
|
||||
|
||||
.depend: $(SRCS)
|
||||
$(CC) $(CFLAGS) -MM $^ > .depend;
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
#include "tests.h"
|
||||
#include <stdbool.h>
|
||||
#include <vx_intrinsics.h>
|
||||
#include <vx_print.h>
|
||||
#include <vx_spawn.h>
|
||||
#include <VX_config.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(int task_id, void * void_arguments) {
|
||||
mat_add_args_t * arguments = (mat_add_args_t *) void_arguments;
|
||||
arguments->z[task_id] = arguments->x[task_id] + arguments->y[task_id];
|
||||
}
|
||||
|
||||
int main() {
|
||||
vx_printf("Let's start... (This might take a while)\n");
|
||||
|
||||
unsigned what[36];
|
||||
bool passed = true;
|
||||
|
||||
for (int i = 0; i < 36; i++) {
|
||||
what[i] = i;
|
||||
if (what[i] != i) {
|
||||
passed = false;
|
||||
vx_printf("T1 Fail On %d", i);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 36; i++) {
|
||||
if (what[i] != i) {
|
||||
passed = false;
|
||||
vx_printf("T2 Fail on %d", i);
|
||||
}
|
||||
}
|
||||
|
||||
if (passed) {
|
||||
vx_printf("Wr->read and repeat(Wr) tests passed!\n");
|
||||
}
|
||||
|
||||
vx_printf("Simple Main\n");
|
||||
|
||||
// TMC test
|
||||
test_tmc();
|
||||
|
||||
// Control Divergence Test
|
||||
vx_printf("test_divergence\n");
|
||||
test_divergence();
|
||||
|
||||
// Test wspawn
|
||||
vx_printf("test_wspawn\n");
|
||||
test_wsapwn();
|
||||
|
||||
vx_printf("Shared Memory test\n");
|
||||
unsigned * ptr = (unsigned *)SMEM_BASE_ADDR;
|
||||
unsigned value = 0;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
*ptr = value;
|
||||
unsigned read_valud = *ptr;
|
||||
vx_printf("ptr: %p\n", ptr);
|
||||
vx_printf("Original Value: %x\n", value);
|
||||
vx_printf("Read Value: %x\n", read_valud);
|
||||
vx_printf("-------------------\n");
|
||||
value++;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
vx_printf("vx_spawn_tasks mat_add_kernel\n");
|
||||
|
||||
mat_add_args_t arguments;
|
||||
arguments.x = x;
|
||||
arguments.y = y;
|
||||
arguments.z = z;
|
||||
arguments.numColums = 4;
|
||||
arguments.numRows = 4;
|
||||
|
||||
vx_spawn_tasks(arguments.numRows * arguments.numColums, mat_add_kernel, &arguments);
|
||||
|
||||
vx_printf("Waiting to ensure other warps are done... (Takes a while)\n");
|
||||
for (int i = 0; i < 5000; i++) {}
|
||||
|
||||
for (int i = 0; i < arguments.numRows; i++) {
|
||||
for (int j = 0; j < arguments.numColums; j++) {
|
||||
unsigned index = (i * arguments.numColums) + j;
|
||||
vx_printf("0x%x ", z[index]);
|
||||
}
|
||||
vx_printf("\n");
|
||||
}
|
||||
vx_printf("Passed!\n");
|
||||
return 0;
|
||||
}
|
||||
30
tests/runtime/simple/main.cpp
Normal file
30
tests/runtime/simple/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "tests.h"
|
||||
#include <vx_print.h>
|
||||
|
||||
int main() {
|
||||
int errors = 0;
|
||||
|
||||
vx_printf("Simple Test\n");
|
||||
|
||||
errors += test_global_memory();
|
||||
|
||||
errors += test_stack_memory();
|
||||
|
||||
errors += test_shared_memory();
|
||||
|
||||
errors += test_tmc();
|
||||
|
||||
errors += test_divergence();
|
||||
|
||||
errors += test_wsapwn();
|
||||
|
||||
errors += test_spawn_tasks();
|
||||
|
||||
if (0 == errors) {
|
||||
vx_printf("Passed!\n");
|
||||
} else {
|
||||
vx_printf("Failed!\n");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
5974
tests/runtime/simple/simple.hex
Normal file
5974
tests/runtime/simple/simple.hex
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,83 +0,0 @@
|
||||
#include "tests.h"
|
||||
#include <stdbool.h>
|
||||
#include <vx_intrinsics.h>
|
||||
#include <vx_print.h>
|
||||
|
||||
int tmc_array[4] = {5, 5, 5, 5};
|
||||
|
||||
void test_tmc_impl() {
|
||||
unsigned tid = vx_thread_id(); // Get TID
|
||||
tmc_array[tid] = tid;
|
||||
}
|
||||
|
||||
void test_tmc() {
|
||||
vx_printf("testing_tmc\n");
|
||||
|
||||
vx_tmc(4);
|
||||
test_tmc_impl();
|
||||
vx_tmc(1);
|
||||
|
||||
vx_printf("%x", tmc_array[0]);
|
||||
vx_printf("%x", tmc_array[1]);
|
||||
vx_printf("%x", tmc_array[2]);
|
||||
vx_printf("%x", tmc_array[3]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int div_arr[4];
|
||||
|
||||
void test_divergence() {
|
||||
vx_tmc(4);
|
||||
|
||||
unsigned tid = vx_thread_id(); // Get TID
|
||||
|
||||
bool b = tid < 2;
|
||||
__if (b) {
|
||||
bool c = tid < 1;
|
||||
__if (c) {
|
||||
div_arr[tid] = 10;
|
||||
}
|
||||
__else {
|
||||
div_arr[tid] = 11;
|
||||
}
|
||||
__endif
|
||||
}
|
||||
__else {
|
||||
bool c = tid < 3;
|
||||
__if (c) {
|
||||
div_arr[tid] = 12;
|
||||
}
|
||||
__else {
|
||||
div_arr[tid] = 13;
|
||||
}
|
||||
__endif
|
||||
}
|
||||
__endif
|
||||
|
||||
vx_tmc(1);
|
||||
|
||||
vx_printf("%x", div_arr[0]);
|
||||
vx_printf("%x", div_arr[1]);
|
||||
vx_printf("%x", div_arr[2]);
|
||||
vx_printf("%x", div_arr[3]);
|
||||
}
|
||||
|
||||
unsigned wsapwn_arr[4];
|
||||
|
||||
void simple_kernel() {
|
||||
unsigned wid = vx_warp_id();
|
||||
|
||||
wsapwn_arr[wid] = wid;
|
||||
|
||||
vx_tmc(0 == wid);
|
||||
}
|
||||
|
||||
void test_wsapwn() {
|
||||
vx_wspawn(4, (unsigned)simple_kernel);
|
||||
simple_kernel();
|
||||
vx_printf("%x", wsapwn_arr[0]);
|
||||
vx_printf("%x", wsapwn_arr[1]);
|
||||
vx_printf("%x", wsapwn_arr[2]);
|
||||
vx_printf("%x", wsapwn_arr[3]);
|
||||
}
|
||||
180
tests/runtime/simple/tests.cpp
Normal file
180
tests/runtime/simple/tests.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
#include "tests.h"
|
||||
#include <stdio.h>
|
||||
#include <vx_intrinsics.h>
|
||||
#include <vx_print.h>
|
||||
#include <vx_spawn.h>
|
||||
|
||||
int check_error(const int* buffer, int size) {
|
||||
int errors = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
int value = buffer[i];
|
||||
int ref_value = 65 + i;
|
||||
if (value == ref_value) {
|
||||
//vx_printf("[%d] %c\n", i, value);
|
||||
} else {
|
||||
vx_printf("*** error: [%d] %x, expected %x\n", i, value, ref_value);
|
||||
++errors;
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define GLOBAL_MEM_SZ 8
|
||||
int global_buffer[GLOBAL_MEM_SZ];
|
||||
|
||||
int test_global_memory() {
|
||||
int errors = 0;
|
||||
|
||||
vx_printf("Global Memory test\n");
|
||||
|
||||
for (int i = 0; i < GLOBAL_MEM_SZ; i++) {
|
||||
global_buffer[i] = 65 + i;
|
||||
}
|
||||
|
||||
return check_error(global_buffer, GLOBAL_MEM_SZ);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int test_stack_memory() {
|
||||
static const int STACK_MEM_SZ = 8;
|
||||
int stack_buffer[STACK_MEM_SZ];
|
||||
int errors = 0;
|
||||
|
||||
vx_printf("Stack Memory test\n");
|
||||
|
||||
for (int i = 0; i < STACK_MEM_SZ; i++) {
|
||||
stack_buffer[i] = 65 + i;
|
||||
}
|
||||
|
||||
return check_error(stack_buffer, STACK_MEM_SZ);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int test_shared_memory() {
|
||||
static const int SHARED_MEM_SZ = 8;
|
||||
int* shared_buffer = (int*)(SMEM_BASE_ADDR-(SMEM_SIZE-SHARED_MEM_SZ-4));
|
||||
int errors = 0;
|
||||
|
||||
vx_printf("Shared Memory test\n");
|
||||
|
||||
for (int i = 0; i < SHARED_MEM_SZ; i++) {
|
||||
shared_buffer[i] = 65 + i;
|
||||
}
|
||||
|
||||
return check_error(shared_buffer, SHARED_MEM_SZ);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int tmc_buffer[NUM_THREADS];
|
||||
|
||||
int test_tmc() {
|
||||
int errors = 0;
|
||||
|
||||
vx_printf("Thread mask test\n");
|
||||
|
||||
vx_tmc(NUM_THREADS);
|
||||
unsigned tid = vx_thread_id();
|
||||
tmc_buffer[tid] = 65 + tid;
|
||||
vx_tmc(1);
|
||||
|
||||
return check_error(tmc_buffer, NUM_THREADS);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int wspawn_buffer[NUM_WARPS];
|
||||
|
||||
void simple_kernel() {
|
||||
unsigned wid = vx_warp_id();
|
||||
wspawn_buffer[wid] = 65 + wid;
|
||||
vx_tmc(0 == wid);
|
||||
}
|
||||
|
||||
int test_wsapwn() {
|
||||
vx_printf("test_wspawn\n");
|
||||
vx_wspawn(NUM_WARPS, simple_kernel);
|
||||
simple_kernel();
|
||||
|
||||
return check_error(wspawn_buffer, NUM_WARPS);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define DIV_BUF_SZ ((NUM_THREADS > 4) ? 4 : NUM_THREADS)
|
||||
int div_buffer[DIV_BUF_SZ];
|
||||
|
||||
int test_divergence() {
|
||||
int errors = 0;
|
||||
|
||||
vx_printf("Control divergence test\n");
|
||||
|
||||
vx_tmc(DIV_BUF_SZ);
|
||||
|
||||
unsigned tid = vx_thread_id();
|
||||
|
||||
bool b = tid < 2;
|
||||
__if (b) {
|
||||
bool c = tid < 1;
|
||||
__if (c) {
|
||||
div_buffer[tid] = 65;
|
||||
}
|
||||
__else {
|
||||
div_buffer[tid] = 66;
|
||||
}
|
||||
__endif
|
||||
}
|
||||
__else {
|
||||
bool c = tid < 3;
|
||||
__if (c) {
|
||||
div_buffer[tid] = 67;
|
||||
}
|
||||
__else {
|
||||
div_buffer[tid] = 68;
|
||||
}
|
||||
__endif
|
||||
}
|
||||
__endif
|
||||
|
||||
vx_tmc(1);
|
||||
|
||||
return check_error(div_buffer, DIV_BUF_SZ);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ST_BUF_SZ 8
|
||||
typedef struct {
|
||||
int * src;
|
||||
int * dst;
|
||||
} st_args_t;
|
||||
|
||||
int st_buffer_src[ST_BUF_SZ];
|
||||
int st_buffer_dst[ST_BUF_SZ];
|
||||
|
||||
void st_kernel(int task_id, void * arg) {
|
||||
st_args_t * arguments = (st_args_t *) arg;
|
||||
arguments->dst[task_id] = arguments->src[task_id];
|
||||
}
|
||||
|
||||
int test_spawn_tasks() {
|
||||
int error = 0;
|
||||
|
||||
st_args_t arg;
|
||||
arg.src = st_buffer_src;
|
||||
arg.dst = st_buffer_dst;
|
||||
|
||||
vx_printf("spawning %d tasks\n", ST_BUF_SZ);
|
||||
|
||||
for (int i = 0; i < ST_BUF_SZ; i++) {
|
||||
st_buffer_src[i] = 65 + i;
|
||||
}
|
||||
|
||||
vx_spawn_tasks(ST_BUF_SZ, st_kernel, &arg);
|
||||
|
||||
return check_error(st_buffer_dst, ST_BUF_SZ);
|
||||
}
|
||||
@@ -1,10 +1,18 @@
|
||||
#ifndef TESTS
|
||||
#define TESTS
|
||||
|
||||
void test_tmc();
|
||||
int test_global_memory();
|
||||
|
||||
void test_divergence();
|
||||
int test_stack_memory();
|
||||
|
||||
void test_wsapwn();
|
||||
int test_shared_memory();
|
||||
|
||||
int test_tmc();
|
||||
|
||||
int test_divergence();
|
||||
|
||||
int test_wsapwn();
|
||||
|
||||
int test_spawn_tasks();
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user