diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/simt_riscv64/sim.c | 100 | ||||
| -rw-r--r-- | tests/simt_riscv64/source.mk | 11 | ||||
| -rw-r--r-- | tests/simt_riscv64/test.c | 67 |
3 files changed, 178 insertions, 0 deletions
diff --git a/tests/simt_riscv64/sim.c b/tests/simt_riscv64/sim.c new file mode 100644 index 0000000..b161491 --- /dev/null +++ b/tests/simt_riscv64/sim.c @@ -0,0 +1,100 @@ +#include <assert.h> + +#include <gran/root.h> +#include <gran/mem/simple_mem.h> +#include <gran/bus/simple_bus.h> +#include <gran/uart/simple_uart.h> +#include <gran/mesh/node1d.h> +#include <gran/cpu/riscv/simt_riscv64.h> + +#include "../build/tests/simt_riscv64/test.inc" + +static stat build_simt(struct clock_domain *clk, uint16_t clusters, uint16_t lanes) +{ + struct component **mesh = calloc(clusters + 1, sizeof(struct component *)); + assert(mesh); + + for (int i = 1; i < clusters + 1; ++i) { + struct component *node = create_mesh_node1d(i, 3); + clock_domain_add(clk, node); + mesh[i] = node; + + struct component *mem = create_simple_mem(4096); + init_simple_mem(mem, 0, + build_tests_simt_riscv64_test_inc_bin_len, + build_tests_simt_riscv64_test_inc_bin); + + uint64_t data_rcv = mesh1d_addr(i, 0, 0); + uint64_t inst_rcv = mesh1d_addr(i, 1, 0); + struct simt_riscv64_conf conf = { + .data_rcv = data_rcv, + .inst_rcv = inst_rcv, + .num_lanes = lanes, + /* each cluster should request instructions from its own + * instruction memory bank */ + .start_pc = mesh1d_addr(i, 2, 0) + }; + + struct component *rv64 = create_simt_riscv64(conf, node, node); + for (int j = 0; j < lanes; ++j) { + simt_riscv64_set_reg(rv64, j, 10, i); /* a0 */ + simt_riscv64_set_reg(rv64, j, 11, j); /* a1 */ + simt_riscv64_set_reg(rv64, j, 12, clusters); /* a2 */ + simt_riscv64_set_reg(rv64, j, 13, lanes); /* a3 */ + } + + clock_domain_add(clk, rv64); + clock_domain_add(clk, mem); + + mesh_node1d_connect(node, simt_riscv64_data_intf(rv64), 0); + mesh_node1d_connect(node, simt_riscv64_inst_intf(rv64), 1); + + mesh_node1d_connect(node, mem, 2); + } + + /* extra I/O node */ + struct component *node = create_mesh_node1d(0, 2); + clock_domain_add(clk, node); + mesh[0] = node; + + struct component *uart = create_simple_uart(); + clock_domain_add(clk, uart); + mesh_node1d_connect(node, uart, 0); + + struct component *mem = create_simple_mem(4096); + init_simple_mem(mem, 0, + build_tests_simt_riscv64_test_inc_bin_len, + build_tests_simt_riscv64_test_inc_bin); + + clock_domain_add(clk, mem); + mesh_node1d_connect(node, mem, 1); + + for (int i = 0; i < clusters + 1; ++i) { + if (i - 1 >= 0) + mesh_node1d_connect_south(mesh[i], mesh[i - 1]); + + if (i + 1 < clusters + 1) + mesh_node1d_connect_north(mesh[i], mesh[i + 1]); + } + + free(mesh); + return OK; +} + +int main() +{ + struct clock_domain *clk = create_clock_domain(NS(1)); + + /* one cluster with four cores + mem for each core (should + * instructions be fetched from cluster local mem?) */ + stat r = build_simt(clk, 8, 8); + assert(r == OK); + + struct gran_root *root = create_root(); + root_add_clock(root, clk); + + r = root_run(root); + assert(r == OK); + + destroy_root(root); +} diff --git a/tests/simt_riscv64/source.mk b/tests/simt_riscv64/source.mk new file mode 100644 index 0000000..e12420b --- /dev/null +++ b/tests/simt_riscv64/source.mk @@ -0,0 +1,11 @@ +SIMT_RISCV64 := tests/simt_riscv64 +SIMT_RISCV64_SIM := $(SIMT_RISCV64)/sim.c + +TESTS += $(SIMT_RISCV64)/sim + +.PHONY: $(SIMT_RISCV64)/sim +$(SIMT_RISCV64)/sim: $(SIMT_RISCV64_SIM) libgran.a + mkdir -p build/$(SIMT_RISCV64) + ./scripts/gen-rv64-fw -d build -o $(SIMT_RISCV64)/test.inc $(SIMT_RISCV64)/test.c + $(COMPILE_TEST) $(SIMT_RISCV64_SIM) libgran.a -o build/$@ + ./scripts/gen-report -d build $@ diff --git a/tests/simt_riscv64/test.c b/tests/simt_riscv64/test.c new file mode 100644 index 0000000..df86774 --- /dev/null +++ b/tests/simt_riscv64/test.c @@ -0,0 +1,67 @@ +#include <stdint.h> + +__attribute__((always_inline)) +static inline uint64_t mesh1d_addr(uint16_t cluster, uint16_t elem, + uint32_t off) +{ + return ((uint64_t)cluster << 48) | ((uint64_t)elem << 32) | off; +} + +__attribute__((always_inline)) +static inline void print_int8(volatile char *uart, unsigned x) +{ + char lo_nibble = (x >> 0) & 0xf; + char hi_nibble = (x >> 4) & 0xf; + + *uart = hi_nibble < 10 ? hi_nibble + '0' : (hi_nibble - 10) + 'a'; + *uart = lo_nibble < 10 ? lo_nibble + '0' : (lo_nibble - 10) + 'a'; +} + +__attribute__((always_inline)) +static inline void print_addr(volatile char *uart, unsigned x, unsigned y) +{ + *uart = '('; + print_int8(uart, x); + *uart = ','; + *uart = ' '; + print_int8(uart, y); + *uart = ')'; + *uart = '\n'; +} + +__attribute__((always_inline)) +static inline uint64_t wrap(unsigned x, unsigned X) +{ + return x + 1 >= X ? 0 : x + 1; +} + +__attribute__((always_inline)) +static inline uint64_t next_idx(unsigned x, unsigned y, unsigned X, unsigned Y) +{ + unsigned yi = wrap(y, Y); + unsigned xi = yi < y ? wrap(x, X) : x; + + return mesh1d_addr(xi, yi, 0); +} + +void _start(unsigned x, unsigned y, unsigned X, unsigned Y) +{ + volatile char *uart = (char *)mesh1d_addr(0, 0, 0); + volatile uint64_t *control = (uint64_t *)mesh1d_addr(0, 1, 0); + + if (x == 1 && y == 0) { + goto do_work; + } else { + while (*control != mesh1d_addr(x, y, 0)) {} + } + +do_work: + print_addr(uart, x, y); + *control = next_idx(x, y, X, Y); + + if (x == X - 1 && y == Y - 1) + asm ("ebreak"); + + /* otherwise just loop */ + while (1) {} +} |
