interplane.Get Omega
Read in your language

ggml-omega

aien-dev/ggml-omega

Brought by drakestapleton

branch main Branches Tags History

ggml-omega / kernels / rope.om

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