1# @ajax/mesh-rt
23The mesh device runtime. A program is C:
45```c
6#include "mesh/rt.h"
78static void init(const mesh_ctx *ctx) { if (mesh_ctx_leader(ctx)) mesh_ctx_set_u32(ctx, 0, 1); }
9static uint32_t task(const mesh_ctx *ctx, uint32_t op, uint32_t arg) { return arg * 3 + 7; }
1011MESH_PROGRAM(init, task);
12```
1314`MESH_PROGRAM` defines the kernel `mesh_main(mb, slot)` (the node loop, @ajax/mesh-rt-loop) and the global
15`MESH_RT_ABI` meshd checks at load. Compiled for nvptx64 it is the GPU image (a sexc `"kind": "ptx"`
16package, then `mesh-ptx-link` for the catalog); compiled for the host, `mesh_main` runs on
17@ajax/mesh-rt-sim's threads in tests.
1819The runtime is split into atomic packages, all header-only and inlined into the kernel:
2021| Package | What |
22|---|---|
23| @ajax/mesh-rt-ptx | PTX primitives |
24| @ajax/mesh-rt-sim | the same primitives on CPU threads, and the launcher |
25| @ajax/mesh-rt-prim | picks one, plus f32 helpers |
26| @ajax/mesh-rt-view | bounds-checked views, faults |
27| @ajax/mesh-rt-block | block collectives in a fixed order, shared memory |
28| @ajax/mesh-rt-ctx | `mesh_ctx` |
29| @ajax/mesh-rt-loop | the node loop |
30| @ajax/mesh-rt-linalg | exact-mode GEMM tile and GEMV |
3132- **Ported from:** alpha-rust-mesh `crates/mesh-rt/src/lib.rs` (`mesh_program!`).
33- **Differences:** the `MESH_RT_ABI` symbol is made with an asm label, because `MESH_RT_ABI` is also the
34 contract's constant (6) in C. Rust's panic handler traps; C has no panics (bounds checks fault instead).