CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / om / moe / moe_group_wide.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note moe_group with contributions per token read from directory_slots instead of the literal 9. |
| 3 | note Profiles: (directory_slots 9, shared_id 256) Qwen3.6-35B; (11, 512) Qwen3.8-Flash-Next. |
| 4 | note req: ids,tgu,tdn,sgu,sdn,xmap,ymap,stride,tokens,seg_entries,map_entries, |
| 5 | note directory_slots,session_generation,current_generation,admitted,shared_id. |
| 6 | note admitted is the external selector/cache admission verdict, NOT qualification here. |
| 7 | note Router ids row = directory_slots-1 routed u32 picks; table rows directory_slots*16 bytes. |
| 8 | note seg_entries must cover ALL R descriptors, including GROUP trailing zero writes. |
| 9 | note Output is exact OMEGA_DEC_GR_WORDS u32 constant-bank words, little endian pairs. |
| 10 | note groups=11 needs a GROUP kernel built for 11 contributions; this unit emits host words only. |
| 11 | fn mwg_word o edit uchar 64 p ulong v ulong to void |
| 12 | for b ulong 4 |
| 13 | put o add mul p 4 b uchar and shr v mul b 8 255 |
| 14 | end |
| 15 | end |
| 16 | fn mwg_pair o edit uchar 64 p ulong v ulong to void |
| 17 | mwg_word o p and v 4294967295 |
| 18 | mwg_word o add p 1 shr v 32 |
| 19 | end |
| 20 | fn mwg_profile r view ulong 16 to ulong |
| 21 | if eq get r 11 9 |
| 22 | if eq get r 15 256 |
| 23 | ret 0 |
| 24 | end |
| 25 | end |
| 26 | if eq get r 11 11 |
| 27 | if eq get r 15 512 |
| 28 | ret 0 |
| 29 | end |
| 30 | end |
| 31 | ret 1 |
| 32 | end |
| 33 | fn mwg_extent r view ulong 16 i ulong to ulong |
| 34 | k = get r 11 |
| 35 | if lt i 3 |
| 36 | width = mul k 16 |
| 37 | if eq i 0 |
| 38 | width = mul sub k 1 4 |
| 39 | end |
| 40 | ret add mul sub get r 8 1 get r 7 width |
| 41 | end |
| 42 | if lt i 5 |
| 43 | ret mul mul get r 8 k 32 |
| 44 | end |
| 45 | ret mul add mul get r 8 k 8 4 |
| 46 | end |
| 47 | fn mwg_overlap a ulong al ulong b ulong bl ulong to bool |
| 48 | if ge a add b bl |
| 49 | ret false |
| 50 | end |
| 51 | ret lt b add a al |
| 52 | end |
| 53 | fn mwg_alias r view ulong 16 to bool |
| 54 | for i ulong 7 |
| 55 | n = mwg_extent r i |
| 56 | if gt get r i sub ulong 18446744073709551615 n |
| 57 | ret true |
| 58 | end |
| 59 | end |
| 60 | for j ulong 4 |
| 61 | for i ulong add j 3 |
| 62 | n = mwg_extent r i |
| 63 | m = mwg_extent r add j 3 |
| 64 | if mwg_overlap get r i n get r add j 3 m |
| 65 | ret true |
| 66 | end |
| 67 | end |
| 68 | end |
| 69 | ret false |
| 70 | end |
| 71 | fn moe_group_wide r view ulong 16 o edit uchar 64 to ulong |
| 72 | if gt get r 8 128 |
| 73 | ret 1 |
| 74 | end |
| 75 | if ne mwg_profile r 0 |
| 76 | ret 1 |
| 77 | end |
| 78 | rows = mul get r 8 get r 11 |
| 79 | if or eq get r 8 0 gt rows 128 |
| 80 | ret 1 |
| 81 | end |
| 82 | if lt get r 9 rows |
| 83 | ret 2 |
| 84 | end |
| 85 | if lt get r 10 add rows 8 |
| 86 | ret 2 |
| 87 | end |
| 88 | if or eq get r 7 0 gt get r 7 4294967295 |
| 89 | ret 2 |
| 90 | end |
| 91 | if lt get r 7 mul get r 11 16 |
| 92 | ret 2 |
| 93 | end |
| 94 | if ne rem get r 7 16 0 |
| 95 | ret 3 |
| 96 | end |
| 97 | for i ulong 7 |
| 98 | if or eq get r i 0 ne rem get r i 8 0 |
| 99 | ret 3 |
| 100 | end |
| 101 | end |
| 102 | if ne get r 12 get r 13 |
| 103 | ret 4 |
| 104 | end |
| 105 | if ne get r 14 1 |
| 106 | ret 4 |
| 107 | end |
| 108 | if mwg_alias r |
| 109 | ret 5 |
| 110 | end |
| 111 | for i ulong 7 |
| 112 | mwg_pair edit o mul i 2 get r i |
| 113 | end |
| 114 | mwg_word o 14 get r 7 |
| 115 | mwg_word o 15 get r 8 |
| 116 | ret 0 |
| 117 | end |