diff --git a/target/sim/Makefile b/target/sim/Makefile index 44b8c2190..80b1f3c03 100644 --- a/target/sim/Makefile +++ b/target/sim/Makefile @@ -433,9 +433,7 @@ PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/snitch_quad_peripheral.h PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/snitch_hbm_xbar_peripheral.h PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/idma.h -.PHONY: sw all-headers clean-headers clean-sw - -all-headers: $(PLATFORM_HEADERS) +.PHONY: sw clean-headers clean-sw sw: $(PLATFORM_HEADERS) $(MAKE) -C sw/ all diff --git a/target/sim/sw/device/Makefile b/target/sim/sw/device/Makefile index 913514b75..1bab68e71 100644 --- a/target/sim/sw/device/Makefile +++ b/target/sim/sw/device/Makefile @@ -7,7 +7,6 @@ # Add user applications to APPS variable APPS = blas/axpy APPS += blas/gemm -APPS += libomptarget_device TARGET ?= all diff --git a/target/sim/sw/device/apps/common.mk b/target/sim/sw/device/apps/common.mk index f6b5d7333..eff90e921 100644 --- a/target/sim/sw/device/apps/common.mk +++ b/target/sim/sw/device/apps/common.mk @@ -32,9 +32,7 @@ BUILDDIR = $(abspath build) # Dependencies INCDIRS += $(RUNTIME_DIR)/src INCDIRS += $(SNRT_DIR)/api -INCDIRS += $(SNRT_DIR)/api/omp INCDIRS += $(SNRT_DIR)/src -INCDIRS += $(SNRT_DIR)/src/omp INCDIRS += $(SNRT_DIR)/vendor/riscv-opcodes INCDIRS += $(SW_DIR)/shared/platform/generated INCDIRS += $(SW_DIR)/shared/platform @@ -101,9 +99,6 @@ $(BUILDDIR): $(DEP): $(SRCS) | $(BUILDDIR) $(RISCV_CC) $(RISCV_CFLAGS) -MM -MT '$(ELF)' $< > $@ -$(BUILDDIR)/%.o: $(SRC_DIR)/%.c | $(BUILDDIR) - $(RISCV_CC) $(RISCV_CFLAGS) -c $< -o $@ - $(ELF): $(DEP) $(LD_SRCS) | $(BUILDDIR) $(RISCV_CC) $(RISCV_CFLAGS) $(RISCV_LDFLAGS) $(SRCS) -o $@ diff --git a/target/sim/sw/device/apps/libomptarget_device/Makefile b/target/sim/sw/device/apps/libomptarget_device/Makefile deleted file mode 100644 index 171b4f9a1..000000000 --- a/target/sim/sw/device/apps/libomptarget_device/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2023 ETH Zurich and University of Bologna. -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 -# -# Cyril Koenig - -# Usage of absolute paths is required to externally include this Makefile -MK_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) -SRC_DIR := $(realpath $(MK_DIR)/src) - -APP ?= omptarget_device -SRCS ?= $(SRC_DIR)/main.c $(SRC_DIR)/sw_mailbox.c -INCDIRS += $(SRC_DIR) - -.PHONY: clean -clean: - -include ../common.mk - -OBJS := $(subst $(SRC_DIR), $(BUILDDIR), $(SRCS:.c=.o)) -LIB := $(BUILDDIR)/libomptarget_device.a - -$(BUILDDIR)/origin.ld: | $(BUILDDIR) - echo "L3_ORIGIN = 0xC0000000;" > $(BUILDDIR)/origin.ld - -# We first extract objects from libnnruntime and then link them with our objects -$(BUILDDIR)/libomptarget_device.a: $(OBJS) | $(BUILDDIR) - cd $(BUILDDIR) && $(RISCV_AR) -x $(SNRT_LIB_DIR)/lib$(SNRT_LIB_NAME).a - $(RISCV_AR) $(RISCV_ARFLAGS) $@ $(BUILDDIR)/*.o - -# For this target, only build the library -all: $(LIB) diff --git a/target/sim/sw/device/apps/libomptarget_device/link.ld b/target/sim/sw/device/apps/libomptarget_device/link.ld deleted file mode 100644 index 0f54b2016..000000000 --- a/target/sim/sw/device/apps/libomptarget_device/link.ld +++ /dev/null @@ -1,130 +0,0 @@ -/* Copyright 2020 ETH Zurich and University of Bologna. */ -/* Solderpad Hardware License, Version 0.51, see LICENSE for details. */ -/* SPDX-License-Identifier: SHL-0.51 */ - -OUTPUT_ARCH( "riscv" ) -ENTRY(_start) - -/* Memory section should be provided in a separate, platform-specific */ -/* file. It should define at least the L1 and L3 memory blocks. */ -MEMORY -{ - L3 : ORIGIN = 0xC0000000, LENGTH = 0x800000 -} - -SECTIONS -{ - - /* Program code goes into L3 */ - .text : - { - . = ALIGN(4); - *(.init) - *(.text.init) - *(.text.startup) - *(.text) - *(.text*) - *(.text) - . = ALIGN(4); - _etext = .; - } >L3 - - /* By default, constant data goes into L3, right after code section */ - .rodata : - { - . = ALIGN(4); - *(.rodata) - *(.rodata*) - . = ALIGN(4); - } >L3 - - /* HTIF section for FESVR */ - .htif : { } >L3 - - /* Thread Local Storage sections */ - .tdata : - { - __tdata_start = .; - *(.tdata .tdata.* .gnu.linkonce.td.*) - __tdata_end = .; - } >L3 - .tbss : - { - __tbss_start = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - __tbss_end = .; - } >L3 - - /* Cluster Local Storage sections */ - .cdata : - { - __cdata_start = .; - *(.cdata .cdata.*) - __cdata_end = .; - } >L3 - .cbss : - { - __cbss_start = .; - *(.cbss .cbss.*) - __cbss_end = .; - } >L3 - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* small data section that can be addressed through the global pointer */ - .sdata : - { - __SDATA_BEGIN__ = .; - __global_pointer$ = . + 0x7f0; - *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) - *(.sdata .sdata.* .gnu.linkonce.s.*) - } >L3 - - /* Initialized data sections goes into L3 */ - .data : - { - __DATA_BEGIN__ = .; - *(.data .data.* .gnu.linkonce.d.*) - SORT(CONSTRUCTORS) - } >L3 - _edata = .; PROVIDE (edata = .); - - /* small bss section */ - . = .; - __bss_start = .; - .sbss : - { - *(.dynsbss) - *(.sbss .sbss.* .gnu.linkonce.sb.*) - *(.scommon) - } >L3 - - /* Uninitialized data section */ - .bss : - { - *(.dynbss) - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. */ - . = ALIGN(. != 0 ? 32 / 8 : 1); - } >L3 - . = ALIGN(32 / 8); - . = SEGMENT_START("ldata-segment", .); - . = ALIGN(32 / 8); - __BSS_END__ = .; - __bss_end = .; - _end = .; PROVIDE (end = .); - - /* Uninitialized data section in L3 */ - .dram : - { - *(.dram) - _edram = .; - } >L3 - - __uart = 0x2002000; -} diff --git a/target/sim/sw/device/apps/libomptarget_device/src/debug.h b/target/sim/sw/device/apps/libomptarget_device/src/debug.h deleted file mode 100644 index dd439f4c7..000000000 --- a/target/sim/sw/device/apps/libomptarget_device/src/debug.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2020 ETH Zurich and University of Bologna. -// Licensed under the Apache License, Version 2.0, see LICENSE for details. -// SPDX-License-Identifier: Apache-2.0 -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern uint32_t snrt_log_level; - -static inline void snrt_debug_set_loglevel(uint32_t lvl) { snrt_log_level = lvl; }; - -#define LOG_ERROR 0 -#define LOG_WARN 1 -#define LOG_INFO 2 -#define LOG_DEBUG 3 -#define LOG_TRACE 4 - -#if defined(DEBUG) - -#define snrt_error(fmt, ...) \ - ({ \ - if (LOG_ERROR <= snrt_log_level) \ - snrt_printf("[\033[31msnrt(%d,%d):error:%s\033[0m] " fmt, snrt_cluster_idx(), \ - snrt_cluster_core_idx(), __func__, ##__VA_ARGS__); \ - }) -#define snrt_warn(fmt, ...) \ - ({ \ - if (LOG_WARN <= snrt_log_level) \ - snrt_printf("[\033[91msnrt(%d,%d):warn:%s\033[0m] " fmt, snrt_cluster_idx(), \ - snrt_cluster_core_idx(), __func__, ##__VA_ARGS__); \ - }) -#define snrt_info(fmt, ...) \ - ({ \ - if (LOG_INFO <= snrt_log_level) \ - snrt_printf("[\033[33msnrt(%d,%d):info:%s\033[0m] " fmt, snrt_cluster_idx(), \ - snrt_cluster_core_idx(), __func__, ##__VA_ARGS__); \ - }) -#define snrt_debug(fmt, ...) \ - ({ \ - if (LOG_DEBUG <= snrt_log_level) \ - snrt_printf("[\033[35msnrt(%d,%d):debug:%s\033[0m] " fmt, snrt_cluster_idx(), \ - snrt_cluster_core_idx(), __func__, ##__VA_ARGS__); \ - }) -#define snrt_trace(fmt, ...) \ - ({ \ - if (LOG_TRACE <= snrt_log_level) \ - snrt_printf("[\033[96msnrt(%d,%d):trace:%s\033[0m] " fmt, snrt_cluster_idx(), \ - snrt_cluster_core_idx(), __func__, ##__VA_ARGS__); \ - }) - -#else // #if defined(DEBUG) - -#define snrt_error(x...) \ - do { \ - } while (0) -#define snrt_warn(x...) \ - do { \ - } while (0) -#define snrt_info(x...) \ - do { \ - } while (0) -#define snrt_debug(x...) \ - do { \ - } while (0) -#define snrt_trace(x...) \ - do { \ - } while (0) - -#endif // defined(SNRT_DEBUG) - -#ifdef __cplusplus -} -#endif diff --git a/target/sim/sw/device/apps/libomptarget_device/src/main.c b/target/sim/sw/device/apps/libomptarget_device/src/main.c deleted file mode 100644 index 17ff5754b..000000000 --- a/target/sim/sw/device/apps/libomptarget_device/src/main.c +++ /dev/null @@ -1,317 +0,0 @@ -// Copyright 2020 ETH Zurich and University of Bologna. -// Licensed under the Apache License, Version 2.0, see LICENSE for details. -// SPDX-License-Identifier: Apache-2.0 -#include - -#include "sw_mailbox.h" -#include "snrt.h" - -volatile uint32_t dma_wait_cycles = 0; - -//================================================================================ -// MACROS AND SETTINGS -//================================================================================ - -// set to >0 for debugging -#define DEBUG_LEVEL_OFFLOAD_MANAGER 1 - -const uint32_t active_pe = 8; - -/* MAILBOX SIGNALING */ -#define MBOX_DEVICE_READY (0x01U) -#define MBOX_DEVICE_START (0x02U) -#define MBOX_DEVICE_BUSY (0x03U) -#define MBOX_DEVICE_DONE (0x04U) -#define MBOX_DEVICE_STOP (0x0FU) -#define MBOX_DEVICE_LOGLVL (0x10U) -#define MBOX_HOST_READY (0x1000U) -#define MBOX_HOST_DONE (0x3000U) - -#define TO_RUNTIME (0x10000000U) // bypass PULP driver -#define RAB_UPDATE (0x20000000U) // handled by PULP driver -#define RAB_SWITCH (0x30000000U) // handled by PULP driver - -//================================================================================ -// TYPES -//================================================================================ - -// Shrinked gomp_team_t descriptor -typedef struct offload_rab_miss_handler_desc_s { - void (*omp_task_f)(void *arg, uint32_t argc); - void *omp_args; - void *omp_argc; - int barrier_id; -} offload_rab_miss_handler_desc_t; - -typedef uint32_t virt_addr_t; -typedef uint32_t virt_pfn_t; - -// This struct represents a miss in the RAB Miss Hardware FIFO. -typedef struct rab_miss_t { - virt_addr_t virt_addr; - int core_id; - int cluster_id; - int intra_cluster_id; - uint8_t is_prefetch; -} rab_miss_t; - -//================================================================================ -// Data -//================================================================================ -static volatile uint32_t g_printf_mutex = 0; - -static volatile uint32_t *soc_scratch = (uint32_t *)(0x02000014); -struct l3_layout l3l; - -const uint32_t snrt_stack_size __attribute__((weak, section(".rodata"))) = 12; - -// The boot data generated along with the system RTL. -// See `hw/system/snitch_cluster/test/tb_lib.hh` for details. -struct snrt_cluster_bootdata { - uint32_t boot_addr; - uint32_t core_count; - uint32_t hartid_base; - uint32_t tcdm_start; - uint32_t tcdm_size; - uint32_t tcdm_offset; - uint64_t global_mem_start; - uint64_t global_mem_end; - uint32_t cluster_count; - uint32_t s1_quadrant_count; - uint32_t clint_base; -}; - -/** - * @brief Called by each hart before the pre-main barrier in snrt crt0 - * - */ -void _snrt_hier_wakeup(void) { - const uint32_t core_id = snrt_cluster_core_idx(); - - // master core wakes other cluster cores through cluster local clint - if (core_id == 0) { - // clear the interrupt from cva6 - snrt_int_sw_clear(snrt_hartid()); - // wake remaining cluster cores - const unsigned cluster_core_num = snrt_cluster_core_num(); - snrt_int_cluster_set(~0x1 & ((1 << cluster_core_num) - 1)); - } else { - // clear my interrupt - snrt_int_cluster_clr(1 << core_id); - } -} - -//================================================================================ -// TODO: Symbols to declare somewhere else on a merge -//================================================================================ -/** - * @brief A re-entrant wrapper to printf - * - */ -void snrt_printf(const char *format, ...) { - va_list args; - - snrt_mutex_acquire(&g_printf_mutex); - - va_start(args, format); - vprintf(format, args); - va_end(args); - - snrt_mutex_release(&g_printf_mutex); -} - -//================================================================================ -// HERO Functions -//================================================================================ - -static void offload_rab_misses_handler(void *arg, uint32_t argc) { - (void)arg; - (void)argc; - snrt_err("unimplemented!\r\n"); - // static void offload_rab_misses_handler(uint32_t *status) { - // uint32_t *status = (uint32_t)arg; - // if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("offload_rab_misses_handler: synch @%p (0x%x)\n", status, - // *(volatile unsigned int *)status); - // do { - // handle_rab_misses(); - // } while (*((volatile uint32_t *)status) != 0xdeadbeefU); - // if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("offload_rab_misses_handler: synch @%p (0x%x)\n", status, - // *(volatile unsigned int *)status); -} - -static int gomp_offload_manager() { - const uint32_t core_id = snrt_cluster_core_idx(); - - // Init the manager (handshake btw host and accelerator is here) - // gomp_init_offload_manager(); - - // FIXME For the momenent we are not using the cmd sended as trigger. - // It should be used to perform the deactivation of the accelerator, - // as well as other operations, like local data allocation or movement. - // FIXME Note that the offload at the moment use several time the mailbox. - // We should compact the offload descriptor and just sent a pointer to - // that descriptor. - uint32_t cmd = (uint32_t)NULL; - uint32_t data; - - // Offloaded function pointer and arguments - void (*offloadFn)(uint64_t) = NULL; - uint64_t offloadArgs = 0x0; - unsigned nbOffloadRabMissHandlers = 0x0; - uint32_t offload_rab_miss_sync = 0x0U; - // offload_rab_miss_handler_desc_t rab_miss_handler = {.omp_task_f = offload_rab_misses_handler, - // .omp_args = (void *)&offload_rab_miss_sync, - // .omp_argc = 1, - // .barrier_id = -1}; - - int cycles = 0; - uint32_t issue_fpu, dma_busy; - rab_miss_t rab_miss; - // reset_vmm(); - - while (1) { - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("Waiting for command...\n"); - - // (1) Wait for the offload trigger cmd == MBOX_DEVICE_START - mailbox_read((unsigned int *)&cmd, 1); - cycles = read_csr(mcycle); - if (MBOX_DEVICE_STOP == cmd) { - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("Got MBOX_DEVICE_STOP from host, stopping execution now.\n"); - break; - } else if (MBOX_DEVICE_LOGLVL == cmd) { - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("Got command 0x%x, setting log level.\n", cmd); - mailbox_read((unsigned int *)&data, 1); - //snrt_debug_set_loglevel(data); - continue; - } else if (MBOX_DEVICE_START != cmd) { - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("Got unexpected command 0x%x, stopping execution now.\n", cmd); - break; - } - - // (2) The host sends through the mailbox the pointer to the function that should be - // executed on the accelerator. - mailbox_read((unsigned int *)&offloadFn, 1); - - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("tgt_fn @ 0x%x\n", (unsigned int)offloadFn); - - // (3) The host sends through the mailbox the pointer to the arguments that should - // be used. - mailbox_read((unsigned int *)&offloadArgs, 1); - - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("tgt_vars @ 0x%x\n", (unsigned int)offloadArgs); - - // (3b) The host sends through the mailbox the number of rab misses handlers threads - mailbox_read((unsigned int *)&nbOffloadRabMissHandlers, 1); - - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("nbOffloadRabMissHandlers %d/%d\n", nbOffloadRabMissHandlers, active_pe); - - // (3c) Spawning nbOffloadRabMissHandlers - unsigned mhCoreMask = 0; - nbOffloadRabMissHandlers = - nbOffloadRabMissHandlers < active_pe - 1 ? nbOffloadRabMissHandlers : active_pe - 1; - if (nbOffloadRabMissHandlers) { - offload_rab_miss_sync = 0x0U; - for (int pid = active_pe - 1, i = nbOffloadRabMissHandlers; i > 0; i--, pid--) { - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("enabling RAB miss handler on %d\n", pid); - mhCoreMask |= (1 << pid); - } - } - omp_getData()->maxThreads = active_pe - nbOffloadRabMissHandlers; - omp_getData()->numThreads = active_pe - nbOffloadRabMissHandlers; - // eu_dispatch_team_config(mhCoreMask); - // eu_dispatch_push((unsigned int)&offload_rab_misses_handler); - // eu_dispatch_push((unsigned int)&offload_rab_miss_sync); - // eu_dispatch_team_config(omp_getData()->coreMask); - - // (4) Ensure access to offloadArgs. It might be in SVM. - if (offloadArgs != 0x0) { - // FIXME - // pulp_tryread((unsigned int *)offloadArgs); - } - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("begin offloading\n"); - // reset_timer(); - // start_timer(); - - //for (unsigned i = 0; i < 16; i += 2) { - // snrt_trace(" %2d: 0x%08x = ... ; %2d: 0x%08x = ...\n", i, ((uint32_t *)offloadArgs)[i], - // /* *((uint32_t *)(((uint32_t *)offloadArgs)[i])) ,*/ i + 1, - // ((uint32_t *)offloadArgs)[i + 1] /*, *((uint32_t *)(((uint32_t *)offloadArgs)[i + 1]))*/ ); - //} - - // (5) Execute the offloaded function. - // snrt_reset_perf_counter(SNRT_PERF_CNT0); - // snrt_reset_perf_counter(SNRT_PERF_CNT1); - // snrt_start_perf_counter(SNRT_PERF_CNT0, SNRT_PERF_CNT_ISSUE_FPU, core_id); - // snrt_start_perf_counter(SNRT_PERF_CNT1, SNRT_PERF_CNT_DMA_BUSY, core_id); - cycles = read_csr(mcycle); - dma_wait_cycles = 0; - - offloadFn(offloadArgs); - // snrt_stop_perf_counter(SNRT_PERF_CNT0); - // snrt_stop_perf_counter(SNRT_PERF_CNT1); - // issue_fpu = snrt_get_perf_counter(SNRT_PERF_CNT0); - // dma_busy = snrt_get_perf_counter(SNRT_PERF_CNT1); - - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("end offloading\n"); - - // (6) Report EOC and profiling - //snrt_info("cycles: %d\r\n", cycles); - - mailbox_write(MBOX_DEVICE_DONE); - cycles = read_csr(mcycle) - cycles; - mailbox_write(cycles); - mailbox_write(dma_wait_cycles); - - //if (DEBUG_LEVEL_OFFLOAD_MANAGER > 0) - // snrt_trace("Kernel execution time [Snitch cycles] = %d\n", cycles); - - if (nbOffloadRabMissHandlers) { - offload_rab_miss_sync = 0xdeadbeefU; - // gomp_atomic_add_thread_pool_idle_cores(nbOffloadRabMissHandlers); - } - } - - return 0; -} - -int main(int argc, char *argv[]) { - (void)argc; - (void)argv; - unsigned core_idx = snrt_cluster_core_idx(); - unsigned core_num = snrt_cluster_core_num(); - - /** - * One core initializes the global data structures - */ - if (snrt_is_dm_core()) { - // read memory layout from scratch2 - memcpy(&l3l, (void *)soc_scratch[2], sizeof(struct l3_layout)); - g_a2h_rb = (struct ring_buf *)l3l.a2h_rb; - g_a2h_mbox = (struct ring_buf *)l3l.a2h_mbox; - g_h2a_mbox = (struct ring_buf *)l3l.h2a_mbox; - } - - snrt_cluster_hw_barrier(); - - __snrt_omp_bootstrap(core_idx); - - gomp_offload_manager(); - - //snrt_trace("bye\n"); - // exit - __snrt_omp_destroy(core_idx); - snrt_hero_exit(0); - return 0; -} diff --git a/target/sim/sw/device/apps/libomptarget_device/src/sw_mailbox.c b/target/sim/sw/device/apps/libomptarget_device/src/sw_mailbox.c deleted file mode 100644 index 96051f2a9..000000000 --- a/target/sim/sw/device/apps/libomptarget_device/src/sw_mailbox.c +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2020 ETH Zurich and University of Bologna. -// Licensed under the Apache License, Version 2.0, see LICENSE for details. -// SPDX-License-Identifier: Apache-2.0 - -#include "sw_mailbox.h" -#include "snrt.h" // snrt_mcycle - -/*********************************************************************************** - * MACROS - ***********************************************************************************/ - -#define SYS_exit 60 -#define SYS_write 64 -#define SYS_read 63 -#define SYS_wake 1235 -#define SYS_cycle 1236 - -/*********************************************************************************** - * DATA - ***********************************************************************************/ -volatile struct ring_buf *g_a2h_rb; -volatile struct ring_buf *g_a2h_mbox; -volatile struct ring_buf *g_h2a_mbox; - -/*********************************************************************************** - * FUNCTIONS - ***********************************************************************************/ - -int syscall(uint64_t which, uint64_t arg0, uint64_t arg1, uint64_t arg2, - uint64_t arg3, uint64_t arg4) { - uint64_t magic_mem[6]; - int ret; - uint32_t retries = 0; - - volatile struct ring_buf *rb = g_a2h_rb; - - magic_mem[0] = which; - magic_mem[1] = arg0; - magic_mem[2] = arg1; - magic_mem[3] = arg2; - magic_mem[4] = arg3; - magic_mem[5] = arg4; - - do { - ret = rb_device_put(rb, (void *)magic_mem); - if (ret) { - ++retries; - csleep(10); - } - } while (ret != 0); - return retries; -} - -#define MBOX_DEVICE_PRINT (0x05U) - -void snrt_putchar(char c) { - //*(volatile uint32_t *)0x2002000 = c; - mailbox_write(MBOX_DEVICE_PRINT); - csleep(1000); - mailbox_write(c); -} - -void snrt_hero_exit(int code) { syscall(SYS_exit, code, 0, 0, 0, 0); } - -/*********************************************************************************** - * MAILBOX - ***********************************************************************************/ - -int mailbox_try_read(uint32_t *buffer) { - return rb_device_get(g_h2a_mbox, buffer) == 0 ? 1 : 0; -} -inline int mailbox_read(uint32_t *buffer, size_t n_words) { - int ret; - while (n_words--) { - do { - ret = rb_device_get(g_h2a_mbox, &buffer[n_words]); - if (ret) { - csleep(10); - } - } while (ret); - } - return 0; -} -int mailbox_write(uint32_t word) { - int ret; - do { - ret = rb_device_put(g_a2h_mbox, &word); - if (ret) { - csleep(10); - } - } while (ret); - return ret; -} diff --git a/target/sim/sw/device/apps/libomptarget_device/src/sw_mailbox.h b/target/sim/sw/device/apps/libomptarget_device/src/sw_mailbox.h deleted file mode 100644 index eef409566..000000000 --- a/target/sim/sw/device/apps/libomptarget_device/src/sw_mailbox.h +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright 2020 ETH Zurich and University of Bologna. -// Licensed under the Apache License, Version 2.0, see LICENSE for details. -// SPDX-License-Identifier: Apache-2.0 -#pragma once - -#include -#include -#include -#include -#include "snrt.h" - -/*********************************************************************************** - * MACROS - ***********************************************************************************/ - -#define MBOX_DEVICE_READY (0x01U) -#define MBOX_DEVICE_START (0x02U) -#define MBOX_DEVICE_BUSY (0x03U) -#define MBOX_DEVICE_DONE (0x04U) -#define MBOX_DEVICE_STOP (0x0FU) -#define MBOX_DEVICE_LOGLVL (0x10U) -#define MBOX_HOST_READY (0x1000U) -#define MBOX_HOST_DONE (0x3000U) - -#define SYS_exit 60 -#define SYS_write 64 -#define SYS_read 63 -#define SYS_wake 1235 -#define SYS_cycle 1236 - -/*********************************************************************************** - * TYPES - ***********************************************************************************/ - -/** - * @brief Ring buffer for simple communication from accelerator to host. - * @tail: Points to the element in `data` which is read next - * @head: Points to the element in `data` which is written next - * @size: Number of elements in `data`. Head and tail pointer wrap at `size` - * @element_size: Size of each element in bytes - * @data_p: points to the base of the data buffer in physical address - * @data_v: points to the base of the data buffer in virtual address space - */ -struct ring_buf { - uint32_t head; - uint32_t size; - uint32_t tail; - uint32_t element_size; - uint64_t data_v; - uint64_t data_p; -}; - - -/*********************************************************************************** - * DATA - ***********************************************************************************/ -extern volatile struct ring_buf *g_a2h_rb; -extern volatile struct ring_buf *g_a2h_mbox; -extern volatile struct ring_buf *g_h2a_mbox; - -/*********************************************************************************** - * INLINES - ***********************************************************************************/ - -static inline void dump_mbox(struct ring_buf *rbuf) { - printf("---DUMPING NOW---\n\r"); - printf("mbox (%x)\n\r", rbuf); - uint8_t* addr = rbuf; - for(int i = 0; i < sizeof(struct ring_buf); i++) { - if(i % 8 == 0) - printf("\n\r(%x) : ", addr); - printf("%x-", *(addr++)); - } - printf("\n\r"); - printf("head : %#x = %u\n\r" , &rbuf->head , rbuf->head ); - printf("size : %#x = %u\n\r" , &rbuf->size , rbuf->size ); - printf("tail : %#x = %u\n\r" , &rbuf->tail , rbuf->tail ); - printf("data_p : %#x = %lx\n\r", &rbuf->data_p , rbuf->data_p ); - printf("data_v : %#x = %lx\n\r", &rbuf->data_v , rbuf->data_v ); - //printf("tail %u, data_v %" PRIu64 ", element_size %u, size %u, data_p %" PRIu64 ", head %u\n\r", rbuf->tail, rbuf->data_v, rbuf->element_size, rbuf->size, rbuf->data_p, rbuf->head); - printf("---DUMPING ENDS---\n\r"); -} - -/** - * @brief Copy data from `el` in the next free slot in the ring-buffer on the - *physical addresses - * - * @param rb pointer to the ring buffer struct - * @param el pointer to the data to be copied into the ring buffer - * @return int 0 on succes, -1 if the buffer is full - */ -static inline int rb_device_put(volatile struct ring_buf *rb, void *el) { - uint32_t next_head = (rb->head + 1) % rb->size; - // caught the tail, can't put data - if (next_head == rb->tail) - return -1; - for (uint32_t i = 0; i < rb->element_size; i++) - *((uint8_t *)rb->data_p + rb->element_size *rb->head + i) = - *((uint8_t *)el + i); - rb->head = next_head; - return 0; -} -/** - * @brief Pop element from ring buffer on virtual addresses - * - * @param rb pointer to ring buffer struct - * @param el pointer to where element is copied to - * @return 0 on success, -1 if no element could be popped - */ -static inline int rb_host_get(volatile struct ring_buf *rb, void *el) { - // caught the head, can't get data - if (rb->tail == rb->head) - return -1; - for (uint32_t i = 0; i < rb->element_size; i++) - *((uint8_t *)el + i) = - *((uint8_t *)rb->data_v + rb->element_size * rb->tail + i); - rb->tail = (rb->tail + 1) % rb->size; - return 0; -} - -/** - * @brief Copy data from `el` in the next free slot in the ring-buffer on the - *virtual addresses - * - * @param rb pointer to the ring buffer struct - * @param el pointer to the data to be copied into the ring buffer - * @return int 0 on succes, -1 if the buffer is full - */ -static inline int rb_host_put(volatile struct ring_buf *rb, void *el) { - uint32_t next_head = (rb->head + 1) % rb->size; - // caught the tail, can't put data - if (next_head == rb->tail) - return -1; - for (uint32_t i = 0; i < rb->element_size; i++) - *((uint8_t *)rb->data_v + rb->element_size *rb->head + i) = - *((uint8_t *)el + i); - rb->head = next_head; - return 0; -} -/** - * @brief Pop element from ring buffer on physicl addresses - * - * @param rb pointer to ring buffer struct - * @param el pointer to where element is copied to - * @return 0 on success, -1 if no element could be popped - */ -static inline int rb_device_get(volatile struct ring_buf *rb, void *el) { - // caught the head, can't get data - if (rb->tail == rb->head) - return -1; - for (uint32_t i = 0; i < rb->element_size; i++) - *((uint8_t *)el + i) = - *((uint8_t *)rb->data_p + rb->element_size * rb->tail + i); - rb->tail = (rb->tail + 1) % rb->size; - return 0; -} -/** - * @brief Init the ring buffer. See `struct ring_buf` for details - */ -static inline void rb_init(volatile struct ring_buf *rb, uint64_t size, - uint64_t element_size) { - rb->tail = 0; - rb->head = 0; - rb->size = size; - rb->element_size = element_size; -} - -/** - * @brief Holds physical addresses of the shared L3 - * @a2h_rb: accelerator to host ring buffer - * @head: base of heap memory - */ -struct l3_layout { - uint32_t a2h_rb; - uint32_t a2h_mbox; - uint32_t h2a_mbox; - uint32_t heap; -}; - -/*********************************************************************************** - * PUBLICS - ***********************************************************************************/ -int syscall(uint64_t which, uint64_t arg0, uint64_t arg1, uint64_t arg2, - uint64_t arg3, uint64_t arg4); - -static inline void csleep(uint32_t cycles) { - uint32_t start = snrt_mcycle(); - while ((snrt_mcycle() - start) < cycles) {} -} - -void snrt_hero_exit(int code); -/** - * @brief Blocking mailbox read access - */ -int mailbox_read(uint32_t *buffer, size_t n_words); -/** - * @brief Non-Blocking mailbox read access. Return 1 on success, 0 on fail - */ -int mailbox_try_read(uint32_t *buffer); -/** - * @brief Blocking mailbox write access - */ -int mailbox_write(uint32_t word); diff --git a/target/sim/sw/device/runtime/Makefile b/target/sim/sw/device/runtime/Makefile index df59d075d..fab277dfe 100644 --- a/target/sim/sw/device/runtime/Makefile +++ b/target/sim/sw/device/runtime/Makefile @@ -19,9 +19,7 @@ SNRT_DIR = $(SNITCH_ROOT)/sw/snRuntime # Dependencies INCDIRS += $(SNRT_DIR)/src -INCDIRS += $(SNRT_DIR)/src/omp INCDIRS += $(SNRT_DIR)/api -INCDIRS += $(SNRT_DIR)/api/omp INCDIRS += $(SNRT_DIR)/vendor/riscv-opcodes INCDIRS += $(SW_DIR)/shared/platform INCDIRS += $(SW_DIR)/shared/platform/generated diff --git a/target/sim/sw/device/runtime/src/occamy_start.c b/target/sim/sw/device/runtime/src/occamy_start.c index bb49676f2..e16e9812e 100644 --- a/target/sim/sw/device/runtime/src/occamy_start.c +++ b/target/sim/sw/device/runtime/src/occamy_start.c @@ -13,9 +13,6 @@ #define SNRT_CRT0_EXIT #define SNRT_CRT0_ALTERNATE_EXIT -static inline void snrt_exit(int exit_code) { -} - static inline void snrt_crt0_callback3() { _snrt_cluster_hw_barrier = cluster_hw_barrier_addr(snrt_cluster_idx()); } diff --git a/target/sim/sw/device/runtime/src/putchar.c b/target/sim/sw/device/runtime/src/putchar.c index 3ef169e56..84f345d0e 100644 --- a/target/sim/sw/device/runtime/src/putchar.c +++ b/target/sim/sw/device/runtime/src/putchar.c @@ -3,4 +3,4 @@ // SPDX-License-Identifier: Apache-2.0 // Provide an implementation for putchar. -void __attribute__((weak)) _putchar(char character) {} +void _putchar(char character) {} diff --git a/target/sim/sw/device/runtime/src/snrt.c b/target/sim/sw/device/runtime/src/snrt.c index cc02c074d..12003018e 100644 --- a/target/sim/sw/device/runtime/src/snrt.c +++ b/target/sim/sw/device/runtime/src/snrt.c @@ -7,11 +7,7 @@ #include "alloc.c" #include "cls.c" #include "cluster_interrupts.c" -#include "dm.c" #include "dma.c" -#include "eu.c" -#include "kmp.c" -#include "omp.c" #include "global_interrupts.c" #include "occamy_device.c" #include "occamy_memory.c" diff --git a/target/sim/sw/device/runtime/src/snrt.h b/target/sim/sw/device/runtime/src/snrt.h index 0dd5f7f59..57686fe94 100644 --- a/target/sim/sw/device/runtime/src/snrt.h +++ b/target/sim/sw/device/runtime/src/snrt.h @@ -18,26 +18,19 @@ #include "cls_decls.h" #include "cluster_interrupt_decls.h" #include "global_interrupt_decls.h" -#include "riscv_decls.h" #include "memory_decls.h" #include "sync_decls.h" #include "team_decls.h" -#include "start_decls.h" // Implementation #include "alloc.h" #include "cls.h" #include "cluster_interrupts.h" -#include "dm.h" #include "dma.h" #include "dump.h" #include "global_interrupts.h" #include "occamy_device.h" #include "occamy_memory.h" -#include "eu.h" -#include "kmp.h" -#include "omp.h" -#include "perf_cnt.h" #include "printf.h" #include "riscv.h" #include "ssr.h" diff --git a/target/sim/sw/device/toolchain.mk b/target/sim/sw/device/toolchain.mk index 7fa4cc69a..9e83aad99 100644 --- a/target/sim/sw/device/toolchain.mk +++ b/target/sim/sw/device/toolchain.mk @@ -6,6 +6,4 @@ BENDER ?= bender SNITCH_ROOT = $(shell $(BENDER) path snitch_cluster) -RISCV_CFLAGS += --sysroot=$(HERO_INSTALL)/rv32imafd-ilp32d/riscv32-unknown-elf -target riscv32-unknown-elf -RISCV_LDFLAGS += -L$(HERO_INSTALL)/lib/clang/15.0.0/rv32imafdvzfh-ilp32d/lib/ -include $(SNITCH_ROOT)/target/snitch_cluster/sw/toolchain.mk +include $(SNITCH_ROOT)/target/snitch_cluster/sw/toolchain.mk \ No newline at end of file