Skip to content

feat(webgpu): execute chained Flow kernels over persistent device resources (#814) - #1408

Merged
godofecht merged 15 commits into
mainfrom
feat/814-webgpu-kernel-chain
Oct 7, 2026
Merged

godofecht merged 15 commits into
mainfrom
feat/814-webgpu-kernel-chain

Conversation

@godofecht

@godofecht godofecht commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Part of #814. Does not close it. The WebGPU counterpart of #1406.

Change

runFlowKernelChain (wasm/crossing_assets/gpu-kernel-chain.mjs, same file under site/wasm-crossings/gpu/, exported from webgpu-host.js) runs several Flow-generated @gpu kernels in one command buffer over persistent GPU buffers and maps only the requested outputs. It checks bindings, aliasing, uniform layout, dispatch and workgroup limits, read-before-write and readback of unwritten resources, and fails on WGSL compile errors. docs/gpu/persistent-compute.md describes it.

Fixed in this rebase, found by running two Flow kernels on a real adapter:

  • Flow reflects every output buffer as read_write (WGSL has no write-only storage buffer). The host treated read_write as a read of uninitialised memory, so any chain with a fresh output was refused. Only read bindings now need prior contents.
  • The uniform block went to queue.writeBuffer as a bare ArrayBuffer, which Deno's WebGPU rejects. It now goes as a Uint8Array.

The mock tests had used an access mode (write) the compiler never emits and a mock that accepted a bare ArrayBuffer, so they passed against the broken host. The mock is now as strict as the real device, the stage helper uses read_write, and a new test uses the exact reflection shape the compiler writes.

tests/scripts/webgpu_hosts.flow runs every tests/webgpu/*.test.mjs with node --test from ./flow test-scripts, skipping when node is absent, so these tests have a runner.

Evidence

Rebased onto main e2205a7.

  • Real device: scale2 then add_one, emitted by ./flow tool tools/gpu/main.flow --crossing-manifest from a two-kernel Flow file, run through runFlowKernelChain in Deno 2.7 (--unstable-webgpu, Metal backend on Apple silicon) over 1,000 elements: execution=webgpu-device, 0 mismatches against 2x + 1. Before the fix the same run failed with Flow GPU resource read before write: b, then with data must be an ArrayBuffer or ArrayBufferView.
  • node --test tests/webgpu/kernel-chain.test.mjs: 9/9. Against the previous host, 4 fail.
  • ./flow test-scripts webgpu_hosts: passes.
  • ./flow tool tests/cli/run.flow: 152 passed, 2 failed (jit_hello, test_mlir: golden drift on main). Shell and Python ratchets pass. test-lang and test-runtime were not run: no Flow source they compile changed.

The real-device script is a one-off and is not committed, since CI has no GPU. MNIST and depth through this host remain open on #814.

Merge notes

#1405 and #1407 also add an export line at the top of webgpu-host.js (and its wasm/crossing_assets copy). Keep all three lines when resolving. Their tests/webgpu/*.test.mjs files are picked up by webgpu_hosts.flow without changes.

@godofecht
godofecht force-pushed the feat/814-webgpu-kernel-chain branch from 25484a3 to 737ab4c Compare October 7, 2026 13:28
@godofecht
godofecht marked this pull request as ready for review October 7, 2026 13:28
@godofecht
godofecht enabled auto-merge October 7, 2026 17:03
@godofecht
godofecht added this pull request to the merge queue Oct 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 7, 2026
@godofecht
godofecht added this pull request to the merge queue Oct 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 7, 2026
Two Flow kernels from tools/gpu --crossing-manifest failed on a real
WebGPU device (Deno, Metal backend). Flow reflects every output as
read_write, and the host treated read_write as a read of uninitialised
memory, so no chain with a fresh output could run. Only read bindings now
need prior contents. The uniform block went to writeBuffer as a bare
ArrayBuffer, which Deno rejects; it now goes as a Uint8Array view.

The mock device now refuses a bare ArrayBuffer as the real one did, the
test stage helper uses the read_write access Flow emits, and a new test
uses the exact reflection shape the compiler writes.
wiki_nav failed with 'gpu/persistent-compute.md is in no nav section'.
webgpu-host.js now re-exports runFlowKernelChain from
./gpu-kernel-chain.mjs, but the crossing builder copied only the host,
so a built page failed its module import and the gpu crossing goldens
failed in the merge queue (7 cases). The builder copies every
'} from "./NAME"' module next to the host. Goldens updated: the new
host, gpu-kernel-chain.mjs, and one more 'wrote' line for gpu pages.
@godofecht
godofecht force-pushed the feat/814-webgpu-kernel-chain branch from 1348752 to 15bb37a Compare October 7, 2026 20:53
@godofecht
godofecht enabled auto-merge October 7, 2026 20:53
@godofecht
godofecht added this pull request to the merge queue Oct 7, 2026
Merged via the queue into main with commit 8712405 Oct 7, 2026
40 checks passed
godofecht added a commit that referenced this pull request Oct 7, 2026
…WGSL kernels (#812)

Rebuilt on main 8712405 as one commit. Conflicts resolved per hunk:
both webgpu-host.js copies keep the #1408 kernel-chain export and the
graph-host export; string.flow keeps main's comment wording. stdlib-api.md
and the LSP completion golden were regenerated.
godofecht added a commit that referenced this pull request Oct 7, 2026
…st.js (#812)

webgpu-host.js re-exports runFlowWebGpuGraph from ./gpu-graph-host.mjs, and the crossing builder from #1408 copies every re-exported module, so the seven gpu pages now write gpu-graph-host.mjs and the new host.
@godofecht
godofecht deleted the feat/814-webgpu-kernel-chain branch October 12, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant