Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/gpu/nvidia/checks/nmm.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / nvidia / checks / nmm.om` 194 lines ยท 4845 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note gpu/nvidia/checks/nmm.om: the matmul() block of CUDApp tests/api_attn_rest_diff.c. The units mm_init, mm_dot, 3 note mm_err and mm_next (gpu/nvidia/om/api/, over ar_dot and ar_err of attn_oracle.om) are the host matmul oracle 4 note of src/omega_gpu_matmul_api.c; the check drives them with that file's loop (ported in nmrun) and compares the 5 note result with the pending C oracle (CUDAPP_MIGRATION_PENDING_C_MATMUL_ORACLE_GUARD) the table holds. Here 6 note mm_init and mm_next are the stand-ins nmm-init.om and nmm-next.om (see there); the units themselves are 7 note proven by nmmq.om. Rows: 8 note M m k n A B C ABS REL MISM PAR 9 note A (m x k) and B (k x n) bfloat16 as 4 hex digits each and C (m x n) float bits as 8 hex 10 note digits each, - when empty; the C oracle answered max_abs_err and max_rel_err (float bits, 11 note 8 hex digits), mismatch_count and parity_verified. The units must give the same bits. 12 note Z K ABS REL MISM PAR 13 note 1 x K x 1 with A all 1.0 and B alternating -1.0, 1.0: a dot product of K terms, past the 14 note `1000000`-term segment of ar_dot when K is larger; built here, not read from the table. 15 note The kept operands live in arrays of 4096 values (A, B and C each); a larger row is refused as malformed 16 note (ckbad, exit 2), never cut. Z rows hold at most `1000003` terms, two arrays of that many bfloat16 in nmz. 17 text t_name "NMM" 18 fn cname to void 19 for i ulong len t_name bound 64 20 ckoc ulong get t_name i 21 end 22 end 23 note value j of hex field i, w bytes wide, as printed (most significant first) 24 fn nmh i ulong j ulong w ulong to ulong 25 v = ulong 0 26 for x ulong w bound 8 27 v = or shl v 8 ckhex i add mul j w x 28 end 29 ret v 30 end 31 note one dot product of the loop; true when mm_dot answered 0, as the C loop requires. p is q[0..4) (the C passes 32 note q with length 4). 33 fn nmdot a view ushort * b view ushort * q view ulong 8 d edit ulong 2 to bool 34 p = new ulong 4 0 35 for i ulong 4 36 put p i get q i 37 end 38 ret eq mm_dot part a 0 get q 6 part b 0 get q 7 p d 0 39 end 40 note the oracle loop of src/omega_gpu_matmul_api.c, q = {0, 0, k, n, m, 0, 0, 0}, z = {0, 0, 0, 1}. w holds m, k, n 41 note in slots 0 to 2 (one array: a function has six parameter slots and an unsized view takes two); z, the 42 note answer (max_abs_err, max_rel_err, mismatch_count, parity_verified), is copied to slots 4 to 7; slot 3 holds r, 43 note the loop's go-on flag. 44 fn nmerr d view ulong 2 c view uint 4096 q view ulong 8 z edit ulong 4 to bool 45 ret eq mm_err d get c get q 5 z 0 46 end 47 fn nmrun a view ushort * b view ushort * c view uint 4096 w edit ulong 8 to bool 48 q = new ulong 8 0 49 d = new ulong 2 0 50 z = new ulong 4 0 51 put q 2 get w 1 52 put q 3 get w 2 53 put q 4 get w 0 54 put z 3 1 55 put w 3 0 56 if mm_init q 57 put w 3 1 58 end 59 for it ulong mul get w 0 get w 2 bound 4096 60 if eq get w 3 0 61 ret false 62 end 63 if not nmdot a b q d 64 ret false 65 end 66 if not nmerr d c q z 67 ret false 68 end 69 put w 3 0 70 if mm_next q 71 put w 3 1 72 end 73 end 74 for i ulong 4 75 put w add i 4 get z i 76 end 77 ret eq get w 3 0 78 end 79 fn nmfill i ulong w ulong cnt ulong o edit ushort 4096 to void 80 if eq cnt 0 81 if ne ckhexn i 0 82 ckbad 83 end 84 ret 85 end 86 if ne ckhexn i mul cnt w 87 ckbad 88 end 89 for j ulong cnt bound 4096 90 put o j ushort nmh i j w 91 end 92 end 93 fn nmfillc cnt ulong o edit uint 4096 to void 94 if eq cnt 0 95 if ne ckhexn 6 0 96 ckbad 97 end 98 ret 99 end 100 if ne ckhexn 6 mul cnt 4 101 ckbad 102 end 103 for j ulong cnt bound 4096 104 put o j uint nmh 6 j 4 105 end 106 end 107 fn nmok w view ulong 8 ia ulong to bool 108 if ne get w 4 nmh ia 0 4 109 ret false 110 end 111 if ne get w 5 nmh add ia 1 0 4 112 ret false 113 end 114 if ne get w 6 cknum add ia 2 115 ret false 116 end 117 ret eq get w 7 cknum add ia 3 118 end 119 fn nmz to bool 120 la = new ushort `1000003` 0 121 lb = new ushort `1000003` 0 122 lc = new uint 4096 0 123 w = new ulong 8 1 124 if ne ckcnt 6 125 ckbad 126 end 127 kk = cknum 1 128 if or eq kk 0 gt kk `1000003` 129 ckbad 130 end 131 if or ne ckhexn 2 4 ne ckhexn 3 4 132 ckbad 133 end 134 for i ulong kk bound `1000003` 135 put la i ushort 16256 136 if eq and i 1 0 137 put lb i ushort 49024 138 else 139 put lb i ushort 16256 140 end 141 end 142 put lc 0 uint `1065353216` 143 put w 1 kk 144 if not nmrun part la 0 kk part lb 0 kk lc w 145 ret false 146 end 147 ret nmok w 2 148 end 149 note the shape m, k, n of an M row into w slots 0 to 2; a shape whose operands pass 4096 values is refused 150 fn nmshape w edit ulong 8 to void 151 for i ulong 3 152 v = cknum add i 1 153 if gt v 4096 154 ckbad 155 end 156 put w i v 157 end 158 if gt mul get w 0 get w 1 4096 159 ckbad 160 end 161 if gt mul get w 1 get w 2 4096 162 ckbad 163 end 164 if gt mul get w 0 get w 2 4096 165 ckbad 166 end 167 if or ne ckhexn 7 4 ne ckhexn 8 4 168 ckbad 169 end 170 end 171 fn crow to bool 172 a = new ushort 4096 0 173 b = new ushort 4096 0 174 c = new uint 4096 0 175 w = new ulong 8 0 176 if ne cklen 0 1 177 ckbad 178 end 179 k0 = ckch 0 0 180 if eq k0 90 181 ret nmz 182 end 183 if or ne k0 77 ne ckcnt 11 184 ckbad 185 end 186 nmshape w 187 nmfill 4 2 mul get w 0 get w 1 a 188 nmfill 5 2 mul get w 1 get w 2 b 189 nmfillc mul get w 0 get w 2 c 190 if not nmrun a b c w 191 ret false 192 end 193 ret nmok w 7 194 end