feat(intrinsics): add KI.vload / KI.vstore! for wide vector memory operations#719
Open
shreyas-omkar wants to merge 5 commits into
Open
feat(intrinsics): add KI.vload / KI.vstore! for wide vector memory operations#719shreyas-omkar wants to merge 5 commits into
shreyas-omkar wants to merge 5 commits into
Conversation
…ions
Implements vectorised load/store for AbstractArray across all KA backends:
- CPU (Ptr path): reinterpret to Ptr{NTuple{N,VecElement{T}}} + unsafe_load/store!
- GPU (LLVMPtr path): reinterpret to LLVMPtr{NTuple{N,VecElement{T}},AS} + unsafe_load/store!
with N*sizeof(T) alignment; lowers to ld.global.v4 (CUDA), global_load_dwordx4
(AMDGPU), or OpLoad <N x T> (SPIR-V/POCL) — avoids pointerref/pointerset which
are unsupported in SPIR-V
- Scalar fallback for N=1 or non-primitive element types
Adds @generated helpers (_vload_ptr, _vload_lptr, _vstore_ptr!, _vstore_lptr!,
_vload_arr, _vstore_arr!) and comprehensive CPU test suite (147 tests, all pass).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ore!
Base vload/vstore! now fall back to scalar indexing for all non-Ptr arrays.
GPU backends inject the vectorized path by registering @device_override for
their concrete device array type, following the KernelIntrinsics.jl pattern:
- src/intrinsics.jl: remove _vload_lptr/_vstore_lptr! and the LLVMPtr branch;
base dispatch is now: Ptr{T} → wide load, everything else → scalar fallback
- src/pocl/backend.jl: add @device_override for KI.vload/KI.vstore! on
CLDeviceArray, using reinterpret(LLVMPtr{NTuple{N,VecElement{T}},AS}, ptr)
+ unsafe_load/unsafe_store! to emit OpLoad <N x T> (SPIR-V/POCL)
CUDA.jl, AMDGPU.jl etc. should add analogous overrides for CuDeviceArray /
ROCDeviceArray to get ld.global.v4.f32 / global_load_dwordx4.
147/147 CPU tests pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…le error
The AbstractArray fallback called pointer(arr, idx) which routes through
unsafe_convert(Ptr{T}, arr) — a path with a runtime string-formatting
error that GPU compilers (CUDA, SPIR-V) reject as an unsupported
dynamic function invocation.
Fix: split into two methods — Array (CPU Ptr path) and AbstractArray
(scalar fallback). GPU @device_overrides catch their device array types
before the AbstractArray fallback, so the Ptr path is never reachable in
GPU IR.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
oneAPI (Intel GPU) throws "Float64 is not supported on this device" when
allocating a oneArray{Float64}, so guard Float64 test cases behind
KernelAbstractions.supports_float64(backend()).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #719 +/- ##
==========================================
- Coverage 62.51% 62.46% -0.06%
==========================================
Files 23 23
Lines 1926 1974 +48
==========================================
+ Hits 1204 1233 +29
- Misses 722 741 +19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
KernelIntrinsics.vloadandKernelIntrinsics.vstore!CPU (
Array{T}): castspointer(arr, idx)toPtr{NTuple{N,VecElement{T}}}and callsunsafe_load/unsafe_store!.Julia/LLVM lowers
NTuple{N,VecElement{T}}to<N x T>, emitting one wideop (e.g.
movups/vmovapson x86).GPU: each backend registers a
@device_overridefor its concrete devicearray type that reinterprets the
LLVMPtrwithN*sizeof(T)alignment.POCL/SPIR-V override is included here (
CLDeviceArrayinsrc/pocl/backend.jl); CUDA.jl and AMDGPU.jl can add analogous overridesin their own KA extensions.
Fallback:
N == 1, non-primitiveT, or any array without a registeredoverride falls back to N scalar accesses via a
@generatedfunction (avoidsclosures, which GPU compilers reject).
Benchmark (POCLBackend, Float32, cyclops)
Speedup is visible in L2/L3-resident workloads where instruction throughput is
the bottleneck; DRAM-bound workloads are flat as expected.