ggml-omega
aien-dev/ggml-omega
Brought by drakestapleton
ggml-omega / kernels / rope.om
| 1 | note rope: one rotated pair. theta = pos * ts^i (f32, multiplied i times as ggml_rope_cache_init), |
| 2 | note times freq_scale; out0 = x0*c - x1*s, out1 = x0*s + x1*c with c, s = cos, sin(theta)*attn_factor. |
| 3 | note xy packs x0 (low 32 bits) and x1; fa packs freq_scale (low) and attn_factor. Returns the packed pair. |
| 4 | fn lo32 v ulong to f32 |
| 5 | ret bitcast f32 uint and v 4294967295 |
| 6 | end |
| 7 | fn hi32 v ulong to f32 |
| 8 | ret bitcast f32 uint shr v 32 |
| 9 | end |
| 10 | fn rth pos ulong i ulong ts ulong fs f32 to f64 |
| 11 | t = f32 bitcast int uint pos |
| 12 | tsf = bitcast f32 uint ts |
| 13 | for k ulong i |
| 14 | t = mul t tsf |
| 15 | end |
| 16 | ret f64 mul fs t |
| 17 | end |
| 18 | fn pack a f32 b f32 to ulong |
| 19 | ret or ulong bitcast uint a shl ulong bitcast uint b 32 |
| 20 | end |
| 21 | fn rope xy ulong pos ulong i ulong ts ulong fa ulong to ulong |
| 22 | th = rth pos i ts lo32 fa |
| 23 | af = hi32 fa |
| 24 | c = mul f32 sc64 th 1 af |
| 25 | s = mul f32 sc64 th 0 af |
| 26 | x0 = lo32 xy |
| 27 | x1 = hi32 xy |
| 28 | o0 = sub mul x0 c mul x1 s |
| 29 | o1 = add mul x0 s mul x1 c |
| 30 | ret pack o0 o1 |
| 31 | end |