Skip to content

Reduce: vectorize contiguous by-block loads - #105

Merged
maleadt merged 2 commits into
JuliaGPU:mainfrom
shreyas-omkar:sh/vec-loads-simd
Aug 20, 2026
Merged

Reduce: vectorize contiguous by-block loads#105
maleadt merged 2 commits into
JuliaGPU:mainfrom
shreyas-omkar:sh/vec-loads-simd

Conversation

@shreyas-omkar

@shreyas-omkar shreyas-omkar commented Jul 29, 2026

Copy link
Copy Markdown
Member

Use aligned 128-bit SIMD loads for stride-1 by-block reductions of 4- and
8-byte primitive elements. Each thread folds a Vec{4} or Vec{2} load into
its local accumulator; unsupported layouts continue through the scalar kernel.

The fast path requires a 16-byte-aligned buffer and row starts, a contiguous
reduced dimension, and an extent that is safe for the kernel's UInt32 index
arithmetic. A shared launcher applies the same dispatch to every by-block call
site.

The original benchmarks measured speedups of up to 44% on CUDA, 19% on AMDGPU,
37% on POCL, and 19% on oneAPI.

Validation:

  • CPU suite: 34,692/34,692
  • CUDA reduction suite with the sibling CUDA checkout: 18,131/18,131
  • OpenCL/POCL reduction suite with the sibling OpenCL checkout: 18,131/18,131
  • CUDA PTX contains one ld.global.v4 for Float32 and one ld.global.v2 for
    Float64

@shreyas-omkar
shreyas-omkar marked this pull request as ready for review August 18, 2026 11:54
@shreyas-omkar

Copy link
Copy Markdown
Member Author

@christiangnrd and @maleadt Please review it :)

@christiangnrd christiangnrd changed the title perf(mapreduce): vectorized SIMD.jl loads for stride-1 by_block redution perf(mapreduce): vectorized SIMD.jl loads for stride-1 by_block reduction Aug 18, 2026
@christiangnrd

Copy link
Copy Markdown
Member

Can you add a few tests that are guaranteed to trigger this path?

@shreyas-omkar

Copy link
Copy Markdown
Member Author

Yes I'll add them.

@christiangnrd

Copy link
Copy Markdown
Member

@shreyas-omkar I added valid_backend_eltypes in #113 to make it easier to remember to filter out eltypes by backend

@shreyas-omkar

Copy link
Copy Markdown
Member Author

@christiangnrd . Thank you for adding it. I have used it in the PR.

Load aligned stride-1 reductions in 128-bit vectors. Keep scalar loads
for unsupported layouts, pointers, types, and index ranges. Route every
by-block call site through the same dispatch.
@maleadt
maleadt force-pushed the sh/vec-loads-simd branch from 71c33cf to 5b84a5d Compare August 19, 2026 13:43
@maleadt maleadt changed the title perf(mapreduce): vectorized SIMD.jl loads for stride-1 by_block reduction perf(reduce): vectorize contiguous by-block loads Aug 19, 2026
@maleadt maleadt changed the title perf(reduce): vectorize contiguous by-block loads Reduce: vectorize contiguous by-block loads Aug 20, 2026
@maleadt
maleadt merged commit 8b4db3f into JuliaGPU:main Aug 20, 2026
54 checks passed
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.

3 participants