Metal: bus error in the LLVM inliner on dynamic code, instead of an InvalidIRError
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 28/100
Research direction
Reproduce the kernel with GPUCompiler main on the stated Julia and M1 setup, comparing optimized compilation with Metal.code_llvm(...; optimize = false). Start at GPUCompiler/src/metal.jl:425 and follow the optimize! and emit_llvm paths, using the LLVM inliner and InvalidIRError behavior as reference points. Done means the dynamic llvmcall case no longer crashes during optimization and reports an InvalidIRError instead.
Written by the indexing model from the issue text.
Description
Compiling a Metal kernel that ends up with dynamic code crashes the process during optimization, instead of reporting an InvalidIRError:
using Metal, UnsafeAtomics # UnsafeAtomics from JuliaConcurrent/UnsafeAtomics.jl#30
const UA = UnsafeAtomics
wrapper(p, x; kwargs...) = UA.add!(p, x, UA.monotonic, UA.device; kwargs...)
k(a) = (wrapper(pointer(a), Int32(1); volatile = true, align = 8); nothing)
@metal threads=1 k(MtlArray(Int32[0]))
[30093] signal 10 (1): Bus error: 10
_ZN12_GLOBAL__N_112CallAnalyzer7analyzeEv at .../libLLVM.dylib
llvm::getInlineCost(...)
...
llvm::InlinerPass::run(...)
...
llvm::ModuleInlinerWrapperPass::run(...)
LLVMRunJuliaPasses at LLVM/JGisQ/lib/18/libLLVM_extra.jl:319
run! at LLVM/JGisQ/src/newpm.jl:380
optimize_module! at GPUCompiler/src/metal.jl:425
optimize! at GPUCompiler/src/optim.jl:52
emit_llvm at GPUCompiler/src/driver.jl:176
GPUCompiler main (037ef5a), Julia 1.12.7, M1. The same crash happens with the Metal atomics branch (#942/#943). With #949, it crashed earlier instead, in check_allocation!/referenced_object.
The code is dynamic because Julia doesn't const-prop the keywords into the non-inlined wrapper, so align is a run-time value and Val(align) becomes a dynamic call to UnsafeAtomics' @generated llvmcall primitive. Base.@constprop :aggressive on the wrapper avoids it. Metal.code_llvm(…; optimize = false) works and gives about 2,400 lines of IR (typejoin, _growbeg!, boxing, …); the crash is in the LLVM inliner over that module. A similar kernel whose dynamic code doesn't involve llvmcall (wrapper(a, x; kwargs...) = store(a, x, Val(kwargs[:index]))) is correctly reported as an InvalidIRError.
- Dominant language
- Julia
- Stars
- 188
- Forks
- 71
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaGPU/GPUCompiler.jl
-
spirv
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliaGPU/GPUCompiler.jl#1008 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
JuliaGPU/GPUCompiler.jl#1050 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
JuliaGPU/GPUCompiler.jl#1049 ·
Maintainers usually reply within 1 day
-
`julia_datalayout` is invalidated by ChainRulesCore, adding ~2 s to the first kernel compilePossibly taken @maleadt claimed this today. Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
JuliaGPU/GPUCompiler.jl#1048 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 1-2 days Newbie friendliness 48/100
JuliaGPU/GPUCompiler.jl#1032 ·
Maintainers usually reply within 1 day
All issues in JuliaGPU/GPUCompiler.jl
Similar issues
-
View of a view is brokenPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
JuliaPy/pyjuliapkg#102 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
JuliaMath/Polynomials.jl#641 ·