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/omega-mv/blob/main/src/omega_gpu_platform.h # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / omega_gpu_platform.h` 267 lines ยท 16042 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* omega_gpu_platform.h -- native platform contract for the Omega GPU engine. 18 * 19 * Native v1 P07 cut A (aienos#286 cut A, aien-architecture#190). This header 20 * names what a GPU backend may ask of the platform it runs on, in a form that 21 * works the same under Linux (today's nvrm/m16 backend) and under AIENOS 22 * (the native backend of later cuts). It is pure C with no Linux header and 23 * no libc call; it builds in the freestanding link target 24 * (`make gpu-engine-freestanding`). 25 * 26 * Rules (from aienos#286 cut A): 27 * - Resources are typed handles (index + generation), never a Linux fd, a 28 * raw pointer or an unchecked physical address. A handle is valid only 29 * while its slot generation matches, so a closed handle is refused. 30 * - Every byte range carries an explicit length and explicit rights. 31 * - CPU views, GPU virtual addresses and bus (SMMU input) addresses are 32 * three distinct types. There is no type for a raw physical address on 33 * purpose: the native backend resolves DMA through the SMMU (cut B). 34 * - Buffers, code and queues have separate kinds and lifetimes. 35 * - A backend negotiates an ABI version and a service set up front; what 36 * the platform does not provide is refused, never emulated. There is no 37 * silent fallback to Linux, to the CPU, or to a remote device. 38 * - Polling a word is not interrupt support: OMEGA_GPU_SVC_IRQ is claimed 39 * only by a platform whose irq_wait blocks on a real device interrupt. 40 * - Anything the CPU polls for a device write (completion markers, 41 * semaphores) is OMEGA_GPU_RIGHT_HOST_POLLED and must be GPU-uncached 42 * (nvidia-open 580.173.02 nvos.h: GPU-cacheable system memory "will not 43 * be coherent with direct CPU mappings"; the 2026-10-02 E1 stall). 44 * 45 * What this header does NOT claim: no device has been opened through it, no 46 * GB10 register has been touched, and the Linux backend still owns every 47 * driver responsibility (docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md). Hardware 48 * evidence for device ownership is NOT_RUN until cut B runs in an attended 49 * window. 50 */ 51 #ifndef OMEGA_GPU_PLATFORM_H 52 #define OMEGA_GPU_PLATFORM_H 53 54 #include 55 #include 56 57 #define OMEGA_GPU_PLATFORM_ABI_MAJOR 1u 58 /* minor: additive change (a service bit or a caps field appended); negotiate refuses a provided minor older than the 59 * required one. 1.1 (P07 cut C session part): DEVICE, QUEUE, CLOCK_NS, HOST_MEM; COMPLETION is poll_word. 60 * 1.2 (omega #457/#459): caps.submit_prefix_words. */ 61 #define OMEGA_GPU_PLATFORM_ABI_MINOR 2u 62 63 /* ---- typed handles ------------------------------------------------------ */ 64 65 /* Generation 0 is never issued, so a zeroed handle is "none". */ 66 typedef struct { uint32_t index; uint32_t generation; } OmegaGpuDeviceHandle; 67 typedef struct { uint32_t index; uint32_t generation; } OmegaGpuBufferHandle; 68 typedef struct { uint32_t index; uint32_t generation; } OmegaGpuQueueHandle; 69 70 /* Handle kinds (also the buffer kinds below share the BUF_* space). */ 71 typedef enum { 72 OMEGA_GPU_HANDLE_DEVICE = 1, 73 OMEGA_GPU_HANDLE_BUF_DATA = 2, /* inputs, outputs, scratch */ 74 OMEGA_GPU_HANDLE_BUF_CODE = 3, /* kernel code: CPU writes once, GPU executes, GPU never writes */ 75 OMEGA_GPU_HANDLE_BUF_QUEUE = 4, /* pushbuffer / submission ring */ 76 OMEGA_GPU_HANDLE_QUEUE = 5, /* a channel or submission queue */ 77 OMEGA_GPU_HANDLE_KIND_COUNT 78 } OmegaGpuHandleKind; 79 80 /* ---- address kinds ------------------------------------------------------ */ 81 82 typedef struct { void *ptr; size_t len; } OmegaCpuView; /* CPU mapping with its length */ 83 typedef struct { uint64_t va; } OmegaGpuVa; /* GPU virtual address (device page tables) */ 84 typedef struct { uint64_t iova; } OmegaGpuBusAddr; /* what the device emits on the fabric (SMMU input) */ 85 86 /* ---- rights and buffer descriptors -------------------------------------- */ 87 88 enum { 89 OMEGA_GPU_RIGHT_CPU_READ = 1u << 0, 90 OMEGA_GPU_RIGHT_CPU_WRITE = 1u << 1, 91 OMEGA_GPU_RIGHT_GPU_READ = 1u << 2, 92 OMEGA_GPU_RIGHT_GPU_WRITE = 1u << 3, 93 OMEGA_GPU_RIGHT_GPU_EXEC = 1u << 4, /* code buffers only */ 94 OMEGA_GPU_RIGHT_HOST_POLLED = 1u << 5, /* CPU polls a device write here: must be GPU-uncached */ 95 OMEGA_GPU_RIGHT_ALL = (1u << 6) - 1u 96 }; 97 98 typedef enum { OMEGA_GPU_CACHE_GPU_UNCACHED = 0, OMEGA_GPU_CACHE_GPU_CACHED = 1 } OmegaGpuCachePolicy; 99 100 typedef struct { 101 uint32_t kind; /* OMEGA_GPU_HANDLE_BUF_DATA, _BUF_CODE or _BUF_QUEUE */ 102 uint32_t rights; /* OMEGA_GPU_RIGHT_* mask, never 0 */ 103 uint32_t gpu_cache; /* OmegaGpuCachePolicy */ 104 uint32_t align; /* bytes, a power of two, 0 means the platform minimum */ 105 uint64_t bytes; /* explicit length, never 0 */ 106 } OmegaGpuBufferDesc; 107 108 /* ---- services and capabilities ------------------------------------------ */ 109 110 enum { 111 OMEGA_GPU_SVC_TIME = 1u << 0, /* monotonic millisecond clock */ 112 OMEGA_GPU_SVC_WAIT = 1u << 1, /* bounded sleep or yield */ 113 OMEGA_GPU_SVC_LOCK = 1u << 2, /* mutual exclusion for queues and tables */ 114 OMEGA_GPU_SVC_MMIO = 1u << 3, /* bounded register access by device handle and region */ 115 OMEGA_GPU_SVC_DMA = 1u << 4, /* device-visible memory with CPU view, GPU VA and bus address */ 116 OMEGA_GPU_SVC_SYNC = 1u << 5, /* explicit CPU<->GPU visibility (cache maintenance, flush) */ 117 OMEGA_GPU_SVC_COMPLETION = 1u << 6, /* POLL an uncached word (poll_word); polling is never an interrupt */ 118 OMEGA_GPU_SVC_IRQ = 1u << 7, /* real device interrupt wait; polling never counts */ 119 OMEGA_GPU_SVC_REQUIRED_V1 = OMEGA_GPU_SVC_TIME | OMEGA_GPU_SVC_WAIT | OMEGA_GPU_SVC_LOCK | 120 OMEGA_GPU_SVC_MMIO | OMEGA_GPU_SVC_DMA | OMEGA_GPU_SVC_SYNC | 121 OMEGA_GPU_SVC_COMPLETION, 122 /* ABI 1.1: what the persistent GPU session (src/omega_gpu_session.c) needs on top of v1 */ 123 OMEGA_GPU_SVC_DEVICE = 1u << 8, /* open / close one device context, driver text of the last failure */ 124 OMEGA_GPU_SVC_QUEUE = 1u << 9, /* submission queue over a BUF_QUEUE ring: open, submit, retire, close */ 125 OMEGA_GPU_SVC_CLOCK_NS = 1u << 10, /* monotonic nanosecond clock (launch timing) */ 126 OMEGA_GPU_SVC_HOST_MEM = 1u << 11, /* CPU-only memory for tables and staging (never device-visible) */ 127 OMEGA_GPU_SVC_REQUIRED_SESSION = OMEGA_GPU_SVC_TIME | OMEGA_GPU_SVC_WAIT | OMEGA_GPU_SVC_LOCK | 128 OMEGA_GPU_SVC_DMA | OMEGA_GPU_SVC_SYNC | OMEGA_GPU_SVC_COMPLETION | 129 OMEGA_GPU_SVC_DEVICE | OMEGA_GPU_SVC_QUEUE | OMEGA_GPU_SVC_CLOCK_NS | 130 OMEGA_GPU_SVC_HOST_MEM, 131 OMEGA_GPU_SVC_ALL = (1u << 12) - 1u 132 }; 133 134 typedef struct { 135 uint32_t abi_major; 136 uint32_t abi_minor; 137 uint32_t services; /* OMEGA_GPU_SVC_* provided (or required) */ 138 uint32_t max_devices; 139 uint32_t max_buffers; /* live buffer handles */ 140 uint32_t max_queues; 141 uint32_t max_inflight; /* jobs in flight per queue (concurrency limit) */ 142 uint64_t max_buffer_bytes; /* one buffer */ 143 uint64_t max_total_bytes; /* all live buffers */ 144 uint32_t submit_prefix_words; /* ABI 1.2: most words queue_submit may put ahead of the caller's words in the ring (the Linux 145 * reference: the omega #457 L2 invalidate); a caller filling the ring budgets 146 * ring words minus this. 0 = never. Not negotiated. */ 147 } OmegaGpuPlatformCaps; 148 149 /* ---- refusals ----------------------------------------------------------- */ 150 151 typedef enum { 152 OMEGA_GPU_PLAT_OK = 0, 153 OMEGA_GPU_PLAT_REFUSED_ARGS, /* NULL or malformed argument */ 154 OMEGA_GPU_PLAT_REFUSED_ABI, /* major differs, or provided minor older than required */ 155 OMEGA_GPU_PLAT_REFUSED_MISSING_SERVICE, /* a required service is not provided */ 156 OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE, /* a claimed service has no function */ 157 OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE, /* index out of range or kind mismatch */ 158 OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE, /* generation mismatch: closed or never opened */ 159 OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH, /* zero length */ 160 OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS, /* empty, unknown or contradictory rights */ 161 OMEGA_GPU_PLAT_REFUSED_BAD_KIND, /* unknown kind */ 162 OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY, /* host-polled buffer asked to be GPU-cached */ 163 OMEGA_GPU_PLAT_REFUSED_LIMIT, /* a capability limit would be exceeded */ 164 OMEGA_GPU_PLAT_REFUSED_BUSY, /* concurrency limit reached */ 165 OMEGA_GPU_PLAT_REFUSED_DEVICE, /* 1.1: the device or its driver refused (diag_text says why) */ 166 OMEGA_GPU_PLAT_REFUSAL_COUNT 167 } OmegaGpuPlatformRefusal; 168 169 const char *omega_gpu_platform_refusal_name(int refusal); /* static strings, never NULL */ 170 171 /* poll_word result when the word did not reach the value in time (not a refusal: nothing was wrong with the call). */ 172 #define OMEGA_GPU_POLL_TIMED_OUT 100 173 174 /* ---- the platform service table ----------------------------------------- */ 175 176 typedef struct { 177 void *ctx; 178 /* TIME, WAIT, LOCK */ 179 uint64_t (*time_now_ms)(void *ctx); 180 int (*wait_ms)(void *ctx, uint64_t ms); 181 int (*lock)(void *ctx, uint32_t lock_id); 182 int (*unlock)(void *ctx, uint32_t lock_id); 183 /* MMIO: bounded by (device, region); the platform refuses an offset past the region. */ 184 int (*mmio_read32)(void *ctx, OmegaGpuDeviceHandle dev, uint32_t region, uint64_t offset, uint32_t *out); 185 int (*mmio_write32)(void *ctx, OmegaGpuDeviceHandle dev, uint32_t region, uint64_t offset, uint32_t value); 186 /* DMA: one allocation yields a handle plus the three views; free by handle only. */ 187 int (*dma_alloc)(void *ctx, OmegaGpuDeviceHandle dev, const OmegaGpuBufferDesc *desc, 188 OmegaGpuBufferHandle *out, OmegaCpuView *cpu, OmegaGpuVa *gpu, OmegaGpuBusAddr *bus); 189 int (*dma_free)(void *ctx, OmegaGpuBufferHandle buf); 190 /* SYNC: explicit visibility over a byte range of one buffer. */ 191 int (*sync_cpu_to_gpu)(void *ctx, OmegaGpuBufferHandle buf, uint64_t offset, uint64_t len); 192 int (*sync_gpu_to_cpu)(void *ctx, OmegaGpuBufferHandle buf, uint64_t offset, uint64_t len); 193 /* COMPLETION, by POLLING (never an interrupt): read one GPU-uncached 32-bit word of a HOST_POLLED buffer until 194 * it has reached expected in serial-number order, (int32_t)(word - expected) >= 0 (the m16_native_wait_marker 195 * rule), or timeout_ms passes. 0 reached, OMEGA_GPU_POLL_TIMED_OUT not reached, else a refusal. *observed is 196 * the last value read. A timeout says nothing about the device: the work may still be running. */ 197 int (*poll_word)(void *ctx, OmegaGpuBufferHandle buf, uint64_t offset, uint32_t expected, 198 uint64_t timeout_ms, uint32_t *observed); 199 /* IRQ: NULL unless OMEGA_GPU_SVC_IRQ is claimed. */ 200 int (*irq_wait)(void *ctx, OmegaGpuDeviceHandle dev, uint64_t timeout_ms); 201 /* ---- ABI 1.1 ---- */ 202 /* DEVICE: open the device context with this ordinal (0 = the one GB10), close it. Closing makes every buffer and 203 * queue handle of the device stale. diag_text: driver text of the most recent failure, "" if none, never NULL. */ 204 int (*device_open)(void *ctx, uint32_t ordinal, OmegaGpuDeviceHandle *out); 205 int (*device_close)(void *ctx, OmegaGpuDeviceHandle dev); 206 const char *(*diag_text)(void *ctx); 207 /* QUEUE: a submission queue whose ring is a BUF_QUEUE buffer of the same device. queue_submit copies nwords method 208 * words into the ring and rings the doorbell (one GPFIFO entry); queue_retire marks every submitted entry consumed 209 * and is called only after the caller saw that work complete. A refused queue_submit rang no doorbell: nothing of it is in 210 * flight (m16_native_submit_methods fails before nvrm_ring). */ 211 int (*queue_open)(void *ctx, OmegaGpuDeviceHandle dev, OmegaGpuBufferHandle ring, OmegaGpuQueueHandle *out); 212 int (*queue_close)(void *ctx, OmegaGpuQueueHandle q); 213 int (*queue_submit)(void *ctx, OmegaGpuQueueHandle q, const uint32_t *words, uint32_t nwords); 214 int (*queue_retire)(void *ctx, OmegaGpuQueueHandle q); 215 /* CLOCK_NS */ 216 uint64_t (*time_now_ns)(void *ctx); 217 /* HOST_MEM: NULL on refusal; host_free(NULL) is a no-op. */ 218 void *(*host_alloc)(void *ctx, size_t bytes); 219 void (*host_free)(void *ctx, void *p); 220 } OmegaGpuPlatform; 221 222 /* ---- contract checks (pure, freestanding) -------------------------------- */ 223 224 /* Version and service negotiation. required.services must be a subset of 225 * provided.services, required limits must not exceed provided limits. */ 226 int omega_gpu_platform_negotiate(const OmegaGpuPlatformCaps *provided, const OmegaGpuPlatformCaps *required); 227 228 /* Every service in caps->services has a function in p; every function 229 * outside caps->services is NULL (no undeclared service, no fallback); the 230 * v1 required set is present. */ 231 int omega_gpu_platform_check(const OmegaGpuPlatform *p, const OmegaGpuPlatformCaps *caps); 232 /* The same, requiring the service set `required` (for example OMEGA_GPU_SVC_REQUIRED_SESSION) instead of the v1 set. 233 * omega_gpu_platform_check(p, caps) is omega_gpu_platform_check_for(p, caps, OMEGA_GPU_SVC_REQUIRED_V1). */ 234 int omega_gpu_platform_check_for(const OmegaGpuPlatform *p, const OmegaGpuPlatformCaps *caps, uint32_t required); 235 236 /* Buffer descriptor rules: kind known, length non-zero and within caps, 237 * rights non-empty and consistent with the kind, host-polled means 238 * GPU-uncached, align a power of two. */ 239 int omega_gpu_platform_check_buffer(const OmegaGpuBufferDesc *d, const OmegaGpuPlatformCaps *caps); 240 241 /* ---- handle table (index + generation) ----------------------------------- */ 242 243 #define OMEGA_GPU_HANDLE_SLOTS 4096u /* 1.1: a serving session holds one buffer per weight tensor (Qwen3-8B: ~260); 244 * speed5/batching: each Qwen3.8 conversation slot adds about 29 (16 KV planes, the 245 * DeltaNet state, launch buffers), so 32 slots on top of the 27B weights passed 1024 */ 246 247 typedef struct { 248 uint32_t generation[OMEGA_GPU_HANDLE_SLOTS]; /* next generation to issue for the slot; starts at 1 */ 249 uint32_t kind[OMEGA_GPU_HANDLE_SLOTS]; 250 uint64_t bytes[OMEGA_GPU_HANDLE_SLOTS]; 251 uint8_t live[OMEGA_GPU_HANDLE_SLOTS]; 252 uint32_t nlive; 253 uint64_t total_bytes; 254 } OmegaGpuHandleTable; 255 256 void omega_gpu_handles_init(OmegaGpuHandleTable *t); 257 /* Opens a slot of the given kind. limit_slots caps live handles of that kind. 258 * bytes is accounted against limit_bytes across all slots; devices and queues 259 * pass bytes 0 and are not byte-accounted. */ 260 int omega_gpu_handles_open(OmegaGpuHandleTable *t, uint32_t kind, uint64_t bytes, uint32_t limit_slots, 261 uint64_t limit_bytes, uint32_t *index, uint32_t *generation); 262 /* OK only for a live slot whose generation and kind match. */ 263 int omega_gpu_handles_check(const OmegaGpuHandleTable *t, uint32_t index, uint32_t generation, uint32_t kind); 264 /* Closes a live, matching slot and bumps its generation so the old handle is stale. */ 265 int omega_gpu_handles_close(OmegaGpuHandleTable *t, uint32_t index, uint32_t generation, uint32_t kind); 266 267 #endif /* OMEGA_GPU_PLATFORM_H */