Skip to content

POCL: fix compilation on Julia 1.12 (exception sites dropped from :obj metadata) - #989

Closed
vchuravy wants to merge 1 commit into
mainfrom
vc/fix-1.12-exception-sites
Closed

vchuravy wants to merge 1 commit into
mainfrom
vc/fix-1.12-exception-sites

Conversation

@vchuravy

Copy link
Copy Markdown
Member

Since #982, every POCL kernel fails to compile on Julia 1.12, already during precompilation:

FieldError: type NamedTuple has no field `exception_sites`, available fields: `entry`, `compiled`, `relocations`, `ir`

All 1.12 jobs of main's CI run for #982 fail this way. PR CI only covers 1.10 and 1.13, so it didn't show up there.

Cause

compile_to_obj read exception_sites from the metadata that GPUCompiler.compile(:obj, job) returns. That path merges emit_llvm's metadata with emit_asm's as (; asm_meta..., ir_meta..., ir). On 1.12, the typed code of compile_unhooked that actually runs infers emit_llvm to return only the (:entry, :compiled, :relocations) variant. It then merges with those constant field names through Base.merge_fallback, so exception_sites is dropped:

%87 = dynamic invoke GPUCompiler.:(var"#emit_llvm#274")(...)::Tuple{LLVM.Module, NamedTuple{(:entry, :compiled, :relocations), ...}}
%160 = invoke Base.merge_fallback(%89::NamedTuple, %159::NamedTuple, (:entry, :compiled, :relocations)::Tuple{Vararg{Symbol}}, (:ir,)::Tuple{Vararg{Symbol}})::NamedTuple

Fresh inference of emit_llvm gives the correct union, which includes the exception_sites variant. Calling compile_unhooked(:llvm, job) and emit_llvm directly returns the key. Splatting the same values by hand keeps it too. So it looks like GPUCompiler's precompiled compile_unhooked, inferred while uses_exception_sites was false for every job, isn't invalidated by our uses_exception_sites method on 1.12. 1.10, 1.11 and 1.13 are fine. This probably wants a fix in GPUCompiler too, but KA shouldn't stay broken in the meantime.

Fix

Compile to :llvm, whose metadata is returned without merging, and emit the object with GPUCompiler.emit_asm. That's what the :obj path does internally.

Testing

Locally on Julia 1.12.6 with the released GPUCompiler 2.23.3, the full test suite passes, apart from two local failures that unmodified main also has on this machine:

  • POCL BFloat16 arithmetic (passes on CI)
  • the POCL session subprocess segfault (passes on CI)

Before this change, every kernel launch failed on 1.12. On 1.13 kernels still compile, and exceptions are still reported by throw site.

🤖 Generated with Claude Code

On Julia 1.12, `GPUCompiler.compile(:obj, job)` returns metadata without
`exception_sites`, so compiling any kernel failed with a `FieldError` since
#982 (including during precompilation). GPUCompiler's precompiled
`compile_unhooked` was inferred while `uses_exception_sites` returned `false`
for all jobs, so it merges the metadata of `emit_llvm` with the field names of
the narrower result; our method doesn't invalidate it on 1.12.

Compile to `:llvm` instead, whose metadata is returned as it is, and emit the
object with `emit_asm`, as the `:obj` path does.

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

Copy link
Copy Markdown
Member Author

Superseded by JuliaGPU/GPUCompiler.jl#1112

