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 / seed / tensix / README.md

138 lines · 10754 bytes Raw Blame History Rendered
1# seed/tensix: vecadd for the Tenstorrent Tensix RISC-V cores
2
3Each Tensix tile on Tenstorrent Wormhole (n150, n300) and Blackhole (p100, p150) cards contains five
4small RISC-V cores: RISCV B, NC, T0, T1 and T2. This directory writes a 32-bit integer vector add for
5these cores, `out[i] = a[i] + b[i]` modulo 2^32, and checks the result with outside tools.
6
7There are two producers of the kernel words, and the gate requires them to agree byte for byte.
8
91. **Seeded Omega (`irrv32.om`).** `seed/out/omc` builds `irrv32.om` into an AArch64 program. That program reads the OSC IR v1 of a scalar unit (`fn addu a uint b uint to uint`, in `vecadd.unit.om`) and lifts it into the elementwise loop `out[i] = f(a[i], b[i])`. The words are built from instruction fields inside Omega.
102. **Rung 6, as in `seed/sm121`.** The unchanged rung-2 assembler `seed/rung2/asm2.bin` reads a plain-text instruction table, `rv32im.tbl` (all 48 RV32I + M instructions), and hand-written listings.
11
12No C, Rust or Python program produces any instruction word.
13
14```sh
15seed/out/omc < seed/tensix/irrv32.om > irrv32 && chmod +x irrv32
16{ printf 'ir\n'; cat seed/tensix/vecadd.unit.om; } | seed/out/omc | ./irrv32 > vecadd.bin # 44 bytes
17```
18
19`irrv32` accepts exactly one function that takes two `uint` parameters and returns `uint`. The function must be a single block that uses only CONST (emitted as lui+addi), MOV (addi), BIN add/sub/mul/and/or/xor, and RET. It may use at most 7 vregs, which map to x5-x7 and then x14-x17. `div`, `rem`, `shl` and `shr` are refused, because Omega traps on a zero divisor or an out-of-range shift and this kernel has no trap path. Other types, control flow and calls are also refused. Every refusal sets a nonzero exit code (20-28) and writes no bytes.
20
21| File | What it is |
22|---|---|
23| `rv32im.tbl` | RV32IM encodings as asm2 table lines. Registers are written as numbers 0-31, because asm2's register parser uses ARM names. |
24| `irrv32.om` | Seeded Omega emitter: OSC IR v1 scalar uint unit → RV32IM elementwise kernel. |
25| `vecadd.unit.om` | The scalar unit `ret add a b`. Its emitted kernel must equal `vecadd.bin`. |
26| `mix.unit.om`, `mix.expect`, `mix-expect.hex` | A second unit, `((a+b)*3000000000) xor a`, which exercises CONST, MOV, mul and xor. It comes with its hand-written disassembly and 64 expected words. |
27| `vecadd.s2` | The kernel: 11 instructions, 44 bytes. a0 = a, a1 = b, a2 = out, a3 = n; it returns through ra. |
28| `vecadd.bin` | The committed kernel bytes. The gate rebuilds them twice and requires the same bytes both times. |
29| `boot-tt.s2` | 9 instructions placed at L1 0x0, where RISCV B starts after reset. It loads the arguments from 0x1000, calls vecadd, then writes the done mark 0x0600d000 to 0x1010 and spins. |
30| `boot-qemu.s2` | Linux user-mode start code for qemu. It calls vecadd, then makes the `write(1, out, 4n)` and `exit(0)` system calls. |
31| `edges.s2`, `edges.expect` | Every table entry once, with fields at their edge values. `edges.expect` is the disassembly written by hand before any disassembler was run. |
32| `vecadd.expect` | The expected disassembly of the kernel. |
33| `a.hex`, `b.hex`, `expect.hex` | 64 little-endian words each. The first six are hand-picked edge cases; 61 of the 64 sums wrap. |
34| `oracle.py` | The oracle driver: interop oracle, not Omega-native, and it never generates kernels. It loads ttsim and talks to it over PCIe the way a host driver would, or wraps an image in an ELF file for qemu. |
35| `gate-tensix.sh` | The gate script. |
36
37Expected values were computed in Wolfram with this query:
38`WolframLanguageEvaluator: a=Join[{0,2^32-1,2^31,2^31-1,2^32-1,16^^12345678}, Table[Mod[2654435761(i+1),2^32],{i,6,63}]]; b=Join[{0,1,2^31,1,2^32-1,16^^87654321}, Table[Mod[2^32-1-40503 i^2+977 i,2^32],{i,6,63}]]; Mod[a+b,2^32]`.
39It reported 64 words, of which 61 have a+b ≥ 2^32.
40`mix-expect.hex` uses the same `a` and `b` with `BitXor[Mod[Mod[a+b,2^32]*3000000000,2^32],a]`. The CONST split for 3000000000 is lui 0xb2d06, addi -512, also from Wolfram.
41
42## Run
43
44```sh
45mkdir -p build/oracle/ttsim-v1.15.0 && cd build/oracle/ttsim-v1.15.0
46for a in wh bh; do curl -LO https://github.com/tenstorrent/ttsim/releases/download/v1.15.0/libttsim_${a}_aarch64.so; done
47sha256sum libttsim_* # the gate refuses anything but the pinned sha256 values below
48cd - && nice -n 19 sh seed/tensix/gate-tensix.sh # 0 PASS, 1 FAIL, 3 NOT_RUN
49```
50
51The host must be AArch64 Linux, because asm2.bin is an AArch64 program. The gate also needs:
52
53- `riscv64-unknown-elf-objdump` and `riscv64-unknown-elf-objcopy`;
54- `llvm-objdump` (version 18);
55- `qemu-riscv32`;
56- `python3`.
57
58If any of these, or a ttsim library, is missing, the gate prints NOT_RUN and exits with code 3.
59
60## What the gate checks
61
62All of these checks are interop oracles, not Omega-native.
63
641. **Same bytes every build.** Each image is assembled twice and both builds must match byte for byte. The kernel must also equal the committed `vecadd.bin`, and both start images must end with exactly those bytes. omc (pinned sha256) builds `irrv32.om` twice; both builds must be identical. `irrv32` emits each unit twice. Its vecadd output must be byte-identical to asm2's `vecadd.bin`. GNU objdump must print exactly `mix.expect` for the mix kernel.
652. **Two independent disassemblers.**
66 - GNU objdump must print exactly `vecadd.expect` and `edges.expect`. These cover all 48 table names: 51 words in total.
67 - LLVM objdump must agree with GNU on every mnemonic and register.
683. **Three runs that compare results.** The kernel runs on:
69 - ttsim Wormhole (Tensix tile (1,1));
70 - ttsim Blackhole (Tensix tile (1,2));
71 - qemu-riscv32.
72
73 Each run must give all 64 sums equal to `expect.hex`. On ttsim, the output buffer is first filled with 0xee bytes, so a kernel that never ran cannot pass. The Omega-emitted vecadd and mix kernels then run on the same three oracles, behind the same start code, against `expect.hex` and `mix-expect.hex`.
744. **Negative controls.** Every one of these must be caught:
75 - C1: one bit flipped in the table (add becomes sub). Caught by GNU objdump and by ttsim.
76 - C2: one wrong expected value.
77 - C3: the wrong register in the listing. Caught by qemu.
78 - C4: one wrong branch-offset bit. ttsim stops with "invalid pc".
79 - C5: an out-of-range immediate. asm2 refuses it.
80 - C6: the unit mutated from add to sub. The emitted bytes change, and ttsim's output differs.
81 - C7: the emitter mutated (a0 stride 8). Caught by qemu.
82 - C8: a `div` unit. `irrv32` refuses it with exit 24 and emits 0 bytes.
83
84## What is established, and what is NOT
85
86**Established (EXERCISED on oracles, 2026-10-26):**
87
88- The table encodes RV32IM the way two independent disassemblers read it.
89- The kernel computes the right sums on ttsim's models of Wormhole B0 and Blackhole A0 RISCV B, and on qemu.
90- Seeded Omega (`irrv32.om`) emits the same vecadd bytes from the scalar unit's OSC IR, and a second kernel (mix) that is correct on the same three oracles.
91
92**NOT established:**
93
94- **Nothing has run on a Tenstorrent card** (NOT_RUN on hardware).
95- ttsim is Tenstorrent's software model, not silicon.
96- The fp32 SFPU path and the Tensix coprocessor (matrix unit) are not used.
97- `irrv32.om` covers straight-line u32 scalar bodies only. Signed types, traps, control flow, loops inside the body and Tensix coprocessor instructions are not lowered.
98- Only RISCV B is used, on a single tile.
99- There is no NoC traffic, no DRAM, and no tt-metal runtime.
100
101## What is open (sources read 2026-10-26)
102
103- **[tt-isa-documentation](https://github.com/tenstorrent/tt-isa-documentation)** at be833101 (code Apache-2.0, images CC BY-ND 4.0; `LICENSE_understanding.txt` notes that patent rights may be needed). It documents:
104 - the baby RISC-V cores. Wormhole is RV32IM. Blackhole adds Zicsr, Zaamo, Zba, Zbb, part of F/Zfh, and `.ttinsn`; T2 also has V.
105 - L1, soft reset, the PCIe TLB windows and NoC coordinates;
106 - about 120 Tensix coprocessor instructions, each with a bit-encoding diagram and a functional model (for example `TensixCoprocessor/MVMUL.md`).
107
108 Coprocessor instructions are pushed by RISC-V `sw` (`BabyRISCV/PushTensixInstruction.md`). So the RISC-V level, the coprocessor instruction level, and the host-to-tile path are all documented well enough for Omega to emit code without closed tools.
109- **[ttsim](https://github.com/tenstorrent/ttsim)** (Apache-2.0), source at b3620244. [Release v1.15.0](https://github.com/tenstorrent/ttsim/releases/tag/v1.15.0) was published 2026-10-25. Pinned libraries:
110 - `libttsim_wh_aarch64.so`: `e2a56ffe04072a10d477db1ef85cdbd5d392d9fc52043bb949b90a4c01ff6b4f`;
111 - `libttsim_bh_aarch64.so`: `2367dccc964c0ce4a20b14520e5f7ac6191bb227fb20e87aca1e94bf7432ced2`.
112- **[tt-metal](https://github.com/tenstorrent/tt-metal)**, **[tt-umd](https://github.com/tenstorrent/tt-umd)**, **[sfpi](https://github.com/tenstorrent/sfpi)** (GCC-based SFPU compiler) and **[tt-llk](https://github.com/tenstorrent/tt-llk)** are Apache-2.0. **[tt-kmd](https://github.com/tenstorrent/tt-kmd)** (the kernel driver) is GPL-2.0. Licences were read from the GitHub API on 2026-10-26. None of these is used here.
113- **RISC-V Unprivileged ISA 20191213**, chapters 2, 7 and 24, for the instruction formats.
114
115## Before a hardware receipt
116
1171. **A card.** An n150 or p150 card, or Tenstorrent cloud access. I have neither.
1182. **The kernel driver.** tt-kmd (GPL-2.0) must be loaded to map BAR0. The same TLB and soft-reset sequence that `oracle.py` uses on ttsim then works on the card. tt-umd does this from C++.
1193. **Firmware and tile choice.** On real cards the ARC firmware and the tt-metal firmware own the tiles. A raw run must use a tile that nothing else is using and must restore soft reset afterwards. Harvested rows and columns change which NoC coordinates are Tensix tiles.
1204. **Running beyond one tile.** NoC reads and writes are needed for DRAM inputs and for using many tiles.
1215. **What the receipt must contain.**
122 - the card model and serial;
123 - the firmware version;
124 - the tt-kmd version;
125 - the image sha256;
126 - the tile coordinates;
127 - the output compared with `expect.hex`;
128 - the same negative controls, run on the card.
129
130## Host dependencies (oracles only)
131
132| Dependency | Version | Role | Omega replacement |
133|---|---|---|---|
134| GNU objdump | binutils 2.42 | disassembler | none needed (read-only oracle) |
135| LLVM objdump | 18.1.3 | second disassembler | none needed (read-only oracle) |
136| ttsim | v1.15.0 | Tensix simulator | none needed (vendor oracle) |
137| qemu-riscv32 | 8.2.2 | RV32 executor | none needed (read-only oracle) |
138| Python | 3.12.3 | `oracle.py` byte transport | an `.om` host loader (dlopen/FFI word plus ELF byte writer; proposal) |