Skip to content

A parallel host phase makes later ! calls silently run on CPU instead of GPU #1065

Closed as not planned

Description

@SiliconState

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

  1. SiliconState commented on Sep 25, 2026

    @SiliconState
    Author

    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.

  2. SiliconState commented on Sep 25, 2026

    @SiliconState
    Author

    Minor evidence correction: the runtime transfer counter divides bytes by 2^20 but labels them MB. 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 output 3841805111.

    The reproduction scope remains as originally stated: live CUDA testing used b7ebee9217c8813067e200b0c0c9153a3be31c5e with the eager corpus-storage twin patch. 47bed75adedd6d6dd811721905f06569bf465f85 was inspected, not live-reproduced on CUDA. The proposed architectural remedy in #1066 is not an implemented fix for this dispatch defect.

  3. SiliconState commented on Sep 26, 2026

    @SiliconState
    Author

    Reproduced live on current main plus PR #1078: c357d59 (base 11c65a2), whose corpus_eval is main's apart from the twin's two gpu_sync calls. RTX 5090, WSL2, --gpu 512MB; turns counted by an LD_PRELOAD shim that forwards CUDA calls unchanged.

    Variant ! calls Output GPU turns
    sequential host bump, --threads 2 3 3841805111 3
    parallel host bump, --threads 2 3 3841805111 1
    parallel host bump, --threads 1 3 3841805111 1

    No message in any run, and --threads 1 behaves the same, so this isn't about worker threads as such, but my original pointer at task_deal/pool_open was the right place. The first unmarked fork leaves corpus_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_bangs is 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.bend hits this too: 2 of 4 turns (details on the PR).

  4. VictorTaelin commented on Sep 27, 2026

    @VictorTaelin
    Contributor

    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.

  5. added
    wontfix
    on Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions