Skip to content

perf(reverse): use a dedicated kernel for the dims reversal - #118

Open
shreyas-omkar wants to merge 4 commits into
JuliaGPU:mainfrom
shreyas-omkar:sh/reverse-kernel-speedup
Open

perf(reverse): use a dedicated kernel for the dims reversal#118
shreyas-omkar wants to merge 4 commits into
JuliaGPU:mainfrom
shreyas-omkar:sh/reverse-kernel-speedup

Conversation

@shreyas-omkar

@shreyas-omkar shreyas-omkar commented Sep 1, 2026

Copy link
Copy Markdown
Member

Benchmarks for the dedicated-kernel dims reversal. reverse(A; dims), Float32, min of 30 runs, ms.

NVIDIA RTX 5080 (CUDA 6.3.1)

size dims old (#114) new (#118) native
4096 x 4096 1 1.384 0.404 0.375
4096 x 4096 2 1.369 0.407 0.185
256 x 65536 1 1.151 0.198 0.377
65536 x 256 2 1.128 0.197 0.183

AMD RX 9060 XT (AMDGPU 2.8.0)

size dims old (#114) new (#118) native
4096 x 4096 1 0.587 0.574 0.584
4096 x 4096 2 0.618 0.608 0.637
256 x 65536 1 0.616 0.718 0.755
65536 x 256 2 0.746 0.696 0.807

On CUDA the dedicated kernel runs the index math inline, which the foreachindex closure did not on NVPTX, giving a 3x to 6x speedup and reaching native parity. On AMD the closure was already inlined, so the numbers are unchanged (no regression).

shreyas-omkar and others added 4 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>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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