@vchuravy vchuravy closed this Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with 301c8f3b8, the merge base.
The environment differs from the baseline's: Hwloc_jll 2.15.0+3 → 2.16.0+0, LLVM 10.4.3 → 10.5.1, LLVMExtra_jll 0.0.56+0 → 0.0.57+0.

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.1% 1 0 32
Latency +0.0% 0 0 13
Applications +0.4% 0 0 5
Benchmark Baseline This PR Change
Performance
pocl/parallel/private/across-barrier 42.3 µs 44.0 µs +4.0% 🔴 slower
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 283 µs 284 µs +0.1%
julia/serial/narrow/masked-reference 708 µs 705 µs −0.4%
pocl/parallel/atomics/histogram 5.25 ms 5.20 ms −0.9%
pocl/parallel/groupreduce/add-f64 1.09 ms 1.09 ms +0.1%
pocl/parallel/groupreduce/fallback 4.39 ms 4.38 ms −0.1%
pocl/parallel/groupscan/add-i32 391 µs 391 µs −0.0%
pocl/parallel/indexing/cartesian3d 40.2 µs 39.8 µs −0.9%
pocl/parallel/indexing/linear3d 40.2 µs 39.9 µs −0.7%
pocl/parallel/indexing/ntuple3d 39.8 µs 39.6 µs −0.4%
pocl/parallel/indexing/ntuple4d 129 µs 126 µs −1.8%
pocl/parallel/localmem/transpose-naive 438 µs 436 µs −0.4%
pocl/parallel/localmem/transpose-tiled 66.4 µs 63.1 µs −5.0%
pocl/parallel/private/across-barrier 42.3 µs 44.0 µs +4.0% 🔴 slower
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 700 ns 651 ns −7.0%
pocl/parallel/stream/copy/dram 6.50 ms 6.28 ms −3.3%
pocl/parallel/stream/triad/cache 1.16 µs 1.38 µs +19.2%
pocl/parallel/stream/triad/dram 9.55 ms 9.59 ms +0.4%
pocl/parallel/util/copyto-small 25.0 ns 24.0 ns −4.0%
pocl/parallel/util/zeros-large 915 µs 935 µs +2.2%
pocl/parallel/util/zeros-small 631 ns 664 ns +5.2%
pocl/serial/arithmetic/contract 1.85 ms 1.85 ms +0.0%
pocl/serial/arithmetic/muladd 705 µs 704 µs −0.0%
pocl/serial/const/marked 668 µs 668 µs +0.0%
pocl/serial/const/unmarked 859 µs 859 µs +0.0%
pocl/serial/math/exp-f64 123 µs 123 µs +0.1%
pocl/serial/math/sin-f64 167 µs 168 µs +0.9%
pocl/serial/narrow/masked 633 µs 631 µs −0.3%
pocl/serial/narrow/unmasked 629 µs 628 µs −0.2%
pocl/serial/stream/triad/dram 8.51 ms 8.50 ms −0.2%
Latency
host/import/ka 602 ms 603 ms +0.3%
host/precompile/ka 27.0 s 27.1 s +0.4%
host/startup 128 ms 130 ms +1.2%
pocl/parallel/launch/dynamic-default 171 ns 166 ns −2.9%
pocl/parallel/launch/groupreduce-f64 773 ns 766 ns −0.9%
pocl/parallel/launch/many-args 677 ns 676 ns −0.1%
pocl/parallel/launch/partial-workgroup 219 ns 216 ns −1.4%
pocl/serial/compile/groupreduce 1.49 s 1.49 s −0.0%
pocl/serial/compile/localmem-barrier 675 ms 675 ms −0.0%
pocl/serial/compile/new-kernel 128 ms 128 ms +0.2%
pocl/serial/compile/new-workgroupsize 8.66 ms 8.81 ms +1.8%
pocl/serial/first-kernel/cold-cache 407 ms 411 ms +1.0%
pocl/serial/first-kernel/warm-cache 331 ms 334 ms +1.0%
Applications
pocl/parallel/dgsem/fluxdiff-node 253 µs 253 µs −0.1%
pocl/parallel/dgsem/weak-element 90.2 µs 90.1 µs −0.1%
pocl/parallel/dgsem/weak-node-localmem 92.8 µs 93.1 µs +0.2%
pocl/parallel/stencil/timestep 7.38 ms 7.55 ms +2.3%
pocl/serial/stencil/timestep 10.5 ms 10.5 ms −0.2%

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

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.27%. Comparing base (301c8f3) to head (69862dd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #989      +/-   ##
==========================================
- Coverage   89.75%   89.27%   -0.49%     
==========================================
  Files          33       33              
  Lines        3065     3011      -54     
==========================================
- Hits         2751     2688      -63     
- Misses        314      323       +9     

☔ 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.

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