omega-kernel-smoke
Minimal Omega GPU kernel smoke verification harness
Brought by drakestapleton
omega-kernel-smoke / reference.py
| 1 | """CPU reference for kernel.om, in plain Python. |
| 2 | |
| 3 | Every fn in kernel.om needs a function here with the same name and parameters. |
| 4 | Return the exact mathematical answer; the check fails if the kernel disagrees. |
| 5 | Raise Trap(n) where the kernel executes `trap n` (Trap is provided by the check). |
| 6 | """ |
| 7 | |
| 8 | |
| 9 | def avg(a, b): |
| 10 | return (a + b) // 2 |
| 11 | |
| 12 | |
| 13 | def gcd(a, b): |
| 14 | while b: |
| 15 | a, b = b, a % b |
| 16 | return a |
| 17 | |
| 18 | |
| 19 | def clamp(x, lo, hi): |
| 20 | if lo > hi: |
| 21 | raise Trap(3) # noqa: F821 - provided by tools/cases.py |
| 22 | return min(max(x, lo), hi) |
| 23 | |
| 24 | |
| 25 | def popc(x): |
| 26 | return bin(x).count("1") |