1/* @ajax/mesh-abi-backend: Backend kinds (cuda, metal, wasm, native) and the H_BACKEND word.
2 *
3 * Part of alpha-c-mesh, a C port of alpha-rust-mesh (README.md says from where). */
4#ifndef MESH_ABI_BACKEND_H
5#define MESH_ABI_BACKEND_H
67#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
1011/* H_BACKEND's low byte. CUDA: one resident kernel per program (mesh-rt,
12 * PTX, nvJitLink). Metal (Apple GPUs): no resident kernels -- a dispatch
13 * cannot see host writes made while it runs -- so meshd's *lease* threads
14 * play the node loop on the CPU: each takes a running program's published
15 * tickets in order, runs them as one dispatch (a threadgroup of NODE_THREADS
16 * per task, a SIMD-group: the warp), and completes them exactly as mesh-rt's
17 * nodes do (results, marks, P_DONE, node records, trace). The rings, the
18 * publisher, control and snapshots are the same words on both. */
19#define MESH_BACKEND_CUDA 0u
20#define MESH_BACKEND_METAL 1u
21/* WebAssembly on the host CPU (wasmtime embedded in meshd; mesh-host
22 * `wasm.rs`): an *executor*, not a GPU. Every meshd has it beside its GPU
23 * backend, and a program whose manifest lists "wasm" first (or lists no
24 * backend this meshd's GPU runs) runs there, on lease lanes -- threads that
25 * play mesh-rt's node loop against the same mailbox words, each lane running
26 * its tickets in its own wasm instance (the guest runtime is crates/mesh-rt-wasm).
27 * `meshd --backend wasm` is a CPU-only meshd: H_BACKEND reads BACKEND_WASM. */
28#define MESH_BACKEND_WASM 2u
29/* Native worker processes (mesh-host `native.rs`): a manifest's
30 * `backends = ["native"]` (alone) makes the program an executable built per
31 * target that runs as its own process beside the GPU backend (see "native
32 * workers" below). An executor, never an H_BACKEND kind. */
33#define MESH_BACKEND_NATIVE 3u
34#define MESH_BACKENDS_LEN 4
35extern const char *const MESH_BACKENDS[4];
3637/* The H_BACKEND / M_BACKEND word: backend and family. */
38static inline uint32_t mesh_backend_word(uint32_t kind, uint32_t family) {
39 return (kind & 0xffu) | (family & 0xffu) << 8;
40}
41static inline uint32_t mesh_backend_kind(uint32_t word) { return word & 0xffu; }
42static inline uint32_t mesh_backend_family(uint32_t word) { return (word >> 8) & 0xffu; }
4344#endif