Repository navigation
Conversation
maleadt
force-pushed
the
tb/noncommutative
branch
from
October 22, 2026 10:07
f5b19f6 to
6fe5ec8
Compare
AcceleratedKernels' reductions combine elements in any order, so a non-commutative operator, such as one keeping the first of equal values, gave wrong results on large arrays (JuliaGPU/AcceleratedKernels.jl#164, was JuliaGPU/CUDA.jl#1058). Base keeps the elements in order, so pass `commutative=false` to AcceleratedKernels (0.5.8) unless the operator is known to commute on the types involved: Base's arithmetic, bitwise and min/max operators on Base's number types, and this package's own reducers, which become named so that they can be marked.
maleadt
force-pushed
the
tb/noncommutative
branch
from
October 23, 2026 13:45
6fe5ec8 to
fef2239
Compare
maleadt
marked this pull request as ready for review
October 23, 2026 13:45
This branch has not been deployed
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.
Fixes JuliaGPU/AcceleratedKernels.jl#164 (was JuliaGPU/CUDA.jl#1058) for GPUArrays users. Needs JuliaGPU/AcceleratedKernels.jl#165 and an AcceleratedKernels release (compat bumped to 0.5.8), hence draft.
Base's reductions keep elements in order, so
mapreducewith a non-commutative operator must give the in-order result. AcceleratedKernels' default kernels assume commutativity. This passescommutative=falseunless the operator is known to commute on the types involved:+,*,add_sumandmul_prodon Base's number types;max/minon reals;&,|andxoron integers andBool;_extrema_rf;findfirst/findlastonCartesianIndex,findmin/findmax,==).The package's own reducers become named functions so that they can be marked.
istriu/istrilnow reduce with&.The check looks at types as well as operators, because
*on matrices or quaternions doesn't commute. Everything else takes the ordered kernels, which cost roughly 1.0x to 1.2x on large inputs.A new
reductions/ordertestsuite entry covers the issue'sfindmax-like example with ties, "last nonzero" and tuple matrix products, whole-array and alongdims. 11 of its 19 tests fail with the old forwarding. It passes on CUDA and JLArrays.