Repository navigation
Description
What Bend should do
I built a third GPU lane on top of commit 8008146, for AMD cards through HIP and HIPRTC. It runs. The patch is 545 lines (comp.ts +376 −11, main.ts +9 −3).
Tested on one card only: Radeon RX 7800 XT (gfx1101, 16 GB), ROCm 7.2.1, WSL2.
The port
HIPRTC compiles the CUDA lane's device code as written: __global__, __shared__ (including the extern __shared__ hold[] sized at launch), __syncthreads(), __threadfence(), __clz, atomicAdd/Sub/CAS. I checked the barrier, shared memory and CAS on the card with 128 × 128 lanes. Two differences:
- HIPRTC defines
__HIPCC_RTC__, not__CUDACC_RTC__. OneBEND_RTCmacro replaces the six tests. - HIPRTC ignores
-default-device, so plain functions compile as host functions.#pragma clang force_cuda_host_device beginfixes it.
The host side is a BEND_HIP block beside BEND_CUDA, nearly one-to-one, with the same hash-keyed .gpu cache. AMD's clang 22 has #embed, and cc_find accepts its version string.
The memory model
Consumer Radeons report concurrentManagedAccess = 0: managed memory is pinned host RAM read over PCIe, and nothing migrates. gpu_probe would refuse the card. Relaxing the probe works but is unusable: lanes keep their stacks, rings and free lists in that block, so queens takes 47 s and tree-bitonic 41 s.
The corpus is index-based, though: every Loc is a word index, and lanes derive their pointers from H + offset at kernel entry. So the device can hold it at another address. My second mode keeps a twin of the corpus in VRAM. Each ! copies in the header, the live ring planes, the static image, the heap under the bump and the live bank entries; runs every round on the device, exchanging only the header; then copies back. CPU and GPU never run together, so this is legal. queens drops from 47 s to 1.4 s of device time.
Numbers
bench/runtime/, perf.ts protocol and spans, 16 CPU threads against the HIP lane with the VRAM twin. Wall seconds, single runs on a desktop, so ±10%. Every row prints the pinned checksum on both lanes.
| bench | 16 threads | HIP wall | HIP device passes |
|---|---|---|---|
| gameoflife | 1.50 | 0.27 | 0.02 |
| nbody | 0.65 | 0.26 | 0.01 |
| raytrace | 0.87 | 0.34 | 0.09 |
| kmeans | 0.93 | 0.42 | 0.15 |
| mandelbrot | 0.54 | 0.28 | 0.02 |
| merkle | 0.63 | 0.39 | 0.02 |
| tree-bitonic | 2.29 | 1.87 | 1.48 |
| bfs | 0.45 | 0.65 | 0.26 |
| tree-matmul | 0.56 | 0.80 | 0.22 |
| symreg | 0.55 | 0.92 | 0.67 |
| terrain | 0.41 | 0.96 | 0.55 |
| editdist | 0.36 | 1.00 | 0.66 |
| hashmap | 0.48 | 1.13 | 0.45 |
| lexer | 0.41 | 1.24 | 0.94 |
| tree-radix | 0.87 | 1.38 | 0.28 |
| queens | 1.17 | 1.63 | 1.39 |
Bimodal, as in the paper. On the divergent programs all device time is inside one work kernel; growth, barriers and packing are about 0 ms. 128 groups was best or near-best on 7 of 10 programs swept; editdist and terrain ran 2 to 3 times faster at 32.
The 11 runnable ! tests print the same bytes as the CPU lane in both memory modes. I cannot run gates/test.ts; a local copy of its rules gives 1299 / 1302 with the patch and 1300 / 1302 without. The difference is a TCP test with no ! that is flaky here on the unpatched tree too.
Weak points
- One card, one OS. No native Linux, no second AMD part, no medians.
- You have no AMD hardware in the gate, so you could not test this lane.
- The memory mode is an environment variable. It should be decided in the probe, with the span from free VRAM.
- The whole heap under the bump is copied both ways on every
!; tree-radix moves 3.7 GB over three turns. - Under WSL, ROCm spends 0.5 s at first use searching Windows directories on
$PATH. I trimPATHaround the first transfer, which is a hack. effs/window_frame.cstill has only its CUDA device path.- The patch carries a debug counter and two tuning variables. I have not checked
gates/repo.ts's size cap.
The question
Would you want an AMD lane in the tree, given you cannot gate it? If yes, I would fix the points above before sending anything. If not, one finding stands without AMD: the corpus is position-independent, so a VRAM-twin mode is open to any card without migrating managed memory.
Why
I don’t have an NVIDIA GPU 🥴
Activity
AdrielSantana commentedon Sep 20, 2026
Bumping this. Unfortunately, I have an AMD GPU too.
costamatheus97 commentedon Sep 20, 2026
Update: a second pass cut most of the copy and start-up cost. The lane now beats 16 CPU threads on 10 of the 16
bench/runtime/programs (7 before), and every remaining loss is device time, not overhead. The patch is now 731 lines (comp.ts+546 −13,main.ts+9 −3).The heap is lazy now. Before, each
!copied the whole heap under the bump up and back down; tree-radix moved 3.7 GB over three turns. Now, after a device turn, the heap's 2 MB chunks are made inaccessible withmprotectand nothing is downloaded. The first host touch of a chunk faults and downloads that chunk alone; a chunk the host writes is marked dirty, and the next!uploads only dirty chunks. The result of a!is usually a few words, so tree-radix now moves 17 MB. The fault handler is chained in front of the stack-guard handler inpool_stack. Tracking by the bump alone is unsound:heap_freeandheap_allocrewrite freed slots in place under the old bump.Start-up. My port zeroed 143 MB of a fresh
mmapthat was already zero: 0.10 s of a 0.25 s floor. Removed. The floor is now about 0.15 s, nearly all inside ROCm.Wall seconds, medians of 3 runs, same protocol as above, all checksums correct:
The stock sizes understate uniform work. They are 1 s programs, so the 0.15 s floor dominates. At 16 times the input, wall time against 16 threads: gameoflife 32x faster, nbody 21x, mandelbrot 14x, raytrace 10x, kmeans 8x. Device time scales linearly. queens and tree-bitonic stay near 1x at any size.
The slow programs are two different problems. I counted dispatches per lane in the work kernel. queens, symreg and editdist are imbalanced: in queens the mean lane does 9% of the longest lane's work, and in symreg one lane runs 3.8 times longer than all the others. lexer and tree-bitonic are balanced to 99%, so their cost is per dispatch and re-balancing cannot help. I tried in-kernel stealing from neighbouring rings: no gain, because after growth every lane holds exactly one task and there is nothing queued to steal. Growing for extra rounds to make smaller tasks made queens slower (1.5 s to 3.7 s).
Checks on the final code. The 11 runnable
!tests are byte-identical to the CPU lane in both memory modes. My local copy of the gate gives 1299 / 1302, the same three failures as before. Two multi-turn tests where the host frees, rebuilds and extends device-built trees between!calls match a Python model. For concurrent faults I ran two tests 150 times each with 16 host threads folding a device-built tree: 300 of 300 correct, with about 41,000 faults waiting on the handler's lock and 32,000 finding their chunk already served by another thread.New weak point. The handler calls
hipMemcpyfrom SIGSEGV. The fault can only come from Bend's own evaluation code, never from inside ROCm, but POSIX does not promise it. A helper thread doing the download would be the clean form. The corpus is also amemfdnow, so no transparent huge pages; I see no loss on these benchmarks.One thing I noticed while testing, in unpatched behaviour: once the host pool has forked, a later
!in the same program runs on the CPU, not the device. With a sequential host phase between them, both!calls reach the device.VictorTaelin commentedon Sep 20, 2026
Thank you for this. It is a serious piece of work: the HIPRTC path, the VRAM-twin mode for consumer Radeons, and the benchmark table are exactly what a port needs, and the fact that queens went from 47 s to 1.4 s says you understood the runtime.
We cannot take it into the repo, and the reason is capacity, not quality. We are a very small team; every line in
comp.tsis a line we have to understand, test on hardware we own, and keep working through every runtime change, and we have no AMD hardware in the test cluster. A GPU lane we cannot run is a lane we would break without knowing. So this is a wontfix on our side for now, with real regret.What we can do: if you open a PR against a branch named
hip(rather thanmain), we will keep it there in this repo so people can find and build it, and we will link it from the issue. When the runtime settles and we have a way to test on AMD, this is the first thing we would look at.Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.
A HIP lane: ! on AMD GPUs, through HIPRTC and a device twin of the co…
HIP: mend the rings' lap bits on the copy a turn did not run on
A ! runs on the GPU on Windows: a device without concurrent managed a…
A ! runs on the GPU on Windows: a device without concurrent managed a…
A ! runs on the GPU on Windows: a device without concurrent managed a…
A ! runs on the GPU on Windows: a device without concurrent managed a…
A ! runs on the GPU on Windows: a device without concurrent managed a…
A ! runs on the GPU on Windows: a device without concurrent managed a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A twin's ring sync copies the slots written since the last sync, so a…
A HIP lane: ! on AMD GPUs, through HIPRTC and a device twin of the co…
A HIP lane: ! on AMD GPUs, through HIPRTC and a device twin of the co…