sort test fix.

This commit is contained in:
Blaise Tine 2021-10-18 00:41:11 -04:00
parent 0d62129d32
commit 456f1df332
3 changed files with 20 additions and 28 deletions

View file

@ -230,6 +230,8 @@ inline void vx_fence() {
#define __endif vx_join();
#define __DIVERGENT__ __attribute__((annotate("divergent")))
#ifdef __cplusplus
}
#endif

View file

@ -1,18 +1,26 @@
RISCV_TOOLCHAIN_PATH ?= /opt/riscv-gnu-toolchain
VORTEX_DRV_PATH ?= $(realpath ../../../driver)
VORTEX_RT_PATH ?= $(realpath ../../../runtime)
VORTEX_HW_PATH ?= $(realpath ../../../hw)
LLVM_PREFIX ?= /opt/llvm-riscv
SYSROOT=${RISCV_TOOLCHAIN_PATH}/riscv32-unknown-elf
OPTS ?= -n16
VX_CC = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-gcc
VX_CXX = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-g++
VX_DP = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-objdump
VX_CP = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-objcopy
VX_CC = ${LLVM_PREFIX}/bin/clang
VX_CXX = ${LLVM_PREFIX}/bin/clang++
VX_DP = ${LLVM_PREFIX}/bin/llvm-objdump
VX_CP = ${LLVM_PREFIX}/bin/llvm-objcopy
VX_CFLAGS += -march=rv32imf -mabi=ilp32f -Os -Wstack-usage=1024 -ffreestanding -nostartfiles -fdata-sections -ffunction-sections
VX_CFLAGS += -I$(VORTEX_RT_PATH)/include -I$(VORTEX_RT_PATH)/../hw
VX_CFLAGS += -O3 -march=rv32imf -mabi=ilp32f -fno-rtti -fno-exceptions -ffreestanding -nostartfiles -fdata-sections -ffunction-sections
VX_CFLAGS += -Xclang -target-feature -Xclang +vortex
VX_CFLAGS += --sysroot=${SYSROOT} --gcc-toolchain=${RISCV_TOOLCHAIN_PATH}
VX_CFLAGS += -I${VORTEX_HW_PATH} -I${VORTEX_RT_PATH}/include
VX_LDFLAGS += -Wl,-Bstatic,-T,$(VORTEX_RT_PATH)/linker/vx_link.ld -Wl,--gc-sections $(VORTEX_RT_PATH)/libvortexrt.a
VX_LDFLAGS += -Wl,-Bstatic,-T${VORTEX_RT_PATH}/linker/vx_link.ld,--gc-sections ${VORTEX_RT_PATH}/libvortexrt.a
VX_DPFLAGS = -arch=riscv32 -mcpu=generic-rv32 -mattr=+m,+f -mattr=+vortex
VX_SRCS = kernel.c
@ -30,7 +38,7 @@ SRCS = main.cpp
all: $(PROJECT) kernel.bin kernel.dump
kernel.dump: kernel.elf
$(VX_DP) -D kernel.elf > kernel.dump
$(VX_DP) $(VX_DPFLAGS) -D kernel.elf > kernel.dump
kernel.bin: kernel.elf
$(VX_CP) -O binary kernel.elf kernel.bin

View file

@ -1,26 +1,9 @@
#include <stdint.h>
#include <vx_intrinsics.h>
#include <vx_spawn.h>
#include <vx_print.h>
#include "common.h"
// Parallel Selection sort
int __attribute__((noinline)) __smaller(int index, int tid, int32_t cur_value, int32_t ref_value) {
int ret = 0;
__if (cur_value < ref_value) {
ret = 1;
} __else {
__if (cur_value == ref_value) {
__if (index < tid) {
ret = 1;
} __endif
} __endif
} __endif
return ret;
}
void kernel_body(int task_id, kernel_arg_t* arg) {
void kernel_body(int __DIVERGENT__ task_id, kernel_arg_t* arg) {
uint32_t num_points = arg->num_points;
int32_t* src_ptr = (int32_t*)arg->src_ptr;
int32_t* dst_ptr = (int32_t*)arg->dst_ptr;
@ -30,10 +13,9 @@ void kernel_body(int task_id, kernel_arg_t* arg) {
uint32_t pos = 0;
for (uint32_t i = 0; i < num_points; ++i) {
int32_t cur_value = src_ptr[i];
pos += __smaller(i, task_id, cur_value, ref_value);
pos += (cur_value < ref_value) || ((cur_value == ref_value) && (i < task_id));
}
dst_ptr[pos] = ref_value;
vx_printf("taskid=%d, pos=%d, value=%d\n", task_id, pos, ref_value);
}
void main() {