diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-02-24 21:31:46 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-02-24 21:31:46 +0200 |
| commit | e991095180f774e3582329447c291a11499989ba (patch) | |
| tree | 0708d2308a229b932a84d8ae803b31d296f9fc0f | |
| parent | 238116c1cf08b93335abd493df110a669786553e (diff) | |
| download | gran-e991095180f774e3582329447c291a11499989ba.tar.gz gran-e991095180f774e3582329447c291a11499989ba.zip | |
overhaul meshes
+ Previous name was grid
23 files changed, 661 insertions, 675 deletions
diff --git a/include/gran/grid/node.h b/include/gran/grid/node.h deleted file mode 100644 index db617f8..0000000 --- a/include/gran/grid/node.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef GRAN_GRID_NODE_H -#define GRAN_GRID_NODE_H - -#include <gran/component.h> -#include <stdint.h> - -struct component *create_grid_node(uint16_t x, uint16_t y); - -stat grid_node_connect(struct component *node, - struct component *left, struct component *right, - struct component *up, struct component *down, - struct component *lower); - -static inline uint64_t grid_addr(uint16_t x, uint16_t y, uint32_t off) -{ - return off - | ((uint64_t)x << 32) - | ((uint64_t)y << 48) - ; -} - -static inline void addr_grid(uint64_t addr, uint32_t *off, uint16_t *x, uint16_t *y) -{ - if (off) *off = addr & 0xffffffff; - if (x) *x = (addr >> 32) & 0xffff; - if (y) *y = (addr >> 48) & 0xffff; -} - -#endif /* GRAN_GRID_NODE_H */ diff --git a/include/gran/mesh/node.h b/include/gran/mesh/node.h new file mode 100644 index 0000000..53ee08b --- /dev/null +++ b/include/gran/mesh/node.h @@ -0,0 +1,31 @@ +#ifndef GRAN_GRID_NODE_H +#define GRAN_GRID_NODE_H + +#include <gran/component.h> +#include <stdint.h> + +struct component *create_mesh_node(uint16_t x, uint16_t y); + +stat mesh_node_connect(struct component *node, + struct component *n, + struct component *s, + struct component *e, + struct component *w, + struct component *l); + +static inline uint64_t mesh_addr(uint16_t x, uint16_t y, uint32_t off) +{ + return off + | ((uint64_t)x << 32) + | ((uint64_t)y << 48) + ; +} + +static inline void addr_mesh(uint64_t addr, uint16_t *x, uint16_t *y, uint32_t *off) +{ + if (off) *off = addr & 0xffffffff; + if (x) *x = (addr >> 32) & 0xffff; + if (y) *y = (addr >> 48) & 0xffff; +} + +#endif /* GRAN_GRID_NODE_H */ diff --git a/include/gran/grid/node3d.h b/include/gran/mesh/node3d.h index e424d9b..4f1c2c7 100644 --- a/include/gran/grid/node3d.h +++ b/include/gran/mesh/node3d.h @@ -1,23 +1,21 @@ -#ifndef GRAN_GRID_NODE3D_H -#define GRAN_GRID_NODE3D_H - -/** @todo rename to mesh to follow conventions a bit better */ +#ifndef GRAN_MESH_NODE3D_H +#define GRAN_MESH_NODE3D_H #include <gran/component.h> #include <stdint.h> -struct component *create_grid_node3d(uint8_t x, uint8_t y, uint8_t z); +struct component *create_mesh_node3d(uint8_t x, uint8_t y, uint8_t z); -stat grid_node3d_connect(struct component *node, +stat mesh_node3d_connect(struct component *node, struct component *n, struct component *s, - struct component *w, struct component *e, + struct component *w, struct component *u, struct component *d, struct component *l); -static inline uint64_t grid3d_addr(uint8_t x, uint8_t y, uint8_t z, uint32_t off) +static inline uint64_t mesh3d_addr(uint8_t x, uint8_t y, uint8_t z, uint32_t off) { return off | ((uint64_t)x << 32) @@ -26,7 +24,7 @@ static inline uint64_t grid3d_addr(uint8_t x, uint8_t y, uint8_t z, uint32_t off ; } -static inline void addr_grid3d(uint64_t addr, uint8_t *x, uint8_t *y, uint8_t *z, uint32_t *off) +static inline void addr_mesh3d(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; diff --git a/src/grid/node.c b/src/grid/node.c deleted file mode 100644 index 512cae3..0000000 --- a/src/grid/node.c +++ /dev/null @@ -1,178 +0,0 @@ -/* very simple grid node with 32bit private region, does not currently signal - * being busy or anything. I think I might have to refine the message passing - * interface I have, but this is good enough. - * - * Each node should have a router beneath it, just to simplify my life. A router - * is basically a bus with a fallback ascension path. - */ -#include <stdbool.h> - -#include <gran/grid/node.h> - -struct port { - struct component *send; - struct packet pkt; - bool busy; -}; - -struct grid_node { - struct component component; - uint16_t x, y; - - struct port left, right, up, down, lower; - - unsigned priority; -}; - -static stat port_clock(struct grid_node *grid, struct port *to, struct port *from) -{ - assert(from->busy); - stat r = SEND(grid, to->send, from->pkt); - if (r == EBUSY) { - grid->priority++; - return OK; - } - - from->busy = false; - return OK; -} - -static struct port *select_input(struct grid_node *grid) -{ - struct port *ports[5] = { - &grid->left, - &grid->right, - &grid->up, - &grid->down, - &grid->lower, - }; - for (size_t i = 0; i < 5; ++i) { - size_t idx = (i + grid->priority) % 5; - struct port *port = ports[idx]; - if (!port) - continue; - - if (!port->busy) - continue; - - return port; - } - - return NULL; -} - -static stat clock_once(struct grid_node *grid) -{ - struct port *input = select_input(grid); - if (!input) - return OK; - - uint16_t x; - uint16_t y; - uint64_t addr = input->pkt.to; - addr_grid(addr, NULL, &x, &y); - - if (grid->x == x && grid->y == y) { - if (!grid->lower.send) - goto nosuch; - - return port_clock(grid, &grid->lower, input); - } - - if (y < grid->y) { - if (!grid->down.send) - goto nosuch; - - return port_clock(grid, &grid->down, input); - } - - if (y > grid->y) { - if (!grid->up.send) - goto nosuch; - - return port_clock(grid, &grid->up, input); - } - - if (x < grid->x) { - if (!grid->left.send) - goto nosuch; - - return port_clock(grid, &grid->left, input); - } - - if (x > grid->x) { - if (!grid->right.send) - goto nosuch; - - return port_clock(grid, &grid->right, input); - } - -nosuch: - abort(); - return OK; -} - -static stat grid_clock(struct grid_node *grid) -{ - clock_once(grid); - return OK; -} - - -static stat port_receive(struct port *port, struct packet pkt) -{ - if (port->busy) - return EBUSY; - - port->pkt = pkt; - port->busy = true; - return OK; -} - -static stat grid_receive(struct grid_node *grid, struct component *from, struct packet pkt) -{ - if (from == grid->lower.send) - return port_receive(&grid->lower, pkt); - - if (from == grid->left.send) - return port_receive(&grid->left, pkt); - - if (from == grid->right.send) - return port_receive(&grid->right, pkt); - - if (from == grid->down.send) - return port_receive(&grid->down, pkt); - - if (from == grid->up.send) - return port_receive(&grid->up, pkt); - - abort(); - return OK; -} - -struct component *create_grid_node(uint16_t x, uint16_t y) -{ - struct grid_node *node = calloc(1, sizeof(struct grid_node)); - if (!node) - return NULL; - - node->component.receive = (receive_callback)grid_receive; - node->component.clock = (clock_callback)grid_clock; - node->x = x; - node->y = y; - return (struct component *)node; -} - -stat grid_node_connect(struct component *node, - struct component *left, struct component *right, - struct component *up, struct component *down, - struct component *lower) -{ - struct grid_node *n = (struct grid_node *)node; - n->left.send = left; - n->right.send = right; - n->up.send = up; - n->down.send = down; - n->lower.send = lower; - return OK; -} diff --git a/src/grid/node3d.c b/src/grid/node3d.c deleted file mode 100644 index f404ea0..0000000 --- a/src/grid/node3d.c +++ /dev/null @@ -1,205 +0,0 @@ -#include <gran/grid/node3d.h> - -struct reg { - struct packet pkt; - bool busy; -}; - -struct node3d { - struct component component; - uint8_t x, y, z; - - uint64_t timestamp; - - struct component *n, *s, *w, *e, *u, *d, *l; - - struct reg n_in, s_in, w_in, e_in, u_in, d_in, l_in; -}; - -static stat reg_receive(struct reg *r, struct packet pkt) -{ - if (r->busy) - return EBUSY; - - r->pkt = pkt; - r->busy = true; - return OK; -} - -/* LX = node.x > pkt.x, etc */ -enum match { - LX = (1 << 0), - LY = (1 << 1), - LZ = (1 << 2), - GX = (1 << 3), - GY = (1 << 4), - GZ = (1 << 5), - NX = (1 << 6), - NY = (1 << 7), - NZ = (1 << 8), -}; - -static void maybe_route_reg(struct node3d *node3d, struct reg *reg, enum match m, uint64_t *oldest, struct packet **pkt, bool **busy) -{ - if (!reg->busy) - return; - - uint8_t x, y, z; - addr_grid3d(reg->pkt.to, &x, &y, &z, NULL); - - if ((m & LX) && x < node3d->x) - return; - - if ((m & LY) && y < node3d->y) - return; - - if ((m & LZ) && z < node3d->z) - return; - - if ((m & GX) && x > node3d->x) - return; - - if ((m & GY) && y > node3d->y) - return; - - if ((m & GZ) && z > node3d->z) - return; - - if ((m & NX) && x == node3d->x) - return; - - if ((m & NY) && y == node3d->y) - return; - - if ((m & NZ) && z == node3d->z) - return; - - if (reg->pkt.timestamp < *oldest) { - *oldest = reg->pkt.timestamp; - *busy = ®->busy; - *pkt = ®->pkt; - } -} - -static stat route(struct node3d *node3d, struct component *next, enum match m) -{ - uint64_t oldest = -1; struct packet *pkt = NULL; bool *busy = NULL; - maybe_route_reg(node3d, &node3d->l_in, m, &oldest, &pkt, &busy); - maybe_route_reg(node3d, &node3d->n_in, m, &oldest, &pkt, &busy); - maybe_route_reg(node3d, &node3d->s_in, m, &oldest, &pkt, &busy); - maybe_route_reg(node3d, &node3d->e_in, m, &oldest, &pkt, &busy); - maybe_route_reg(node3d, &node3d->w_in, m, &oldest, &pkt, &busy); - maybe_route_reg(node3d, &node3d->u_in, m, &oldest, &pkt, &busy); - maybe_route_reg(node3d, &node3d->d_in, m, &oldest, &pkt, &busy); - - /* no suitable match */ - if (pkt == NULL) - return OK; - - assert(busy); - - if (!next) { - abort(); /* for now, eventually should probably return to sender */ - return OK; - } - - stat ret = SEND(node3d, next, *pkt); - if (ret == EBUSY) - return OK; - - *busy = false; - return OK; -} - -static stat node3d_clock(struct node3d *node3d) -{ - node3d->timestamp++; - - stat ret = OK; - if ((ret = route(node3d, node3d->e, LX | NX))) - return ret; - - if ((ret = route(node3d, node3d->w, GX | NX))) - return ret; - - if ((ret = route(node3d, node3d->n, LX | GX | LY | NY))) - return ret; - - if ((ret = route(node3d, node3d->s, LX | GX | GY | NY))) - return ret; - - if ((ret = route(node3d, node3d->u, LX | GX | LY | GY | LZ | NZ))) - return ret; - - if ((ret = route(node3d, node3d->d, LX | GX | LY | GY | GZ | NZ))) - return ret; - - if ((ret = route(node3d, node3d->l, LX | LY | LZ | GX | GY | GZ))) - return ret; - - return OK; -} - -static stat node3d_receive(struct node3d *node3d, struct component *from, struct packet pkt) -{ - if (from == node3d->l) { - /* add time when packet entered network */ - pkt.timestamp = node3d->timestamp; - return reg_receive(&node3d->l_in, pkt); - } - - if (from == node3d->n) - return reg_receive(&node3d->n_in, pkt); - - if (from == node3d->s) - return reg_receive(&node3d->s_in, pkt); - - if (from == node3d->w) - return reg_receive(&node3d->w_in, pkt); - - if (from == node3d->e) - return reg_receive(&node3d->e_in, pkt); - - if (from == node3d->u) - return reg_receive(&node3d->u_in, pkt); - - if (from == node3d->d) - return reg_receive(&node3d->d_in, pkt); - - abort(); - return OK; -} - -struct component *create_grid_node3d(uint8_t x, uint8_t y, uint8_t z) -{ - struct node3d *node = calloc(1, sizeof(struct node3d)); - if (!node) - return NULL; - - node->component.receive = (receive_callback)node3d_receive; - node->component.clock = (clock_callback)node3d_clock; - node->x = x; - node->y = y; - node->z = z; - return (struct component *)node; -} - -stat grid_node3d_connect(struct component *node, - struct component *n, - struct component *s, - struct component *w, - struct component *e, - struct component *u, - struct component *d, - struct component *l) -{ - struct node3d *node3d = (struct node3d *)node; - node3d->n = n; - node3d->s = s; - node3d->w = w; - node3d->e = e; - node3d->u = u; - node3d->d = d; - node3d->l = l; - return OK; -} diff --git a/src/grid/source.mk b/src/grid/source.mk deleted file mode 100644 index 79fe708..0000000 --- a/src/grid/source.mk +++ /dev/null @@ -1 +0,0 @@ -SOURCES += src/grid/node.c src/grid/node3d.c diff --git a/src/mesh/node.c b/src/mesh/node.c new file mode 100644 index 0000000..2ac921a --- /dev/null +++ b/src/mesh/node.c @@ -0,0 +1,164 @@ +#include <gran/mesh/node.h> + +struct reg { + struct packet pkt; + bool busy; +}; + +struct node { + struct component component; + uint16_t x, y; + + uint64_t timestamp; + + struct component *n, *s, *e, *w, *l; + + struct reg n_in, s_in, e_in, w_in, l_in; +}; + +enum order { + N, S, E, W, L +}; + +static inline void maybe_pick(struct reg *output[5], enum order d, struct reg *r) +{ + if (output[d] && output[d]->pkt.timestamp < r->pkt.timestamp) + return; + + output[d] = r; +} + +static stat node_clock(struct node *node) +{ + node->timestamp++; + + struct reg *output[5] = {NULL, NULL, NULL, NULL, NULL}; + struct reg *input[5] = { + &node->n_in, + &node->s_in, + &node->e_in, + &node->w_in, + &node->l_in + }; + + uint8_t X = node->x, Y = node->y; + for (size_t i = 0; i < 5; ++i) { + struct reg *r = input[i]; + if (!r->busy) + continue; + + uint16_t x, y; + addr_mesh(r->pkt.to, &x, &y, NULL); + if (x < X) { + maybe_pick(output, W, r); + continue; + } + + if (x > X) { + maybe_pick(output, E, r); + continue; + } + + if (y < Y) { + maybe_pick(output, S, r); + continue; + } + + if (y > Y) { + maybe_pick(output, N, r); + continue; + } + + maybe_pick(output, L, r); + } + + struct component *target[7] = { + node->n, + node->s, + node->e, + node->w, + node->l + }; + + for (size_t i = 0; i < 5; ++i) { + if (!output[i]) + continue; + + if (!target[i]) { + /* for now, should send packet back with an error or something */ + abort(); + } + + stat ret = SEND(node, target[i], output[i]->pkt); + if (ret == EBUSY) + continue; + + assert(ret == OK); + output[i]->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; +} + +static stat node_receive(struct node *node, struct component *from, struct packet pkt) +{ + if (from == node->l) { + /* add time when packet entered network */ + pkt.timestamp = node->timestamp; + return reg_receive(&node->l_in, pkt); + } + + if (from == node->n) + return reg_receive(&node->n_in, pkt); + + if (from == node->s) + return reg_receive(&node->s_in, pkt); + + if (from == node->e) + return reg_receive(&node->e_in, pkt); + + if (from == node->w) + return reg_receive(&node->w_in, pkt); + + abort(); + return OK; +} + +struct component *create_mesh_node(uint16_t x, uint16_t y) +{ + struct node *node = calloc(1, sizeof(struct node)); + if (!node) + return NULL; + + node->component.receive = (receive_callback)node_receive; + node->component.clock = (clock_callback)node_clock; + node->x = x; + node->y = y; + return (struct component *)node; +} + +stat mesh_node_connect(struct component *node, + struct component *n, + struct component *s, + struct component *e, + struct component *w, + struct component *l) +{ + struct node *nod = (struct node *)node; + nod->n = n; + nod->s = s; + nod->e = e; + nod->w = w; + nod->l = l; + return OK; +} diff --git a/src/mesh/node3d.c b/src/mesh/node3d.c new file mode 100644 index 0000000..d00f762 --- /dev/null +++ b/src/mesh/node3d.c @@ -0,0 +1,189 @@ +#include <gran/mesh/node3d.h> + +struct reg { + struct packet pkt; + bool busy; +}; + +struct node3d { + struct component component; + uint8_t x, y, z; + + uint64_t timestamp; + + struct component *n, *s, *e, *w, *u, *d, *l; + + struct reg n_in, s_in, e_in, w_in, u_in, d_in, l_in; +}; + +enum order { + N, S, E, W, U, D, L +}; + +static inline void maybe_pick(struct reg *output[7], enum order d, struct reg *r) +{ + if (output[d] && output[d]->pkt.timestamp < r->pkt.timestamp) + return; + + output[d] = r; +} + +static stat node3d_clock(struct node3d *node3d) +{ + node3d->timestamp++; + + struct reg *output[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + struct reg *input[7] = { + &node3d->n_in, + &node3d->s_in, + &node3d->e_in, + &node3d->w_in, + &node3d->u_in, + &node3d->d_in, + &node3d->l_in + }; + + uint8_t X = node3d->x, Y = node3d->y, Z = node3d->z; + for (size_t i = 0; i < 7; ++i) { + struct reg *r = input[i]; + if (!r->busy) + continue; + + uint8_t x, y, z; + addr_mesh3d(r->pkt.to, &x, &y, &z, NULL); + if (x < X) { + maybe_pick(output, W, r); + continue; + } + + if (x > X) { + maybe_pick(output, E, r); + continue; + } + + if (y < Y) { + maybe_pick(output, S, r); + continue; + } + + if (y > Y) { + maybe_pick(output, N, r); + continue; + } + + if (z < Z) { + maybe_pick(output, D, r); + continue; + } + + if (z > Z) { + maybe_pick(output, U, r); + continue; + } + + maybe_pick(output, L, r); + } + + struct component *target[7] = { + node3d->n, + node3d->s, + node3d->e, + node3d->w, + node3d->u, + node3d->d, + node3d->l + }; + + for (size_t i = 0; i < 7; ++i) { + if (!output[i]) + continue; + + if (!target[i]) { + /* for now, should send packet back with an error or something */ + abort(); + } + + stat ret = SEND(node3d, target[i], output[i]->pkt); + if (ret == EBUSY) + continue; + + assert(ret == OK); + output[i]->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; +} + +static stat node3d_receive(struct node3d *node3d, struct component *from, struct packet pkt) +{ + if (from == node3d->l) { + /* add time when packet entered network */ + pkt.timestamp = node3d->timestamp; + return reg_receive(&node3d->l_in, pkt); + } + + if (from == node3d->n) + return reg_receive(&node3d->n_in, pkt); + + if (from == node3d->s) + return reg_receive(&node3d->s_in, pkt); + + if (from == node3d->e) + return reg_receive(&node3d->e_in, pkt); + + if (from == node3d->w) + return reg_receive(&node3d->w_in, pkt); + + if (from == node3d->u) + return reg_receive(&node3d->u_in, pkt); + + if (from == node3d->d) + return reg_receive(&node3d->d_in, pkt); + + abort(); + return OK; +} + +struct component *create_mesh_node3d(uint8_t x, uint8_t y, uint8_t z) +{ + struct node3d *node = calloc(1, sizeof(struct node3d)); + if (!node) + return NULL; + + node->component.receive = (receive_callback)node3d_receive; + node->component.clock = (clock_callback)node3d_clock; + node->x = x; + node->y = y; + node->z = z; + return (struct component *)node; +} + +stat mesh_node3d_connect(struct component *node, + struct component *n, + struct component *s, + struct component *e, + struct component *w, + struct component *u, + struct component *d, + struct component *l) +{ + struct node3d *node3d = (struct node3d *)node; + node3d->n = n; + node3d->s = s; + node3d->e = e; + node3d->w = w; + node3d->u = u; + node3d->d = d; + node3d->l = l; + return OK; +} diff --git a/src/mesh/source.mk b/src/mesh/source.mk new file mode 100644 index 0000000..55a7d03 --- /dev/null +++ b/src/mesh/source.mk @@ -0,0 +1 @@ +SOURCES += src/mesh/node.c src/mesh/node3d.c diff --git a/tests/simple_grid/sim.c b/tests/simple_grid/sim.c deleted file mode 100644 index 87250c8..0000000 --- a/tests/simple_grid/sim.c +++ /dev/null @@ -1,134 +0,0 @@ -/* testcase for a 64x64 grid of processors, that all just spam the first memory - * region due to there being a 'lock' variable there, more or less the worst - * possible program for performance. */ -#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/grid/node.h> -#include <gran/cpu/riscv/simple_riscv64.h> - -unsigned char _tmp_test_bin[] = { - 0x93, 0x96, 0x05, 0x03, 0x13, 0x18, 0x05, 0x02, 0x93, 0x86, 0x06, 0x08, - 0xb3, 0xe6, 0x06, 0x01, 0x9b, 0x88, 0x05, 0x00, 0x63, 0x18, 0x05, 0x00, - 0x93, 0x07, 0x20, 0x00, 0x9b, 0x88, 0x05, 0x00, 0x63, 0x84, 0xf5, 0x0c, - 0x23, 0xb0, 0x06, 0x00, 0x1b, 0x57, 0x35, 0x00, 0xb7, 0x17, 0x00, 0x00, - 0x13, 0x06, 0x80, 0x02, 0x13, 0x77, 0x77, 0x00, 0x23, 0x80, 0xc7, 0x00, - 0x13, 0x07, 0x07, 0x03, 0x13, 0x76, 0x75, 0x00, 0x23, 0x80, 0xe7, 0x00, - 0x13, 0x07, 0x06, 0x03, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x06, 0xc0, 0x02, - 0x1b, 0xd7, 0x35, 0x00, 0x23, 0x80, 0xc7, 0x00, 0x13, 0x77, 0x77, 0x00, - 0x13, 0x06, 0x00, 0x02, 0x23, 0x80, 0xc7, 0x00, 0x13, 0x07, 0x07, 0x03, - 0x13, 0xf6, 0x75, 0x00, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0x06, 0x03, - 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0x90, 0x02, 0x23, 0x80, 0xe7, 0x00, - 0x13, 0x07, 0xa0, 0x00, 0x23, 0x80, 0xe7, 0x00, 0x93, 0x07, 0xf0, 0x00, - 0x1b, 0x07, 0x05, 0x00, 0x63, 0x04, 0xf5, 0x02, 0x63, 0x86, 0xf8, 0x02, - 0x9b, 0x85, 0x15, 0x00, 0x93, 0x95, 0x05, 0x03, 0x93, 0x85, 0x05, 0x08, - 0x33, 0x68, 0xb8, 0x00, 0x93, 0x07, 0x10, 0x00, 0x23, 0x30, 0xf8, 0x00, - 0x23, 0xb0, 0x06, 0x00, 0x67, 0x80, 0x00, 0x00, 0xe3, 0x90, 0xe8, 0xfe, - 0x73, 0x00, 0x10, 0x00, 0x1b, 0x05, 0x15, 0x00, 0x13, 0x15, 0x05, 0x03, - 0x13, 0x58, 0x05, 0x01, 0x93, 0x05, 0x00, 0x08, 0x33, 0x68, 0xb8, 0x00, - 0x93, 0x07, 0x10, 0x00, 0x23, 0x30, 0xf8, 0x00, 0x23, 0xb0, 0x06, 0x00, - 0x67, 0x80, 0x00, 0x00, 0xb7, 0x17, 0x00, 0x00, 0x13, 0x07, 0x00, 0x03, - 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0xa0, 0x00, 0x23, 0x80, 0xe7, 0x00, - 0x6f, 0xf0, 0xdf, 0xf2 -}; -unsigned int _tmp_test_bin_len = 256; - -static struct component *get_grid(struct component **grid, int i, int j, uint8_t x, uint8_t y) -{ - if (i < 0) - return NULL; - - if (j < 0) - return NULL; - - if (i >= x) - return NULL; - - if (j >= y) - return NULL; - - return grid[i * x + j]; -} - -static stat build_grid(struct clock_domain *clk, uint8_t x, uint8_t y) -{ - struct component **grid = calloc(x * y, sizeof(struct component *)); - assert(grid); - - struct component **pes = calloc(x * y, sizeof(struct component *)); - assert(pes); - - for (size_t i = 0; i < x; ++i) - for (size_t j = 0; j < y; ++j) { - struct component *node = create_grid_node(i, j); - clock_domain_add(clk, node); - grid[i * x + j] = node; - - if (i == 0 && j == 0) - continue; - - if (i == 0 && j == 1) - continue; - - struct component *imem = create_simple_mem(4096); - init_simple_mem(imem, 0, _tmp_test_bin_len, _tmp_test_bin); - - uint64_t rcv = grid_addr(i, j, 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 */ - - clock_domain_add(clk, rv64); - clock_domain_add(clk, imem); - - pes[i * x + j] = rv64; - } - - struct component *uart = create_simple_uart(); - clock_domain_add(clk, uart); - grid_node_connect(grid[0], NULL, grid[x], grid[1], NULL, uart); - - struct component *dmem = create_simple_mem(4096); - clock_domain_add(clk, dmem); - grid_node_connect(grid[1], NULL, grid[x + 1], grid[2], grid[0], dmem); - - for (int i = 0; i < x; ++i) - for (int j = 0; j < y; ++j) { - if (i == 0 && j == 0) - continue; - - if (i == 0 && j == 1) - continue; - - struct component *node = grid[i * x + j]; - struct component *lower = pes[i * x + j]; - struct component *left = get_grid(grid, i - 1, j , x, y); - struct component *right = get_grid(grid, i + 1, j , x, y); - struct component *up = get_grid(grid, i , j + 1, x, y); - struct component *down = get_grid(grid, i , j - 1, x, y); - grid_node_connect(node, left, right, up, down, lower); - } - - free(pes); - free(grid); - return OK; -} - -int main() -{ - struct clock_domain *clk = create_clock_domain(NS(1)); - - stat r = build_grid(clk, 16, 16); - 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_grid/source.mk b/tests/simple_grid/source.mk deleted file mode 100644 index e2dd442..0000000 --- a/tests/simple_grid/source.mk +++ /dev/null @@ -1,6 +0,0 @@ -GRID_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_grid/sim.c" - -TEST_PROGS += build/tests/simple_grid/sim - -build/tests/simple_grid/sim: $(GRID_TEST_OBJ) $(OBJS) - $(COMPILE) $(GRID_TEST_OBJ) $(OBJS) -o $@ diff --git a/tests/simple_grid/test.c b/tests/simple_grid/test.c deleted file mode 100644 index 2891a6e..0000000 --- a/tests/simple_grid/test.c +++ /dev/null @@ -1,44 +0,0 @@ -#define X 16 -#define Y 16 - -void _start(unsigned short x, unsigned short y) -{ - volatile unsigned long *control = (unsigned long *)(((unsigned long)x << 32) | ((unsigned long)y << 48) + 128); - volatile char *uart = (char *)4096; - - /* very hacky, not recommended but good enough for testing */ - if (x == 0 && y == 2) { - *uart = '0'; - *uart = '\n'; - } - else - *control = 0; /* go to sleep */ - - *uart = '('; - /* [0 - 16] as two octal numbers */ - *uart = ((x >> 3) & 0x7) + '0'; - *uart = ((x >> 0) & 0x7) + '0'; - - *uart = ','; - *uart = ' '; - - *uart = ((y >> 3) & 0x7) + '0'; - *uart = ((y >> 0) & 0x7) + '0'; - - *uart = ')'; - *uart = '\n'; - - if (x == 15 && y == 15) - asm ("ebreak\n"); - - if (y == 15) { - x++; - y = 0; - } - else - y++; - - volatile unsigned long *next = (unsigned long *)(((unsigned long)x << 32) | ((unsigned long)y << 48) + 128); - *next = 1; /* wake next core */ - *control = 0; /* go to sleep again */ -} diff --git a/tests/simple_grid3d/source.mk b/tests/simple_grid3d/source.mk deleted file mode 100644 index 4c19568..0000000 --- a/tests/simple_grid3d/source.mk +++ /dev/null @@ -1,18 +0,0 @@ -GRID3D_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_grid3d/sim.c" -TEST_PROGS += build/tests/simple_grid3d/sim - -build/tests/simple_grid3d/test.inc: tests/simple_grid3d/test.c - riscv64-unknown-elf-gcc -O2 -Wall -Wextra -ffreestanding -nostdlib \ - -march=rv64i -mabi=lp64 \ - -o build/tests/simple_grid3d/test \ - tests/simple_grid3d/test.c - riscv64-unknown-elf-objcopy -Obinary \ - build/tests/simple_grid3d/test \ - build/tests/simple_grid3d/test.bin - xxd -i build/tests/simple_grid3d/test.bin \ - > build/tests/simple_grid3d/test.inc - -build/tests/simple_grid3d/sim.o: build/tests/simple_grid3d/test.inc - -build/tests/simple_grid3d/sim: $(GRID3D_TEST_OBJ) $(OBJS) - $(COMPILE) $(GRID3D_TEST_OBJ) $(OBJS) -o $@ diff --git a/tests/simple_mesh/sim.c b/tests/simple_mesh/sim.c new file mode 100644 index 0000000..c3cdc33 --- /dev/null +++ b/tests/simple_mesh/sim.c @@ -0,0 +1,127 @@ +#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/node.h> +#include <gran/cpu/riscv/simple_riscv64.h> + +#include "../build/tests/simple_mesh/test.inc" + +static size_t idx_1d(int x, int y, uint8_t xw, uint8_t yw) +{ + (void)xw; /* maybe unused */ + assert(0 <= x && x < xw); + assert(0 <= y && y < yw); + return (x * yw) + y; +} + +static struct component *mesh_at(struct component **mesh, + int x, int y, + uint8_t xw, uint8_t yw) +{ + if (x < 0) + return NULL; + + if (y < 0) + return NULL; + + if (x >= xw) + return NULL; + + if (y >= yw) + return NULL; + + return mesh[idx_1d(x, y, xw, yw)]; +} + +static void connect_mesh(struct component **mesh, struct component *c, + uint16_t x, uint16_t y, + uint16_t xw, uint16_t yw) +{ + mesh_node_connect(mesh_at(mesh, x, y, xw, yw), + mesh_at(mesh, x , y+1, xw, yw), + mesh_at(mesh, x , y-1, xw, yw), + mesh_at(mesh, x+1, y , xw, yw), + mesh_at(mesh, x-1, y , xw, yw), + c); +} + +static stat build_mesh(struct clock_domain *clk, uint16_t x, uint16_t y) +{ + struct component **mesh = calloc(x * y, sizeof(struct component *)); + assert(mesh); + + struct component **pes = calloc(x * y, sizeof(struct component *)); + assert(pes); + + for (size_t i = 0; i < x; ++i) + for (size_t j = 0; j < y; ++j) { + struct component *node = create_mesh_node(i, j); + clock_domain_add(clk, node); + mesh[idx_1d(i, j, x, y)] = node; + + if (i == 0 && j == 0) + continue; + + if (i == 0 && j == 1) + continue; + + struct component *imem = create_simple_mem(4096); + init_simple_mem(imem, 0, + build_tests_simple_mesh_test_bin_len, + build_tests_simple_mesh_test_bin); + + uint64_t rcv = mesh_addr(i, j, 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, x); /* a3 */ + simple_riscv64_set_reg(rv64, 13, y); /* a4 */ + + clock_domain_add(clk, rv64); + clock_domain_add(clk, imem); + + pes[idx_1d(i, j, x, y)] = rv64; + } + + struct component *uart = create_simple_uart(); + clock_domain_add(clk, uart); + connect_mesh(mesh, uart, 0, 0, x, y); + + struct component *dmem = create_simple_mem(4096); + clock_domain_add(clk, dmem); + connect_mesh(mesh, dmem, 0, 1, x, y); + + for (int i = 0; i < x; ++i) + for (int j = 0; j < y; ++j) { + if (i == 0 && j == 0) + continue; + + if (i == 0 && j == 1) + continue; + + connect_mesh(mesh, pes[idx_1d(i, j, x, y)], i, j, x, y); + } + + free(mesh); + free(pes); + return OK; +} + +int main() +{ + struct clock_domain *clk = create_clock_domain(NS(1)); + + stat r = build_mesh(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/simple_mesh/source.mk b/tests/simple_mesh/source.mk new file mode 100644 index 0000000..748e252 --- /dev/null +++ b/tests/simple_mesh/source.mk @@ -0,0 +1,18 @@ +MESH_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_mesh/sim.c" +TEST_PROGS += build/tests/simple_mesh/sim + +build/tests/simple_mesh/test.inc: tests/simple_mesh/test.c + riscv64-unknown-elf-gcc -O2 -Wall -Wextra -ffreestanding -nostdlib \ + -march=rv64i -mabi=lp64 \ + -o build/tests/simple_mesh/test \ + tests/simple_mesh/test.c + riscv64-unknown-elf-objcopy -Obinary \ + build/tests/simple_mesh/test \ + build/tests/simple_mesh/test.bin + xxd -i build/tests/simple_mesh/test.bin \ + > build/tests/simple_mesh/test.inc + +build/tests/simple_mesh/sim.o: build/tests/simple_mesh/test.inc + +build/tests/simple_mesh/sim: $(MESH_TEST_OBJ) $(OBJS) + $(COMPILE) $(MESH_TEST_OBJ) $(OBJS) -o $@ diff --git a/tests/simple_mesh/test.c b/tests/simple_mesh/test.c new file mode 100644 index 0000000..b1bbe84 --- /dev/null +++ b/tests/simple_mesh/test.c @@ -0,0 +1,55 @@ +__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) +{ + *uart = '('; + print_int8(uart, x); + *uart = ','; + *uart = ' '; + print_int8(uart, y); + *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 X, unsigned Y) +{ + unsigned yi = wrap(y, Y); + unsigned xi = yi < y ? wrap(x, X) : x; + + return (xi << 16) | yi; +} + +void _start(unsigned x, unsigned y, unsigned X, unsigned Y) +{ + volatile char *uart = (char *)4096; + volatile unsigned *control = (unsigned *)(1ULL << 48); + + if (x == 0 && y == 2) { + goto do_work; + } else { + while (*control != ((x << 16) | y)) {} + } + +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) {} +} diff --git a/tests/simple_grid3d/sim.c b/tests/simple_mesh3d/sim.c index 6df29dd..9557d83 100644 --- a/tests/simple_grid3d/sim.c +++ b/tests/simple_mesh3d/sim.c @@ -4,10 +4,10 @@ #include <gran/mem/simple_mem.h> #include <gran/bus/simple_bus.h> #include <gran/uart/simple_uart.h> -#include <gran/grid/node3d.h> +#include <gran/mesh/node3d.h> #include <gran/cpu/riscv/simple_riscv64.h> -#include "../build/tests/simple_grid3d/test.inc" +#include "../build/tests/simple_mesh3d/test.inc" static size_t idx_1d(int x, int y, int z, uint8_t xw, uint8_t yw, uint8_t zw) { @@ -18,7 +18,7 @@ static size_t idx_1d(int x, int y, int z, uint8_t xw, uint8_t yw, uint8_t zw) return (x * yw * zw) + (y * zw) + z; } -static struct component *grid_at(struct component **grid, +static struct component *mesh_at(struct component **mesh, int x, int y, int z, uint8_t xw, uint8_t yw, uint8_t zw) { @@ -40,27 +40,27 @@ static struct component *grid_at(struct component **grid, if (z >= zw) return NULL; - return grid[idx_1d(x, y, z, xw, yw, zw)]; + return mesh[idx_1d(x, y, z, xw, yw, zw)]; } -static void connect_grid3d(struct component **grid, struct component *c, +static void connect_mesh3d(struct component **mesh, struct component *c, uint8_t x, uint8_t y, uint8_t z, uint8_t xw, uint8_t yw, uint8_t zw) { - grid_node3d_connect(grid_at(grid, x, y, z, xw, yw, zw), - grid_at(grid, x , y+1, z , xw, yw, zw), - grid_at(grid, x , y-1, z , xw, yw, zw), - grid_at(grid, x-1, y , z , xw, yw, zw), - grid_at(grid, x+1, y , z , xw, yw, zw), - grid_at(grid, x , y , z+1, xw, yw, zw), - grid_at(grid, x , y , z-1, xw, yw, zw), + mesh_node3d_connect(mesh_at(mesh, x, y, z, xw, yw, zw), + mesh_at(mesh, x , y+1, z , xw, yw, zw), + mesh_at(mesh, x , y-1, z , xw, yw, zw), + mesh_at(mesh, x+1, y , z , xw, yw, zw), + mesh_at(mesh, x-1, y , z , xw, yw, zw), + mesh_at(mesh, x , y , z+1, xw, yw, zw), + mesh_at(mesh, x , y , z-1, xw, yw, zw), c); } -static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_t z) +static stat build_mesh3d(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 **mesh = calloc(x * y * z, sizeof(struct component *)); + assert(mesh); struct component **pes = calloc(x * y * z, sizeof(struct component *)); assert(pes); @@ -68,9 +68,9 @@ static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_ 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_grid_node3d(i, j, k); + struct component *node = create_mesh_node3d(i, j, k); clock_domain_add(clk, node); - grid[idx_1d(i, j, k, x, y, z)] = node; + mesh[idx_1d(i, j, k, x, y, z)] = node; if (i == 0 && j == 0 && k == 0) continue; @@ -80,10 +80,10 @@ static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_ struct component *imem = create_simple_mem(4096); init_simple_mem(imem, 0, - build_tests_simple_grid3d_test_bin_len, - build_tests_simple_grid3d_test_bin); + build_tests_simple_mesh3d_test_bin_len, + build_tests_simple_mesh3d_test_bin); - uint64_t rcv = grid3d_addr(i, j, k, 0); + uint64_t rcv = mesh3d_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 */ @@ -100,11 +100,11 @@ static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_ struct component *uart = create_simple_uart(); clock_domain_add(clk, uart); - connect_grid3d(grid, uart, 0, 0, 0, x, y, z); + connect_mesh3d(mesh, uart, 0, 0, 0, x, y, z); struct component *dmem = create_simple_mem(4096); clock_domain_add(clk, dmem); - connect_grid3d(grid, dmem, 0, 0, 1, x, y, z); + connect_mesh3d(mesh, dmem, 0, 0, 1, x, y, z); for (int i = 0; i < x; ++i) for (int j = 0; j < y; ++j) @@ -115,12 +115,12 @@ static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_ if (i == 0 && j == 0 && k == 1) continue; - connect_grid3d(grid, + connect_mesh3d(mesh, pes[idx_1d(i, j, k, x, y, z)], i, j, k, x, y, z); } - free(grid); + free(mesh); free(pes); return OK; } @@ -129,7 +129,7 @@ int main() { struct clock_domain *clk = create_clock_domain(NS(1)); - stat r = build_torus3d(clk, 4, 4, 4); + stat r = build_mesh3d(clk, 4, 4, 4); assert(r == OK); struct gran_root *root = create_root(); diff --git a/tests/simple_mesh3d/source.mk b/tests/simple_mesh3d/source.mk new file mode 100644 index 0000000..30aea2c --- /dev/null +++ b/tests/simple_mesh3d/source.mk @@ -0,0 +1,18 @@ +MESH3D_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_mesh3d/sim.c" +TEST_PROGS += build/tests/simple_mesh3d/sim + +build/tests/simple_mesh3d/test.inc: tests/simple_mesh3d/test.c + riscv64-unknown-elf-gcc -O2 -Wall -Wextra -ffreestanding -nostdlib \ + -march=rv64i -mabi=lp64 \ + -o build/tests/simple_mesh3d/test \ + tests/simple_mesh3d/test.c + riscv64-unknown-elf-objcopy -Obinary \ + build/tests/simple_mesh3d/test \ + build/tests/simple_mesh3d/test.bin + xxd -i build/tests/simple_mesh3d/test.bin \ + > build/tests/simple_mesh3d/test.inc + +build/tests/simple_mesh3d/sim.o: build/tests/simple_mesh3d/test.inc + +build/tests/simple_mesh3d/sim: $(MESH3D_TEST_OBJ) $(OBJS) + $(COMPILE) $(MESH3D_TEST_OBJ) $(OBJS) -o $@ diff --git a/tests/simple_grid3d/test.c b/tests/simple_mesh3d/test.c index 2953d41..2953d41 100644 --- a/tests/simple_grid3d/test.c +++ b/tests/simple_mesh3d/test.c diff --git a/tests/starved_grid/source.mk b/tests/starved_grid/source.mk deleted file mode 100644 index 428435f..0000000 --- a/tests/starved_grid/source.mk +++ /dev/null @@ -1,6 +0,0 @@ -STARVED_TEST_OBJ != ./scripts/gen-deps --sources "tests/starved_grid/sim.c" - -TEST_PROGS += build/tests/starved_grid/sim - -build/tests/starved_grid/sim: $(STARVED_TEST_OBJ) $(OBJS) - $(COMPILE) $(STARVED_TEST_OBJ) $(OBJS) -o $@ diff --git a/tests/starved_grid/sim.c b/tests/starved_mesh/sim.c index d858917..1967e0b 100644 --- a/tests/starved_grid/sim.c +++ b/tests/starved_mesh/sim.c @@ -1,4 +1,4 @@ -/* testcase for a 64x64 grid of processors, that all just spam the first memory +/* testcase for a 64x64 mesh of processors, that all just spam the first memory * region due to there being a 'lock' variable there, more or less the worst * possible program for performance. */ #include <assert.h> @@ -7,7 +7,7 @@ #include <gran/mem/simple_mem.h> #include <gran/bus/simple_bus.h> #include <gran/uart/simple_uart.h> -#include <gran/grid/node.h> +#include <gran/mesh/node.h> #include <gran/cpu/riscv/simple_riscv64.h> unsigned char _tmp_test_bin[] = { @@ -36,7 +36,7 @@ unsigned char _tmp_test_bin[] = { }; unsigned int _tmp_test_bin_len = 260; -static struct component *get_grid(struct component **grid, int i, int j, uint8_t x, uint8_t y) +static struct component *get_mesh(struct component **mesh, int i, int j, uint8_t x, uint8_t y) { if (i < 0) return NULL; @@ -50,22 +50,22 @@ static struct component *get_grid(struct component **grid, int i, int j, uint8_t if (j >= y) return NULL; - return grid[i * x + j]; + return mesh[i * x + j]; } -static stat build_grid(struct clock_domain *clk, uint8_t x, uint8_t y) +static stat build_mesh(struct clock_domain *clk, uint8_t x, uint8_t y) { - struct component **grid = calloc(x * y, sizeof(struct component *)); - assert(grid); + struct component **mesh = calloc(x * y, sizeof(struct component *)); + assert(mesh); struct component **pes = calloc(x * y, sizeof(struct component *)); assert(pes); for (size_t i = 0; i < x; ++i) for (size_t j = 0; j < y; ++j) { - struct component *node = create_grid_node(i, j); + struct component *node = create_mesh_node(i, j); clock_domain_add(clk, node); - grid[i * x + j] = node; + mesh[i * x + j] = node; if (i == 0 && j == 0) continue; @@ -76,7 +76,7 @@ static stat build_grid(struct clock_domain *clk, uint8_t x, uint8_t y) struct component *imem = create_simple_mem(4096); init_simple_mem(imem, 0, _tmp_test_bin_len, _tmp_test_bin); - uint64_t rcv = grid_addr(i, j, 0); + uint64_t rcv = mesh_addr(i, j, 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 */ @@ -89,11 +89,11 @@ static stat build_grid(struct clock_domain *clk, uint8_t x, uint8_t y) struct component *uart = create_simple_uart(); clock_domain_add(clk, uart); - grid_node_connect(grid[0], NULL, grid[x], grid[1], NULL, uart); + mesh_node_connect(mesh[0], NULL, mesh[x], mesh[1], NULL, uart); struct component *dmem = create_simple_mem(4096); clock_domain_add(clk, dmem); - grid_node_connect(grid[1], NULL, grid[x + 1], grid[2], grid[0], dmem); + mesh_node_connect(mesh[1], NULL, mesh[x + 1], mesh[2], mesh[0], dmem); for (int i = 0; i < x; ++i) for (int j = 0; j < y; ++j) { @@ -103,17 +103,17 @@ static stat build_grid(struct clock_domain *clk, uint8_t x, uint8_t y) if (i == 0 && j == 1) continue; - struct component *node = grid[i * x + j]; + struct component *node = mesh[i * x + j]; struct component *lower = pes[i * x + j]; - struct component *left = get_grid(grid, i - 1, j , x, y); - struct component *right = get_grid(grid, i + 1, j , x, y); - struct component *up = get_grid(grid, i , j + 1, x, y); - struct component *down = get_grid(grid, i , j - 1, x, y); - grid_node_connect(node, left, right, up, down, lower); + struct component *left = get_mesh(mesh, i - 1, j , x, y); + struct component *right = get_mesh(mesh, i + 1, j , x, y); + struct component *up = get_mesh(mesh, i , j + 1, x, y); + struct component *down = get_mesh(mesh, i , j - 1, x, y); + mesh_node_connect(node, left, right, up, down, lower); } free(pes); - free(grid); + free(mesh); return OK; } @@ -121,7 +121,7 @@ int main() { struct clock_domain *clk = create_clock_domain(NS(1)); - stat r = build_grid(clk, 16, 16); + stat r = build_mesh(clk, 16, 16); assert(r == OK); struct gran_root *root = create_root(); diff --git a/tests/starved_mesh/source.mk b/tests/starved_mesh/source.mk new file mode 100644 index 0000000..2d3a6e8 --- /dev/null +++ b/tests/starved_mesh/source.mk @@ -0,0 +1,6 @@ +STARVED_TEST_OBJ != ./scripts/gen-deps --sources "tests/starved_mesh/sim.c" + +TEST_PROGS += build/tests/starved_mesh/sim + +build/tests/starved_mesh/sim: $(STARVED_TEST_OBJ) $(OBJS) + $(COMPILE) $(STARVED_TEST_OBJ) $(OBJS) -o $@ diff --git a/tests/starved_grid/test.c b/tests/starved_mesh/test.c index c91868c..c91868c 100644 --- a/tests/starved_grid/test.c +++ b/tests/starved_mesh/test.c |
