Optimize Radix sort. - #97
Conversation
|
Current OpenCL sort failures seem to be related (or surfaced by) radix sort. On my device, it hangs when julia isn't launched with MWE: using pocl_jll, OpenCL; import AcceleratedKernels as AK; begin
v_arr = rand(Int32, 68931)
v = CLArray(v_arr);
@info "Sorting"
AK.sort!(v; alg=AK.RadixSort())
@info "Sorted"
issorted(Array(v))
endThis is probably POCL since this MWE passes on the Asahi driver |
|
histogram completes fine. AK.accumulate hangs for n > 512. Fix is pushed. Can you test the repro once on Mac? |
64e0aec to
e090e0c
Compare
a227115 to
e10caf2
Compare
82aebf9 to
57660d5
Compare
|
@christiangnrd and @maleadt Please review it. |
6798e18 to
bc8ddbd
Compare
bc8ddbd to
18639af
Compare
|
Reviewed and tightened this a little:
I also removed the tile abstraction for now; it was pretty unused here. I'd prefer if we land this separately (porting more from GemmKernels.jl's abstraction like the 2D support, and adapting multiple algorithms here to validate the design). Validated on OpenCL.jl and Metal.jl. Performance improvements are real, so this is looking good. |
|
OpenCL.jl fixed in JuliaPackaging/Yggdrasil#14480, CUDA.jl failure is JuliaConcurrent/UnsafeAtomics.jl#23. |
Rework the GPU LSD radix sort (8-bit, 256 buckets) for discrete-GPU throughput while staying portable across backends (no sub-group intrinsics): - atomic histogram + chunked O(32)-rank scatter where the backend reports shared-memory atomics; portable scan/broadcast fallback otherwise - process multiple items per thread in the histogram and scatter, shrinking the per-(digit, block) histogram and its scan - single-kernel fast path for arrays that fit one tile (n <= 2*block_size), running the whole multi-pass sort in shared memory - a small Tile primitive (src/tile.jl) for block-strided, coalesced, tail-safe indexing, shared by the histogram and scatter kernels - block_size keyword: default 256 (safe on every backend, fits Metal's 32 KiB threadgroup budget); pass 512 for ~1.3-1.4x on discrete NVIDIA Measured vs CUDA.jl's built-in sort: 5-25x faster. Vs torch/CUB: level on the RTX 5080 at large sizes, within ~1.2-2.1x on the RTX 3060. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
18639af to
f8682c7
Compare
|
Hm, I can't reproduce the oneAPI failure. In any case, looks unrelated to this branch. |
CUDA (RTX 5080), 4M elements
AMD (RX 9060 XT), 4M elements