Repository navigation
Conversation
The job-wide `always_inline` option marks all eligible specializations cheap to inline. Back-ends that need only a few methods inlined, e.g. a Base wrapper whose constant arguments a Julia IR pass has to see in the caller, can now list them with `always_inline_methods(job)`. Their specializations are marked cheap the same way, so call-site guards and constant propagation are kept. Dispatch doesn't change, and other methods of the same function, including user overloads, follow Julia's usual policy. The list is part of the inference configuration, like `julia_ir_passes`, so it must be a pure function of the job's target and params.
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.
always_inlineis all or nothing: it makes every function of the job cheap to inline. A back-end sometimes needs only a few methods it doesn't own inlined into their callers. The case at hand is CUDA.jl's nativeprint/printlnin kernels (JuliaGPU/CUDA.jl#3665): string literals are turned into Symbols by a Julia IR pass, which only sees the literal once every frame between it and the hostcall has been inlined. Withstdoutoverlaid to a device IO (#1147),println("a", "b")goes through Base's ownprintln(xs...), which isn't@inlineand exceeds the inlining threshold with two or more literals (print(xs...)with three), so the kernel fails to compile:This adds an interface function listing the methods to treat that way:
Specializations of the listed
Methods are marked cheap to inline, through the same mechanism asalways_inline(#890), so call-site guards and constant propagation are kept, and@noinlinemethods and always-throwing calls are left alone as before. Dispatch doesn't change: other methods of the same function, like a user'sprint(io, ::MyType), follow Julia's usual policy. The list is stored on the interpreter likejulia_ir_passesand falls under the samecache_ownercontract (a pure function of the job's target and params), so caching needs no change, and launches don't call it.Alternatives: overlaying Base's wrappers with
@inlinecopies shadows every Base and user method they match; raisinginline_cost_thresholdaffects every kernel and still has a limit (8 literals need a threshold of 400 instead of 100); a predicate onMethodInstances or a method-table declaration (like binding overlays) would be more machinery for a fixed per-back-end list.Tested on Julia 1.10 through 1.15-DEV with a new native test: the listed method is inlined, also when it comes from the cache, while a more specific method of the same function, a
@noinlinemethod and other jobs are unaffected. With CUDA.jl listing Base'sprint/printlnwrappers, kernels compile with 1 to 9 literals throughprintln(xs...)andprint(xs...)(before: at most 1 and 2), and the compile times of unrelated kernels stay within 1% (medians over 14-20 fresh sessions).