runtime dynamic loading for driver-specific implementations

This commit is contained in:
Blaise Tine 2024-05-26 19:05:17 -07:00
parent d413786b9e
commit 32f39264ef
22 changed files with 331 additions and 169 deletions

View file

@ -30,13 +30,15 @@ clean-all:
$(MAKE) -C tests clean-all
# Install setup
KERNEL_LIB_DST = $(PREFIX)/kernel/lib$(XLEN)
RUNTIME_LIB_DST = $(PREFIX)/runtime/lib
KERNEL_INC_DST = $(PREFIX)/kernel/include
KERNEL_LIB_DST = $(PREFIX)/kernel/lib$(XLEN)
RUNTIME_INC_DST = $(PREFIX)/runtime/include
RUNTIME_LIB_DST = $(PREFIX)/runtime/lib
KERNEL_HEADERS = $(wildcard $(VORTEX_HOME)/kernel/include/*.h)
KERNEL_LIBS = $(wildcard kernel/*.a)
RUNTIME_HEADERS = $(wildcard $(VORTEX_HOME)/runtime/include/*.h)
RUNTIME_LIBS = $(wildcard runtime/*.so)
INSTALL_DIRS = $(KERNEL_LIB_DST) $(RUNTIME_LIB_DST) $(KERNEL_INC_DST) $(RUNTIME_INC_DST)
@ -49,14 +51,14 @@ $(KERNEL_INC_DST)/%.h: $(VORTEX_HOME)/kernel/include/%.h | $(KERNEL_INC_DST)
$(RUNTIME_INC_DST)/%.h: $(VORTEX_HOME)/runtime/include/%.h | $(RUNTIME_INC_DST)
cp $< $@
$(KERNEL_LIB_DST)/libvortex.a: kernel/libvortexrt.a | $(KERNEL_LIB_DST)
$(KERNEL_LIB_DST)/%.a: kernel/%.a | $(KERNEL_LIB_DST)
cp $< $@
$(RUNTIME_LIB_DST)/libvortex.so: runtime/stub/libvortex.so | $(RUNTIME_LIB_DST)
$(RUNTIME_LIB_DST)/%.so: runtime/%.so | $(RUNTIME_LIB_DST)
cp $< $@
install: $(INSTALL_DIRS) \
$(KERNEL_HEADERS:$(VORTEX_HOME)/kernel/include/%=$(KERNEL_INC_DST)/%) \
$(RUNTIME_HEADERS:$(VORTEX_HOME)/runtime/include/%=$(RUNTIME_INC_DST)/%) \
$(KERNEL_LIB_DST)/libvortex.a \
$(RUNTIME_LIB_DST)/libvortex.so
$(KERNEL_LIBS:kernel/%=$(KERNEL_LIB_DST)/%) \
$(RUNTIME_LIBS:runtime/%=$(RUNTIME_LIB_DST)/%)

View file

@ -13,7 +13,7 @@ SRC_DIR := $(VORTEX_HOME)/kernel/src
LLVM_CFLAGS += --sysroot=$(RISCV_SYSROOT)
LLVM_CFLAGS += --gcc-toolchain=$(RISCV_TOOLCHAIN_PATH)
LLVM_CFLAGS += -Xclang -target-feature -Xclang +vortex -mllvm -vortex-branch-divergence=0
#LLVM_CFLAGS += -I$(RISCV_SYSROOT)/include/c++/9.2.0/$(RISCV_PREFIX)
#LLVM_CFLAGS += -I$(RISCV_SYSROOT)/include/c++/9.2.0/$(RISCV_PREFIX)
#LLVM_CFLAGS += -I$(RISCV_SYSROOT)/include/c++/9.2.0
#LLVM_CFLAGS += -Wl,-L$(RISCV_TOOLCHAIN_PATH)/lib/gcc/$(RISCV_PREFIX)/9.2.0
#LLVM_CFLAGS += --rtlib=libgcc
@ -34,7 +34,7 @@ CFLAGS += -O3 -mcmodel=medany -fno-exceptions -fdata-sections -ffunction-section
CFLAGS += -I$(INC_DIR) -I$(ROOT_DIR)/hw
CFLAGS += -DXLEN_$(XLEN)
PROJECT := libvortexrt
PROJECT := libvortex
SRCS = $(SRC_DIR)/vx_start.S $(SRC_DIR)/vx_syscalls.c $(SRC_DIR)/vx_print.S $(SRC_DIR)/tinyprintf.c $(SRC_DIR)/vx_print.c $(SRC_DIR)/vx_spawn.c $(SRC_DIR)/vx_serial.S $(SRC_DIR)/vx_perf.c

View file

@ -27,7 +27,7 @@ set(CMAKE_CXX_FLAGS "-v --gcc-toolchain=${TOOLDIR}/riscv-gnu-toolchain -march=rv
set(CMAKE_SYSROOT "${TOOLDIR}/riscv32-gnu-toolchain/riscv32-unknown-elf")
# Linker flags
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld -nostartfiles -Wl,-Bstatic,--gc-sections,-T,${VORTEX_HOME}/kernel/scripts/link32.ld ${VORTEX_BUILD}/kernel/libvortexrt.a")
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld -nostartfiles -Wl,-Bstatic,--gc-sections,-T,${VORTEX_HOME}/kernel/scripts/link32.ld ${VORTEX_BUILD}/kernel/libvortex.a")
# Don't run the linker on compiler check
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

View file

@ -0,0 +1,92 @@
#ifndef CALLBACKS_H
#define CALLBACKS_H
#include <vortex.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
// open the device and connect to it
int (*dev_open) (vx_device_h* hdevice);
// Close the device when all the operations are done
int (*dev_close) (vx_device_h hdevice);
// return device configurations
int (*dev_caps) (vx_device_h hdevice, uint32_t caps_id, uint64_t *value);
// allocate device memory and return address
int (*mem_alloc) (vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer);
// reserve memory address range
int (*mem_reserve) (vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer);
// release device memory
int (*mem_free) (vx_buffer_h hbuffer);
// set device memory access rights
int (*mem_access) (vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags);
// return device memory address
int (*mem_address) (vx_buffer_h hbuffer, uint64_t* address);
// get device memory info
int (*mem_info) (vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used);
// Copy bytes from host to device memory
int (*copy_to_dev) (vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size);
// Copy bytes from device memory to host
int (*copy_from_dev) (void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size);
// Start device execution
int (*start) (vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments);
// Wait for device ready with milliseconds timeout
int (*ready_wait) (vx_device_h hdevice, uint64_t timeout);
// read device configuration registers
int (*dcr_read) (vx_device_h hdevice, uint32_t addr, uint32_t* value);
// write device configuration registers
int (*dcr_write) (vx_device_h hdevice, uint32_t addr, uint32_t value);
// query device performance counter
int (*mpm_query) (vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value);
} callbacks_t;
int vx_dev_init(callbacks_t* callbacks);
#define __VX_DEV_INT(drv) \
extern int vx_dev_init(callbacks_t* callbacks) { \
if (nullptr == callbacks) \
return -1; \
*callbacks = { \
vx_##drv##_dev_open, \
vx_##drv##_dev_close, \
vx_##drv##_dev_caps, \
vx_##drv##_mem_alloc, \
vx_##drv##_mem_reserve, \
vx_##drv##_mem_free, \
vx_##drv##_mem_access, \
vx_##drv##_mem_address, \
vx_##drv##_mem_info, \
vx_##drv##_copy_to_dev, \
vx_##drv##_copy_from_dev, \
vx_##drv##_start, \
vx_##drv##_ready_wait, \
vx_##drv##_dcr_read, \
vx_##drv##_dcr_write, \
vx_##drv##_mpm_query \
}; \
return 0; \
}
#ifdef __cplusplus
}
#endif
#endif

View file

@ -73,7 +73,7 @@ public:
vx_dump_perf(device, stdout);
}
int get_perf_class() const {
int perf_class() const {
return perf_class_;
}
@ -82,7 +82,7 @@ private:
int perf_class_;
};
AutoPerfDump gAutoPerfDump;
static AutoPerfDump gAutoPerfDump;
int profiling_add(vx_device_h hdevice) {
return gAutoPerfDump.add(hdevice);
@ -283,7 +283,7 @@ extern int vx_dump_perf(vx_device_h hdevice, FILE* stream) {
return int(caclAverage(part, total) * 100);
};
auto perf_class = gAutoPerfDump.get_perf_class();
auto perf_class = gAutoPerfDump.perf_class();
// PERF: pipeline stalls
uint64_t sched_idles = 0;

View file

@ -2,7 +2,7 @@ include ../common.mk
TARGET ?= opaesim
DESTDIR ?= $(CURDIR)
DESTDIR ?= $(CURDIR)/..
SYN_DIR := $(HW_DIR)/syn/altera/opae
@ -54,7 +54,7 @@ ifdef PERF
CXXFLAGS += -DPERF_ENABLE
endif
PROJECT := libvortex.so
PROJECT := libvortex-opae.so
all: $(DESTDIR)/$(PROJECT)
@ -66,4 +66,4 @@ $(DESTDIR)/$(PROJECT): $(SRCS) $(OPAESIM)
clean:
DESTDIR=$(DESTDIR) $(MAKE) -C $(ROOT_DIR)/sim/opaesim clean
rm -rf $(DESTDIR)/$(PROJECT)
rm -f $(DESTDIR)/$(PROJECT)

View file

@ -11,7 +11,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <vortex.h>
#include <utils.h>
#include <malloc.h>
#include "driver.h"
@ -38,6 +37,8 @@
#include "scope.h"
#endif
#include <callbacks.h>
using namespace vortex;
#define CMD_MEM_READ AFU_IMAGE_CMD_MEM_READ
@ -563,7 +564,7 @@ struct vx_buffer {
///////////////////////////////////////////////////////////////////////////////
extern int vx_dev_open(vx_device_h* hdevice) {
int vx_opae_dev_open(vx_device_h* hdevice) {
if (nullptr == hdevice)
return -1;
@ -591,7 +592,7 @@ extern int vx_dev_open(vx_device_h* hdevice) {
return 0;
}
extern int vx_dev_close(vx_device_h hdevice) {
int vx_opae_dev_close(vx_device_h hdevice) {
if (nullptr == hdevice)
return -1;
@ -610,7 +611,7 @@ extern int vx_dev_close(vx_device_h hdevice) {
return 0;
}
extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
int vx_opae_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
if (nullptr == hdevice)
return -1;
@ -629,7 +630,7 @@ extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
return 0;
}
extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer) {
int vx_opae_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer) {
if (nullptr == hdevice
|| nullptr == hbuffer
|| 0 == size)
@ -657,7 +658,7 @@ extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer
return 0;
}
extern int vx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer) {
int vx_opae_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer) {
if (nullptr == hdevice
|| nullptr == hbuffer
|| 0 == size)
@ -682,7 +683,7 @@ extern int vx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size,
return 0;
}
extern int vx_mem_free(vx_buffer_h hbuffer) {
int vx_opae_mem_free(vx_buffer_h hbuffer) {
if (nullptr == hbuffer)
return 0;
@ -700,7 +701,7 @@ extern int vx_mem_free(vx_buffer_h hbuffer) {
return err;
}
extern int vx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags) {
int vx_opae_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags) {
if (nullptr == hbuffer)
return -1;
@ -715,7 +716,7 @@ extern int vx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, in
return device->mem_access(buffer->addr + offset, size, flags);
}
extern int vx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
int vx_opae_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
if (nullptr == hbuffer)
return -1;
@ -728,7 +729,7 @@ extern int vx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
return 0;
}
extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used) {
int vx_opae_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used) {
if (nullptr == hdevice)
return -1;
@ -753,7 +754,7 @@ extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_us
return 0;
}
extern int vx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size) {
int vx_opae_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size) {
if (nullptr == hbuffer || nullptr == host_ptr)
return -1;
@ -768,7 +769,7 @@ extern int vx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t ds
return device->upload(buffer->addr + dst_offset, host_ptr, size);
}
extern int vx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size) {
int vx_opae_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size) {
if (nullptr == hbuffer || nullptr == host_ptr)
return -1;
@ -783,7 +784,7 @@ extern int vx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_of
return device->download(host_ptr, buffer->addr + src_offset, size);
}
extern int vx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments) {
int vx_opae_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments) {
if (nullptr == hdevice || nullptr == hkernel || nullptr == harguments)
return -1;
@ -796,7 +797,7 @@ extern int vx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h hargum
return device->start(kernel->addr, arguments->addr);
}
extern int vx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
int vx_opae_ready_wait(vx_device_h hdevice, uint64_t timeout) {
if (nullptr == hdevice)
return -1;
@ -807,7 +808,7 @@ extern int vx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
return device->ready_wait(timeout);
}
extern int vx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
int vx_opae_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
if (nullptr == hdevice)
return -1;
@ -826,7 +827,7 @@ extern int vx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
return 0;
}
extern int vx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
int vx_opae_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
if (nullptr == hdevice)
return -1;
@ -837,7 +838,7 @@ extern int vx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
return device->dcr_write(addr, value);
}
extern int vx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value) {
int vx_opae_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value) {
if (nullptr == hdevice)
return -1;
@ -854,4 +855,6 @@ extern int vx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, ui
*value = _value;
return 0;
}
}
__VX_DEV_INT(opae)

View file

@ -1,6 +1,6 @@
include ../common.mk
DESTDIR ?= $(CURDIR)
DESTDIR ?= $(CURDIR)/..
SRC_DIR := $(VORTEX_HOME)/runtime/rtlsim
@ -31,14 +31,16 @@ ifdef PERF
CXXFLAGS += -DPERF_ENABLE
endif
PROJECT := libvortex.so
PROJECT := libvortex-rtlsim.so
all: $(DESTDIR)/$(PROJECT)
$(DESTDIR)/$(PROJECT): $(SRCS)
$(DESTDIR)/librtlsim.so:
DESTDIR=$(DESTDIR) $(MAKE) -C $(ROOT_DIR)/sim/rtlsim $(DESTDIR)/librtlsim.so
$(DESTDIR)/$(PROJECT): $(SRCS) $(DESTDIR)/librtlsim.so
$(CXX) $(CXXFLAGS) $(SRCS) $(LDFLAGS) -o $@
clean:
DESTDIR=$(DESTDIR) $(MAKE) -C $(ROOT_DIR)/sim/rtlsim clean
rm -rf $(DESTDIR)/$(PROJECT) *.o
DESTDIR=$(DESTDIR) $(MAKE) -C $(ROOT_DIR)/sim/rtlsim clean-lib
rm -f $(DESTDIR)/$(PROJECT)

View file

@ -30,6 +30,8 @@
#include <util.h>
#include <processor.h>
#include <callbacks.h>
using namespace vortex;
#define RAM_PAGE_SIZE 4096
@ -293,7 +295,7 @@ struct vx_buffer {
///////////////////////////////////////////////////////////////////////////////
extern int vx_dev_open(vx_device_h* hdevice) {
int vx_rtlsim_dev_open(vx_device_h* hdevice) {
if (nullptr == hdevice)
return -1;
@ -313,7 +315,7 @@ extern int vx_dev_open(vx_device_h* hdevice) {
return 0;
}
extern int vx_dev_close(vx_device_h hdevice) {
int vx_rtlsim_dev_close(vx_device_h hdevice) {
if (nullptr == hdevice)
return -1;
@ -326,7 +328,7 @@ extern int vx_dev_close(vx_device_h hdevice) {
return 0;
}
extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
int vx_rtlsim_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
if (nullptr == hdevice)
return -1;
@ -345,7 +347,7 @@ extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
return 0;
}
extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer) {
int vx_rtlsim_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer) {
if (nullptr == hdevice
|| nullptr == hbuffer
|| 0 == size)
@ -371,7 +373,7 @@ extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer
return 0;
}
extern int vx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer) {
int vx_rtlsim_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer) {
if (nullptr == hdevice
|| nullptr == hbuffer
|| 0 == size)
@ -396,7 +398,7 @@ extern int vx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size,
return 0;
}
extern int vx_mem_free(vx_buffer_h hbuffer) {
int vx_rtlsim_mem_free(vx_buffer_h hbuffer) {
if (nullptr == hbuffer)
return 0;
@ -414,7 +416,7 @@ extern int vx_mem_free(vx_buffer_h hbuffer) {
return err;
}
extern int vx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags) {
int vx_rtlsim_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags) {
if (nullptr == hbuffer)
return -1;
@ -429,7 +431,7 @@ extern int vx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, in
return device->mem_access(buffer->addr + offset, size, flags);
}
extern int vx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
int vx_rtlsim_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
if (nullptr == hbuffer)
return -1;
@ -442,7 +444,7 @@ extern int vx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
return 0;
}
extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used) {
int vx_rtlsim_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used) {
if (nullptr == hdevice)
return -1;
@ -467,7 +469,7 @@ extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_us
return 0;
}
extern int vx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size) {
int vx_rtlsim_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size) {
if (nullptr == hbuffer || nullptr == host_ptr)
return -1;
@ -482,7 +484,7 @@ extern int vx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t ds
return device->upload(buffer->addr + dst_offset, host_ptr, size);
}
extern int vx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size) {
int vx_rtlsim_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size) {
if (nullptr == hbuffer || nullptr == host_ptr)
return -1;
@ -497,7 +499,7 @@ extern int vx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_of
return device->download(host_ptr, buffer->addr + src_offset, size);
}
extern int vx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments) {
int vx_rtlsim_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments) {
if (nullptr == hdevice || nullptr == hkernel || nullptr == harguments)
return -1;
@ -510,7 +512,7 @@ extern int vx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h hargum
return device->start(kernel->addr, arguments->addr);
}
extern int vx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
int vx_rtlsim_ready_wait(vx_device_h hdevice, uint64_t timeout) {
if (nullptr == hdevice)
return -1;
@ -521,7 +523,7 @@ extern int vx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
return device->ready_wait(timeout);
}
extern int vx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
int vx_rtlsim_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
if (nullptr == hdevice || NULL == value)
return -1;
@ -540,7 +542,7 @@ extern int vx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
return 0;
}
extern int vx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
int vx_rtlsim_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
if (nullptr == hdevice)
return -1;
@ -551,7 +553,7 @@ extern int vx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
return device->dcr_write(addr, value);
}
extern int vx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value) {
int vx_rtlsim_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value) {
if (nullptr == hdevice)
return -1;
@ -568,4 +570,6 @@ extern int vx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, ui
*value = _value;
return 0;
}
}
__VX_DEV_INT(rtlsim)

View file

@ -1,6 +1,6 @@
include ../common.mk
DESTDIR ?= $(CURDIR)
DESTDIR ?= $(CURDIR)/..
SRC_DIR := $(VORTEX_HOME)/runtime/simx
@ -22,14 +22,16 @@ else
CXXFLAGS += -O2 -DNDEBUG
endif
PROJECT := libvortex.so
PROJECT := libvortex-simx.so
all: $(DESTDIR)/$(PROJECT)
$(DESTDIR)/$(PROJECT): $(SRCS)
$(DESTDIR)/libsimx.so:
DESTDIR=$(DESTDIR) $(MAKE) -C $(ROOT_DIR)/sim/simx $(DESTDIR)/libsimx.so
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@
$(DESTDIR)/$(PROJECT): $(SRCS) $(DESTDIR)/libsimx.so
$(CXX) $(CXXFLAGS) $(SRCS) $(LDFLAGS) -o $@
clean:
DESTDIR=$(DESTDIR) $(MAKE) -C $(ROOT_DIR)/sim/simx clean
rm -rf $(DESTDIR)/$(PROJECT) *.o
DESTDIR=$(DESTDIR) $(MAKE) -C $(ROOT_DIR)/sim/simx clean-lib
rm -f $(DESTDIR)/$(PROJECT)

View file

@ -19,7 +19,6 @@
#include <future>
#include <chrono>
#include <vortex.h>
#include <utils.h>
#include <malloc.h>
@ -33,6 +32,8 @@
#include <mem.h>
#include <constants.h>
#include <callbacks.h>
using namespace vortex;
#ifndef NDEBUG
@ -288,7 +289,7 @@ struct vx_buffer {
///////////////////////////////////////////////////////////////////////////////
extern int vx_dev_open(vx_device_h* hdevice) {
int vx_simx_dev_open(vx_device_h* hdevice) {
if (nullptr == hdevice)
return -1;
@ -308,7 +309,7 @@ extern int vx_dev_open(vx_device_h* hdevice) {
return 0;
}
extern int vx_dev_close(vx_device_h hdevice) {
int vx_simx_dev_close(vx_device_h hdevice) {
if (nullptr == hdevice)
return -1;
@ -321,7 +322,7 @@ extern int vx_dev_close(vx_device_h hdevice) {
return 0;
}
extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
int vx_simx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
if (nullptr == hdevice)
return -1;
@ -340,7 +341,7 @@ extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
return 0;
}
extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer) {
int vx_simx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer) {
if (nullptr == hdevice
|| nullptr == hbuffer
|| 0 == size)
@ -366,7 +367,7 @@ extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer
return 0;
}
extern int vx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer) {
int vx_simx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer) {
if (nullptr == hdevice
|| nullptr == hbuffer
|| 0 == size)
@ -391,7 +392,7 @@ extern int vx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size,
return 0;
}
extern int vx_mem_free(vx_buffer_h hbuffer) {
int vx_simx_mem_free(vx_buffer_h hbuffer) {
if (nullptr == hbuffer)
return 0;
@ -409,7 +410,7 @@ extern int vx_mem_free(vx_buffer_h hbuffer) {
return err;
}
extern int vx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags) {
int vx_simx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags) {
if (nullptr == hbuffer)
return -1;
@ -424,7 +425,7 @@ extern int vx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, in
return device->mem_access(buffer->addr + offset, size, flags);
}
extern int vx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
int vx_simx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
if (nullptr == hbuffer)
return -1;
@ -437,7 +438,7 @@ extern int vx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
return 0;
}
extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used) {
int vx_simx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used) {
if (nullptr == hdevice)
return -1;
@ -462,7 +463,7 @@ extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_us
return 0;
}
extern int vx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size) {
int vx_simx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size) {
if (nullptr == hbuffer || nullptr == host_ptr)
return -1;
@ -477,7 +478,7 @@ extern int vx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t ds
return device->upload(buffer->addr + dst_offset, host_ptr, size);
}
extern int vx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size) {
int vx_simx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size) {
if (nullptr == hbuffer || nullptr == host_ptr)
return -1;
@ -492,7 +493,7 @@ extern int vx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_of
return device->download(host_ptr, buffer->addr + src_offset, size);
}
extern int vx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments) {
int vx_simx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments) {
if (nullptr == hdevice || nullptr == hkernel || nullptr == harguments)
return -1;
@ -505,7 +506,7 @@ extern int vx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h hargum
return device->start(kernel->addr, arguments->addr);
}
extern int vx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
int vx_simx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
if (nullptr == hdevice)
return -1;
@ -516,7 +517,7 @@ extern int vx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
return device->ready_wait(timeout);
}
extern int vx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
int vx_simx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
if (nullptr == hdevice || NULL == value)
return -1;
@ -535,7 +536,7 @@ extern int vx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
return 0;
}
extern int vx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
int vx_simx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
if (nullptr == hdevice)
return -1;
@ -546,7 +547,7 @@ extern int vx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
return device->dcr_write(addr, value);
}
extern int vx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value) {
int vx_simx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value) {
if (nullptr == hdevice)
return -1;
@ -563,4 +564,6 @@ extern int vx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, ui
*value = _value;
return 0;
}
}
__VX_DEV_INT(simx)

View file

@ -1,6 +1,6 @@
include ../common.mk
DESTDIR ?= $(CURDIR)
DESTDIR ?= $(CURDIR)/..
SRC_DIR := $(VORTEX_HOME)/runtime/stub
@ -8,16 +8,16 @@ CXXFLAGS += -std=c++11 -O2 -Wall -Wextra -pedantic -Wfatal-errors
CXXFLAGS += -I$(INC_DIR) -I$(COMMON_DIR) -I$(ROOT_DIR)/hw -I$(SIM_DIR)/common
CXXFLAGS += -fPIC
LDFLAGS += -shared -pthread
LDFLAGS += -shared -pthread -ldl
SRCS := $(SRC_DIR)/vortex.cpp $(COMMON_DIR)/utils.cpp
PROJECT := libvortex.so
all: $(PROJECT)
all: $(DESTDIR)/$(PROJECT)
$(PROJECT): $(SRCS)
$(DESTDIR)/$(PROJECT): $(SRCS)
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@
clean:
rm -rf $(PROJECT) obj_dir
rm -f $(DESTDIR)/$(PROJECT)

View file

@ -11,69 +11,106 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <vortex.h>
#include <callbacks.h>
#include <unistd.h>
#include <string.h>
#include <string>
#include <cstdlib>
#include <dlfcn.h>
#include <iostream>
extern int vx_dev_open(vx_device_h* /*hdevice*/) {
return -1;
static callbacks_t g_callbacks;
static void* g_drv_handle = nullptr;
typedef int (*vx_dev_init_t)(callbacks_t*);
int vx_dev_open(vx_device_h* hdevice) {
{
const char* driverName = getenv("VORTEX_DRIVER");
if (driverName == nullptr) {
driverName = "simx";
}
std::string driverName_s(driverName);
std::string libName = "libvortex-" + driverName_s + ".so";
auto handle = dlopen(libName.c_str(), RTLD_LAZY);
if (handle == nullptr) {
std::cerr << "Cannot open library: " << dlerror() << std::endl;
return 1;
}
auto vx_dev_init = (vx_dev_init_t)dlsym(handle, "vx_dev_init");
auto dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot load symbol 'vx_init': " << dlsym_error << std::endl;
dlclose(handle);
return 1;
}
vx_dev_init(&g_callbacks);
g_drv_handle = handle;
}
return (g_callbacks.dev_open)(hdevice);
}
extern int vx_dev_close(vx_device_h /*hdevice*/) {
return -1;
int vx_dev_close(vx_device_h hdevice) {
int ret = (g_callbacks.dev_close)(hdevice);
dlclose(g_drv_handle);
return ret;
}
extern int vx_dev_caps(vx_device_h /*hdevice*/, uint32_t /*caps_id*/, uint64_t* /*value*/) {
return -1;
int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t* value) {
return (g_callbacks.dev_caps)(hdevice, caps_id, value);
}
extern int vx_mem_alloc(vx_device_h /*hdevice*/, uint64_t /*size*/, int /*flags*/, vx_buffer_h* /*hbuffer*/) {
return -1;
int vx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer) {
return (g_callbacks.mem_alloc)(hdevice, size, flags, hbuffer);
}
extern int vx_mem_reserve(vx_device_h /*hdevice*/, uint64_t /*address*/, uint64_t /*size*/, int /*flags*/, vx_buffer_h* /*hbuffer*/) {
return -1;
int vx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer) {
return (g_callbacks.mem_reserve)(hdevice, address, size, flags, hbuffer);
}
extern int vx_mem_free(vx_buffer_h /*hbuffer*/) {
return -1;
int vx_mem_free(vx_buffer_h hbuffer) {
return (g_callbacks.mem_free)(hbuffer);
}
extern int vx_mem_access(vx_buffer_h /*hbuffer*/, uint64_t /*offset*/, uint64_t /*size*/, int /*flags*/) {
return -1;
int vx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags) {
return (g_callbacks.mem_access)(hbuffer, offset, size, flags);
}
extern int vx_mem_address(vx_buffer_h /*hbuffer*/, uint64_t* /*address*/) {
return -1;
int vx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
return (g_callbacks.mem_address)(hbuffer, address);
}
extern int vx_mem_info(vx_device_h /*hdevice*/, uint64_t* /*mem_free*/, uint64_t* /*mem_used*/) {
return 0;
int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used) {
return (g_callbacks.mem_info)(hdevice, mem_free, mem_used);
}
extern int vx_copy_to_dev(vx_buffer_h /*hbuffer*/, const void* /*host_ptr*/, uint64_t /*dst_offset*/, uint64_t /*size*/) {
return -1;
int vx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size) {
return (g_callbacks.copy_to_dev)(hbuffer, host_ptr, dst_offset, size);
}
extern int vx_copy_from_dev(void* /*host_ptr*/, vx_buffer_h /*hbuffer*/, uint64_t /*src_offset*/, uint64_t /*size*/) {
return -1;
int vx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size) {
return (g_callbacks.copy_from_dev)(host_ptr, hbuffer, src_offset, size);
}
extern int vx_start(vx_device_h /*hdevice*/, vx_buffer_h /*hkernel*/, vx_buffer_h /*harguments*/) {
return -1;
int vx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments) {
return (g_callbacks.start)(hdevice, hkernel, harguments);
}
extern int vx_ready_wait(vx_device_h /*hdevice*/, uint64_t /*timeout*/) {
return -1;
int vx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
return (g_callbacks.ready_wait)(hdevice, timeout);
}
extern int vx_dcr_read(vx_device_h /*hdevice*/, uint32_t /*addr*/, uint32_t* /*value*/) {
return -1;
int vx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
return (g_callbacks.dcr_read)(hdevice, addr, value);
}
extern int vx_dcr_write(vx_device_h /*hdevice*/, uint32_t /*addr*/, uint32_t /*value*/) {
return -1;
int vx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
return (g_callbacks.dcr_write)(hdevice, addr, value);
}
extern int vx_mpm_query(vx_device_h /*hdevice*/, uint32_t /*addr*/, uint32_t /*core_id*/, uint64_t* /*value*/) {
return -1;
int vx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value) {
return (g_callbacks.mpm_query)(hdevice, addr, core_id, value);
}

View file

@ -2,7 +2,7 @@ include ../common.mk
TARGET ?= xrtsim
DESTDIR ?= $(CURDIR)
DESTDIR ?= $(CURDIR)/..
SRC_DIR := $(VORTEX_HOME)/runtime/xrt
@ -24,7 +24,7 @@ else
LDFLAGS += -luuid -lxrt_coreutil
endif
PROJECT := libvortex.so
PROJECT := libvortex-xrt.so
# Debugigng
ifdef DEBUG
@ -49,5 +49,5 @@ $(DESTDIR)/$(PROJECT): $(SRCS) $(XRTSIM)
clean:
DESTDIR=$(DESTDIR) $(MAKE) -C $(ROOT_DIR)/sim/xrtsim clean
rm -rf $(DESTDIR)/$(PROJECT)
rm -f $(DESTDIR)/$(PROJECT)

View file

@ -11,7 +11,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <vortex.h>
#include <malloc.h>
#include <utils.h>
#include <VX_config.h>
@ -39,6 +38,8 @@
#include <fpga.h>
#endif
#include <callbacks.h>
using namespace vortex;
#ifndef XRTSIM
@ -701,7 +702,7 @@ struct vx_buffer {
///////////////////////////////////////////////////////////////////////////////
extern int vx_dev_open(vx_device_h* hdevice) {
int vx_xrt_dev_open(vx_device_h* hdevice) {
if (nullptr == hdevice)
return -1;
@ -880,7 +881,7 @@ extern int vx_dev_open(vx_device_h* hdevice) {
return 0;
}
extern int vx_dev_close(vx_device_h hdevice) {
int vx_xrt_dev_close(vx_device_h hdevice) {
if (nullptr == hdevice)
return -1;
@ -897,7 +898,7 @@ extern int vx_dev_close(vx_device_h hdevice) {
return 0;
}
extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
int vx_xrt_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
if (nullptr == hdevice)
return -1;
@ -916,7 +917,7 @@ extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
return 0;
}
extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer) {
int vx_xrt_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer_h* hbuffer) {
if (nullptr == hdevice
|| nullptr == hbuffer
|| 0 == size)
@ -944,7 +945,7 @@ extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, int flags, vx_buffer
return 0;
}
extern int vx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer) {
int vx_xrt_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size, int flags, vx_buffer_h* hbuffer) {
if (nullptr == hdevice
|| nullptr == hbuffer
|| 0 == size)
@ -969,7 +970,7 @@ extern int vx_mem_reserve(vx_device_h hdevice, uint64_t address, uint64_t size,
return 0;
}
extern int vx_mem_free(vx_buffer_h hbuffer) {
int vx_xrt_mem_free(vx_buffer_h hbuffer) {
if (nullptr == hbuffer)
return 0;
@ -987,7 +988,7 @@ extern int vx_mem_free(vx_buffer_h hbuffer) {
return err;
}
extern int vx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags) {
int vx_xrt_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, int flags) {
if (nullptr == hbuffer)
return -1;
@ -1002,7 +1003,7 @@ extern int vx_mem_access(vx_buffer_h hbuffer, uint64_t offset, uint64_t size, in
return device->mem_access(buffer->addr + offset, size, flags);
}
extern int vx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
int vx_xrt_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
if (nullptr == hbuffer)
return -1;
@ -1015,7 +1016,7 @@ extern int vx_mem_address(vx_buffer_h hbuffer, uint64_t* address) {
return 0;
}
extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used) {
int vx_xrt_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_used) {
if (nullptr == hdevice)
return -1;
@ -1040,7 +1041,7 @@ extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_us
return 0;
}
extern int vx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size) {
int vx_xrt_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t dst_offset, uint64_t size) {
if (nullptr == hbuffer || nullptr == host_ptr)
return -1;
@ -1059,7 +1060,7 @@ extern int vx_copy_to_dev(vx_buffer_h hbuffer, const void* host_ptr, uint64_t ds
return 0;
}
extern int vx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size) {
int vx_xrt_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_offset, uint64_t size) {
if (nullptr == hbuffer || nullptr == host_ptr)
return -1;
@ -1078,7 +1079,7 @@ extern int vx_copy_from_dev(void* host_ptr, vx_buffer_h hbuffer, uint64_t src_of
return 0;
}
extern int vx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments) {
int vx_xrt_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h harguments) {
if (nullptr == hdevice || nullptr == hkernel || nullptr == harguments)
return -1;
@ -1093,7 +1094,7 @@ extern int vx_start(vx_device_h hdevice, vx_buffer_h hkernel, vx_buffer_h hargum
return device->start(kernel->addr, arguments->addr);
}
extern int vx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
int vx_xrt_ready_wait(vx_device_h hdevice, uint64_t timeout) {
if (nullptr == hdevice)
return -1;
@ -1108,7 +1109,7 @@ extern int vx_ready_wait(vx_device_h hdevice, uint64_t timeout) {
return 0;
}
extern int vx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
int vx_xrt_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
if (nullptr == hdevice)
return -1;
@ -1127,7 +1128,7 @@ extern int vx_dcr_read(vx_device_h hdevice, uint32_t addr, uint32_t* value) {
return 0;
}
extern int vx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
int vx_xrt_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
if (nullptr == hdevice)
return -1;
@ -1138,7 +1139,7 @@ extern int vx_dcr_write(vx_device_h hdevice, uint32_t addr, uint32_t value) {
return device->dcr_write(addr, value);
}
extern int vx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value) {
int vx_xrt_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, uint64_t* value) {
if (nullptr == hdevice)
return -1;
@ -1155,4 +1156,6 @@ extern int vx_mpm_query(vx_device_h hdevice, uint32_t addr, uint32_t core_id, ui
*value = _value;
return 0;
}
}
__VX_DEV_INT(xrt)

View file

@ -122,7 +122,8 @@ $(DESTDIR)/vortex_afu.h : $(AFU_DIR)/vortex_afu.vh
$(SCRIPT_DIR)/gen_config.py -i $^ -o $@
$(DESTDIR)/$(PROJECT): $(SRCS) $(DESTDIR)/vortex_afu.h $(SCOPE_JSON)
verilator --build --exe -O3 $(VL_FLAGS) --cc $(TOP) --top-module $(TOP) $(SRCS) -CFLAGS '$(CXXFLAGS)' -LDFLAGS '$(LDFLAGS)' --Mdir $(DESTDIR)/obj_dir -o $@
verilator --build --exe -O3 $(VL_FLAGS) --cc $(TOP) --top-module $(TOP) $(SRCS) -CFLAGS '$(CXXFLAGS)' -LDFLAGS '$(LDFLAGS)' --Mdir $@.obj_dir -o $@
clean:
rm -rf $(DESTDIR)/obj_dir $(DESTDIR)/vortex.xml $(DESTDIR)/scope.json $(DESTDIR)/vortex_afu.h $(DESTDIR)/$(PROJECT)
rm -rf $(DESTDIR)/$(PROJECT).obj_dir
rm -f $(DESTDIR)/vortex.xml $(DESTDIR)/scope.json $(DESTDIR)/vortex_afu.h $(DESTDIR)/$(PROJECT)

View file

@ -67,7 +67,7 @@ VL_FLAGS += -j $(THREADS)
ifdef DEBUG
VL_FLAGS += --trace --trace-structs $(DBG_FLAGS)
CXXFLAGS += -g -O0 $(DBG_FLAGS)
else
else
VL_FLAGS += -DNDEBUG
CXXFLAGS += -O2 -DNDEBUG
endif
@ -83,10 +83,17 @@ PROJECT := rtlsim
all: $(DESTDIR)/$(PROJECT)
$(DESTDIR)/$(PROJECT): $(SRCS) $(SRC_DIR)/main.cpp
verilator --build $(VL_FLAGS) $^ -CFLAGS '$(CXXFLAGS) -DSTARTUP_ADDR=0x80000000' -LDFLAGS '$(LDFLAGS)' --Mdir $(DESTDIR)/obj_dir -o $@
$(DESTDIR)/lib$(PROJECT).so: $(SRCS)
verilator --build $(VL_FLAGS) $^ -CFLAGS '$(CXXFLAGS)' -LDFLAGS '-shared $(LDFLAGS)' --Mdir $(DESTDIR)/obj_dir -o $@
verilator --build $(VL_FLAGS) $^ -CFLAGS '$(CXXFLAGS) -DSTARTUP_ADDR=0x80000000' -LDFLAGS '$(LDFLAGS)' --Mdir $@.obj_dir -o $@
clean:
rm -rf $(DESTDIR)/obj_dir $(DESTDIR)/$(PROJECT) $(DESTDIR)/lib$(PROJECT).so
$(DESTDIR)/lib$(PROJECT).so: $(SRCS)
verilator --build $(VL_FLAGS) $^ -CFLAGS '$(CXXFLAGS)' -LDFLAGS '-shared $(LDFLAGS)' --Mdir $@.obj_dir -o $@
clean-lib:
rm -rf $(DESTDIR)/lib$(PROJECT).so.obj_dir
rm -f $(DESTDIR)/lib$(PROJECT).so
clean-exe:
rm -rf $(DESTDIR)/$(PROJECT).obj_dir
rm -f $(DESTDIR)/$(PROJECT)
clean: clean-lib clean-exe

View file

@ -22,14 +22,14 @@ SRCS += $(SRC_DIR)/processor.cpp $(SRC_DIR)/cluster.cpp $(SRC_DIR)/socket.cpp $(
ifdef DEBUG
CXXFLAGS += -g -O0 -DDEBUG_LEVEL=$(DEBUG)
#CXXFLAGS += -g -O0 -DDEBUG_LEVEL=$(DEBUG) -fsanitize=address -fno-omit-frame-pointer
else
else
CXXFLAGS += -O2 -DNDEBUG
endif
PROJECT := simx
all: $(DESTDIR)/$(PROJECT)
$(DESTDIR)/$(PROJECT): $(SRCS) $(SRC_DIR)/main.cpp
$(CXX) $(CXXFLAGS) -DSTARTUP_ADDR=0x80000000 $^ $(LDFLAGS) -o $@
@ -39,5 +39,10 @@ $(DESTDIR)/lib$(PROJECT).so: $(SRCS)
.depend: $(SRCS)
$(CXX) $(CXXFLAGS) -MM $^ > .depend;
clean:
rm -rf $(DESTDIR)/$(PROJECT) $(DESTDIR)/lib$(PROJECT).so
clean-lib:
rm -f $(DESTDIR)/lib$(PROJECT).so
clean-exe:
rm -f $(DESTDIR)/$(PROJECT)
clean: clean-lib clean-exe

View file

@ -118,7 +118,8 @@ $(DESTDIR)/scope.json: $(DESTDIR)/vortex.xml
$(SCRIPT_DIR)/scope.py $^ -o $@
$(DESTDIR)/$(PROJECT): $(SRCS) $(SCOPE_JSON)
verilator --build --exe -O3 $(VL_FLAGS) --cc $(TOP) --top-module $(TOP) $(SRCS) -CFLAGS '$(CXXFLAGS)' -LDFLAGS '$(LDFLAGS)' --Mdir $(DESTDIR)/obj_dir -o $@
verilator --build --exe -O3 $(VL_FLAGS) --cc $(TOP) --top-module $(TOP) $(SRCS) -CFLAGS '$(CXXFLAGS)' -LDFLAGS '$(LDFLAGS)' --Mdir $@.obj_dir -o $@
clean:
rm -rf $(DESTDIR)/obj_dir $(DESTDIR)/vortex.xml $(DESTDIR)/scope.json $(DESTDIR)/$(PROJECT)
rm -rf $(DESTDIR)/$(PROJECT).obj_dir
rm -f $(DESTDIR)/vortex.xml $(DESTDIR)/scope.json $(DESTDIR)/$(PROJECT)

View file

@ -28,7 +28,7 @@ CFLAGS += -DXLEN_$(XLEN) -DNDEBUG
LIBC_LIB += -L$(LIBC_VORTEX)/lib -lm -lc -lgcc
LDFLAGS += -Wl,-Bstatic,--gc-sections,-T,$(VORTEX_KN_PATH)/scripts/link$(XLEN).ld,--defsym=STARTUP_ADDR=0x80000000 $(ROOT_DIR)/kernel/libvortexrt.a $(LIBC_LIB)
LDFLAGS += -Wl,-Bstatic,--gc-sections,-T,$(VORTEX_KN_PATH)/scripts/link$(XLEN).ld,--defsym=STARTUP_ADDR=0x80000000 $(ROOT_DIR)/kernel/libvortex.a $(LIBC_LIB)
all: $(PROJECT).elf $(PROJECT).bin $(PROJECT).dump

View file

@ -37,7 +37,7 @@ VX_CFLAGS += -mllvm -disable-loop-idiom-all # disable memset/memcpy loop idiom
VX_LLCFLAGS += -target-feature +m -target-feature +vortex
#VX_LLCFLAGS += -mllvm -vortex-branch-divergence=0
VX_LDFLAGS += -Wl,-Bstatic,--gc-sections,-T$(VORTEX_KN_PATH)/scripts/link$(XLEN).ld,--defsym=STARTUP_ADDR=$(STARTUP_ADDR) $(ROOT_DIR)/kernel/libvortexrt.a $(VX_LIBS)
VX_LDFLAGS += -Wl,-Bstatic,--gc-sections,-T$(VORTEX_KN_PATH)/scripts/link$(XLEN).ld,--defsym=STARTUP_ADDR=$(STARTUP_ADDR) $(ROOT_DIR)/kernel/libvortex.a $(VX_LIBS)
CXXFLAGS += -std=c++11 -Wall -Wextra -Wfatal-errors
CXXFLAGS += -Wno-deprecated-declarations -Wno-unused-parameter -Wno-narrowing
@ -100,7 +100,7 @@ setup:
endif
$(PROJECT): setup $(OBJS)
$(CXX) $(CXXFLAGS) $(filter-out setup, $^) $(LDFLAGS) -L$(ROOT_DIR)/runtime/stub -lvortex -L$(POCL_RT_PATH)/lib -lOpenCL -o $@
$(CXX) $(CXXFLAGS) $(filter-out setup, $^) $(LDFLAGS) -L$(ROOT_DIR)/runtime -lvortex -L$(POCL_RT_PATH)/lib -lOpenCL -o $@
$(PROJECT).host: setup $(OBJS_HOST)
$(CXX) $(CXXFLAGS) $(filter-out setup, $^) $(LDFLAGS) -lOpenCL -o $@
@ -109,19 +109,19 @@ run-gpu: $(PROJECT).host kernel.cl
./$(PROJECT).host $(OPTS)
run-simx: $(PROJECT) kernel.pocl
LD_LIBRARY_PATH=$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime/simx:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) ./$(PROJECT) $(OPTS)
LD_LIBRARY_PATH=$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) VORTEX_DRIVER=simx ./$(PROJECT) $(OPTS)
run-rtlsim: $(PROJECT) kernel.pocl
LD_LIBRARY_PATH=$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime/rtlsim:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) ./$(PROJECT) $(OPTS)
LD_LIBRARY_PATH=$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) VORTEX_DRIVER=rtlsim ./$(PROJECT) $(OPTS)
run-opae: $(PROJECT) kernel.pocl
SCOPE_JSON_PATH=$(ROOT_DIR)/runtime/opae/scope.json OPAE_DRV_PATHS=$(OPAE_DRV_PATHS) LD_LIBRARY_PATH=$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime/opae:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) ./$(PROJECT) $(OPTS)
SCOPE_JSON_PATH=$(ROOT_DIR)/runtime/opae/scope.json OPAE_DRV_PATHS=$(OPAE_DRV_PATHS) LD_LIBRARY_PATH=$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) VORTEX_DRIVER=opae ./$(PROJECT) $(OPTS)
run-xrt: $(PROJECT) kernel.pocl
ifeq ($(TARGET), hw)
XRT_INI_PATH=$(XRT_SYN_DIR)/xrt.ini EMCONFIG_PATH=$(FPGA_BIN_DIR) XRT_DEVICE_INDEX=$(XRT_DEVICE_INDEX) XRT_XCLBIN_PATH=$(FPGA_BIN_DIR)/vortex_afu.xclbin LD_LIBRARY_PATH=$(XILINX_XRT)/lib:$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime/xrt:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) ./$(PROJECT) $(OPTS)
XRT_INI_PATH=$(XRT_SYN_DIR)/xrt.ini EMCONFIG_PATH=$(FPGA_BIN_DIR) XRT_DEVICE_INDEX=$(XRT_DEVICE_INDEX) XRT_XCLBIN_PATH=$(FPGA_BIN_DIR)/vortex_afu.xclbin LD_LIBRARY_PATH=$(XILINX_XRT)/lib:$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) VORTEX_DRIVER=xrt ./$(PROJECT) $(OPTS)
else
XCL_EMULATION_MODE=$(TARGET) XRT_INI_PATH=$(XRT_SYN_DIR)/xrt.ini EMCONFIG_PATH=$(FPGA_BIN_DIR) XRT_DEVICE_INDEX=$(XRT_DEVICE_INDEX) XRT_XCLBIN_PATH=$(FPGA_BIN_DIR)/vortex_afu.xclbin LD_LIBRARY_PATH=$(XILINX_XRT)/lib:$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime/xrt:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) ./$(PROJECT) $(OPTS)
XCL_EMULATION_MODE=$(TARGET) XRT_INI_PATH=$(XRT_SYN_DIR)/xrt.ini EMCONFIG_PATH=$(FPGA_BIN_DIR) XRT_DEVICE_INDEX=$(XRT_DEVICE_INDEX) XRT_XCLBIN_PATH=$(FPGA_BIN_DIR)/vortex_afu.xclbin LD_LIBRARY_PATH=$(XILINX_XRT)/lib:$(POCL_RT_PATH)/lib:$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) $(POCL_RT_FLAGS) VORTEX_DRIVER=xrt ./$(PROJECT) $(OPTS)
endif
.depend: $(SRCS)

