Use SIMD shuffles for native scans#874
Open
KookiesNKareem wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
@maleadt The Julia 1.13 job seems to have timed out after an hour rather than hitting a test failure. The |
Member
|
Thanks for the PR! Did you use AI for this PR? If so I kindly ask that you update the description with details as requested in the readme |
Contributor
Author
|
Yeah, of course, sorry about that. I updated the description. |
KookiesNKareem
marked this pull request as ready for review
July 15, 2026 19:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Use SIMD shuffles to reduce synchronization overhead in the native scan implementation.
The existing partial scan uses a Blelloch tree in threadgroup memory. For a 1024-thread block, this requires roughly 21 threadgroup barriers. The new path:
simd_shuffle_upThis requires no barriers for scans of up to 32 elements and two barriers for the hierarchical scan.
The SIMD path is limited to types supported by the existing shuffle intrinsics. Based on the measured crossover, 64–256-thread scans retain the existing Blelloch implementation, while 512-thread and larger scans use the hierarchical SIMD implementation. Unsupported types also continue to use the existing implementation.
The multi-block scan logic and algorithm selection between native kernels and MPSGraph are unchanged. Floating-point
accumulate(max/min, ...)uses the native path automatically because MPSGraph does not preserve Julia's NaN propagation semantics.Performance
Benchmarked on an Apple M4 with Julia 1.12.5. Each case scans 4,194,304 total elements, with 40 alternating before/after samples. Reported values are medians.
Native addition:
Float32Float32Float32Int32Int32Int32Floating-point max/min scans, which automatically use the native implementation:
accumulate(max)accumulate(max)accumulate(max)accumulate(min)accumulate(min)accumulate(min)The 256-thread case continues to dispatch to the existing implementation because the SIMD implementation did not consistently win at that crossover.
Correctness
The operand order and handling of padded lanes and initial values are preserved. Floating-point association can differ, as it already can with the existing parallel Blelloch scan.
The added tests cover a non-power-of-two multi-block addition scan and a non-additive scan along a non-leading dimension. Existing tests cover small scans, initializers, supported operations, and NaN propagation.
Validation:
AI Use:
This PR was made with the assistance of GPT 5.6 Sol Extra High. I reviewed all the code and benchmark results myself.