skip to content
==> include/mesh/abi/ext.h <==
1/* @ajax/mesh-abi-ext: The manifest extension (PX_*): counter names, fields, placement, occupancy, param, executor, shared and scratch.
2 *
3 * Part of alpha-c-mesh, a C port of alpha-rust-mesh (README.md says from where). */
4#ifndef MESH_ABI_EXT_H
5#define MESH_ABI_EXT_H
6
7#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10#include "mesh/abi/base.h"
11#include "mesh/abi/control_block.h"
12#include "mesh/abi/placement.h"
13#include "mesh/abi/fields.h"
14
15/* ---------------------------------------------------------------- manifest extension */
16/* Per slot, PX_BYTES at `prog_ext(s)`: the manifest's display metadata, for
17 * viewers and the http program (meshd writes it with the table entry). */
18#define MESH_PROG_EXT 0x30000
19#define MESH_PX_BYTES 0x400
20#define MESH_PX_COUNTER_NAMES 0x00 /* [u8; 16] x COUNTERS, NUL padded */
21#define MESH_PX_FIELD_COUNT 0x40 /* u32 */
22/* u32 PLACE_CAP_* (the manifest's `place`), written with the extension. */
23#define MESH_PX_PLACE_CAP 0x44
24/* u32 PLACE_* and u32 the system it names (pin: the runner; split: the
25 * owner), written by meshd at every placement change (and after any rewrite
26 * of the extension).  0/0 = local. */
27#define MESH_PX_PLACE 0x48
28#define MESH_PX_PLACE_SYS 0x4c
29/* [u8; PLACE_PARTS_MAX]: split's assignment, part b -> system (PART_NONE: no part / not split). */
30#define MESH_PX_PLACE_ASSIGN 0x50
31/* u32 cuOccupancyMaxActiveBlocksPerMultiprocessor of the image's mesh_main
32 * (one-warp blocks) on this machine's GPU, and u32 its local bytes per
33 * thread: written by meshd with the extension (per machine: PTX is shared,
34 * SASS and occupancy are not). */
35#define MESH_PX_PER_SM 0x70
36#define MESH_PX_LOCAL 0x74
37/* u32 the manifest's `param` (default 0), written with the extension: a
38 * program constant every member of a cluster reads alike (it is folded into
39 * the image hash, which replication and the lockstep HELLO compare).
40 * sha256d: log2 of the nonces per task, so g = N c + k tiles the nonce space. */
41#define MESH_PX_PARAM 0x78
42/* u32, host: the executor running the slot's current image, BACKEND_* (cuda,
43 * metal: the machine's GPU; wasm: lease lanes on the CPU; native: a worker
44 * process).  Set at load, upgrade and rollback with the rest of the entry. */
45#define MESH_PX_EXEC 0x7c
46#define MESH_PX_FIELDS 0x80 /* FIELD_BYTES x MAX_FIELDS */
47#define MESH_FIELD_BYTES 32
48#define MESH_MAX_FIELDS 27
49/* u32 the manifest's `shared_bytes` (the program's shared memory per node,
50 * after the runtime's RT_SHARED_BYTES), written with the extension. */
51#define MESH_PX_SHARED (MESH_PX_FIELDS + MESH_FIELD_BYTES * MESH_MAX_FIELDS)
52/* u32 the register cap the image was compiled with on this machine (CUDA:
53 * nvJitLink -maxrregcount, so that a block of 32 x warps threads fits the
54 * SM's register file; 0: none), written with the extension. */
55#define MESH_PX_REG_CAP (MESH_PX_SHARED + 4)
56/* u32 the manifest's `scratch_bytes`, and u64 the scratch's device address on
57 * this machine (0: none), written with the extension: a program's own device
58 * memory (CUDA: cuMemAlloc'd in the context that runs it -- meshd's, or the
59 * MPS worker's; Metal: a private-to-the-program MTLBuffer bound at index 3),
60 * zeroed at load, kept while the image is loaded, never mapped to the host
61 * (`ctx.scratch_view()`, `scratch_ptr()`; a GEMM's matrices, a model's weights).  The CPU executors
62 * have none. */
63#define MESH_PX_SCRATCH_BYTES (MESH_PX_REG_CAP + 4)
64#define MESH_PX_SCRATCH (MESH_PX_SCRATCH_BYTES + 8)
65/* The largest manifest `scratch_bytes` (1 GiB). */
66#define MESH_MAX_SCRATCH_BYTES ((uint32_t)(1 << 30))
67#define MESH_FD_NAME 0x00 /* [u8; 20], NUL padded */
68#define MESH_FD_NAME_MAX 19
69#define MESH_FD_TYPE 0x14 /* FT_* */
70#define MESH_FD_OFF 0x18 /* view offset */
71#define MESH_FT_U32 0u
72#define MESH_FT_I32 1u
73#define MESH_FT_F32 2u
74#define MESH_FT_U64 3u
75#define MESH_FT_U8 4u
76#define MESH_FIELD_TYPES_LEN 5
77extern const char *const MESH_FIELD_TYPES[5];
78#define MESH_EXT_FIELDS_LEN 15
79extern const mesh_field MESH_EXT_FIELDS[15];
80
81/* Slot s's manifest extension. */
82static inline size_t mesh_prog_ext(uint32_t slot) { return MESH_PROG_EXT + MESH_PX_BYTES * (size_t)slot; }
83
84/* The Rust const asserts that only involve this package. */
85_Static_assert(MESH_PX_LOCAL + 4 <= MESH_PX_FIELDS, "PX_LOCAL + 4 <= PX_FIELDS");
86_Static_assert(MESH_PX_FIELDS + MESH_FIELD_BYTES * MESH_MAX_FIELDS <= MESH_PX_SHARED, "PX_FIELDS + FIELD_BYTES * MAX_FIELDS <= PX_SHARED");
87_Static_assert(MESH_PX_SCRATCH + 8 <= MESH_PX_BYTES, "PX_SCRATCH + 8 <= PX_BYTES");
88_Static_assert((MESH_PX_SCRATCH % 8 == 0), "PX_SCRATCH.is_multiple_of(8)");
89_Static_assert(MESH_PX_FIELD_COUNT < MESH_PX_PLACE_CAP, "PX_FIELD_COUNT < PX_PLACE_CAP");
90_Static_assert(MESH_PX_PLACE_SYS + 4 <= MESH_PX_PLACE_ASSIGN, "PX_PLACE_SYS + 4 <= PX_PLACE_ASSIGN");
91_Static_assert(MESH_FD_OFF + 4 <= MESH_FIELD_BYTES, "FD_OFF + 4 <= FIELD_BYTES");
92_Static_assert(MESH_FD_NAME + MESH_FD_NAME_MAX < MESH_FD_TYPE, "FD_NAME + FD_NAME_MAX < FD_TYPE");
93
94#endif