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 / kflow / TILE-WORDS.md

64 lines · 3754 bytes Raw Blame History Rendered
1# Tile words for OMEGESE: proposal (PROPOSED, not implemented)
2
3Status: PROPOSED. No compiler, encoder or table changed for this proposal. The two hand-written listings
4`sm121/tmatmul16.s2` and `sm121/tsoftmax.s2` are what these words should generate, instruction for
5instruction; they are EXERCISED on the host (kflow encode, verify, package, emulate) and NOT_RUN on a GPU.
6
7## Why words, not a library
8
9Both listings were written by hand from the PTX ISA 9.4 fragment tables. Most of their 46 and 38 instructions (plus a padding NOP each)
10are fragment addressing (lane to row and column, offsets, packing two f16 into one register), and the one real
11bug found so far was a register clobber in a butterfly (README, "Tile kernels"). Those are exactly the parts a
12compiler should own: the writer states the tile shapes, the compiler picks the fragment layout and registers.
13
14## Words
15
16Prefix order and argument conventions as in OM-2. Types: `f16`, `bf16`, `f32` element types; a tile value
17is `tile T R C` (rows, columns), held in registers spread over the 32 lanes of a warp. Only shapes the target
18has a table row for are accepted; anything else is a compile error, never a silent fallback.
19
20| word | meaning | sm_121 lowering (rows in `seed/sm121/sm121.tbl`) |
21| --- | --- | --- |
22| `tload T R C P ld` | load an R x C tile of T from global P (row stride `ld` elements) into the fragment layout the next `tmma` needs | `ldg.0`/`ldg.w.1`/`ldg.2` (32-bit pairs along a row), `ldg.u16.2` + IMAD pack (pairs down a column) |
23| `tmma A B C` | D = A x B + C, f32 accumulate; A `tile f16 16 16`, B `tile f16 16 N` (N = 8k), C `tile f32 16 N` or `0` | one `hmma.0`/`hmma.f16.2` (bf16: `hmma.bf16.2`) per 8 columns; `0` lowers to RZ |
24| `tstore P ld D` | store an f32 tile from the accumulator layout | `stg.0`/`stg.1`/`stg.2` |
25| `wmax x` / `wsum x` | the maximum / sum of x over the 32 lanes, the same value in every lane | 5 x (`shfl.0`/`shfl.bfly.1`/`shfl.2` into a fresh register, then `fmnmx.max.2` or `fadd`) |
26| `ex2 x` / `rcp x` | approximate 2^x and 1/x (PTX ex2.approx.f32: 2 ulp; rcp.approx.f32: 1 ulp) | `mufu.ex2.2`, `mufu.rcp.2` |
27
28With these, the two kernels are short (sketch, not compiled):
29
30```
31fn tmatmul16 a ptr b ptr d ptr to void
32ta = tload f16 16 16 a 16
33tb = tload f16 16 16 b 16
34tstore d 16 tmma ta tb 0
35end
36
37fn tsoftmax x ptr y ptr to void
38i = add mul ctaid 32 tid
39v = get x i
40m = wmax v
41e = ex2 mul sub v m 1.44269502162933349609375f32
42put y i mul e rcp wsum e
43end
44```
45
46## Required checks before any word is accepted
47
481. Every row the lowering emits is checked against nvcc/cuobjdump words (not against this emitter), as done for
49 the 48 instructions in the README table, and every emitted instruction against `nvdisasm -b SM121`.
502. kemu runs the generated kernel against an f64 reference within a tolerance derived with Wolfram (the
51 README gives the two used here), with a negative control per word (wrong fragment layout, transposed B,
52 butterfly turned into SHFL.DOWN).
533. The generated listing for the two sketches above is byte-identical to the hand listings, or every
54 difference is explained.
554. A chip run on sm_121 in an authorized window before anything is called QUALIFIED.
56
57## Open questions
58
59- Warp-collective words need every lane to reach them together. The language has no notion of a warp yet;
60 kemu reports `DIVERGED` when that is broken, but the compiler should reject it statically.
61- Tile values span 32 lanes. OM-2 values are per thread, so `tile` needs a type rule (no `get`/`put` on a
62 tile, only the tile words).
63- Larger shapes (K loops, multiple warps, shared memory staging with LDSM) and an sm_80 lowering (the same
64 HMMA.16816 exists there) are follow-ons; so is a CUDA Tile IR round-trip.