Hipbridge : Repo recognizes CUDA kernels, swaps in verified AMD/Triton implementations, proves correctness numerically

Pre-alpha but cool approach for CUDA→ROCm work:

  • Recognizes the kernel pattern from source (libclang analysis)
  • Proposes a tuned AMD Triton substitute only if the pattern + operand evidence actually supports it
  • Proves it against a float64 oracle, using your compiled kernel (hipcc/nvcc), not a copy

Unrecognized kernel → UNKNOWN, no silent fallback. Coverage: 7 kernels (softmax, layer norm ±affine, RMS norm ±affine, RoPE, fused RMS+RoPE) the row-wise part of a transformer’s inference path. All verified on MI300X (gfx942) + RTX 4060/WSL2.

Perf on MI300X (CI-measured):

  • 1.3x–1.9x faster than a competently written hand-tuned HIP kernel at large shapes
  • fp16/bf16 ~1.7x faster than fp32
  • RoPE is the exception — loses to hand-written HIP in every precision (no reduction to exploit)
  • Below ~16M elements: 3x–5x regression (Triton launch overhead dominates)

Super cool details:

  • Benchmarks against 3 baselines (naive, competent hand-written HIP, torch) specifically to avoid strawman comparisons
  • Was able to catch own weak HIP baseline inflating numbers early on
  • Sanity-checks the original kernel against the oracle before trusting any comparison (avoided a bug where a broken original made the candidate look 3.9e75x “better”)
  • Refuses to print a ratio if candidate/baseline aren’t both actually on device

How does ensure that it refuses to print a ratio if candidate/baseline aren’t both actually on device?

  1. Every side is timed with device events, not wall-clock time. Both the candidate kernel and the baseline (e.g. torch) are timed using GPU device events (the same way native kernels are timed inside the generated driver). This isn’t just for accuracy it’s how the tool can tell whether something actually ran on the GPU at all. A device event only fires if there was device execution to time.

  2. It detects when something silently fell back to CPU. The concrete failure case describe: on a Windows box, torch only had a CPU-only wheel installed (no GPU-enabled build, and Triton has no Windows build either). So the “candidate” silently ran on the CPU while the original ran on the GPU. Nothing crashed it just quietly executed in the wrong place.

  3. Before printing a ratio, it checks both sides landed on the same execution target. It also prints a warning up front when it detects torch has no GPU visibility, so the mismatch is called out before you even get to the results table, not buried in a footnote after.

  4. The reason built this guard in the first place: first-ever run of the benchmark, on that Windows/CPU-torch box, produced a “3.6x speedup” a completely fake number, since it was really just comparing a fast GPU op against a slow CPU op and calling it a win for the candidate. Note explicitly that a footnote wouldn’t have been good enough, because people just quote the headline number. So, the fix was structural: no ratio is computed at all unless both sides are confirmed on device.

    Looking for collaborators with a 7900 XTX or R9700. The issue: the AMD side is only proven on MI300X, which is wave64. Radeon cards run wave32 in HIP, so the “wavefront is 64” note and the 63/64/65 shape straddle don’t cover RDNA yet.

    feel free reach out on the discord - @core5132

1 Like

Hello, thank you for sharing, I will leave couple suggestions. A small thing, maybe move the latency-bound note higher up. The 1.3x to 1.9x wins happen at 4096x4096, but under roughly 16M elements it goes 3x to 5x slower. Single token decode is just one row, so a lot of local setups land on the slow side. Might help to say up front that it’s a prefill and batch tool. You already mention it, it’s just easy to miss.

Really like the verifier-gates-translator design — the float64 oracle, ULP budgets, and the 63/64/65 wavefront sweep especially. I come from a build/test + silicon-verification background, so correctness-first migration is exactly how I think.

I’d love to help extend coverage to computer-vision kernels, which the README flags as out-of-scope today. Several map onto patterns you already recognize — e.g. RGB→grayscale is a clean elementwise.flat (per-pixel weighted sum of three planes, no reduction); resize/conv would follow.

I’ve scaffolded a starting point on a branch — CUDA reference + tuned-HIP baseline + an AMD-tuned Triton rgb_to_gray, all marked UNVERIFIED — plus a short plan doc: GitHub - srikantharun/hipbridge at cv-kernels · GitHub

One design question before I wire it into verify/suites.py and run it on an MI300X: the current suites each transform a single tensor, but grayscale takes three input planes. Is Suite.extras/Operand the intended home for extra input planes, or would you prefer a small shapes.image() + inputs extension for a CV family? Happy to match whatever fits your architecture.

Is CV coverage something you’d welcome? If so I’ll verify on MI300X (fp32/fp16/bf16) and open a PR with evidence in results/.