Repository navigation
Conversation
Parallel-region formation treats successors of a barrier block as entries of disjoint regions. Bounds-checked Julia kernels can instead branch around a variable-trip loop and reconverge at the next barrier, producing a malformed region and aborting work-group function generation. Detect successors that reach a common block before crossing another barrier and move their branch to a common post-barrier block. Successors ending at distinct barriers retain the existing conditional-barrier handling. Add a reduced SPIR-V regression that builds and executes with the loops, loopvec, and CBS handlers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A second shape fixed by splitting reconverging barrier successors: a guarded section between barriers whose early exit, such as the never-taken bounds-check failure path of a Julia kernel, leaves the kernel without reaching the next barrier. Padding work-items branch from the barrier straight to the end of the section, so both barrier successors lie in the same parallel region. Because the early exit makes that region multi-exit, IsolateRegions does not insert a dedicated post-barrier entry. Region formation then took the first such successor as the region entry. Either padding work-items entered the work-item loop past its per-work-item control and executed the guarded code, or a bogus region with a two-successor exit was formed and WorkitemLoops::createLoopAround asserted. Both kernels in the test are written in OpenCL C, and both failed with the loops and loopvec handlers before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 26, 2026
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.
Tracking PR for the CanonicalizeBarriers fix from pocl#2281, which upstream closed: they won't change the legacy work-item loop handlers and are moving kernel-compiler work to their loopvec rewrite instead. The JuliaGPU PoCL JLLs carry these commits as a local patch (Yggdrasil
P/pocl:pocl_next0004–0005,pocl0004), so this PR keeps them rebased and reviewable until upstream main fixes these shapes another way.Parallel-region formation treats the successors of a barrier block as entries of separate regions. That holds for conditional barriers, but not when a branch after the barrier reconverges before the next barrier: both successors then belong to one region, and
Kernel::createParallelRegionBeforepicks whichever comes first as its entry.IsolateRegionsnormally prevents this by giving the region a dedicated entry block, but only when LLVM'sRegionInfosees a single-entry single-exit region.Two shapes from bounds-checked Julia kernels defeat that:
ParallelRegion::chainAfter.getParallelRegionsforms a bogus region whose exit has two successors andWorkitemLoops::createLoopAroundfailsExitBB->getTerminator()->getNumSuccessors() == 1. This is what KernelAbstractions.jl 0.10'strailing_uniform!andqualified!tests hit on PoCL main, through both the SPIR-V and the OpenCL C input paths (Implement KernelInterface, and support KernelAbstractions 0.10 OpenCL.jl#519).The second shape only needs an early
return/gotoinside a guarded section, so it also occurs in plain OpenCL C:The fix detects barrier successors that reach a common block without crossing another barrier, and moves their branch into a shared post-barrier block, as CanonicalizeBarriers already does for CBS. Branches whose arms end at distinct barriers keep the existing conditional-barrier handling.
Tests
regression/barrier_divergent_skip: reduced SPIR-V for the loop-skipping shape.regression/barrier_early_exit: two OpenCL C kernels for the early-exit shape, one per symptom.Both run with the loops, loopvec and CBS handlers. Without the fix, both fail with loops and loopvec (
barrier_divergent_skiponly with assertions enabled), and pass with CBS. Theworkgroup/,regression/andkernel_compiler_unit_tests/ctest subsets show no new failures (checked on macOS/arm64 with LLVM 20). KernelAbstractions.jl's test suite passes through OpenCL.jl on an asserts build with this change.