==> include/mesh/mps_wire.h <==1/* @ajax/mesh-mps-wire: the frames between meshd and its --isolation mps
2 * worker processes (mesh-host mps.rs): a u32 LE length (op + body), the u8
3 * op, its body. On the worker's stdin and stdout. */
4#ifndef MESH_MPS_WIRE_H
5#define MESH_MPS_WIRE_H
6
7#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10
11/* meshd -> worker */
12#define MESH_W_LOAD 1 /* u32 threads, u32 smem (the launch shape), u32 scratch bytes, u32 name_len, the name, the cubin */
13#define MESH_W_LAUNCH 2 /* u32 gen, u32 slot, u32 nodes */
14#define MESH_W_QUIT 3
15#define MESH_W_UNLOAD 4 /* no reply: the module goes, the context stays (pooled) */
16#define MESH_W_READY 5 /* replied with W_READY, u32 ok, once the context exists */
17/* worker -> meshd, same framing */
18#define MESH_W_LOADED 1 /* u32 ok; ok: u32 rt_abi, regs, per_sm, local, sms, u64 mailbox dev, u64 scratch dev; else the error */
19#define MESH_W_LAUNCHED 2 /* u32 ok; else the error */
20#define MESH_W_DONE 3 /* u32 gen, u32 ok; else the error: the stream of launch gen finished */
21
22/* The largest frame read_frame accepts (64 MiB). */
23#define MESH_W_FRAME_MAX (64u << 20)
24
25/* One frame: *out (malloc'd) and *n bytes. */
26void mesh_mps_frame(uint8_t op, const uint8_t *body, size_t n, uint8_t **out, size_t *out_len);
27/* Writes one frame to fd, whole (EINTR retried). */
28bool mesh_mps_write_frame(int fd, uint8_t op, const uint8_t *body, size_t n);
29/* Reads one frame from fd: *op and *body (malloc'd, *n bytes). False at EOF,
30 * on a read error, or on a frame of 0 or more than MESH_W_FRAME_MAX bytes. */
31bool mesh_mps_read_frame(int fd, uint8_t *op, uint8_t **body, size_t *n);
32/* The little-endian u32 at o, 0 past the end. */
33uint32_t mesh_mps_u32_at(const uint8_t *b, size_t n, size_t o);
34uint64_t mesh_mps_u64_at(const uint8_t *b, size_t n, size_t o);
35/* Appends a little-endian u32 / u64 to a growing body. */
36void mesh_mps_put_u32(uint8_t **b, size_t *n, uint32_t v);
37void mesh_mps_put_u64(uint8_t **b, size_t *n, uint64_t v);
38void mesh_mps_put_bytes(uint8_t **b, size_t *n, const void *p, size_t k);
39
40#endif