Skip to content

POCL: keep the queue fallback out of the inference of launches - #1001

Open
giordano wants to merge 2 commits into
mainfrom
mg/pocl-queue-inference-barrier
Open

giordano wants to merge 2 commits into
mainfrom
mg/pocl-queue-inference-barrier

Conversation

@giordano

Copy link
Copy Markdown
Collaborator

This seems to reduce a little bit CPU compilation latency in CliMA/Oceananigans.jl#5799

In Oceananigans, with -O0 --check-bounds=yes as in its CI, solving a Poisson problem on a new grid size compiles 19 CPU kernels, which took 2.5-2.8 s and now take 2.3-2.4 s; its test of Poisson solvers on stretched grids, which does that for about 270 grid sizes, goes from 606-675 to 550-608 s, and allocates 153 instead of 171 GiB. Launches that fall back to the queue allocate 176 more bytes for the dynamic call (240 instead of 64), and take as long as before; the first @opencl launch takes about 165 instead of 250 ms.

`launch_and_wait`, which is compiled for every kernel, runs a host kernel, or falls back to the
queue when there is none: when PoCL can't create a host kernel, or when the work-group's stack
would exceed `host_kernel_stack_limit`. KernelAbstractions' own launches always pass 3-d sizes, so
for them the queue is a rare fallback, but inference analyzed it for every kernel anyway:
`launch_queued`, `launch_converted`, `clcall` and nanoOpenCL's `call`, `convert_arguments` and
`set_args!`, partly with abstract types, and all of it specialized on the kernel and its arguments.

The queue is now a `@noinline` function, `launch_queued_and_wait`. Launches that may run a host
kernel call it through `Base.inferencebarrier`, so that it is only compiled for the kernels that
fall back to it. Whether a launch may run a host kernel only depends on the types of its keyword
arguments (`may_run_on_host`): launches without 3-d `global_size` and `local_size`, like `@opencl`
launches with integer sizes, always run on the queue, and keep calling it directly, without a
dynamic call or allocations. Host launches are unchanged.

The precompile workload's `@kernel` launch no longer compiles the queue, so the workload also
launches a kernel on the queue, with `@opencl`, which `@opencl` launches use from the package
image.

In Oceananigans, with `-O0 --check-bounds=yes` as in its CI, solving a Poisson problem on a new
grid size compiles 19 CPU kernels, which took 2.5-2.8 s and now take 2.3-2.4 s; its test of
Poisson solvers on stretched grids, which does that for about 270 grid sizes, goes from 606-675 to
550-608 s, and allocates 153 instead of 171 GiB. Launches that fall back to the queue allocate
176 more bytes for the dynamic call (240 instead of 64), and take as long as before; the first
`@opencl` launch takes about 165 instead of 250 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@giordano
giordano force-pushed the mg/pocl-queue-inference-barrier branch from 643c6cd to 6d36f0d Compare November 28, 2026 14:15
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with a585449d8, the merge base.
The environment differs from the baseline's: OS Linux 6.8.0-124-generic → Linux 6.8.0-151-generic, Package 0.10.9 → 0.10.10, CompilerCaching 0.5.4 → 0.6.0, GPUCompiler 2.24.0 → 2.25.0, GPUToolbox 3.6.0 → 3.7.0, KernelAbstractions 0.10.9 → 0.10.10, LLVM 10.7.0 → 10.8.1, LLVMExtra_jll 0.0.60+0 → 0.0.61+0, LinearAlgebraExt 0.10.9 → 0.10.10, SPIRV_LLVM_Backend_jll 23.1.4+5 → 23.1.4+6.

Times are the minimum time of every benchmark. A change is unusual when it exceeds both three times the benchmark's typical change between consecutive runs on the default branch and a minimum per category (performance 3%, latency 5%, applications 3%, other 3%). A benchmark that starts or stops allocating is listed however few the allocations. A single run can still be a fluke, so rerun before drawing conclusions.

