Skip to content

docs: experimental Metal associate kernel and benches - #41

Merged
jkbennitt merged 1 commit into
mainfrom
experiments/metal-kernels
Nov 10, 2026
Merged

jkbennitt merged 1 commit into
mainfrom
experiments/metal-kernels

Conversation

@jkbennitt

Copy link
Copy Markdown
Member

Why

Jason asked compute-heavy bots to try an AI-written GPU kernel on unsga3-bend (inspired by a custom CUDA kernel that cut an OCR loop from hours to minutes). This PR is the measured prototype: a hand-written Metal associate kernel on the Mac mini M4, compared with the current Bend CPU path and Bend's own ! Metal backend.

What changed

  • New isolated folder experiments/metal-kernels/ (MSL + CUDA source, Swift host, Python reference, Bend product/bang harnesses, Mac results).
  • New docs/PERF_NOTES.md section with the tables.
  • No src/ / LAWS.bend / PROOF.bend edits, no product Run path change, no release cut, no CHANGELOG version section.

Hot spot

Fresh --threads 1 profiles (bend 2.0.40) picked association (perp distance + argmin, plus niche-count histogram) as the largest uniform map a kernel can honestly target. At oracle DTLZ2 92×150 it is 16–18% of wall; nds (23–27%) is divergent and niche fill (25–27%) is sequential/RNG-ordered.

Headline numbers (JMac-mini M4, 2026-11-10 00:48–00:52 America/New_York)

Hand MSL e2e vs Bend product (current path): 1.51× at 184×91 (DTLZ2 combined pool), 50.5× at 2048×276, 277× at 32k×3003. Hand MSL e2e vs Bend ! Metal: 17.9× at 184×91; Bend ! stack-overflows at 2048×276 and 32k×3003. Full table, ranges, checksums, and break-even: experiments/metal-kernels/results/TABLES.md and the new PERF_NOTES section.

Correctness

  • Python ref vs Bend product (box) and vs MSL (Mac), n=8 r=5 seed=1: exact argmin indices, matching niche counts, max abs distance 5.4e-9 / 3.0e-8.
  • Every completed bench size: matching sum_idx. Observed max abs distance ≤ 5.6e-8 (tolerance abs 1e-6 / rel 1e-5).
  • Product IGD path unchanged by construction (no src/ edits). verify still runs the seed-1 yardstick.

CUDA

associate.cu is the same algorithm. nvcc is not on the box; a CUDA toolkit is not a cheap install. No compile-check, no CUDA timings claimed.

Lane

Low risk: non-production experiment + docs only. Nothing here is imported by src/algorithm.bend. Please auto-merge on green verify.

Add an isolated experiments/metal-kernels prototype (MSL + CUDA source,
Bend product and bang harnesses, Mac results) and a PERF_NOTES section.
No product Run path change, no LAWS/PROOF edits, no release cut.
@jkbennitt jkbennitt added the low-risk Auto-merges on green required CI. Never prod, money, auth, secrets, pricing, or public posts. label Nov 10, 2026
@jkbennitt
jkbennitt enabled auto-merge November 10, 2026 05:54
@jkbennitt
jkbennitt merged commit 320a718 into main Nov 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

low-risk Auto-merges on green required CI. Never prod, money, auth, secrets, pricing, or public posts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant