==> include/mesh/needs.h <==1/* @ajax/mesh-manifest-needs: what a program needs and prefers (its manifest's
2 * scheduling keys), ported from mesh-host sched.rs's Replicas, Migrate, Term
3 * and Needs. The manifest parser fills it; the fleet scheduler reads it.
4 * Term::matches (which needs the scheduler's Member) stays with the scheduler. */
5#ifndef MESH_NEEDS_H
6#define MESH_NEEDS_H
7
8#include "mesh/text.h"
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13
14/* Replicas: All, or N(n). */
15typedef struct {
16 bool all;
17 uint32_t n;
18} mesh_replicas;
19
20/* How the scheduler may move a program: with its view, by a fresh start elsewhere, or not at all. */
21typedef enum { MESH_MIGRATE_STATE, MESH_MIGRATE_RESTART, MESH_MIGRATE_NEVER } mesh_migrate;
22const char *mesh_migrate_word(mesh_migrate m); /* "state", "restart", "never" */
23
24/* A placement term (`prefer`, `avoid`, `group_members`). */
25typedef enum { MESH_TERM_BACKEND, MESH_TERM_HOST, MESH_TERM_SYSTEM, MESH_TERM_ARCH } mesh_term_kind;
26typedef struct {
27 mesh_term_kind kind;
28 char *s; /* BACKEND, HOST, ARCH */
29 uint32_t system; /* SYSTEM */
30} mesh_term;
31
32/* "cuda", "host:NAME", "system:K" (K < MAX_SYSTEMS), "arch:A". False with *err:
33 * "\"x\": a backend (cuda, metal, wasm, native), \"host:NAME\", \"system:K\" or \"arch:A\"". */
34bool mesh_term_parse(const char *s, mesh_term *out, char **err);
35char *mesh_term_word(const mesh_term *t); /* "cuda", "host:dgx-00", "system:3", "arch:x86_64" */
36bool mesh_term_eq(const mesh_term *a, const mesh_term *b);
37void mesh_term_copy(mesh_term *dst, const mesh_term *src);
38void mesh_term_free(mesh_term *t);
39
40typedef struct mesh_needs {
41 char **backends;
42 size_t nbackends;
43 char *arch; /* NULL: any */
44 uint32_t min_mem_mb;
45 mesh_term *prefer;
46 size_t nprefer;
47 mesh_term *avoid;
48 size_t navoid;
49 mesh_replicas replicas;
50 bool pack;
51 char *colocate_with; /* NULL: none */
52 /* The programs it feeds (pipes): a migration stops a producer before its consumer. */
53 char **feeds;
54 size_t nfeeds;
55 char *group; /* NULL: none */
56 uint32_t group_size; /* 0: every eligible member */
57 mesh_term *group_members;
58 size_t ngroup_members;
59 int32_t priority;
60 /* Reservations: CPU cores and MiB. */
61 float cpu;
62 uint32_t mem_mb;
63 mesh_migrate migrate;
64 bool lockstep;
65 uint32_t view_bytes;
66 /* A GPU node's shape (manifest warps, shared_bytes). */
67 uint32_t warps;
68 uint32_t shared;
69} mesh_needs;
70
71/* Needs::default(): backends ["cuda"], replicas All, migrate State, warps 1. */
72void mesh_needs_default(mesh_needs *n);
73void mesh_needs_copy(mesh_needs *dst, const mesh_needs *src);
74bool mesh_needs_eq(const mesh_needs *a, const mesh_needs *b);
75void mesh_needs_free(mesh_needs *n);
76/* Rust's derived `{:?}`: Needs { backends: ["cuda"], arch: None, ... }. */
77void mesh_needs_debug(mesh_text *t, const mesh_needs *n);
78void mesh_term_debug(mesh_text *t, const mesh_term *x);
79
80/* Helpers for string lists ({:?} of Vec<String>, copies). */
81void mesh_strs_debug(mesh_text *t, char *const *v, size_t n);
82char **mesh_strs_copy(char *const *v, size_t n);
83void mesh_strs_free(char **v, size_t n);
84bool mesh_strs_eq(char *const *a, size_t an, char *const *b, size_t bn);
85
86#endif