Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/src/omega_fp8_slot_table.h # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / src / omega_fp8_slot_table.h` 77 lines · 3813 bytes Raw Blame History 1 #ifndef OMEGA_FP8_SLOT_TABLE_H 2 #define OMEGA_FP8_SLOT_TABLE_H 3 /* 4 * omega_fp8_slot_table: the host-only state machine behind omega_gpu_fp8_slots (Expert Ribbon, omega#533). 5 * No device code: every rule about who may read or rewrite a slot lives here so it can be tested without a chip. 6 * 7 * One record per slot: state, pins, key (caller's expert identity), version. 8 * EMPTY --begin_load--> LOADING --finish_load(ok)--> READY (version = next ring-wide version, never reused) 9 * LOADING --finish_load(fail)-> EMPTY (nothing published) 10 * READY --begin_load (0 pins)--> LOADING (the old version dies at that moment: pin(old) is STALE from then on) 11 * READY --evict (0 pins)--> EMPTY 12 * pin(slot, version) succeeds only on READY with exactly that version; begin_load and evict refuse (BUSY) while 13 * pins > 0. A pin is held for as long as any launch or recorded command list may read the slot; the caller drops it 14 * after the launch's completion marker (synchronous APIs: when the call returns; command lists: after submit). 15 * Versions are a single ring-wide counter starting at 1, so a (slot, version) pair names exactly one load (no ABA). 16 * Thread-safe (one mutex per table). 17 */ 18 #include 19 #include 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 enum { 25 OMEGA_FP8_SLOT_OK = 0, 26 OMEGA_FP8_SLOT_BAD_ARGS = -1, /* slot out of range, unpin without a pin, NULL */ 27 OMEGA_FP8_SLOT_BUSY = -6, /* pinned or already loading: nothing changed */ 28 OMEGA_FP8_SLOT_STALE = -7 /* the slot is not READY at that version (evicted, reloaded or never loaded) */ 29 }; 30 31 typedef enum { OMEGA_FP8_SLOT_EMPTY = 0, OMEGA_FP8_SLOT_LOADING = 1, OMEGA_FP8_SLOT_READY = 2 } OmegaFp8SlotState; 32 33 typedef struct { 34 uint32_t state; /* OmegaFp8SlotState */ 35 uint32_t pins; 36 uint64_t key; /* caller's identity of the loaded expert (meaningful in READY) */ 37 uint64_t version; /* version of the READY contents; 0 = never published */ 38 } OmegaFp8SlotRec; 39 40 typedef struct { 41 uint64_t loads; /* finish_load(ok) */ 42 uint64_t load_failures; /* finish_load(fail) */ 43 uint64_t busy_refusals; /* begin_load / evict refused because pinned or loading */ 44 uint64_t stale_refusals; /* pin refused */ 45 uint64_t evictions; 46 uint64_t pins; /* successful pins */ 47 uint32_t pinned_now; /* sum of pins over slots */ 48 uint32_t pinned_high; /* high-water of pinned_now */ 49 } OmegaFp8SlotStats; 50 51 typedef struct { 52 pthread_mutex_t mu; 53 uint32_t slots; 54 OmegaFp8SlotRec *rec; 55 uint64_t next_version; 56 int mutant; /* TEST ONLY: 1 = begin_load ignores pins (the negative control must catch a rewritten in-use slot) */ 57 OmegaFp8SlotStats stats; 58 } OmegaFp8SlotTable; 59 60 int omega_fp8_slot_table_init(OmegaFp8SlotTable *t, uint32_t slots); 61 void omega_fp8_slot_table_fini(OmegaFp8SlotTable *t); 62 int omega_fp8_slot_begin_load(OmegaFp8SlotTable *t, uint32_t slot); 63 /* ok != 0 publishes (READY, *version = new version); ok == 0 leaves the slot EMPTY. Must follow begin_load. */ 64 int omega_fp8_slot_finish_load(OmegaFp8SlotTable *t, uint32_t slot, uint64_t key, int ok, uint64_t *version); 65 int omega_fp8_slot_pin(OmegaFp8SlotTable *t, uint32_t slot, uint64_t version); 66 int omega_fp8_slot_unpin(OmegaFp8SlotTable *t, uint32_t slot, uint64_t version); 67 int omega_fp8_slot_evict(OmegaFp8SlotTable *t, uint32_t slot); 68 int omega_fp8_slot_query(OmegaFp8SlotTable *t, uint32_t slot, OmegaFp8SlotRec *out); 69 /* 1 when no slot is pinned or loading (safe to free the memory behind the table). */ 70 int omega_fp8_slot_table_idle(OmegaFp8SlotTable *t); 71 void omega_fp8_slot_table_stats(OmegaFp8SlotTable *t, OmegaFp8SlotStats *out); 72 void omega_fp8_slot_table_set_mutant(OmegaFp8SlotTable *t, int mutant); 73 74 #ifdef __cplusplus 75 } 76 #endif 77 #endif