Skip to content

fix(gpu): reject oversized transfers and f32 kernel counts before the backend (#814) - #1403

Merged
godofecht merged 2 commits into
mainfrom
fix/814-gpu-transfer-and-dispatch-bounds
Oct 8, 2026
Merged

godofecht merged 2 commits into
mainfrom
fix/814-gpu-transfer-and-dispatch-bounds

Conversation

@godofecht

@godofecht godofecht commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Part of #814 (GPU resource safety). Rebased as one commit on main f313b641.

Change

  • lib/stdlib/gpu_memory.flow: reject a copy larger than either buffer's size, unknown allocation flags, typed allocation counts that overflow the byte size, and f32 kernel counts beyond any of the three buffers or the shader's 32-bit count. All before the backend is called.
  • runtime/gpu_memory.h: flow_gpu_f32_launch_fits, used by the Metal dispatch to check native sizes before compute init.
  • runtime/gpu_metal.m: shared-to-shared device copy uses memmove.
  • Docs: "Buffer-size and dispatch safety" in docs/library/gpu-memory.md.

Dropped from the draft: tests/native/gpu_f32_bounds.c (no runner executes it). The Flow test moved from tests/lang to tests/runtime, because test-lang does not link the GPU runtime.

Proof (macOS arm64, real Metal)

  • tests/runtime/test_gpu_memory_bounds.flow: passes; with main's gpu_memory.flow it exits 12 (flags 99 accepted).
  • ./flow test-gpu: gpu_features and Metal codegen pass.
  • examples/gpu/gpu_mul_backward.flow (real Metal f32 kernels): PASS. examples/gpu/gpu_memory_roundtrip.flow: PASS.

Gates (on f313b64)

test-lang 274/0, test-runtime 36/0, test-gpu pass, tests/tools pass, tests/cli 152/2 (jit_hello, test_mlir: known drift on this Mac).

Merge note

#1406 changes the same bounds check in runtime/gpu_metal.m. When it is rebased after this lands, the resolution keeps #1406's comment and calls flow_gpu_f32_launch_fits before compute init.

Remaining for #814

Model execution over shared GPU resources (MNIST / depth parity on Metal and WebGPU) is the work in #1406 and #1408.

@godofecht
godofecht force-pushed the fix/814-gpu-transfer-and-dispatch-bounds branch from 9fd7cf8 to 2b5e093 Compare October 7, 2026 12:37
@godofecht godofecht changed the title fix(gpu): reject oversized transfers and overflowing f32 dispatches (#814) fix(gpu): reject oversized transfers and f32 kernel counts before the backend (#814) Oct 7, 2026
@godofecht
godofecht marked this pull request as ready for review October 7, 2026 12:38
@godofecht
godofecht force-pushed the fix/814-gpu-transfer-and-dispatch-bounds branch from 2b5e093 to ba1d634 Compare October 7, 2026 16:28
@godofecht godofecht changed the title fix(gpu): reject oversized transfers and f32 kernel counts before the backend (#814) GPU train: #1403, #1404, #1406, #1408, #1407, #1405 (#811, #812, #814 parts) Oct 7, 2026
@godofecht
godofecht enabled auto-merge October 7, 2026 17:03
@godofecht
godofecht force-pushed the fix/814-gpu-transfer-and-dispatch-bounds branch from d8c2ec5 to ba1d634 Compare October 7, 2026 17:12
@godofecht godofecht changed the title GPU train: #1403, #1404, #1406, #1408, #1407, #1405 (#811, #812, #814 parts) fix(gpu): reject oversized transfers and f32 kernel counts before the backend (#814) Oct 7, 2026
@godofecht
godofecht added this pull request to the merge queue Oct 7, 2026
@godofecht
godofecht removed this pull request from the merge queue due to a manual request Oct 7, 2026
@godofecht
godofecht force-pushed the fix/814-gpu-transfer-and-dispatch-bounds branch from ba1d634 to 50a8fb4 Compare October 7, 2026 17:57
@godofecht
godofecht added this pull request to the merge queue Oct 7, 2026
@godofecht
godofecht removed this pull request from the merge queue due to a manual request Oct 7, 2026
… backend (#814)

The gpu_memory wrappers passed any positive byte count to the backend.
They now reject a copy larger than either buffer's size, unknown
allocation flags, typed allocation counts that overflow the byte size,
and f32 kernel counts beyond any of the three buffers or the shader's
32-bit count. The Metal dispatch checks the native sizes again through
flow_gpu_f32_launch_fits before it initialises compute, and
shared-to-shared device copies use memmove.

tests/runtime/test_gpu_memory_bounds.flow exits 12 with main's library
(it accepts flags 99) and passes here.
flowc MLIR goldens fail on the three corpus programs that compile
gpu_memory.flow. parity_mlir --record on main plus #1404, keeping only
those rows and the new tests/runtime/test_gpu_memory_bounds.flow.
@godofecht
godofecht force-pushed the fix/814-gpu-transfer-and-dispatch-bounds branch from 50a8fb4 to 0492e74 Compare October 7, 2026 23:37
@godofecht
godofecht enabled auto-merge October 7, 2026 23:37
@godofecht
godofecht added this pull request to the merge queue Oct 7, 2026
Merged via the queue into main with commit 0b73094 Oct 8, 2026
28 checks passed
godofecht added a commit that referenced this pull request Oct 8, 2026
…kernels (#814)

parity_mlir --record on main plus #1404 and #1403, keeping the rows for
programs this PR changes (gpu_memory, its stub, the mnist and depth
examples, the memory bounds test) and its new gpu_tensor module and
tests.
godofecht added a commit that referenced this pull request Oct 8, 2026
…kernels (#814)

parity_mlir --record on main plus #1404 and #1403, keeping the rows for
programs this PR changes (gpu_memory, its stub, the mnist and depth
examples, the memory bounds test) and its new gpu_tensor module and
tests.
@godofecht
godofecht deleted the fix/814-gpu-transfer-and-dispatch-bounds branch October 12, 2026 23:03
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