View file

@ -45,12 +45,12 @@ VX_LIBS += -L$(LIBC_VORTEX)/lib -lm -lc
VX_LIBS += $(LIBCRT_VORTEX)/lib/baremetal/libclang_rt.builtins-riscv$(XLEN).a
#VX_LIBS += -lgcc
VX_LDFLAGS += -Wl,-Bstatic,--gc-sections,-T,$(VORTEX_KN_PATH)/scripts/link$(XLEN).ld,--defsym=STARTUP_ADDR=$(STARTUP_ADDR) $(ROOT_DIR)/kernel/libvortexrt.a $(VX_LIBS)
VX_LDFLAGS += -Wl,-Bstatic,--gc-sections,-T,$(VORTEX_KN_PATH)/scripts/link$(XLEN).ld,--defsym=STARTUP_ADDR=$(STARTUP_ADDR) $(ROOT_DIR)/kernel/libvortex.a $(VX_LIBS)
CXXFLAGS += -std=c++11 -Wall -Wextra -pedantic -Wfatal-errors
CXXFLAGS += -I$(VORTEX_RT_PATH)/include -I$(ROOT_DIR)/hw
LDFLAGS += -L$(ROOT_DIR)/runtime/stub -lvortex
LDFLAGS += -L$(ROOT_DIR)/runtime -lvortex
# Debugigng
ifdef DEBUG
@ -86,19 +86,19 @@ $(PROJECT): $(SRCS)
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@
run-simx: $(PROJECT) kernel.vxbin
LD_LIBRARY_PATH=$(ROOT_DIR)/runtime/simx:$(LD_LIBRARY_PATH) ./$(PROJECT) $(OPTS)
LD_LIBRARY_PATH=$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) VORTEX_DRIVER=simx ./$(PROJECT) $(OPTS)
run-opae: $(PROJECT) kernel.vxbin
SCOPE_JSON_PATH=$(ROOT_DIR)/runtime/opae/scope.json OPAE_DRV_PATHS=$(OPAE_DRV_PATHS) LD_LIBRARY_PATH=$(ROOT_DIR)/runtime/opae:$(LD_LIBRARY_PATH) ./$(PROJECT) $(OPTS)
SCOPE_JSON_PATH=$(ROOT_DIR)/runtime/opae/scope.json OPAE_DRV_PATHS=$(OPAE_DRV_PATHS) LD_LIBRARY_PATH=$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) VORTEX_DRIVER=rtlsim ./$(PROJECT) $(OPTS)
run-rtlsim: $(PROJECT) kernel.vxbin
LD_LIBRARY_PATH=$(ROOT_DIR)/runtime/rtlsim:$(LD_LIBRARY_PATH) ./$(PROJECT) $(OPTS)
LD_LIBRARY_PATH=$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) VORTEX_DRIVER=opae ./$(PROJECT) $(OPTS)
run-xrt: $(PROJECT) kernel.vxbin
ifeq ($(TARGET), hw)
XRT_INI_PATH=$(XRT_SYN_DIR)/xrt.ini EMCONFIG_PATH=$(FPGA_BIN_DIR) XRT_DEVICE_INDEX=$(XRT_DEVICE_INDEX) XRT_XCLBIN_PATH=$(FPGA_BIN_DIR)/vortex_afu.xclbin LD_LIBRARY_PATH=$(XILINX_XRT)/lib:$(ROOT_DIR)/runtime/xrt:$(LD_LIBRARY_PATH) ./$(PROJECT) $(OPTS)
XRT_INI_PATH=$(XRT_SYN_DIR)/xrt.ini EMCONFIG_PATH=$(FPGA_BIN_DIR) XRT_DEVICE_INDEX=$(XRT_DEVICE_INDEX) XRT_XCLBIN_PATH=$(FPGA_BIN_DIR)/vortex_afu.xclbin LD_LIBRARY_PATH=$(XILINX_XRT)/lib:$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) VORTEX_DRIVER=xrt ./$(PROJECT) $(OPTS)
else
XCL_EMULATION_MODE=$(TARGET) XRT_INI_PATH=$(XRT_SYN_DIR)/xrt.ini EMCONFIG_PATH=$(FPGA_BIN_DIR) XRT_DEVICE_INDEX=$(XRT_DEVICE_INDEX) XRT_XCLBIN_PATH=$(FPGA_BIN_DIR)/vortex_afu.xclbin LD_LIBRARY_PATH=$(XILINX_XRT)/lib:$(ROOT_DIR)/runtime/xrt:$(LD_LIBRARY_PATH) ./$(PROJECT) $(OPTS)
XCL_EMULATION_MODE=$(TARGET) XRT_INI_PATH=$(XRT_SYN_DIR)/xrt.ini EMCONFIG_PATH=$(FPGA_BIN_DIR) XRT_DEVICE_INDEX=$(XRT_DEVICE_INDEX) XRT_XCLBIN_PATH=$(FPGA_BIN_DIR)/vortex_afu.xclbin LD_LIBRARY_PATH=$(XILINX_XRT)/lib:$(ROOT_DIR)/runtime:$(LD_LIBRARY_PATH) VORTEX_DRIVER=xrt ./$(PROJECT) $(OPTS)
endif
.depend: $(SRCS)