interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / backend / amd / gfx942 / rope.om

107 lines · 2163 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note Q27 config 017b9c7a: theta 10000000, rotary dim 64; text positions share all MRoPE axes.
4note Input exactly one little-endian u32 position; output cos[32], sin[32] binary32 words.
5note Explicit binary32 frequency, position and angle boundaries follow Transformers v5.8.0.
6note Binary64 exp and Cody-Waite reduction; no libm, host runtime, Python or GPU dependency.
7note Exit 64 for a malformed position record, 74 for I/O failure. No output on malformed input.
8global rin uchar 4
9global rout uchar 256
10global rend uchar 1
11global trig f64 2
12fn rexp x f64 to f64
13n = uint div x 0.6931471805599453f64
14r = sub x mul f64 n 0.6931471805599453f64
15t = 1.0f64
16y = 1.0f64
17for j ulong 18
18t = div mul t r f64 add j 1
19y = add y t
20end
21scale = bitcast f64 shl add ulong n 1023 52
22ret mul y scale
23end
24fn rfreq i ulong to f32
25x = div mul f64 i 16.11809565095832f64 32.0f64
26power = f32 rexp x
27ret div 1.0f32 power
28end
29fn rtrig x f64 to void
30n = ulong add mul x 0.6366197723675813f64 0.5f64
31r = sub x mul f64 n 1.570796012878418f64
32r = sub r mul f64 n bitcast f64 ulong 0x3e95110b4611a626
33z = neg mul r r
34st = r
35sv = r
36ct = 1.0f64
37cv = 1.0f64
38for j ulong 10
39k = add mul j 2 2
40st = div mul st z f64 mul k add k 1
41ct = div mul ct z f64 mul k sub k 1
42sv = add sv st
43cv = add cv ct
44end
45q = and n 3
46if eq q 0
47put trig 0 cv
48put trig 1 sv
49end
50if eq q 1
51put trig 0 neg sv
52put trig 1 cv
53end
54if eq q 2
55put trig 0 neg cv
56put trig 1 neg sv
57end
58if eq q 3
59put trig 0 sv
60put trig 1 neg cv
61end
62end
63fn rput p ulong x f64 to void
64b = ulong bitcast uint f32 x
65for j ulong 4
66put rout add p j uchar and shr b mul j 8 255
67end
68end
69fn main to int
70n = ulong 0
71while lt n 4 bound 999999
72r = read 0 rin n sub 4 n
73if lt r 0
74ret 74
75end
76if eq r 0
77ret 64
78end
79n = add n ulong r
80end
81r = read 0 rend 0 1
82if lt r 0
83ret 74
84end
85if ne r 0
86ret 64
87end
88p = ulong 0
89for j ulong 4
90p = or p shl ulong get rin j mul j 8
91end
92for i ulong 32
93angle = mul f32 p rfreq i
94rtrig f64 angle
95rput mul i 4 get trig 0
96rput add 128 mul i 4 get trig 1
97end
98n = 0
99while lt n 256 bound 999999
100r = write 1 rout n sub 256 n
101if le r 0
102ret 74
103end
104n = add n ulong r
105end
106ret 0
107end