omega-tool-model
First-party Omega tool-use model source, serving harnesses, and verification records
Brought by drakestapleton
omega-tool-model / deployment / fast / cache.om
| 1 | note Reuse host-built launch bytes only for the same slot, kernel, grid, argument words and invalidate flag. |
| 2 | note The checked variant rebuilds every hit and compares every byte before the unchanged submit/wait. |
| 3 | fn cachekey id uint gx uint gy uint gz uint to void |
| 4 | put ckey 0 id |
| 5 | put ckey 1 gx |
| 6 | put ckey 2 gy |
| 7 | put ckey 3 gz |
| 8 | put ckey 4 get gkna 0 |
| 9 | put ckey 5 get gkinv 0 |
| 10 | for i uint get gkna 0 |
| 11 | put ckey add i 6 get gkarg i |
| 12 | end |
| 13 | end |
| 14 | |
| 15 | fn cachematch slot ulong to bool |
| 16 | if eq get clen slot 0 |
| 17 | ret false |
| 18 | end |
| 19 | base = mul slot 40 |
| 20 | for i ulong add 6 ulong get gkna 0 |
| 21 | if ne get ckeys add base i get ckey i |
| 22 | ret false |
| 23 | end |
| 24 | end |
| 25 | ret true |
| 26 | end |
| 27 | |
| 28 | fn cacheverify slot ulong to void |
| 29 | n = get gbused 0 |
| 30 | if ne n get clen slot |
| 31 | exit 89 |
| 32 | end |
| 33 | for i ulong n |
| 34 | if ne get gbcmd i get cbytes add mul slot 4096 i |
| 35 | exit 89 |
| 36 | end |
| 37 | end |
| 38 | end |
| 39 | |
| 40 | fn cachestore slot ulong to void |
| 41 | n = get gbused 0 |
| 42 | if gt n 4096 |
| 43 | ret |
| 44 | end |
| 45 | for i ulong n |
| 46 | put cbytes add mul slot 4096 i get gbcmd i |
| 47 | end |
| 48 | for i ulong add 6 ulong get gkna 0 |
| 49 | put ckeys add mul slot 40 i get ckey i |
| 50 | end |
| 51 | put clen slot n |
| 52 | put cslot 1 1 |
| 53 | end |
| 54 | |
| 55 | fn cachebuild id uint gx uint gy uint gz uint to void |
| 56 | slot = get cslot 0 |
| 57 | put cslot 1 0 |
| 58 | if ge slot 256 |
| 59 | gkbuild id gx gy gz |
| 60 | ret |
| 61 | end |
| 62 | cachekey id gx gy gz |
| 63 | hit = cachematch slot |
| 64 | if hit |
| 65 | put ccnt 0 add get ccnt 0 1 |
| 66 | if eq CACHECHK 1 |
| 67 | gkbuild id gx gy gz |
| 68 | cacheverify slot |
| 69 | else |
| 70 | put gbused 0 get clen slot |
| 71 | put gkinv 0 0 |
| 72 | end |
| 73 | put cslot 1 1 |
| 74 | else |
| 75 | put ccnt 1 add get ccnt 1 1 |
| 76 | gkbuild id gx gy gz |
| 77 | cachestore slot |
| 78 | end |
| 79 | end |