Repository navigation
Conversation
KernelAbstractions 0.10 adds KernelInterface, whose sub-group functions are needed for the warp-level primitives of the KernelAbstractions backend. Until it is released, take KernelAbstractions, KernelInterface and SPIRVIntrinsics (needed by the POCL-based CPU backend) from their development branches via [sources]. Sources can only be given for packages listed in [deps] or [extras], so the packages are added to [extras] (and the test target). Assisted-by: Claude Code (Opus 5.5)
…Interface sub-groups Map @warpsize, @laneid, @active_mask, @shfl_sync, @shfl_up_sync, @shfl_down_sync, @shfl_xor_sync, @vote_any_sync, @vote_all_sync and @vote_ballot_sync to the sub-group functions of KernelInterface (KernelAbstractions 0.10) instead of throwing: - @warpsize -> KernelInterface.get_max_sub_group_size() - @laneid -> KernelInterface.get_sub_group_local_id() (1-based, as in PS) - @active_mask -> bits of the lanes of the sub-group (UInt64); KernelInterface does not track the active lanes of divergent branches - shuffles -> KernelInterface.shfl/shfl_up/shfl_down/shfl_xor with width, which have CUDA semantics; without width the full sub-group width is used - votes -> KernelInterface.sub_group_any/all/ballot (ballot is a UInt64) KernelInterface has no lane masks: all lanes of a sub-group have to take part, so the mask is ignored, and a literal partial mask is rejected at macro expansion. With KernelAbstractions 0.9 the primitives throw. Assisted-by: Claude Code (Opus 5.5)
Check the mapping of the macros to the KernelInterface-based functions, the rejection of literal partial masks, and run a kernel using all primitives (with and without width, a shuffle of a tuple, and a warp reduction) on the KernelAbstractions backend if it supports sub-groups (e.g. the POCL-based CPU backend, with sub-groups of 32 work-items). Assisted-by: Claude Code (Opus 5.5)
KernelAbstractions 0.10 expands @LocalMem to a call through the KernelInterface module object. ParallelStencil passes kernels to @kernel with the macros already expanded, and @kernel deepcopies the kernel definition, which fails for modules ("deepcopy of Modules not supported"). Call KernelInterface.localmemory by name instead when KernelInterface is available. Also run the @sharedmem tests on the KernelAbstractions backend. Assisted-by: Claude Code (Opus 5.5)
@parallel with more than one positional argument (e.g. ranges, nblocks and nthreads) generates a runtime check that used an unqualified @ArgumentError, which is not defined in the caller's module. Assisted-by: Claude Code (Opus 5.5)
…h KernelAbstractions 0.9 KernelAbstractions 0.9 has no KernelInterface (so no warp-level primitives), and its thread-based CPU backend doesn't support @sync_threads in ParallelStencil kernels. Assisted-by: Claude Code (Opus 5.5)
Owner
|
@vchuravy : Thanks for opening the PR! Looking at the CI. the issue with Julia1.11 appears to be compatibility requirements with GPUToolbox visible in the last line of the output here ("KernelAbstractions [63c18a36] is fixed to version 0.10.0-dev"): |
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.
Draft: this depends on unreleased KernelAbstractions changes, JuliaGPU/KernelAbstractions.jl#830 and #831, which add portable sub-group (warp) operations to KernelAbstractions 0.10 through its KernelInterface. Until those are released,
[sources]points at their branch, and at JuliaGPU/OpenCL.jl#526 for the CPU backend's SPIR-V intrinsics.So far, ParallelStencil's warp macros threw "not supported" on the KernelAbstractions backend. This implements them on KernelInterface:
@warpsize()KI.get_max_sub_group_size()(a compile-time constant)@laneid()KI.get_sub_group_local_id()(1-based, as in ParallelStencil)@active_mask()@shfl_sync(m, v, lane[, w])KI.shfl(v, lane, w); withoutw, the sub-group width@shfl_up_sync/@shfl_down_sync/@shfl_xor_syncKI.shfl_up/KI.shfl_down/KI.shfl_xorwith a width (CUDA's semantics: lanes without a partner keep their own value)@vote_any_sync/@vote_all_sync/@vote_ballot_syncKI.sub_group_any/KI.sub_group_all/KI.sub_group_ballot(UInt64, as on the AMDGPU and CPU backends)Semantics:
0x0000ffff) is rejected when the macro expands.@active_mask: reports the lanes that exist in the sub-group, not the lanes active in a divergent branch.Also in this PR:
@sharedMemwith KernelAbstractions 0.10: KernelAbstractions'@localmeminterpolates a module object, which breaks@kernel'sdeepcopyof the pre-expanded kernel. The fix emitsKernelInterface.localmemoryby name. The@sharedMemtests now also run on the KernelAbstractions backend.@ArgumentErrorin the code generated by@parallelwith more than one positional argument wasn't qualified, giving anUndefVarErrorin the caller.Testing (Julia 1.12, KernelAbstractions' CPU backend (POCL), 4 threads):
ParallelKernel/test_kernel_language.jlpasses 67/67 on KernelAbstractions. That includes every primitive with and without a width, a tuple shuffle, a butterfly reduction and the ballot.test_parallel113/113,FiniteDifferences3D108/108,test_allocators428/428.Known issues:
Pkg.test()doesn't resolve with KernelAbstractions 0.10 yet: the test target includes Enzyme, which is incompatible with GPUCompiler 2.10 that KernelAbstractions 0.10 needs. I ran the test files with a driver that leaves Enzyme out.@shfl_xor_sync, unlike CUDA and the docs.@laneidusesactivelane(), which is wrong under divergence.🤖 Generated with Claude Code