Repository navigation
Conversation
Metal's package image can't hold AcceleratedKernels' operations as they run on Metal: this extension isn't loaded while Metal precompiles, so the kernels its workload compiles use the default tunings, and the first `sum`, `cumsum` or `any` of a session compiles its host code and kernels again. A `@compile_workload` in the extension caches them with the tunings that apply. It covers whole-array reductions (both passes), reductions of a matrix along either dimension, `cumsum`, `any` and `all` of Float32 arrays, and the sum of an Int array. On an M1 with Julia 1.13, the first call on 10^6 elements or a 1000x1000 matrix takes 50 ms instead of 450 for `sum`, 80 instead of 710 for `cumsum`, 100 instead of 730 for `any`, and 110 and 30 instead of 290 and 200 for `sum` along `dims=1` and `dims=2`. The extension's image grows by 6.5 MB, and loading Metal takes no measurable extra time. As in Metal's own workload, it runs on Julia 1.11 and later only, and only when Metal's workload launches kernels too, which it reports with `Metal.can_precompile_launches` (JuliaGPU/Metal.jl#1124). With older versions of Metal, which can't tell and implement some of these operations differently, the workload is skipped.
This branch has not been deployed
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.
Metal.jl's package image can't hold AcceleratedKernels' operations as they run on Metal: this extension isn't loaded while Metal precompiles, so the kernels its workload compiles use the default tunings rather than the ones set here, and the first
sum,cumsumoranyof a session compiles its host code and kernels again. (The inference barriers of #189 prevent invalidations, but can't make those kernels match.)This adds a
@compile_workloadto the extension that covers whole-array reductions (both passes), reductions of a matrix along either dimension,cumsum,anyandallof Float32 arrays, and the sum of an Int array, at sizes that select the same kernels as a vector of 10^6 elements and a 1000×1000 matrix. Like Metal's own workload it runs on Julia 1.11 and later, and only when Metal's workload launches kernels too, which it reports withMetal.can_precompile_launches(JuliaGPU/Metal.jl#1124); with older versions of Metal, which can't tell and implement some of these operations differently, it is skipped.sumsum(; dims=1)sum(; dims=2)cumsumanyallsum(Together with Metal.jl#1124 the first
sumtakes 15 ms andcumsum24 ms.) Loading Metal takes no measurable extra time; the extension's image grows from 0.08 to 6.6 MB and its precompilation from 2.3 to 5.5 s. Operations it doesn't cover, likemaximum,countor Intcumsum, aren't affected.