Repository navigation
Compile with GPUCompiler's do-block compile - #1184
Conversation
Lower and inspect the IR inside the callback of `GPUCompiler.compile(f, :llvm, job)`, which creates the context, activates it around the callback and frees the IR afterwards, instead of managing a `JuliaContext` and disposing of the module here. With GPUCompiler's llvmgpu toolchain, the IR that `compile` returns can belong to libLLVMGPU (a newer LLVM than Julia's), and LLVM.jl then needs that library's context to be active to work with it. Metal's IR still comes from Julia's LLVM today, so nothing breaks yet, but this prepares Metal for being compiled with libLLVMGPU like the other back-ends. Requires GPUCompiler 2.24.
8e59a90 to
ced2f91
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1184 +/- ##
==========================================
+ Coverage 87.39% 89.82% +2.43%
==========================================
Files 105 105
Lines 10108 9554 -554
==========================================
- Hits 8834 8582 -252
+ Misses 1274 972 -302 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Benchmark resultsCompared with 7cdead9cb, the merge base. 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.
All benchmarks
History: https://juliagpu.org/perf/?pkg=metal |
emit_metallibnow lowers and inspects the IR inside the callback of GPUCompiler's new do-blockcompile(JuliaGPU/GPUCompiler.jl#1124), which creates the context, keeps it active around the callback and frees the IR afterwards. The body of the old@disposeblock (logging detection, thejulia.metal.rngmarker, the AIR downgrade and theMetalLibFunction) moved unchanged intolower_to_air, which returns only plain data; the result is still type-asserted so its uses stay statically dispatched and precompiled. The Downgrade to AIR signpost now nests inside Generate LLVM IR. GPUCompiler compat is raised to 2.24.The reason is GPUCompiler's upcoming
llvmgputoolchain (JuliaGPU/GPUCompiler.jl#1122): with it, the IRcompilereturns can belong to libLLVMGPU, a newer LLVM than Julia's, and LLVM.jl can only work with that IR while its context is active (for the other back-ends, touching it outside the block segfaults). Metal's IR still comes from Julia's LLVM today, so nothing crashes yet; this prepares Metal for being compiled with libLLVMGPU like the other back-ends. Before that can be enabled,finish_ir!'sarg_eltypesannotation (which usesconvert(LLVMType, ...)) and some of GPUCompiler's own Metal passes will need to build their LLVM types directly.Validated on an M1 (macOS 27, Julia 1.12) with GPUCompiler #1122 plus the do-block form: the execution, compiler and device tests (
execution capturing relocations metallib precompilation output closures closure_boxes unions kernelabstractions metalcall device) pass with the default toolchain (6492 tests) and withtoolchain = "llvmgpu"(3686 + 2806; thekernelabstractionstests also launch on KernelAbstractions' CPU back-end, which needs JuliaGPU/KernelAbstractions.jl#995 under llvmgpu). Precompilation coverage is unchanged: the first kernel in a fresh session compiles in 0.25 s before and after, and--trace-compilereports the same 68 methods.