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_numeric_ldst_gb10.h

94 lines · 5093 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#ifndef OMEGA_NUMERIC_LDST_GB10_H
18#define OMEGA_NUMERIC_LDST_GB10_H
19/*
20 * E1 row 2: general global load/store on the GB10 (docs/numeric/E1_LDST_GB10.md).
21 *
22 * Contract. One thread per element i < count copies one element from the input
23 * to the output through the register file:
24 * reg = LOAD_ld ( in + i * in_stride + in_off )
25 * STORE_st( out + i * out_stride + out_off, reg )
26 * ld is U8, S8, U16, S16 (zero or sign extended to 32 bits), B32, B64 or B128.
27 * st is B8, B16, B32, B64 or B128 (the low st bytes of the register file,
28 * little endian). Strides are byte counts applied with a 64-bit multiply-add,
29 * offsets are signed 24-bit byte offsets in the instruction.
30 *
31 * Rules (omega_ldst_check_spec): a store may not be wider than what the load
32 * filled (4 bytes for the narrow loads, else the load width); stride and
33 * offset of each side are multiples of that side's width and the stride is at
34 * least the width (so output elements never overlap); stride < 2^24; offset in
35 * [-2^23, 2^23); count <= OMEGA_DS_MAX_BATCH. Buffer bases are 16-byte aligned.
36 *
37 * Encodings (every field below was read back with nvdisasm 13.0.85 -b SM121 as
38 * an offline decoder, see tools/ldst_nvdisasm_check.sh):
39 * LDG: w0 = 0x7981 | Rd<<16 | Ra<<24; w1 = UR | off24<<8;
40 * w2 = 0x0c1e1100 | size<<9; size 0 U8, 1 S8, 2 U16, 3 S16, 4 32, 5 64, 6 128
41 * STG: w0 = 0x7986 | Ra<<24; w1 = Rdata | off24<<8;
42 * w2 = 0x0c100004 | 0x1100 | size<<9 (UR4); size 0 8, 2 16, 4 32, 5 64, 6 128
43 * IMAD.WIDE.U32 imm: w1 = imm (the stride in bytes).
44 * The kernel keeps the 17 verified prologue words of the vecadd kernel
45 * (src/omega_blackwell_encoder.c); only the words above are new.
46 */
47#include <stddef.h>
48#include <stdint.h>
49
50typedef enum { OMEGA_LD_U8 = 0, OMEGA_LD_S8, OMEGA_LD_U16, OMEGA_LD_S16, OMEGA_LD_B32, OMEGA_LD_B64, OMEGA_LD_B128, OMEGA_LD_COUNT } OmegaLdKind;
51typedef enum { OMEGA_ST_B8 = 0, OMEGA_ST_B16, OMEGA_ST_B32, OMEGA_ST_B64, OMEGA_ST_B128, OMEGA_ST_COUNT } OmegaStKind;
52
53typedef struct {
54 uint8_t ld, st;
55 uint32_t in_stride, out_stride; /* bytes */
56 int32_t in_off, out_off; /* bytes, signed 24-bit */
57} OmegaLdstSpec;
58
59#define OMEGA_LDST_CODE_BYTES 384u /* 24 instructions */
60#define OMEGA_LDST_PAD 0x10000u /* bytes in front of element 0 the executor allocates, so negative offsets stay in the buffer */
61
62size_t omega_ld_bytes(OmegaLdKind k);
63size_t omega_st_bytes(OmegaStKind k);
64const char *omega_ldst_describe(const OmegaLdstSpec *s, char *buf, size_t len);
65
66/* 0 ok, -1 refused with the reason in why. */
67int omega_ldst_check_spec(const OmegaLdstSpec *s, size_t count, char *why, size_t why_len);
68
69/* Lowest and one-past-highest byte (relative to the base) each side touches over count elements. */
70int omega_ldst_extent(const OmegaLdstSpec *s, size_t count, int64_t *in_lo, int64_t *in_hi, int64_t *out_lo, int64_t *out_hi);
71
72/* The kernel image, its expected nvdisasm listing (one "addr text ;" line per instruction), a
73 * structural check (rebuilds the kernel from the fields it decodes and compares every byte). */
74int omega_ldst_build_kernel(const OmegaLdstSpec *s, uint8_t *code, size_t max, size_t *out_len);
75int omega_ldst_listing(const OmegaLdstSpec *s, char *buf, size_t len);
76int omega_ldst_check_kernel(const OmegaLdstSpec *s, const uint8_t *code, size_t len, char *why, size_t why_len);
77
78/* Host model. in/out point at element-0 base addresses; in_len/out_len are the bytes available
79 * from lo_pad bytes before the base to the end. Returns 0, or -1 when any access leaves
80 * [-pad, len-pad) or the spec is refused. */
81int omega_ldst_host_run(const OmegaLdstSpec *s, const uint8_t *in_buf, size_t in_len, uint8_t *out_buf, size_t out_len,
82 size_t pad, size_t count);
83
84/* GB10: same contract on the chip. in_buf/out_buf are whole buffers with pad bytes before element 0;
85 * out_buf is copied in first (so the caller's fill pattern is what unwritten bytes read back as)
86 * and copied back after. OMEGA_NUMERIC_* code; OMEGA_NUMERIC_ERR_DEVICE in a CPU-only build. */
87int omega_ldst_gb10_run(const OmegaLdstSpec *s, const uint8_t *in_buf, size_t in_len, uint8_t *out_buf, size_t out_len,
88 size_t pad, size_t count);
89
90
91/* Label printed in the OMEGA_DEVERR stderr line (spec=<id>); the chip harness sets the table index. Default -1. */
92void omega_ldst_gb10_set_spec_id(int id);
93
94#endif