[pocl] Back @private Scratchpad with GPUCompiler.alloca#714
Draft
vchuravy wants to merge 2 commits into
Draft
Conversation
Back the POCL `Scratchpad` (`@private`) with `GPUCompiler.alloca`, a direct per-workitem stack allocation, instead of a StaticArrays `MArray`. The returned `Ptr` is wrapped in a `CLDeviceArray` over OpenCL "Function" storage (LLVM addrspace 0), where the SPIR-V target places allocas. Its alignment (`Base.datatype_alignment(T)`) matches `CLDeviceArray`'s element accesses. Requires GPUCompiler 1.23 (JuliaGPU/GPUCompiler.jl#859), which adds the `alloca` intrinsic. Drops the now-unused StaticArrays import from the POCL back-end (StaticArrays is still used by the CPU back-end). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #714 +/- ##
==========================================
- Coverage 62.51% 0.00% -62.52%
==========================================
Files 23 22 -1
Lines 1926 1737 -189
==========================================
- Hits 1204 0 -1204
- Misses 722 1737 +1015 ☔ 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.
Summary
Replaces the POCL back-end's
MArray-backed@privatescratchpad with a direct per-workitem stack allocation viaGPUCompiler.alloca. The returnedPtris wrapped in aCLDeviceArrayover OpenCL "Function" storage (LLVM addrspace 0), which is where the SPIR-V target places allocas.This drops the StaticArrays dependency from the POCL back-end (StaticArrays is still used by the CPU back-end).
Why
GPUCompiler.allocaemits a real entry-blockallocathat the optimizer can promote, in the target's alloca address space — avoiding the unsoundness ofllvmcall+allocaand the overhead/semantics ofMArray. See the motivation in the companion GPUCompiler PR.Alignment
The alloca is aligned to
Base.datatype_alignment(T), which is exactly the alignmentCLDeviceArrayuses for its element loads/stores (alignment(::CLDeviceArray{T})), so accesses are consistent.isbits-union element types are intentionally unsupported (GPUCompiler.allocaguards onisbitstype(T)).Status
Draft — depends on JuliaGPU/GPUCompiler.jl#859 (adds the
allocaintrinsic).Project.tomlcompat is bumped toGPUCompiler = "1.23"; this can be un-drafted once that is merged and released.Testing
Verified end-to-end against the local GPUCompiler branch:
@private Float32 (4,)lowers toalloca [16 x i8], align 4in addrspace 0 with no survivingjulia.gpu.alloca, and the kernel runs correctly on the POCL CPU device.🤖 Generated with Claude Code