Skip to content

feat(gpu): real Metal tensor model kernels on current main (#814) - #1406

Merged
godofecht merged 5 commits into
mainfrom
feat/814-real-metal-tensor-rebased
Oct 8, 2026
Merged

godofecht merged 5 commits into
mainfrom
feat/814-real-metal-tensor-rebased

Conversation

@godofecht

@godofecht godofecht commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Part of #814. Does not close it. This is the older #1364 branch rebased onto current main, without replacing the existing vgpu conformance runner.

Change

  • lib/stdlib/gpu_tensor.flow: shaped, typed tensor views over GpuBuffer with shape, dtype and access checks, overflow-checked dimensions, shared-storage views and explicit host and private-buffer transfers.
  • runtime/gpu_metal.m: Metal compute kernels scale_bias_f32, relu_f32, invert_clamp01_f32 and gemm_f32, with element-count and capacity checks before any uint32 conversion, GEMM output aliasing refused, and a counter of completed device dispatches. The non-Apple stub returns -1.
  • lib/stdlib/gpu_memory.flow: externs for the model kernels and gpu_model_dispatch_count. The allocation, copy and f32 kernel guards landed in fix(gpu): reject oversized transfers and f32 kernel counts before the backend (#814) #1403.
  • examples/gpu/vgpu/mnist.flow and depth_estimation.flow run a small deterministic model on the GPU path and compare it with a host Tensor reference. They print GPU_DEVICE_EXECUTED metal only after a Metal command buffer completes.
  • tools/gpu_test: the mnist and depth cases report NUMERICAL on Metal only when the reference matches and the device marker is present.

Added in the rebases: docs/library/stdlib-api.md and the LSP completion golden regenerated on current main; nav, coverage and stdlib-map entries for gpu_tensor next to the #1405 and #1407 entries; test_gpu_tensor and test_gpu_model listed in flow ml test.

Added for the merge queue, which runs gates the PR job skips:

  • tests/gpu/expected/examples_gpu_vgpu_{mnist,depth_estimation}_flow_{metal,wgsl}: the examples now have one kernel per stage, so tests/gpu/run.flow failed 4 cases. Recorded from the Flow tool with GPU_GATE_SAVE; 40/0.
  • compiler/fixtures/mlir/corpus.txt: parity_mlir --record, keeping only the rows this PR changes (gpu_memory, its stub, the mnist and depth examples, the memory bounds test) and the new gpu_tensor module and tests.

The examples are fixed-shape models. They do not classify the MNIST test set or run a trained depth network.

Evidence

On main 0b73094, macOS arm64 with a Metal device.

  • ./flow run examples/gpu/vgpu/mnist.flow: GPU_DEVICE_EXECUTED metal, match 1. depth_estimation.flow: GPU_DEVICE_EXECUTED metal, match 1.
  • ./flow gpu test --suite vgpu --all-backends: gradient EXACT on both backends; mnist and depth NUMERICAL on metal (metal-device-dispatch), UNSUPPORTED on webgpu.
  • ./flow ml test, ./flow test-gpu: pass.
  • ./flow test-scripts gpu_tensor gpu_vgpu: all passed.
  • parity_mlir PASS, tests/gpu/run.flow 40/0, tests/gpu/crossing.flow 16/0.
  • gen_stdlib_docs --check, doc_coverage, doc_links, wiki_nav: clean. LSP transcripts 9/9.
  • ./flow test-lang, ./flow test-runtime: all pass.

Merge notes

@godofecht
godofecht force-pushed the feat/814-real-metal-tensor-rebased branch from b33f188 to 205c80a Compare October 7, 2026 12:48
@godofecht
godofecht marked this pull request as ready for review October 7, 2026 12:49
godofecht added a commit that referenced this pull request Oct 7, 2026
gpu_graph and gpu_tensor (#1406) both exported GPU_ACCESS_READ, _WRITE and
_READ_WRITE, and a program cannot import two modules that export the same
const. The graph constants are now GPU_GRAPH_ACCESS_*. Added coverage, nav
and stdlib-map entries for gpu_graph, gpu_graph_export and
gpu_graph_kernels, regenerated stdlib-api.md and the LSP completion
golden, and rewrote the Backends section of gpu-graph.md plainly. Prose
fixes the commit hook asked for in gpu-graph.md, gpu_graph_kernels.flow
and one string.flow comment (the same edit as #1401 and #1406).
godofecht added a commit that referenced this pull request Oct 7, 2026
…odules

gpu_stage_codegen reassigned immutable lets (components, uv_type,
tex_type, uv_expr), so the strict check failed and ./flow test-lang had
never run test_gpu_stage_codegen. They are now let mut, and the struct
fields carry commas like the rest of the stdlib. Added coverage, nav and
stdlib-map entries for gpu_resource_types and gpu_stage_codegen,
regenerated stdlib-api.md and the LSP completion golden. Two comments
reworded for the prose hook (string.flow matches #1401, #1406, #1407).
@godofecht
godofecht enabled auto-merge October 7, 2026 17:03
godofecht added a commit that referenced this pull request Oct 8, 2026
…#814)

#1406 splits the mnist and depth examples into named stage kernels, so
tests/gpu/run.flow failed 4 cases. Recorded from the Flow tool with
GPU_GATE_SAVE; the gate passes 40/0.
@godofecht
godofecht force-pushed the feat/814-real-metal-tensor-rebased branch from 50ffef8 to 5feb996 Compare October 8, 2026 00:48
@godofecht
godofecht added this pull request to the merge queue Oct 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 8, 2026
Native Metal tensor compute over shared GPU resources, typed allocation
and kernel-count guards, fail-closed Metal error semantics, rejection of
overlapping GEMM output, gpu_tensor docs and index entries, and the
gpu_tensor and gpu_model tests wired into flow ml test.
…#814)

#1406 splits the mnist and depth examples into named stage kernels, so
tests/gpu/run.flow failed 4 cases. Recorded from the Flow tool with
GPU_GATE_SAVE; the gate passes 40/0.
…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.
…#814)

The Linux runner reports 'CASE mnist [metal] UNSUPPORTED w=- ...
reason=device-execution', so the check for 'UNSUPPORTED
reason=device-execution' as one string failed in the Native tools job.
…814)

flow ml test now runs both, so tests/mlir_commands ml_test differed by
those two lines in the goldens job.
@godofecht
godofecht enabled auto-merge October 8, 2026 02:52
@godofecht
godofecht force-pushed the feat/814-real-metal-tensor-rebased branch from 2bc63b4 to 874546b Compare October 8, 2026 02:52
@godofecht
godofecht added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit fef4005 Oct 8, 2026
32 checks passed
@godofecht
godofecht deleted the feat/814-real-metal-tensor-rebased 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