Geometric mean Unusual: slower Unusual: faster Compared
Performance +0.5% 0 0 32
Latency −0.8% 1 3 13
Applications +1.1% 0 0 5
Benchmark Baseline This PR Change
Latency
pocl/serial/first-kernel/warm-cache 321 ms 287 ms −10.6% 🟢 faster
pocl/serial/first-kernel/cold-cache 395 ms 362 ms −8.2% 🟢 faster
pocl/serial/compile/new-kernel 127 ms 138 ms +8.7% 🔴 slower
pocl/serial/compile/groupreduce 1.51 s 1.42 s −5.8% 🟢 faster
All benchmarks
Benchmark Baseline This PR Change
Performance
julia/serial/arithmetic/muladd-reference 655 µs 655 µs −0.0%
julia/serial/math/exp-f64-reference 284 µs 284 µs +0.0%
julia/serial/narrow/masked-reference 715 µs 711 µs −0.6%
pocl/parallel/atomics/histogram 5.21 ms 5.25 ms +0.8%
pocl/parallel/groupreduce/add-f64 1.09 ms 1.09 ms +0.2%
pocl/parallel/groupreduce/fallback 4.38 ms 4.39 ms +0.2%
pocl/parallel/groupscan/add-i32 393 µs 392 µs −0.2%
pocl/parallel/indexing/cartesian3d 39.5 µs 41.4 µs +4.7%
pocl/parallel/indexing/linear3d 39.9 µs 38.9 µs −2.5%
pocl/parallel/indexing/ntuple3d 40.5 µs 41.5 µs +2.3%
pocl/parallel/indexing/ntuple4d 127 µs 129 µs +1.2%
pocl/parallel/localmem/transpose-naive 433 µs 435 µs +0.6%
pocl/parallel/localmem/transpose-tiled 65.9 µs 68.4 µs +3.9%
pocl/parallel/private/across-barrier 42.5 µs 42.3 µs −0.3%
pocl/parallel/scheduling/default 117 µs 117 µs −0.0%
pocl/parallel/scheduling/explicit 117 µs 117 µs +0.1%
pocl/parallel/stream/copy/cache 663 ns 658 ns −0.8%
pocl/parallel/stream/copy/dram 6.50 ms 6.58 ms +1.2%
pocl/parallel/stream/triad/cache 1.29 µs 1.17 µs −9.4%
pocl/parallel/stream/triad/dram 9.54 ms 9.72 ms +2.0%
pocl/parallel/util/copyto-small 25.0 ns 29.0 ns +16.0%
pocl/parallel/util/zeros-large 941 µs 917 µs −2.5%
pocl/parallel/util/zeros-small 627 ns 636 ns +1.4%
pocl/serial/arithmetic/contract 1.85 ms 1.85 ms +0.0%
pocl/serial/arithmetic/muladd 705 µs 705 µs −0.0%
pocl/serial/const/marked 668 µs 668 µs −0.0%
pocl/serial/const/unmarked 860 µs 860 µs −0.1%
pocl/serial/math/exp-f64 123 µs 122 µs −0.8%
pocl/serial/math/sin-f64 167 µs 168 µs +0.5%
pocl/serial/narrow/masked 635 µs 643 µs +1.2%
pocl/serial/narrow/unmasked 635 µs 628 µs −1.2%
pocl/serial/stream/triad/dram 8.62 ms 8.56 ms −0.8%
Latency
host/import/ka 764 ms 765 ms +0.1%
host/precompile/ka 27.1 s 27.3 s +0.7%
host/startup 130 ms 130 ms +0.1%
pocl/parallel/launch/dynamic-default 165 ns 163 ns −1.2%
pocl/parallel/launch/groupreduce-f64 770 ns 770 ns +0.0%
pocl/parallel/launch/many-args 662 ns 684 ns +3.3%
pocl/parallel/launch/partial-workgroup 234 ns 238 ns +1.7%
pocl/serial/compile/groupreduce 1.51 s 1.42 s −5.8% 🟢 faster
pocl/serial/compile/localmem-barrier 674 ms 685 ms +1.6%
pocl/serial/compile/new-kernel 127 ms 138 ms +8.7% 🔴 slower
pocl/serial/compile/new-workgroupsize 8.73 ms 8.83 ms +1.2%
pocl/serial/first-kernel/cold-cache 395 ms 362 ms −8.2% 🟢 faster
pocl/serial/first-kernel/warm-cache 321 ms 287 ms −10.6% 🟢 faster
Applications
pocl/parallel/dgsem/fluxdiff-node 246 µs 249 µs +1.3%
pocl/parallel/dgsem/weak-element 90.7 µs 89.8 µs −0.9%
pocl/parallel/dgsem/weak-node-localmem 93.1 µs 92.6 µs −0.6%
pocl/parallel/stencil/timestep 7.29 ms 7.34 ms +0.8%
pocl/serial/stencil/timestep 10.1 ms 10.6 ms +5.2%

History: https://juliagpu.org/perf/?pkg=kernelabstractions

@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.08%. Comparing base (a585449) to head (841d731).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1001      +/-   ##
==========================================
- Coverage   90.79%   89.08%   -1.72%     
==========================================
  Files          33       33              
  Lines        3293     3015     -278     
==========================================
- Hits         2990     2686     -304     
- Misses        303      329      +26     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Launching a kernel on the queue waits for it, which allocates on Julia 1.10 and 1.11 (and is
shielded from task cancellation on 1.14+), with or without the previous change: the `@opencl`
launch of the test allocates 1.9-4.1 kB on 1.10 and 0.4-1.9 kB on 1.11 with KernelAbstractions
0.10.9 as well, and nothing on 1.12 and 1.13. The test now skips the check on those versions, as
the other tests of launch allocations do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant