Skip to content

Add dims support to sort, sort!, sortperm and sortperm! - #117

Open
shreyas-omkar wants to merge 1 commit into
JuliaGPU:mainfrom
shreyas-omkar:sh/sort-dims
Open

Add dims support to sort, sort!, sortperm and sortperm!#117
shreyas-omkar wants to merge 1 commit into
JuliaGPU:mainfrom
shreyas-omkar:sh/sort-dims

Conversation

@shreyas-omkar

@shreyas-omkar shreyas-omkar commented Aug 24, 2026

Copy link
Copy Markdown
Member

Adds a dims keyword to sort/sort!/sortperm/sortperm! for portable per-slice N-D sorting across CPU and every GPU backend, using the same tag-and-lexicographic-sort strategy as AMDGPU.jl #1033

Sort or permute each 1D slice along an integer `dims` independently,
matching Base. The default `dims=:` keeps the existing flat behaviour.

There is no batched sort kernel, so each element is tagged with its slice
and the whole array is sorted once by (slice, value), then scattered back
into place. sortperm carries the original index as the payload and uses it
to break ties, keeping the permutation stable. This reuses the backend's
tuned sort and runs unchanged on CPU and every GPU backend.
@shreyas-omkar shreyas-omkar changed the title Add dims support to sort and sort! Add dims support to sort, sort!, sortperm and sortperm! Aug 24, 2026
@shreyas-omkar
shreyas-omkar marked this pull request as draft August 24, 2026 09:49
@shreyas-omkar

Copy link
Copy Markdown
Member Author

@christiangnrd Please take a look. :)

@shreyas-omkar
shreyas-omkar marked this pull request as ready for review August 26, 2026 06:51
@shreyas-omkar

shreyas-omkar commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

NVIDIA RTX 5080 (CUDA 13.3.0)

N-D sort(A; dims) Float32, 1,048,576 elements

size dims AK ms CUDA ms AK/CUDA
1024 x 1024 1 0.649 0.349 1.86x
1024 x 1024 2 0.671 0.469 1.43x
256 x 4096 1 0.641 0.435 1.47x
256 x 4096 2 0.682 0.706 0.97x
4096 x 256 1 0.659 0.494 1.33x
4096 x 256 2 0.663 0.543 1.22x

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