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_gpu_q36_native.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_gpu_q36_native.h` 135 lines · 6530 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #ifndef OMEGA_GPU_Q36_NATIVE_H 3 #define OMEGA_GPU_Q36_NATIVE_H 4 #include "omega_gpu_native_runtime.h" 5 #include "omega_gpu_cmdlist_native.h" 6 /* Native append returns the successful command-list ordinal, not status zero. */ 7 static inline int omega_q36_native_record_status(int ordinal) { 8 #if defined(CUDAPP_MIGRATION_PENDING_LEFTOVERS) && CUDAPP_MIGRATION_PENDING_LEFTOVERS 9 return ordinal < 0 ? ordinal : 0; 10 #else 11 uint64_t result = UINT64_MAX; 12 (void)omega_leftovers(&result, 2, (uint64_t)(int64_t)ordinal, 0, 0, 0); 13 return (int)(int64_t)result; 14 #endif 15 } 16 /* Borrowed router-owner facts. The caller holds the session lock and consumes 17 * them before recording can replace either cached kernel. Exact encoded bytes 18 * exclude the code allocation's prefetch tail. This conveys no admission. */ 19 struct OmegaGpuRouter; 20 typedef struct { 21 OmegaGpuMem code, gate, norm, directory, launch_buffer; 22 uint64_t code_bytes; 23 uint64_t owner_generation, code_generation; 24 const uint64_t *gu_directory, *dn_directory; 25 uint32_t entries; 26 } OmegaGpuQ36RouterObservation; 27 int omega_gpu_q36_router_observe(const struct OmegaGpuRouter *, uint32_t layer, 28 uint64_t recorded_code_va, OmegaGpuQ36RouterObservation *); 29 /* Same mode-final callback in production and the existing typed HOST_ONLY 30 * platform oracle. Borrowed exact owner descriptors only, not an admission 31 * constructor. ordinal=UINT64_MAX matches every occurrence of that owner; 32 * GU/DN use their independently retained successful-add ordinal instead. */ 33 typedef struct { 34 OmegaGpuMem code; 35 uint64_t code_bytes, role, ordinal; 36 } OmegaGpuQ36MoeCode; 37 typedef struct { 38 uint64_t context[16]; 39 OmegaGpuQ36MoeCode code[272]; /* six-role variants plus selected pair windows */ 40 uint32_t code_count; 41 uint8_t nested[2048]; /* only actual groups10..21; cleared before projection */ 42 } OmegaGpuQ36MoeProjection; 43 int omega_gpu_q36_moe_project(const OmegaGpuCmdList *, 44 const OmegaGpuCmdListConsumed *, void *projection); 45 /* Independently retained source-owner identities, not an expected-wire view. 46 * Admission owns this immutable snapshot. No production constructor exists. 47 * Live code, launches, directories and allocations replace their groups. */ 48 typedef struct { 49 uint8_t hashes[2048]; 50 } OmegaGpuQ36NativeProvenance; 51 /* Private graph-owned, immutable accepted-record snapshot. No public setter, 52 * q-flag constructor, manifest-string activation, or new qualification store. 53 * Production construction stays absent until the independent evaluator/judge 54 * can supply an exact accepted receipt through the existing admission chain. 55 * A NULL state means no qualified native candidate, not a failed incumbent. */ 56 typedef struct { 57 uint64_t query[64], rows[1024]; 58 uint8_t wanted[4096], records[65536]; 59 OmegaGpuNativeArtifact artifact[16]; 60 OmegaGpuNativeLease prepared[16]; 61 const uint8_t *expected_closure; /* same retained full MC wire for paired GU/DN */ 62 const OmegaGpuQ36NativeProvenance *provenance; 63 } OmegaGpuQ36NativeState; 64 /* Private lookup keys identify actual graph operations, never qualification. 65 * Each operation/window owns its original immutable selector query and bytes. 66 * Paired MoE roles retain the same independently frozen expected closure. */ 67 typedef struct { 68 uint64_t keys[128], count; 69 OmegaGpuQ36NativeState *context; /* points inside the graph-owned immutable arena */ 70 } OmegaGpuQ36NativeGraph; 71 static inline int omega_q36_native_context(OmegaGpuQ36NativeGraph *g, 72 const uint64_t actual[4], OmegaGpuQ36NativeState **context) { 73 uint64_t bits = 0; 74 int64_t result; 75 *context = NULL; 76 if (!g) return 1; 77 if (omega_native_context_lookup(&bits, g->keys, 128, g->count, actual, 4) != OMEGA_OK) 78 return -1; 79 memcpy(&result, &bits, sizeof result); 80 #if defined(CUDAPP_MIGRATION_PENDING_LEFTOVERS) && CUDAPP_MIGRATION_PENDING_LEFTOVERS 81 if (result == 0) return 1; 82 if (result < 0 || !g->context) return -1; 83 #else 84 uint64_t disposition = UINT64_MAX; 85 (void)omega_leftovers(&disposition, 5, bits, g->context != NULL, 0, 0); 86 if (disposition != 0) return (int)(int64_t)disposition; 87 #endif 88 /* The generated unique-match resolver bounds result to 1..count<=32. */ 89 *context = &g->context[(uint64_t)result - 1]; 90 return 0; 91 } 92 static inline int omega_q36_native_begin_selected(OmegaGpuQ36NativeState *s, OmegaGpuNativeCache *cache, 93 const OmegaGpuNativeArtifact **artifact, OmegaGpuNativeLease *lease, const uint64_t **row) { 94 uint64_t out[32] = {0}, result = 0; 95 if (row) *row = NULL; 96 if (!s) return 1; 97 if (omega_native_graph(&result, s->query, 64, s->rows, 1024, cache->pool, 528, 98 s->wanted, 4096, s->records, 65536, out, 32) != OMEGA_OK || result != 0) return -1; 99 /* The generated resolver already bounds the immutable ordinal to <16. */ 100 *artifact = &s->artifact[out[1]]; 101 *lease = (OmegaGpuNativeLease){cache, out[17], out[18], out[19]}; 102 /* The returned lease pins the selected exact resident realization. Recording 103 * takes its own reference; the temporary selection pin is always released. */ 104 if (omega_native_bound(*artifact, lease) != 0) { 105 (void)omega_native_lease_op(lease, 9, 0); 106 *lease = (OmegaGpuNativeLease){0}; 107 return -1; 108 } 109 if (row) *row = s->rows + out[1] * 64; 110 return 0; 111 } 112 static inline int omega_q36_native_begin(OmegaGpuQ36NativeState *s, OmegaGpuNativeCache *cache, 113 const OmegaGpuNativeArtifact **artifact, OmegaGpuNativeLease *lease) { 114 return omega_q36_native_begin_selected(s, cache, artifact, lease, NULL); 115 } 116 static inline void omega_q36_native_end(const OmegaGpuNativeLease *lease) { 117 (void)omega_native_lease_op(lease, 9, 0); 118 } 119 static inline void omega_q36_native_release(OmegaGpuQ36NativeState *s) { 120 if (!s) return; 121 for (unsigned i = 0; i < 16; ++i) 122 if (s->prepared[i].cache) (void)omega_native_lease_op(&s->prepared[i], 5, 0); 123 } 124 static inline void omega_q36_native_graph_release(OmegaGpuQ36NativeGraph *g) { 125 if (!g || !g->context) return; 126 #if defined(CUDAPP_MIGRATION_PENDING_LEFTOVERS) && CUDAPP_MIGRATION_PENDING_LEFTOVERS 127 for (uint64_t i = 0; i < g->count && i < 32; ++i) 128 #else 129 /* Iteration invokes host lease effects; Omega decides the bounded extent. */ 130 for (uint64_t i = 0, more = 0; 131 omega_leftovers(&more, 6, g->count, i, 0, 0) == OMEGA_OK && more; ++i) 132 #endif 133 omega_q36_native_release(&g->context[i]); 134 } 135 #endif