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
omega-mv / seed / kflow / sm121 / tsoftmax.s2
| 1 | ; tsoftmax.s2 -- softmax of each 32-value f32 row, one warp per row, on sm_121 (GB10), written by hand for |
| 2 | ; asm2 with seed/sm121/sm121.tbl. X 0x380 (16 rows x 32 f32), Y 0x388 (same shape); 16 CTAs of 32 threads, |
| 3 | ; row = CTA, column = lane: y = 2^((x - m) * log2 e) / sum, m = row max. |
| 4 | ; The row max and the row sum are warp butterflies (SHFL.BFLY 16 8 4 2 1, each followed by FMNMX or FADD), |
| 5 | ; so every lane ends with the same m and the same sum (the same additions in a lane-dependent order; the |
| 6 | ; harness bound covers any order). log2 e is the f32 0x3fb8aa3b (1.44269502162933349609375, the same word |
| 7 | ; nvcc 13.0 emits for expf); MUFU.EX2 and MUFU.RCP are the approximate units (PTX ISA 9.4 ex2.approx.f32: |
| 8 | ; 2 ulp from correctly rounded; rcp.approx.f32: 1 ulp). |
| 9 | ; Each ";=" line is the instruction text expected from nvdisasm -b SM121 for the next instruction. |
| 10 | ; Control words are MODELED and unmeasured: S2R LDC LDCU LDG SHFL MUFU set scoreboard 0 (0x000e2200) and |
| 11 | ; their first reader waits on it (wait mask bit 20, 0x001fcc00); fixed-latency steps stall 6. No GPU ran |
| 12 | ; this (NOT_RUN). |
| 13 | ;= S2R R0, SR_TID.X |
| 14 | s2r.0 0 |
| 15 | s2r.1 |
| 16 | s2r.2 33 |
| 17 | ctl 0x000e2200 |
| 18 | ;= S2R R1, SR_CTAID.X |
| 19 | s2r.0 1 |
| 20 | s2r.1 |
| 21 | s2r.2 37 |
| 22 | ctl 0x000e2200 |
| 23 | ;= LDCU.64 UR4, c[0x0][0x358] |
| 24 | ldcu.64.0 4 |
| 25 | ldcu.64.1 107 |
| 26 | ldcu.64.2 |
| 27 | ctl 0x000e2200 |
| 28 | ;= LDC.64 R2, c[0x0][0x380] |
| 29 | ldc.64.0 2 |
| 30 | ldc.64.1 224 |
| 31 | ldc.64.2 |
| 32 | ctl 0x000e2200 |
| 33 | ;= LDC.64 R4, c[0x0][0x388] |
| 34 | ldc.64.0 4 |
| 35 | ldc.64.1 226 |
| 36 | ldc.64.2 |
| 37 | ctl 0x000e2200 |
| 38 | ; element index ctaid * 32 + tid (R6), addresses R8:R9 (X) and R10:R11 (Y) |
| 39 | ;= IMAD R6, R1, 0x20, R0 |
| 40 | imad.i.0 6 1 |
| 41 | imad.i.1 0x00000020 |
| 42 | imad.i.2 0 |
| 43 | ctl 0x001fcc00 |
| 44 | ;= IMAD.WIDE.U32 R8, R6, 0x4, R2 |
| 45 | imad.wide.0 8 6 |
| 46 | imad.wide.1 0x00000004 |
| 47 | imad.wide.2 2 |
| 48 | ctl 0x000fcc00 |
| 49 | ;= IMAD.WIDE.U32 R10, R6, 0x4, R4 |
| 50 | imad.wide.0 10 6 |
| 51 | imad.wide.1 0x00000004 |
| 52 | imad.wide.2 4 |
| 53 | ctl 0x000fcc00 |
| 54 | ;= LDG.E R12, desc[UR4][R8.64] |
| 55 | ldg.0 12 8 |
| 56 | ldg.w.1 4 0 |
| 57 | ldg.2 |
| 58 | ctl 0x000e2200 |
| 59 | ; m = row max (R13; R19 holds the partner value) |
| 60 | ;= SHFL.BFLY PT, R13, R12, 0x10, 0x1f |
| 61 | shfl.0 13 12 |
| 62 | shfl.bfly.1 16 |
| 63 | shfl.2 |
| 64 | ctl 0x001e2200 |
| 65 | ;= FMNMX R13, R12, R13, !PT |
| 66 | fmnmx.0 13 12 |
| 67 | r.1 13 |
| 68 | fmnmx.max.2 |
| 69 | ctl 0x001fcc00 |
| 70 | ;= SHFL.BFLY PT, R19, R13, 0x8, 0x1f |
| 71 | shfl.0 19 13 |
| 72 | shfl.bfly.1 8 |
| 73 | shfl.2 |
| 74 | ctl 0x000e2200 |
| 75 | ;= FMNMX R13, R13, R19, !PT |
| 76 | fmnmx.0 13 13 |
| 77 | r.1 19 |
| 78 | fmnmx.max.2 |
| 79 | ctl 0x001fcc00 |
| 80 | ;= SHFL.BFLY PT, R19, R13, 0x4, 0x1f |
| 81 | shfl.0 19 13 |
| 82 | shfl.bfly.1 4 |
| 83 | shfl.2 |
| 84 | ctl 0x000e2200 |
| 85 | ;= FMNMX R13, R13, R19, !PT |
| 86 | fmnmx.0 13 13 |
| 87 | r.1 19 |
| 88 | fmnmx.max.2 |
| 89 | ctl 0x001fcc00 |
| 90 | ;= SHFL.BFLY PT, R19, R13, 0x2, 0x1f |
| 91 | shfl.0 19 13 |
| 92 | shfl.bfly.1 2 |
| 93 | shfl.2 |
| 94 | ctl 0x000e2200 |
| 95 | ;= FMNMX R13, R13, R19, !PT |
| 96 | fmnmx.0 13 13 |
| 97 | r.1 19 |
| 98 | fmnmx.max.2 |
| 99 | ctl 0x001fcc00 |
| 100 | ;= SHFL.BFLY PT, R19, R13, 0x1, 0x1f |
| 101 | shfl.0 19 13 |
| 102 | shfl.bfly.1 1 |
| 103 | shfl.2 |
| 104 | ctl 0x000e2200 |
| 105 | ;= FMNMX R13, R13, R19, !PT |
| 106 | fmnmx.0 13 13 |
| 107 | r.1 19 |
| 108 | fmnmx.max.2 |
| 109 | ctl 0x001fcc00 |
| 110 | ; e = 2^((x - m) * log2 e) (R14); x - m is exact for the harness inputs |
| 111 | ;= FADD R14, R12, -R13 |
| 112 | fadd.0 14 12 |
| 113 | fsub.1 13 |
| 114 | f.2 |
| 115 | ctl 0x000fcc00 |
| 116 | ;= MOV R15, 0x3fb8aa3b |
| 117 | mov.i.0 15 |
| 118 | mov.i.1 0x3fb8aa3b |
| 119 | mov.i.2 |
| 120 | ctl 0x000fcc00 |
| 121 | ;= FMUL R14, R14, R15 |
| 122 | fmul.0 14 14 |
| 123 | r.1 15 |
| 124 | fmul.2 |
| 125 | ctl 0x000fcc00 |
| 126 | ;= MUFU.EX2 R14, R14 |
| 127 | mufu.0 14 |
| 128 | r.1 14 |
| 129 | mufu.ex2.2 |
| 130 | ctl 0x000e2200 |
| 131 | ; s = row sum (R16) |
| 132 | ;= SHFL.BFLY PT, R16, R14, 0x10, 0x1f |
| 133 | shfl.0 16 14 |
| 134 | shfl.bfly.1 16 |
| 135 | shfl.2 |
| 136 | ctl 0x001e2200 |
| 137 | ;= FADD R16, R14, R16 |
| 138 | fadd.0 16 14 |
| 139 | r.1 16 |
| 140 | f.2 |
| 141 | ctl 0x001fcc00 |
| 142 | ;= SHFL.BFLY PT, R17, R16, 0x8, 0x1f |
| 143 | shfl.0 17 16 |
| 144 | shfl.bfly.1 8 |
| 145 | shfl.2 |
| 146 | ctl 0x000e2200 |
| 147 | ;= FADD R16, R16, R17 |
| 148 | fadd.0 16 16 |
| 149 | r.1 17 |
| 150 | f.2 |
| 151 | ctl 0x001fcc00 |
| 152 | ;= SHFL.BFLY PT, R17, R16, 0x4, 0x1f |
| 153 | shfl.0 17 16 |
| 154 | shfl.bfly.1 4 |
| 155 | shfl.2 |
| 156 | ctl 0x000e2200 |
| 157 | ;= FADD R16, R16, R17 |
| 158 | fadd.0 16 16 |
| 159 | r.1 17 |
| 160 | f.2 |
| 161 | ctl 0x001fcc00 |
| 162 | ;= SHFL.BFLY PT, R17, R16, 0x2, 0x1f |
| 163 | shfl.0 17 16 |
| 164 | shfl.bfly.1 2 |
| 165 | shfl.2 |
| 166 | ctl 0x000e2200 |
| 167 | ;= FADD R16, R16, R17 |
| 168 | fadd.0 16 16 |
| 169 | r.1 17 |
| 170 | f.2 |
| 171 | ctl 0x001fcc00 |
| 172 | ;= SHFL.BFLY PT, R17, R16, 0x1, 0x1f |
| 173 | shfl.0 17 16 |
| 174 | shfl.bfly.1 1 |
| 175 | shfl.2 |
| 176 | ctl 0x000e2200 |
| 177 | ;= FADD R16, R16, R17 |
| 178 | fadd.0 16 16 |
| 179 | r.1 17 |
| 180 | f.2 |
| 181 | ctl 0x001fcc00 |
| 182 | ; y = e * (1 / s) |
| 183 | ;= MUFU.RCP R17, R16 |
| 184 | mufu.0 17 |
| 185 | r.1 16 |
| 186 | mufu.rcp.2 |
| 187 | ctl 0x000e2200 |
| 188 | ;= FMUL R18, R14, R17 |
| 189 | fmul.0 18 14 |
| 190 | r.1 17 |
| 191 | fmul.2 |
| 192 | ctl 0x001fcc00 |
| 193 | ;= STG.E desc[UR4][R10.64], R18 |
| 194 | stg.0 10 |
| 195 | stg.1 18 0 |
| 196 | stg.2 4 |
| 197 | stg.3 |
| 198 | ;= EXIT |
| 199 | exit.0 |
| 200 | z.1 |
| 201 | exit.2 |
| 202 | exit.3 |
| 203 | ;= BRA 0x250 |
| 204 | bra.0 7 63 |
| 205 | bra.1 -1 |
| 206 | bra.back.2 |
| 207 | bra.self.3 |
| 208 | nop.0 |
| 209 | nop.1 |
| 210 | nop.2 |
| 211 | nop.3 |