interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / src / omega_gpu_serving.h

64 lines · 3980 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/*
18 * omega_gpu_serving.h: OPT-IN up-front reservation of the GB10 serving buffers (sovereign-core design
19 * note docs/design/gb10-weight-ownership.md, sc#277).
20 *
21 * Without this call nothing changes: the attention staging pool, the matmul activation and result
22 * buffers and the matmul kernel cache grow on demand, which on the GB10 means one driver allocation
23 * per new context length and per row-count growth (omega PR #332 measured 458 after warm-up over 428
24 * tokens). With it, a daemon calls omega_gpu_reserve_serving once after loading weights, and every
25 * later call inside the declared bounds reuses the same buffers. A call outside the bounds is refused
26 * with TOO_LARGE and a clear omega_gpu_*_last_error() text ("serving reservation exceeded: need N
27 * bytes, reserved M"); it never asks the driver for more memory, so it cannot fault the session.
28 *
29 * Not covered (documented follow-ups): the elementwise API's scratch (it stops growing after the
30 * first full-size call), the attention kernel cache (8 slots, one kernel per model shape and context split count), and the
31 * first build of each distinct matmul shape unless the server prepares every shape it will run
32 * (omega_gpu_matmul_prepare: one small code buffer per shape, pinned) and then seals
33 * (omega_gpu_serving_seal): after that an unprepared shape is refused, never built.
34 */
35#ifndef OMEGA_GPU_SERVING_H
36#define OMEGA_GPU_SERVING_H
37
38#include <stdint.h>
39
40typedef struct {
41 uint32_t max_context; /* longest sequence (tokens) one attention call may cover */
42 uint32_t max_seqs; /* sequences per attention call; 0 = 1 */
43 uint32_t num_q_heads, num_kv_heads, head_dim; /* the model's attention shape */
44 uint32_t kv_block_size; /* paged KV block size in tokens (power of two); 0 = the paged bf16 path is not used */
45 uint32_t max_rows; /* most rows one matmul call may carry (prefill chunk) */
46 uint32_t max_k; /* widest weight input dimension */
47 uint32_t max_n; /* widest weight output dimension for calls of up to max_rows rows */
48 uint32_t max_n_one_row; /* widest output dimension for calls of at most 16 rows (lm_head); 0 = max_n */
49 uint32_t kernel_slots; /* matmul kernel cache slots; 0 = leave at 8; at most 128. Qwen3-4B, rows 1..256: 83 distinct kernels (grid_x and the row/column block vary with rows) */
50} OmegaGpuServingBounds;
51
52/* Opens the device if needed. 0 on success, else the first failing OMEGA_GPU_MATMUL_* / ATTN_* code
53 * (omega_gpu_matmul_last_error() has the text). All-or-nothing: each API rolls back its own buffers when one of its
54 * allocations fails, and this call rolls back the attention half when the matmul half fails, so a failed reserve
55 * leaves nothing flagged. Notes: a refused paged/batched attention call may follow earlier launch chunks that already
56 * wrote their outputs (TOO_LARGE = output incomplete); max_seqs is checked per launch chunk, not per call. */
57int omega_gpu_reserve_serving(const OmegaGpuServingBounds *b);
58
59/* After the server prepared its matmul shapes: refuse any unprepared one from now on (omega_gpu_matmul_seal). */
60void omega_gpu_serving_seal(void);
61/* Lift the reservation and the seal: buffers stay, growth is allowed again. (Closing the device also ends both.) */
62void omega_gpu_serving_release(void);
63
64#endif