Skip to content

Avoid boxing compiler jobs during kernel resolution - #967

Merged
maleadt merged 1 commit into
mainfrom
tb/compiler-job-allocations
Sep 14, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/compiler-job-allocations

Conversation

@maleadt

@maleadt maleadt commented Sep 14, 2026

Copy link
Copy Markdown
Member

Kernel resolution constructs a CompilerJob immediately before passing it through an unspecialized compile_or_lookup boundary, which can force the job onto the heap. Allow specialization on the job's target and compiler-parameter types, and keep the method @noinline so 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.

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

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.49%. Comparing base (995e296) to head (453cfc9).
⚠️ Report is 1 commits behind head on main.

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@maleadt
maleadt merged commit a43eeca into main Sep 14, 2026
19 checks passed
@maleadt
maleadt deleted the tb/compiler-job-allocations branch September 14, 2026 12:50
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.
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