Skip to content

feat(reverse): Add dims support to reverse - #114

Open
shreyas-omkar wants to merge 3 commits into
JuliaGPU:mainfrom
shreyas-omkar:sh/reverse-dims
Open

feat(reverse): Add dims support to reverse#114
shreyas-omkar wants to merge 3 commits into
JuliaGPU:mainfrom
shreyas-omkar:sh/reverse-dims

Conversation

@shreyas-omkar

Copy link
Copy Markdown
Member

No description provided.

shreyas-omkar and others added 2 commits August 21, 2026 18:04
Add a `dims` keyword to `reverse!`/`reverse`, reaching parity with
`Base.reverse` and the vendor reverse kernels. `dims=:` (the default)
keeps the fast flat path - each thread swaps one mirrored pair - while
`dims=d` (an integer or iterable) reverses only along those dimensions
via a general ND kernel written on `foreachindex`, so it runs on every
backend (CUDA/AMDGPU/oneAPI/Metal/POCL) and the CPU-threaded path from
one implementation. Invalid dims throw `ArgumentError`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Exercise single-dim, multi-dim ((1,2)/(2,3)/(1,3)/:), size-1 degenerate
dims and 3-D arrays across in-place, out-of-place and allocating forms,
plus ArgumentError on out-of-range dims. Verified on CPU-threaded,
AMDGPU (ROCm) and POCL backends.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shreyas-omkar
shreyas-omkar marked this pull request as ready for review August 24, 2026 09:03
@shreyas-omkar

Copy link
Copy Markdown
Member Author

@christiangnrd I have added dims support for reverse. Please check it out once.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@christiangnrd

Copy link
Copy Markdown
Member

I had Claude take a look and it added a few test cases.

Was you plan to finish the reverse interface to add reverse(v [, start=firstindex(v) [, stop=lastindex(v) ]] ) in this PR or were you planning on opening a follow-up after the fact?

@shreyas-omkar

Copy link
Copy Markdown
Member Author

I had Claude take a look and it added a few test cases.

Was you plan to finish the reverse interface to add reverse(v [, start=firstindex(v) [, stop=lastindex(v) ]] ) in this PR or were you planning on opening a follow-up after the fact?

I planned on making a follow up PR once this is merged. We can do it in this PR too. What would be ideal??

@christiangnrd

Copy link
Copy Markdown
Member

Separate is fine and should make them easier to merge

@shreyas-omkar

Copy link
Copy Markdown
Member Author

NVIDIA RTX 5080 (CUDA 13.3.0)

1D reverse!(v) in-place (copy ms = memory-bandwidth ceiling)

N type AK ms CUDA ms AK GB/s AK/CUDA
1,000,000 Float32 0.020 0.013 405 0.64x
1,000,000 Int64 0.025 0.015 649 0.62x
16,000,000 Float32 0.082 0.067 1562 0.82x
16,000,000 Int64 0.325 0.319 788 0.98x
64,000,000 Float32 0.638 0.655 803 1.03x
64,000,000 Int64 1.285 1.285 797 1.00x

1D reverse(v) out-of-place

N type AK ms CUDA ms AK GB/s AK/CUDA
16,000,000 Float32 0.175 0.163 731 0.93x
16,000,000 Int64 0.333 0.320 770 0.96x
64,000,000 Float32 0.650 0.635 788 0.98x
64,000,000 Int64 1.283 1.284 798 1.00x

N-D reverse(A; dims) Float32, 67,108,864 elements

size dims AK ms CUDA ms AK/CUDA
8192 x 8192 1 4.185 0.676 0.16x
8192 x 8192 2 4.185 0.674 0.16x
8192 x 8192 (1,2) 4.186 0.676 0.16x
16384 x 4096 1 4.175 0.674 0.16x
16384 x 4096 2 4.180 0.673 0.16x
16384 x 4096 (1,2) 4.171 0.675 0.16x

AMD RX 9060 XT (RDNA4 / gfx1200, AMDGPU 2.5.1)

1D reverse!(v) in-place (copy ms = memory-bandwidth ceiling)

N type AK ms AMD ms AK GB/s AK/AMD
1,000,000 Float32 0.025 0.031 322 1.25x
1,000,000 Int64 0.037 0.038 428 1.01x
16,000,000 Float32 0.450 0.467 285 1.04x
16,000,000 Int64 0.941 0.907 272 0.96x
64,000,000 Float32 1.809 1.851 283 1.02x
64,000,000 Int64 3.684 3.630 278 0.99x

1D reverse(v) out-of-place

N type AK ms AMD ms AK GB/s AK/AMD
16,000,000 Float32 0.570 0.607 224 1.06x
16,000,000 Int64 1.138 0.953 225 0.84x
64,000,000 Float32 1.693 1.726 302 1.02x
64,000,000 Int64 3.429 3.353 299 0.98x

N-D reverse(A; dims) Float32, 67,108,864 elements

size dims AK ms AMD ms AK/AMD
8192 x 8192 1 1.841 1.838 1.00x
8192 x 8192 2 1.820 1.842 1.01x
8192 x 8192 (1,2) 2.566 1.839 0.72x
16384 x 4096 1 1.825 1.823 1.00x
16384 x 4096 2 1.815 1.827 1.01x
16384 x 4096 (1,2) 1.834 1.843 1.00x

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.

2 participants