This commit is contained in:
Blaise Tine 2021-06-28 23:07:39 -07:00
commit 75cc3d060b
43 changed files with 89446 additions and 212932 deletions

View file

@ -17,12 +17,14 @@ CXXFLAGS += -DDUMP_PERF_STATS
LDFLAGS += -shared -pthread
#LDFLAGS += -dynamiclib -pthread
DBG_FLAGS += -DDEBUG_LEVEL=3
SRCS = vortex.cpp ../common/vx_utils.cpp
SRCS += $(SIMX_DIR)/util.cpp $(SIMX_DIR)/args.cpp $(SIMX_DIR)/mem.cpp $(SIMX_DIR)/pipeline.cpp $(SIMX_DIR)/warp.cpp $(SIMX_DIR)/core.cpp $(SIMX_DIR)/decode.cpp $(SIMX_DIR)/execute.cpp
# Debugigng
ifdef DEBUG
CXXFLAGS += $(DBG_FLAGS) -DUSE_DEBUG=3
CXXFLAGS += $(DBG_FLAGS)
else
CXXFLAGS += -DNDEBUG
endif

View file

@ -243,19 +243,26 @@ bool Simulator::is_busy() const {
return vortex_->busy;
}
void Simulator::run() {
int Simulator::run() {
int exitcode = 0;
#ifndef NDEBUG
std::cout << std::dec << timestamp << ": [sim] run()" << std::endl;
#endif
// execute program
while (vortex_->busy
&& !get_ebreak()) {
while (vortex_->busy) {
if (get_ebreak()) {
exitcode = get_last_wb_value(3);
break;
}
this->step();
}
// wait 5 cycles to flush the pipeline
this->wait(5);
return exitcode;
}
bool Simulator::get_ebreak() const {

View file

@ -42,11 +42,7 @@ public:
void step();
void wait(uint32_t cycles);
void run();
int get_last_wb_value(int reg) const;
bool get_ebreak() const;
int run();
void print_stats(std::ostream& out);
@ -63,7 +59,11 @@ private:
void eval();
void eval_mem_bus();
void eval_mem_bus();
int get_last_wb_value(int reg) const;
bool get_ebreak() const;
std::list<mem_req_t> mem_rsp_vec_ [MEMORY_BANKS];
uint32_t last_mem_rsp_bank_;

View file

@ -106,49 +106,54 @@ int main(int argc, char **argv) {
};
for (std::string test : tests) {
std::cout << "\n---------------------------------------\n";
std::cout << "\n***************************************\n";
std::cout << test << std::endl;
RAM ram;
Simulator simulator;
simulator.attach_ram(&ram);
simulator.load_ihex(test.c_str());
simulator.run();
int exitcode = simulator.run();
bool status = (1 == simulator.get_last_wb_value(3));
if (1 == exitcode) {
std::cout << "Passed" << std::endl;
} else {
std::cout << "Failed: exitcode=" << exitcode << std::endl;
passed = false;
}
if (status) std::cout << "Passed: " << test << std::endl;
if (!status) std::cout << "Failed: " << test << std::endl;
passed = passed && status;
if (!passed)
break;
}
for (std::string test : tests_fp) {
std::cout << "\n---------------------------------------\n";
std::cout << "\n***************************************\n";
std::cout << test << std::endl;
RAM ram;
Simulator simulator;
simulator.attach_ram(&ram);
simulator.load_ihex(test.c_str());
simulator.run();
int exitcode = simulator.run();
bool status = (1 == simulator.get_last_wb_value(3));
if (1 == exitcode) {
std::cout << "Passed" << std::endl;
} else {
std::cout << "Failed: exitcode=" << exitcode << std::endl;
passed = false;
}
if (status) std::cout << "Passed: " << test << std::endl;
if (!status) std::cout << "Failed: " << test << std::endl;
passed = passed && status;
if (!passed)
break;
}
std::cout << "\n***************************************\n";
if (passed) std::cout << "PASSED ALL TESTS\n";
if (!passed) std::cout << "Failed one or more tests\n";
if (passed) {
std::cout << "PASSED ALL TESTS\n";
} else {
std::cout << "Failed one or more tests\n";
}
#else
@ -160,30 +165,43 @@ int main(int argc, char **argv) {
Simulator simulator;
simulator.attach_ram(&ram);
simulator.load_ihex(test);
simulator.run();
int exitcode = simulator.run();
if (exitcode != 0) {
std::cout << "*** error: exitcode=" << exitcode << std::endl;
passed = false;
}
#endif
} else {
} else {
parse_args(argc, argv);
for (auto program : programs) {
std::cout << "Running " << program << " .." << std::endl;
std::cout << "Running " << program << " ..." << std::endl;
RAM ram;
Simulator simulator;
simulator.attach_ram(&ram);
simulator.load_ihex(program);
simulator.run();
int exitcode = simulator.run();
if (riscv_test) {
bool status = (1 == simulator.get_last_wb_value(3));
if (status) std::cout << "Passed." << std::endl;
if (!status) std::cout << "Failed." << std::endl;
passed = passed && status;
if (!passed)
break;
if (1 == exitcode) {
std::cout << "Passed" << std::endl;
} else {
std::cout << "Failed: exitcode=" << exitcode << std::endl;
passed = false;
}
} else {
if (exitcode != 0) {
std::cout << "*** error: exitcode=" << exitcode << std::endl;
passed = false;
}
}
if (!passed)
break;
}
}

View file

@ -57,8 +57,10 @@ inline void vx_tmc(unsigned num_threads) {
asm volatile (".insn s 0x6b, 0, x0, 0(%0)" :: "r"(num_threads));
}
typedef void (*vx_wspawn_pfn)();
// Spawn warps
inline void vx_wspawn(unsigned num_warps, void* func_ptr) {
inline void vx_wspawn(unsigned num_warps, vx_wspawn_pfn func_ptr) {
asm volatile (".insn s 0x6b, 1, %1, 0(%0)" :: "r"(num_warps), "r"(func_ptr));
}

View file

@ -18,21 +18,23 @@ struct context_t {
uint32_t work_dim;
};
typedef void (*pfn_workgroup_func) (
const void * /* args */,
typedef void (*vx_spawn_kernel_cb) (
const void * /* arg */,
const struct context_t * /* context */,
uint32_t /* group_x */,
uint32_t /* group_y */,
uint32_t /* group_z */
);
typedef void (*pfn_callback)(int task_id, void *arg);
typedef void (*vx_spawn_tasks_cb)(int task_id, void *arg);
void vx_spawn_kernel(struct context_t * ctx, pfn_workgroup_func wg_func, void * arg);
typedef void (*vx_serial_cb)(int task_id, void *arg);
void vx_spawn_tasks(int num_tasks, pfn_callback callback, void * arg);
void vx_spawn_kernel(struct context_t * ctx, vx_spawn_kernel_cb callback, void * arg);
void vx_serial(pfn_callback callback, void * arg);
void vx_spawn_tasks(int num_tasks, vx_spawn_tasks_cb callback, void * arg);
void vx_serial(vx_serial_cb callback, void * arg);
#ifdef __cplusplus
}

View file

@ -11,7 +11,7 @@ extern "C" {
#define MIN(a, b) ((a) < (b) ? (a) : (b))
typedef struct {
pfn_callback callback;
vx_spawn_tasks_cb callback;
void * arg;
int offset;
int N;
@ -20,7 +20,7 @@ typedef struct {
typedef struct {
struct context_t * ctx;
pfn_workgroup_func wg_func;
vx_spawn_kernel_cb callback;
void * arg;
int offset;
int N;
@ -77,7 +77,7 @@ void spawn_remaining_tasks_callback(int nthreads) {
vx_tmc(1);
}
void vx_spawn_tasks(int num_tasks, pfn_callback callback , void * arg) {
void vx_spawn_tasks(int num_tasks, vx_spawn_tasks_cb callback , void * arg) {
// device specs
int NC = vx_num_cores();
int NW = vx_num_warps();
@ -159,7 +159,7 @@ static void spawn_kernel_callback() {
int gid1 = p_wspawn_args->ctx->global_offset[1] + j;
int gid2 = p_wspawn_args->ctx->global_offset[2] + k;
(p_wspawn_args->wg_func)(p_wspawn_args->arg, p_wspawn_args->ctx, gid0, gid1, gid2);
(p_wspawn_args->callback)(p_wspawn_args->arg, p_wspawn_args->ctx, gid0, gid1, gid2);
}
vx_tmc(0 == wid);
@ -188,12 +188,12 @@ static void spawn_kernel_remaining_callback(int nthreads) {
int gid1 = p_wspawn_args->ctx->global_offset[1] + j;
int gid2 = p_wspawn_args->ctx->global_offset[2] + k;
(p_wspawn_args->wg_func)(p_wspawn_args->arg, p_wspawn_args->ctx, gid0, gid1, gid2);
(p_wspawn_args->callback)(p_wspawn_args->arg, p_wspawn_args->ctx, gid0, gid1, gid2);
vx_tmc(1);
}
void vx_spawn_kernel(struct context_t * ctx, pfn_workgroup_func wg_func, void * arg) {
void vx_spawn_kernel(struct context_t * ctx, vx_spawn_kernel_cb callback, void * arg) {
// total number of WGs
int X = ctx->num_groups[0];
int Y = ctx->num_groups[1];
@ -241,7 +241,9 @@ void vx_spawn_kernel(struct context_t * ctx, pfn_workgroup_func wg_func, void *
char log2X = fast_log2(X);
//--
wspawn_kernel_args_t wspawn_args = { ctx, wg_func, arg, core_id * wgs_per_core, fW, rW, isXYpow2, isXpow2, log2XY, log2X };
wspawn_kernel_args_t wspawn_args = {
ctx, callback, arg, core_id * wgs_per_core, fW, rW, isXYpow2, isXpow2, log2XY, log2X
};
g_wspawn_args[core_id] = &wspawn_args;
//--

View file

@ -42,6 +42,11 @@ _start:
.type _exit, @function
.global _exit
_exit:
beqz a0, label_exit_next
mv gp, a0
ecall;
label_exit_next:
# dump performance CSRs
call vx_perf_dump

View file

@ -15,7 +15,7 @@ SRCS = util.cpp args.cpp mem.cpp pipeline.cpp warp.cpp core.cpp decode.cpp execu
# Debugigng
ifdef DEBUG
CXXFLAGS += $(DBG_FLAGS)
CXXFLAGS += -DDEBUG_LEVEL=3
else
CXXFLAGS += -DNDEBUG
endif

View file

@ -91,6 +91,8 @@ void Core::clear() {
inst_in_schedule_.valid = true;
warps_[0]->setTmask(0, true);
ebreak_ = false;
}
void Core::step() {
@ -377,4 +379,12 @@ void Core::writeToStdOut(Addr addr, Word data) {
std::cout << std::dec << "#" << tid << ": " << ss_buf.str() << std::flush;
ss_buf.str("");
}
}
void Core::trigger_ebreak() {
ebreak_ = true;
}
bool Core::check_ebreak() const {
return ebreak_;
}

View file

@ -70,7 +70,10 @@ public:
Word dcache_read(Addr, Size);
void dcache_write(Addr, Word, Size);
void dcache_write(Addr, Word, Size);
void trigger_ebreak();
bool check_ebreak() const;
private:
@ -101,6 +104,8 @@ private:
RAM shared_mem_;
#endif
bool ebreak_;
Pipeline inst_in_schedule_;
Pipeline inst_in_fetch_;
Pipeline inst_in_decode_;

View file

@ -1,11 +1,13 @@
#pragma once
//#define USE_DEBUG 3
#ifndef DEBUG_LEVEL
#define DEBUG_LEVEL 3
#endif
#define DEBUG_HEADER << "DEBUG "
//#define DEBUG_HEADER << "DEBUG " << __FILE__ << ':' << std::dec << __LINE__ << ": "
#ifdef USE_DEBUG
#ifndef NDEBUG
#include <iostream>
#include <iomanip>
@ -13,19 +15,19 @@
#define DX(x) x
#define D(lvl, x) do { \
if ((lvl) <= USE_DEBUG) { \
if ((lvl) <= DEBUG_LEVEL) { \
std::cout DEBUG_HEADER << x << std::endl; \
} \
} while(0)
#define DPH(lvl, x) do { \
if ((lvl) <= USE_DEBUG) { \
if ((lvl) <= DEBUG_LEVEL) { \
std::cout DEBUG_HEADER << x; \
} \
} while(0)
#define DPN(lvl, x) do { \
if ((lvl) <= USE_DEBUG) { \
if ((lvl) <= DEBUG_LEVEL) { \
std::cout << x; \
} \
} while(0)

View file

@ -402,9 +402,7 @@ void Warp::execute(const Instr &instr, Pipeline *pipeline) {
case 0:
if (csr_addr < 2) {
// ECALL/EBREAK
tmask_.reset();
active_ = tmask_.any();
pipeline->stall_warp = true;
core_->trigger_ebreak();
}
break;
case 1:

View file

@ -67,24 +67,33 @@ int main(int argc, char **argv) {
}
bool running;
int exitcode = 0;
do {
running = false;
for (auto& core : cores) {
core->step();
if (core->running())
if (core->running()) {
running = true;
}
if (core->check_ebreak()) {
exitcode = core->getIRegValue(3);
break;
}
}
} while (running);
if (riscv_test) {
bool status = (1 == cores[0]->getIRegValue(3));
if (status) {
if (1 == exitcode) {
std::cout << "Passed." << std::endl;
exitcode = 0;
} else {
std::cout << "Failed." << std::endl;
return -1;
std::cout << "Failed." << std::endl;
}
} else {
if (exitcode != 0) {
std::cout << "*** error: exitcode=" << exitcode << std::endl;
}
}
return 0;
return exitcode;
}

View file

@ -1,18 +1,15 @@
all:
$(MAKE) -C hello
$(MAKE) -C fibonacci
$(MAKE) -C simple
$(MAKE) -C dev
$(MAKE) -C hello
$(MAKE) -C nlTest
run:
$(MAKE) -C simple run
$(MAKE) -C dev run
$(MAKE) -C hello run
$(MAKE) -C nlTest run
$(MAKE) -C fibonacci run
$(MAKE) -C simple run
clean:
$(MAKE) -C simple clean
$(MAKE) -C dev clean
$(MAKE) -C hello clean
$(MAKE) -C nlTest clean
$(MAKE) -C fibonacci clean
$(MAKE) -C simple clean

View file

@ -1,36 +0,0 @@
RISCV_TOOLCHAIN_PATH ?= /opt/riscv-gnu-toolchain
VORTEX_RT_PATH ?= $(realpath ../../../runtime)
CC = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-gcc
AR = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-gcc-ar
DP = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-objdump
CP = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-objcopy
CFLAGS += -march=rv32imf -mabi=ilp32f -O3 -Wstack-usage=1024 -ffreestanding -nostartfiles -fdata-sections -ffunction-sections
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_dev_main
SRCS = vx_dev_main.c
all: $(PROJECT).elf $(PROJECT).hex $(PROJECT).dump
$(PROJECT).dump: $(PROJECT).elf
$(DP) -D $(PROJECT).elf > $(PROJECT).dump
$(PROJECT).hex: $(PROJECT).elf
$(CP) -O ihex $(PROJECT).elf $(PROJECT).hex
$(PROJECT).elf: $(SRCS)
$(CC) $(CFLAGS) $(SRCS) $(LDFLAGS) -o $(PROJECT).elf
run: $(PROJECT).hex
(cd ../../../hw/simulate/obj_dir && ./VVortex ../../../tests/runtime/dev/$(PROJECT).hex)
.depend: $(SRCS)
$(CC) $(CFLAGS) -MM $^ > .depend;
clean:
rm -rf *.elf *.hex *.dump .depend

View file

@ -1,90 +0,0 @@
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <vx_intrinsics.h>
#include <vx_print.h>
#include <vx_spawn.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];
}
void vx_print_mat(unsigned * matPtr, int numRows, int numCols)
{
vx_printf("---------------------\n");
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
unsigned index = (i * numCols) + j;
vx_printf("0x%x ", matPtr[index]);
}
vx_printf("\n");
}
}
int main() {
// void * hellp = malloc(4);
vx_printf("Confirm Dev Main\n");
vx_printf("vx_spawn_tasks\n");
mat_add_args_t arguments;
arguments.x = x;
arguments.y = y;
arguments.z = z;
arguments.numColums = 4;
arguments.numRows = 4;
// First kernel call
vx_spawn_tasks(arguments.numRows * arguments.numColums, mat_add_kernel, &arguments);
vx_print_mat(z, arguments.numRows, arguments.numColums);
arguments.x = z;
arguments.y = y;
arguments.z = z;
arguments.numColums = 4;
arguments.numRows = 4;
// Second Kernel Call
vx_spawn_tasks(arguments.numRows * arguments.numColums, mat_add_kernel, &arguments);
vx_print_mat(z, arguments.numRows, arguments.numColums);
vx_printf("Passed!\n");
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -11,9 +11,9 @@ CFLAGS += -I$(VORTEX_RT_PATH)/include -I$(VORTEX_RT_PATH)/../hw
LDFLAGS += -lm -Wl,-Bstatic,-T,$(VORTEX_RT_PATH)/linker/vx_link.ld -Wl,--gc-sections $(VORTEX_RT_PATH)/libvortexrt.a
PROJECT = vx_nl_main
PROJECT = fibonacci
SRCS = vx_nl_main.c
SRCS = main.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/nlTest/$(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;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,32 @@
#include <stdio.h>
const int Num = 9;
const int Ans = 34;
int fibonacci(int n) {
if (n <= 1)
return n;
return fibonacci(n-1) + fibonacci(n-2);
}
int main() {
int errors = 0;
int fib = fibonacci(Num);
printf("fibonacci(%d) = %d\n", Num, fib);
if (fib == Ans) {
printf("Passed!\n");
} else {
printf("Failed! value=%d, expected=%d\n", fib, Ans);
errors = 1;
}
return errors;
}

View file

@ -13,7 +13,7 @@ LDFLAGS += -Wl,-Bstatic,-T,$(VORTEX_RT_PATH)/linker/vx_link.ld -Wl,--gc-sections
PROJECT = hello
SRCS = hello.cpp
SRCS = main.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/hello/$(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;

View file

@ -1,20 +0,0 @@
#include <stdio.h>
struct hello {
int a;
hello()
{
a = 55;
}
};
hello nameing;
int main()
{
nameing.a = 20;
int b;
printf("Passed!\n");
return 0;
}

File diff suppressed because it is too large Load diff

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}

View file

@ -1,26 +0,0 @@
#include <stdio.h>
#include <math.h>
#include <vx_print.h>
const int Num = 9;
const float fNum = 9.0f;
int fibonacci(int n) {
if (n <= 1)
return n;
return fibonacci(n-1) + fibonacci(n-2);
}
int main() {
int fib = fibonacci(Num);
float isq = 1.0f / sqrt(fNum);
vx_printf("fibonacci(%d) = %d\n", Num, fib);
vx_printf("invAqrt(%f) = %f\n", fNum, isq);
vx_printf("Passed!\n");
return 0;
}

File diff suppressed because it is too large Load diff

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -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;

View file

@ -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;
}

View 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

View file

@ -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]);
}

View 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);
}

View file

@ -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