Repository navigation
Avoid boxing compiler jobs during kernel resolution - #967
Merged
Merged
Conversation
Specialize compile_or_lookup on the backend target and parameter types. Keep it out of line to avoid duplicating the body in callers specialized per kernel, while preserving the existing GPUCompiler cache path.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #967 +/- ##
==========================================
- Coverage 86.66% 86.49% -0.17%
==========================================
Files 77 77
Lines 5488 5486 -2
==========================================
- Hits 4756 4745 -11
- Misses 732 741 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Metal Benchmarks
Details
| Benchmark suite | Current: 453cfc9 | Previous: 995e296 | Ratio |
|---|---|---|---|
array/accumulate/Float32/1d |
405125 ns |
405542 ns |
1.00 |
array/accumulate/Float32/dims=1 |
376791 ns |
372041 ns |
1.01 |
array/accumulate/Float32/dims=1L |
8800458 ns |
8810875 ns |
1.00 |
array/accumulate/Float32/dims=2 |
439875 ns |
435208 ns |
1.01 |
array/accumulate/Float32/dims=2L |
2619333 ns |
2657042 ns |
0.99 |
array/accumulate/Int64/1d |
847542 ns |
843625 ns |
1.00 |
array/accumulate/Int64/dims=1 |
936958 ns |
937334 ns |
1.00 |
array/accumulate/Int64/dims=1L |
9527542 ns |
9526041 ns |
1.00 |
array/accumulate/Int64/dims=2 |
1253292 ns |
1244209 ns |
1.01 |
array/accumulate/Int64/dims=2L |
6526375 ns |
6508750 ns |
1.00 |
array/broadcast |
230083 ns |
219583 ns |
1.05 |
array/construct |
2208 ns |
2208 ns |
1 |
array/permutedims/2d |
448666 ns |
452000 ns |
0.99 |
array/permutedims/3d |
1013958 ns |
1012833 ns |
1.00 |
array/permutedims/4d |
1288208 ns |
1014375 ns |
1.27 |
array/private/copy |
233292 ns |
236292 ns |
0.99 |
array/private/copyto!/cpu_to_gpu |
201083 ns |
186375 ns |
1.08 |
array/private/copyto!/gpu_to_cpu |
200542 ns |
194042 ns |
1.03 |
array/private/copyto!/gpu_to_gpu |
212250 ns |
198500 ns |
1.07 |
array/private/iteration/findall/bool |
1060000 ns |
906875 ns |
1.17 |
array/private/iteration/findall/int |
1230375 ns |
1227291 ns |
1.00 |
array/private/iteration/findfirst/bool |
1129000 ns |
1097459 ns |
1.03 |
array/private/iteration/findfirst/int |
1139500 ns |
886833 ns |
1.28 |
array/private/iteration/findmin/1d |
1216167 ns |
1218125 ns |
1.00 |
array/private/iteration/findmin/2d |
1053500 ns |
1054042 ns |
1.00 |
array/private/iteration/logical |
1692417 ns |
1688666 ns |
1.00 |
array/private/iteration/scalar |
1262375 ns |
1229959 ns |
1.03 |
array/random/rand/Float32 |
433166 ns |
428125 ns |
1.01 |
array/random/rand/Int64 |
525250 ns |
519292 ns |
1.01 |
array/random/rand!/Float32 |
389500 ns |
381250 ns |
1.02 |
array/random/rand!/Int64 |
409666 ns |
409750 ns |
1.00 |
array/random/randn/Float32 |
403042 ns |
401125 ns |
1.00 |
array/random/randn!/Float32 |
367125 ns |
351792 ns |
1.04 |
array/reductions/mapreduce/Float32/1d |
422583 ns |
419000 ns |
1.01 |
array/reductions/mapreduce/Float32/dims=1 |
345542 ns |
337000 ns |
1.03 |
array/reductions/mapreduce/Float32/dims=1L |
630208 ns |
633833 ns |
0.99 |
array/reductions/mapreduce/Float32/dims=2 |
342709 ns |
346542 ns |
0.99 |
array/reductions/mapreduce/Float32/dims=2L |
1018500 ns |
1011792 ns |
1.01 |
array/reductions/mapreduce/Int64/1d |
595209 ns |
615708 ns |
0.97 |
array/reductions/mapreduce/Int64/dims=1 |
615500 ns |
624416 ns |
0.99 |
array/reductions/mapreduce/Int64/dims=1L |
1039334 ns |
1030250 ns |
1.01 |
array/reductions/mapreduce/Int64/dims=2 |
784125 ns |
784500 ns |
1.00 |
array/reductions/mapreduce/Int64/dims=2L |
2195458 ns |
2185417 ns |
1.00 |
array/reductions/reduce/Float32/1d |
422000 ns |
424584 ns |
0.99 |
array/reductions/reduce/Float32/dims=1 |
346667 ns |
290042 ns |
1.20 |
array/reductions/reduce/Float32/dims=1L |
632708 ns |
635250 ns |
1.00 |
array/reductions/reduce/Float32/dims=2 |
241792 ns |
239334 ns |
1.01 |
array/reductions/reduce/Float32/dims=2L |
456708 ns |
448583 ns |
1.02 |
array/reductions/reduce/Int64/1d |
627833 ns |
615917 ns |
1.02 |
array/reductions/reduce/Int64/dims=1 |
633625 ns |
629834 ns |
1.01 |
array/reductions/reduce/Int64/dims=1L |
1039458 ns |
1024750 ns |
1.01 |
array/reductions/reduce/Int64/dims=2 |
246917 ns |
253083 ns |
0.98 |
array/reductions/reduce/Int64/dims=2L |
643584 ns |
648042 ns |
0.99 |
array/shared/copy |
135709 ns |
134916 ns |
1.01 |
array/shared/copyto!/cpu_to_gpu |
37750 ns |
38375 ns |
0.98 |
array/shared/copyto!/gpu_to_cpu |
37291 ns |
37542 ns |
0.99 |
array/shared/copyto!/gpu_to_gpu |
38125 ns |
37875 ns |
1.01 |
array/shared/iteration/findall/bool |
1073083 ns |
1065875 ns |
1.01 |
array/shared/iteration/findall/int |
1241333 ns |
1240708 ns |
1.00 |
array/shared/iteration/findfirst/bool |
960208 ns |
917791 ns |
1.05 |
array/shared/iteration/findfirst/int |
969000 ns |
970959 ns |
1.00 |
array/shared/iteration/findmin/1d |
1079292 ns |
1082458 ns |
1.00 |
array/shared/iteration/findmin/2d |
1049584 ns |
1046291 ns |
1.00 |
array/shared/iteration/logical |
1569708 ns |
1395750 ns |
1.12 |
array/shared/iteration/scalar |
3729.125 ns |
3791.75 ns |
0.98 |
array/sorting/1d |
2116417 ns |
2096084 ns |
1.01 |
array/sorting/2d |
8292833 ns |
8304750 ns |
1.00 |
integration/byval/reference |
1109833 ns |
1106541 ns |
1.00 |
integration/byval/slices=1 |
1109958 ns |
1106000 ns |
1.00 |
integration/byval/slices=2 |
2028834 ns |
2018875 ns |
1.00 |
integration/byval/slices=3 |
6578042 ns |
6556000 ns |
1.00 |
integration/metaldevrt |
374625 ns |
375792 ns |
1.00 |
kernel/indexing |
199500 ns |
206667 ns |
0.97 |
kernel/indexing_checked |
366500 ns |
371500 ns |
0.99 |
kernel/launch |
1845.8 ns |
1925 ns |
0.96 |
kernel/rand |
388875 ns |
387000 ns |
1.00 |
latency/import |
1794315291 ns |
1795851375 ns |
1.00 |
latency/precompile |
26227473167 ns |
26182965750 ns |
1.00 |
latency/ttfp |
2293915791 ns |
2301209125 ns |
1.00 |
metal/synchronization/context |
559.1397849462365 ns |
553.7005347593583 ns |
1.01 |
metal/synchronization/stream |
346.38709677419354 ns |
354.96190476190475 ns |
0.98 |
This comment was automatically generated by workflow using github-action-benchmark.
SimonDanisch
pushed a commit
to SimonDanisch/Metal.jl
that referenced
this pull request
Sep 24, 2026
`mtlfunction` cached a pipeline per device only when `indirect = false`, so every indirect pipeline (every dispatch Mantle records into an indirect command buffer) was re-linked on every plan rebuild. They are cached in `indirect_pipelines` now, beside `pipelines`. `compile_or_lookup` takes the job specialised and `@noinline`, as upstream JuliaGPU#967: the `@nospecialize` boxed it on every call, 336 -> 128 bytes per cached lookup and 448 -> 240 per `@metal` launch, measured on an M5.
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.
Kernel resolution constructs a
CompilerJobimmediately before passing it through an unspecializedcompile_or_lookupboundary, which can force the job onto the heap. Allow specialization on the job's target and compiler-parameter types, and keep the method@noinlineso its body is not duplicated into callers specialized per kernel. Kernel identity remains a field of the job, so this does not introduce per-kernel specialization or another cache.Applies the approach from KernelAbstractions.jl#769.
Syntax and whitespace checks passed. Runtime behavior and allocation savings have not been measured on macOS/Metal hardware.