Reuse Stockham twiddles in large batched Bluestein FFTs - #4084
Reuse Stockham twiddles in large batched Bluestein FFTs#4084PhysicistJohn wants to merge 2 commits into
Conversation
zcbenz
left a comment
There was a problem hiding this comment.
Precomputing twiddles should help but doing it in host seems to be eating a lot of performance. Can you try doing it with a metal kernel? We can't really merge changes like this.
|
Thanks, Cheng. Agreed. I moved the table generation onto Metal: one private kernel writes the 584 Stockham twiddles, which the selected fused Bluestein path reuses in both internal passes. Against |
Proposed changes
Fused Bluestein FFTs run the same Stockham plan twice and currently recompute its radix twiddles in each pass. For complex64 transforms using the 4096-point internal plan with total batch at least 1024, this change dispatches one private Metal kernel to generate a 584-value twiddle table, then reuses it in both internal transforms. Smaller batches, other plans, and real transforms retain dynamic twiddles. There are no public API changes.
Results
The implementation was benchmarked against
mainatbb6d960fon an Apple M5 Max using static Metal. Across 20 selected end-to-endfftandifftcells, the median of the per-cell candidate/main ratios was1.03856x(3.856%). Each full-matrix cell used six balanced fresh-process rounds, 10 warmups, and nine samples of 30 transforms. Fresh 12- or 24-round targeted reruns placed every initially noisy candidate/main 95% lower bound above 1.0. The targeted 2047-point, batch-2048 cases remained near-neutral at1.0056xforward and1.0028xinverse. An unchanged 4096-point Stockham control measured0.9984x, with a 95% interval of[0.9817, 1.0186].All 48 deterministic accuracy comparisons passed. Relative to the benchmark baseline, the selected path adds 16,384 bytes of measured peak allocation, 38,432 bytes to
mlx.metallib, 4,080 bytes tolibmlx.a, and one private Metal kernel entry point.Validation
mainat7729d587Checklist