From d2000e805336475c39083958bac6d027440e429d Mon Sep 17 00:00:00 2001 From: Dan Petrisko Date: Mon, 16 Jan 2023 05:32:37 -0800 Subject: [PATCH] Adding SPSC kernel --- software/spmd/spsc_queue/Makefile | 15 +++++++ software/spmd/spsc_queue/main.cpp | 68 +++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 software/spmd/spsc_queue/Makefile create mode 100644 software/spmd/spsc_queue/main.cpp diff --git a/software/spmd/spsc_queue/Makefile b/software/spmd/spsc_queue/Makefile new file mode 100644 index 000000000..7070cd18d --- /dev/null +++ b/software/spmd/spsc_queue/Makefile @@ -0,0 +1,15 @@ +bsg_tiles_X = 4 +bsg_tiles_Y = 2 + +all: main.run + +OBJECT_FILES := main.o + +include ../Makefile.include + +main.riscv: $(LINK_SCRIPT) $(OBJECT_FILES) $(SPMD_COMMON_OBJECTS) $(BSG_MANYCORE_LIB) + $(RISCV_LINK) $(filter %.o, $^) -L. "-l:$(BSG_MANYCORE_LIB)" -o $@ $(RISCV_LINK_OPTS) + +main.o: Makefile + +include $(BSG_MANYCORE_DIR)/software/mk/Makefile.tail_rules diff --git a/software/spmd/spsc_queue/main.cpp b/software/spmd/spsc_queue/main.cpp new file mode 100644 index 000000000..87316abb5 --- /dev/null +++ b/software/spmd/spsc_queue/main.cpp @@ -0,0 +1,68 @@ +//This kernel performs a barrier among all tiles in tile group + +#include "bsg_manycore.h" +#include "bsg_set_tile_x_y.h" +#include "bsg_manycore_spsc_queue.hpp" +#include "bsg_tile_group_barrier.hpp" + +bsg_barrier barrier; + +#define BUFFER_ELS 24 +#define CHAIN_LEN 8 +#define NUM_PACKETS 1000 + +int buffer_chain [CHAIN_LEN*BUFFER_ELS] __attribute__ ((section (".dram"))) = {0}; +int buffer_count [CHAIN_LEN] __attribute__ ((section (".dram"))) = {0}; + +int main() +{ + bsg_set_tile_x_y(); + + int *buffer = &buffer_chain[0] + (__bsg_id * BUFFER_ELS); + int *count = &buffer_count[0] + (__bsg_id); + + int *next_buffer = &buffer_chain[0] + ((__bsg_id+1) * BUFFER_ELS); + int *next_count = &buffer_count[0] + (__bsg_id+1); + + bsg_manycore_spsc_queue_recv recv_spsc(buffer, count); + bsg_manycore_spsc_queue_send send_spsc(next_buffer, next_count); + + int packets = 0; + int recv_data; + int send_data; + do + { + if (__bsg_id == 0) + { + recv_data = packets; + } + else + { + recv_data = recv_spsc.recv(); + } + + //bsg_printf("[%d] RECV %d\n", __bsg_id, recv_data); + + send_data = recv_data; + + if (__bsg_id == CHAIN_LEN-1) + { + if (recv_data != packets) + { + bsg_fail(); + } + } + else + { + send_spsc.send(send_data); + } + + //bsg_printf("[%d] SEND %d\n", __bsg_id, send_data); + } while (++packets < NUM_PACKETS); + + barrier.sync(); + bsg_finish(); + bsg_wait_while(1); + return 0; +} +