Repository navigation
Description
What you did
I ran two semantically identical programs through the CUDA lane. Both contain three marked calls:
t0 = gen!(16n, 1)
t1 = bump(t0)
t2 = flip!(t1)
IO.print(U32.show(sum!(t2)))The only difference is the unmarked host bump implementation.
Sequential control:
def bump(t: Tr) -> Tr:
match t:
case Lf{v}:
Lf{U32.inc(v)}
case Nd{l, r}:
x = bump(l)
y = bump(r)
Nd{x, y}Parallel host phase:
def bump(t: Tr) -> Tr:
match t:
case Lf{v}:
Lf{U32.inc(v)}
case Nd{l, r}:
x y = bump(l) bump(r)
Nd{x, y}The CUDA test backend increments a counter immediately around the existing corpus_eval GPU seam; it does not change which calls are dispatched. I ran each binary with --threads 2 --gpu 512MB and required the GPU banner plus exact CPU/GPU output.
What happened
Both CPU programs print the same value:
3841805111
The sequential-host control reaches all three marked GPU calls:
bend: gpu twin: 3 turns, 0.039 s in turns, 0.037 s copying 160.7 MB
The parallel-host variant reaches only the first marked call:
bend: gpu twin: 1 turns, 0.019 s in turns, 0.018 s copying 32.4 MB
It still exits 0 and prints 3841805111; the later two marked calls silently execute on CPU.
This reproduces on NVIDIA CUDA the observation recorded in #891's HIP work: after the host pool has forked, a later ! can stay on the CPU; a sequential host phase does not trigger it.
The live CUDA reproduction used upstream commit b7ebee9217c8813067e200b0c0c9153a3be31c5e with the corpus-storage twin patch. That patch wraps the existing GPU seam to copy the corpus and count turns; the dispatch decision remains upstream's io_gpu && fid_bangs(...) branch.
I also inspected current main at 47bed75adedd6d6dd811721905f06569bf465f85. The surrounding code has evolved, so I am not claiming a live current-main reproduction, but the same mechanism remains: corpus_eval recognizes a marked task on the main thread, while pool_open() starts persistent workers and cube_run(H, false) hands host work to them.
Expected behavior: each reachable ! call uses the selected GPU lane, independent of whether an earlier unmarked host phase used parallel CPU workers. If a marked call cannot migrate back to the GPU seam, the runtime should at minimum report that it fell back rather than silently changing lanes.
A likely place to investigate is the ownership/routing of tasks produced by task_deal after pool_open: worker threads drain rings directly, while the GPU-dispatch test lives only in the main-thread corpus_eval loop.
Complete file
import Base
type Tr is Data:
Lf{v: U32}
Nd{l: Tr, r: Tr}
def gen(+n: Nat, +x: U32) -> Tr:
match n:
case 0n:
Lf{x}
case 1n+p:
l r = gen(p, U32.shl(x)) gen(p, U32.inc(U32.shl(x)))
Nd{l, r}
def bump(t: Tr) -> Tr:
match t:
case Lf{v}:
Lf{U32.inc(v)}
case Nd{l, r}:
x y = bump(l) bump(r)
Nd{x, y}
def flip(t: Tr) -> Tr:
match t:
case Lf{v}:
Lf{v}
case Nd{l, r}:
x y = flip(l) flip(r)
Nd{y, x}
def sum(t: Tr) -> U32:
match t:
case Lf{v}:
v
case Nd{l, r}:
x y = sum(l) sum(r)
U32.add(U32.xor(U32.mul(x, 2654435761), y), 7)
def main() -> IO(Unit):
t0 = gen!(16n, 1)
t1 = bump(t0)
t2 = flip!(t1)
IO.print(U32.show(sum!(t2)))For the sequential control, replace x y = bump(l) bump(r) with the two sequential assignments shown above.
Environment
- Bend source under test:
b7ebee9217c8813067e200b0c0c9153a3be31c5e - Current main inspected:
47bed75adedd6d6dd811721905f06569bf465f85 - Linux x86_64, Ubuntu 26.04 / WSL2
- RTX 5090, driver 610.62, CUDA 13.1, clang 21.1.8
Activity
SiliconState commentedon Sep 25, 2026
Related architecture request: #1066. The scheduler must reliably return every marked phase to the GPU seam before a device-resident/dirty-range corpus can support dynamic programs correctly.
SiliconState commentedon Sep 25, 2026
Minor evidence correction: the runtime transfer counter divides bytes by
2^20but labels themMB. The quoted 160.7 and 32.4 figures are MiB, not decimal MB. This does not change the observed 3-versus-1 GPU-turn counts or the exact output3841805111.The reproduction scope remains as originally stated: live CUDA testing used
b7ebee9217c8813067e200b0c0c9153a3be31c5ewith the eager corpus-storage twin patch.47bed75adedd6d6dd811721905f06569bf465f85was inspected, not live-reproduced on CUDA. The proposed architectural remedy in #1066 is not an implemented fix for this dispatch defect.SiliconState commentedon Sep 26, 2026
Reproduced live on current main plus PR #1078:
c357d59(base11c65a2), whosecorpus_evalis main's apart from the twin's twogpu_synccalls. RTX 5090, WSL2,--gpu 512MB; turns counted by an LD_PRELOAD shim that forwards CUDA calls unchanged.!callsbump,--threads 2bump,--threads 2bump,--threads 1No message in any run, and
--threads 1behaves the same, so this isn't about worker threads as such, but my original pointer attask_deal/pool_openwas the right place. The first unmarked fork leavescorpus_eval's seam loop (task_deal(H, r, 0, 0, (Cur)0); pool_open(); cube_run(H, false); break;), and the rest of that evaluation runs in the CPU cube;fid_bangsis only checked in the seam loop. That predicts GPU turns = the!calls reached before the first host fork, which matches all five programs I counted (3/3, 1/3, 10/10, 2/4, 4/4).PR #1078's own
tests/run/gpu_turns.bendhits this too: 2 of 4 turns (details on the PR).gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device
VictorTaelin commentedon Sep 27, 2026
This works as designed. A
!goes to the GPU only when it is the root of an IO step. A!reached inside CPU-parallel work (after a host fork) runs on the CPU, together with that work. WONTFIX.txt now says so: "!goes to the GPU only at the root of an IO step (#1065)".Note: an AI wrote this reply after I made the decision. If anything here is wrong, reply and I will review it myself.
gpu_turns builds h without a fork, so all four ! turns reach the device
Bend 2.0.32: the issue triage, root fixes, one verdict everywhere
gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device
gpu_turns builds h without a fork, so all four ! turns reach the device