aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-08-29 22:41:27 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-08-29 22:41:27 +0300
commit260689ea747f93b018ec4a25a2526a7aa05b7cb0 (patch)
treea30befd0bafa3a44ec495aaaa8ced56112265f81
parent50a9b6780e04ae27cd03323d7fec02e15f7d3086 (diff)
downloadgran-260689ea747f93b018ec4a25a2526a7aa05b7cb0.tar.gz
gran-260689ea747f93b018ec4a25a2526a7aa05b7cb0.zip
remove torus3d
+ Might try to fix it at some point in the future but for now I don't want to carry around broken code
-rw-r--r--include/gran/torus3d/node.h38
-rw-r--r--src/torus3d/node.c233
-rw-r--r--src/torus3d/source.mk1
-rw-r--r--tests/simple_torus3d/sim.c121
-rw-r--r--tests/simple_torus3d/source.mk11
-rw-r--r--tests/simple_torus3d/test.c64
6 files changed, 0 insertions, 468 deletions
diff --git a/include/gran/torus3d/node.h b/include/gran/torus3d/node.h
deleted file mode 100644
index 1240bb4..0000000
--- a/include/gran/torus3d/node.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef GRAN_TORUS3D_NODE_H
-#define GRAN_TORUS3D_NODE_H
-
-#include <gran/component.h>
-#include <stdint.h>
-
-struct component *create_torus3d_node(uint8_t x, uint8_t y, uint8_t z);
-
-stat torus3d_node_connect(struct component *node,
- struct component *x_in,
- struct component *y_in,
- struct component *z_in,
- struct component *child,
- struct component *x_out,
- struct component *y_out,
- struct component *z_out);
-
-static inline void addr_torus3d(uint64_t addr, uint8_t *x, uint8_t *y,
- uint8_t *z, uint32_t *off)
-{
- if (off) *off = addr & 0xffffffff;
- if (x) *x = (addr >> 32) & 0xff;
- if (y) *y = (addr >> 40) & 0xff;
- if (z) *z = (addr >> 48) & 0xff;
- assert(((addr >> 56) & 0xff) == 0);
-}
-
-static inline uint64_t torus3d_addr(uint8_t x, uint8_t y, uint8_t z,
- uint32_t off)
-{
- return off
- | ((uint64_t)x << 32)
- | ((uint64_t)y << 40)
- | ((uint64_t)z << 48)
- ;
-}
-
-#endif /* GRAN_TORUS3D_NODE_H */
diff --git a/src/torus3d/node.c b/src/torus3d/node.c
deleted file mode 100644
index 11f15e8..0000000
--- a/src/torus3d/node.c
+++ /dev/null
@@ -1,233 +0,0 @@
-#include <gran/torus3d/node.h>
-
-struct port {
- struct reg r[2];
-};
-
-struct torus3d_node {
- struct component component;
- uint8_t x, y, z /*, w for 4D but that might be a bit overkill*/;
-
- struct component *x_next, *y_next, *z_next,
- *x_prev, *y_prev, *z_prev,
- *child;
-
- struct port port_x, port_y, port_z;
-
- struct reg x_in, y_in, z_in, child_in;
-
- bool prio;
-};
-
-static stat port_receive(struct torus3d_node *torus3d, struct port *port,
- struct reg *reg)
-{
- if (!reg->busy)
- return OK;
-
- /* source */
- uint8_t sx, sy, sz;
- addr_torus3d(reg->pkt.from, &sx, &sy, &sz, NULL);
-
- /* dst */
- uint8_t dx, dy, dz;
- addr_torus3d(reg->pkt.to, &dx, &dy, &dz, NULL);
-
- /* Dally/spiral routing though I'm a bit unsure if this works for 2D/3D
- * toruses (1D seems to work, 2D not so much atm) */
- int chan = is_set(&reg->pkt, PACKET_DONE);
- if (port->r[chan].busy)
- return OK;
-
- printf("(%d, %d, %d) to (%d, %d, %d) via (%d, %d, %d) c %d\n",
- sx, sy, sz,
- dx, dy, dz,
- torus3d->x, torus3d->y, torus3d->z,
- chan);
-
- port->r[chan].pkt = reg->pkt;
- port->r[chan].busy = true;
- reg->busy = false;
- return OK;
-}
-
-static stat reg_receive(struct reg *r, struct packet pkt)
-{
- if (r->busy)
- return EBUSY;
-
- r->pkt = pkt;
- r->busy = true;
- return OK;
-}
-
-enum match {
- MX = (1 << 0),
- MY = (1 << 1),
- MZ = (1 << 2),
- NX = (1 << 3),
- NY = (1 << 4),
- NZ = (1 << 5),
-};
-
-static void maybe_route_reg(struct torus3d_node *torus3d, struct reg *reg,
- enum match m, uint64_t *oldest, struct packet **pkt,
- bool **busy)
-{
- if (!reg->busy)
- return;
-
- uint8_t x, y, z;
- addr_torus3d(reg->pkt.to, &x, &y, &z, NULL);
-
- if ((m & MX) && x != torus3d->x)
- return;
-
- if ((m & MY) && y != torus3d->y)
- return;
-
- if ((m & MZ) && z != torus3d->z)
- return;
-
- if ((m & NX) && x == torus3d->x)
- return;
-
- if ((m & NY) && y == torus3d->y)
- return;
-
- if ((m & NZ) && z == torus3d->z)
- return;
-
- if (reg->pkt.timestamp < *oldest) {
- *oldest = reg->pkt.timestamp;
- *busy = &reg->busy;
- *pkt = &reg->pkt;
- }
-}
-
-static stat route(struct torus3d_node *torus3d, struct component *next,
- enum match m)
-{
- bool prio = torus3d->prio;
- uint64_t oldest = -1; struct packet *pkt = NULL; bool *busy = NULL;
-
- /* prioritise current priority port */
- maybe_route_reg(torus3d, &torus3d->port_x.r[prio], m,
- &oldest, &pkt, &busy);
-
- maybe_route_reg(torus3d, &torus3d->port_y.r[prio], m,
- &oldest, &pkt, &busy);
-
- maybe_route_reg(torus3d, &torus3d->port_z.r[prio], m,
- &oldest, &pkt, &busy);
-
- /* if no suitable match found, check other ports as well */
- if (pkt == NULL) {
- maybe_route_reg(torus3d, &torus3d->port_x.r[!prio], m,
- &oldest, &pkt, &busy);
-
- maybe_route_reg(torus3d, &torus3d->port_y.r[!prio], m,
- &oldest, &pkt, &busy);
-
- maybe_route_reg(torus3d, &torus3d->port_z.r[!prio], m,
- &oldest, &pkt, &busy);
- }
-
- maybe_route_reg(torus3d, &torus3d->child_in, m,
- &oldest, &pkt, &busy);
-
- /* no suitable match */
- if (pkt == NULL)
- return OK;
-
- assert(busy);
-
- stat ret = SEND(torus3d, next, *pkt);
- if (ret == EBUSY)
- return OK;
-
- *busy = false;
- return OK;
-}
-
-static stat torus3d_clock(struct torus3d_node *torus3d)
-{
- torus3d->prio = !torus3d->prio;
-
- stat ret = OK;
- if ((ret = port_receive(torus3d, &torus3d->port_x, &torus3d->x_in)))
- return ret;
-
- if ((ret = port_receive(torus3d, &torus3d->port_y, &torus3d->y_in)))
- return ret;
-
- if ((ret = port_receive(torus3d, &torus3d->port_z, &torus3d->z_in)))
- return ret;
-
- if ((ret = route(torus3d, torus3d->x_next, NX)))
- return ret;
-
- if ((ret = route(torus3d, torus3d->y_next, NY | MX)))
- return ret;
-
- if ((ret = route(torus3d, torus3d->z_next, NZ | MX | MY)))
- return ret;
-
- if ((ret = route(torus3d, torus3d->child, MX | MY | MZ)))
- return ret;
-
- return OK;
-}
-
-static stat torus3d_receive(struct torus3d_node *torus3d,
- struct component *from, struct packet pkt)
-{
- if (from == torus3d->child)
- return reg_receive(&torus3d->child_in, pkt);
-
- if (from == torus3d->x_prev)
- return reg_receive(&torus3d->x_in, pkt);
-
- if (from == torus3d->y_prev)
- return reg_receive(&torus3d->y_in, pkt);
-
- if (from == torus3d->z_prev)
- return reg_receive(&torus3d->z_in, pkt);
-
- abort();
- return OK;
-}
-
-struct component *create_torus3d_node(uint8_t x, uint8_t y, uint8_t z)
-{
- struct torus3d_node *node = calloc(1, sizeof(struct torus3d_node));
- if (!node)
- return NULL;
-
- node->component.receive = (receive_callback)torus3d_receive;
- node->component.clock = (clock_callback)torus3d_clock;
- node->x = x;
- node->y = y;
- node->z = z;
- return (struct component *)node;
-}
-
-stat torus3d_node_connect(struct component *node,
- struct component *x_in,
- struct component *y_in,
- struct component *z_in,
- struct component *child,
- struct component *x_out,
- struct component *y_out,
- struct component *z_out)
-{
- struct torus3d_node *n = (struct torus3d_node *)node;
- n->x_prev = x_in;
- n->y_prev = y_in;
- n->z_prev = z_in;
- n->child = child;
- n->x_next = x_out;
- n->y_next = y_out;
- n->z_next = z_out;
- return OK;
-}
diff --git a/src/torus3d/source.mk b/src/torus3d/source.mk
deleted file mode 100644
index 30f8e87..0000000
--- a/src/torus3d/source.mk
+++ /dev/null
@@ -1 +0,0 @@
-GRAN_SOURCES += src/torus3d/node.c
diff --git a/tests/simple_torus3d/sim.c b/tests/simple_torus3d/sim.c
deleted file mode 100644
index c53eed6..0000000
--- a/tests/simple_torus3d/sim.c
+++ /dev/null
@@ -1,121 +0,0 @@
-#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/torus3d/node.h>
-#include <gran/cpu/riscv/simple_riscv64.h>
-
-#include "../build/tests/simple_torus3d/test.inc"
-
-static size_t idx_1d(int x, int y, int z, uint8_t xw, uint8_t yw, uint8_t zw)
-{
- uint8_t xi = (x + xw) % xw;
- uint8_t yi = (y + yw) % yw;
- uint8_t zi = (z + zw) % zw;
- return (xi * yw * zw) + (yi * zw) + zi;
-}
-
-static void torus3d_connect_grid(struct component **grid, struct component *c,
- uint8_t x, uint8_t y, uint8_t z,
- uint8_t xw, uint8_t yw, uint8_t zw)
-{
- torus3d_node_connect(grid[idx_1d(x, y, z, xw, yw, zw)],
- grid[idx_1d(x-1, y, z, xw, yw, zw)],
- grid[idx_1d(x, y-1, z, xw, yw, zw)],
- grid[idx_1d(x, y, z-1, xw, yw, zw)],
- c,
- grid[idx_1d(x+1, y, z, xw, yw, zw)],
- grid[idx_1d(x, y+1, z, xw, yw, zw)],
- grid[idx_1d(x, y, z+1, xw, yw, zw)]);
-}
-
-static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y,
- uint8_t z)
-{
- struct component **grid = calloc(x * y * z, sizeof(struct component *));
- assert(grid);
-
- struct component **pes = calloc(x * y * z, sizeof(struct component *));
- assert(pes);
-
- for (size_t i = 0; i < x; ++i)
- for (size_t j = 0; j < y; ++j)
- for (size_t k = 0; k < z; ++k) {
- struct component *node = create_torus3d_node(i, j, k);
- clock_domain_add(clk, node);
- grid[idx_1d(i, j, k, x, y, z)] = node;
-
- if (i == 0 && j == 0 && k == 0)
- continue;
-
- if (i == 0 && j == 0 && k == 1)
- continue;
-
- struct component *imem =
- create_simple_mem(4096);
- init_simple_mem(imem, 0,
- build_tests_simple_torus3d_test_inc_bin_len,
- build_tests_simple_torus3d_test_inc_bin);
-
- uint64_t rcv = torus3d_addr(i, j, k, 0);
- struct component *rv64 =
- create_simple_riscv64(rcv, 0, imem,
- node);
- simple_riscv64_set_reg(rv64, 10, i); /* a0 */
- simple_riscv64_set_reg(rv64, 11, j); /* a1 */
- simple_riscv64_set_reg(rv64, 12, k); /* a2 */
- simple_riscv64_set_reg(rv64, 13, x); /* a3 */
- simple_riscv64_set_reg(rv64, 14, y); /* a4 */
- simple_riscv64_set_reg(rv64, 15, z); /* a5 */
-
- clock_domain_add(clk, rv64);
- clock_domain_add(clk, imem);
-
- pes[idx_1d(i, j, k, x, y, z)] = rv64;
- }
-
- struct component *uart = create_simple_uart();
- clock_domain_add(clk, uart);
- torus3d_connect_grid(grid, uart, 0, 0, 0, x, y, z);
-
- struct component *dmem = create_simple_mem(4096);
- clock_domain_add(clk, dmem);
- torus3d_connect_grid(grid, dmem, 0, 0, 1, x, y, z);
-
- for (int i = 0; i < x; ++i)
- for (int j = 0; j < y; ++j)
- for (int k = 0; k < z; ++k) {
- if (i == 0 && j == 0 && k == 0)
- continue;
-
- if (i == 0 && j == 0 && k == 1)
- continue;
-
- torus3d_connect_grid(grid,
- pes[idx_1d(i, j, k, x, y,
- z)],
- i, j, k, x, y, z);
- }
-
- free(grid);
- free(pes);
- return OK;
-}
-
-int main()
-{
- struct clock_domain *clk = create_clock_domain(NS(1));
-
- stat r = build_torus3d(clk, 1, 10, 10);
- 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/simple_torus3d/source.mk b/tests/simple_torus3d/source.mk
deleted file mode 100644
index d376d05..0000000
--- a/tests/simple_torus3d/source.mk
+++ /dev/null
@@ -1,11 +0,0 @@
-SIMPLE_TORUS3D := tests/simple_torus3d
-SIMPLE_TORUS3D_SIM := $(SIMPLE_TORUS3D)/sim.c
-
-TESTS += $(SIMPLE_TORUS3D)/sim
-
-.PHONY: $(SIMPLE_TORUS3D)/sim
-$(SIMPLE_TORUS3D)/sim: $(SIMPLE_TORUS3D_SIM) libgran.a
- mkdir -p build/$(SIMPLE_TORUS3D)
- ./scripts/gen-rv64-fw -d build -o $(SIMPLE_TORUS3D)/test.inc $(SIMPLE_TORUS3D)/test.c
- $(COMPILE_TEST) $(SIMPLE_TORUS3D_SIM) libgran.a -o build/$@
- ./scripts/gen-report -d build $@
diff --git a/tests/simple_torus3d/test.c b/tests/simple_torus3d/test.c
deleted file mode 100644
index 646b387..0000000
--- a/tests/simple_torus3d/test.c
+++ /dev/null
@@ -1,64 +0,0 @@
-__attribute__((always_inline))
-static inline void print_int8(volatile char *uart, unsigned x)
-{
- *uart = ((x >> 4) & 0xf) + '0';
- *uart = ((x >> 0) & 0xf) + '0';
-}
-
-__attribute__((always_inline))
-static inline void print_addr(volatile char *uart, unsigned x, unsigned y,
- unsigned z)
-{
- *uart = '(';
- print_int8(uart, x);
- *uart = ',';
- *uart = ' ';
- print_int8(uart, y);
- *uart = ',';
- *uart = ' ';
- print_int8(uart, z);
- *uart = ')';
- *uart = '\n';
-}
-
-__attribute__((always_inline))
-static inline unsigned wrap(unsigned x, unsigned X)
-{
- return x + 1 >= X ? 0 : x + 1;
-}
-
-__attribute__((always_inline))
-static inline unsigned next_idx(unsigned x, unsigned y, unsigned z, unsigned X,
- unsigned Y, unsigned Z)
-{
- unsigned zi = wrap(z, Z);
- unsigned yi = zi < z ? wrap(y, Y) : y;
- unsigned xi = yi < y ? wrap(x, X) : x;
-
- return (xi << 16) | (yi << 8) | zi;
-}
-
-void _start(unsigned x, unsigned y, unsigned z, unsigned X, unsigned Y,
- unsigned Z)
-{
- volatile char *uart = (char *)4096;
- /* x = 1ULL << 32, y = 1ULL << 40, z = 1ULL << 48 I guess */
- volatile unsigned *control = (unsigned *)(1ULL << 48);
-
-
- if (x == 0 && y == 0 && z == 2) {
- goto do_work;
- } else {
- while (*control != ((x << 16) | (y << 8) | z)) {}
- }
-
-do_work:
- print_addr(uart, x, y, z);
- *control = next_idx(x, y, z, X, Y, Z);
-
- if (x == X - 1 && y == Y - 1 && z == Z - 1)
- asm ("ebreak");
-
- /* otherwise just loop */
- while (1) {}
-}