Skip to content

Commit 68883fe

Browse files
authored
TTFX-related improvements (#856)
1 parent 0c08fd0 commit 68883fe

4 files changed

Lines changed: 43 additions & 4 deletions

File tree

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "GPUCompiler"
22
uuid = "61eb1bfa-7361-4325-ad38-22787b887f55"
3-
version = "1.22.4"
3+
version = "1.22.5"
44
authors = ["Tim Besard <tim.besard@gmail.com>"]
55

66
[workspace]
@@ -14,6 +14,7 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1414
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1515
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1616
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
17+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
1718
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
1819
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1920
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
@@ -34,6 +35,7 @@ Logging = "1"
3435
NVPTX_LLVM_Backend_jll = "22"
3536
PrecompileTools = "1"
3637
Preferences = "1"
38+
REPL = "1"
3739
Scratch = "1"
3840
Serialization = "1"
3941
TOML = "1"

src/jlgen.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,17 +984,24 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
984984
push!(code_instances, ci)
985985
end
986986
else
987+
# `jl_get_llvm_cis` can report stale CIs that no longer cover the world
988+
# this job was compiled in. The explicit cache lookup path already filters
989+
# by world; do the same here before de-duplicating by MI.
990+
filter!(code_instances) do ci
991+
ci.min_world <= job.world <= ci.max_world
992+
end
993+
987994
# To avoid a clash in the compiled cache containing both with an interpreter token (like GPUCompiler.GPUCompilerCacheToken) and native,
988995
# prefer the non-native code-instance.
989996
# TODO: in the future we should migrate compiled to have the ci as the key, not the mi.
990-
native_mis = Set{MethodInstance}()
997+
owned_mis = Set{MethodInstance}()
991998
for ci in code_instances
992999
if ci.owner !== nothing
993-
push!(native_mis, ci.def::MethodInstance)
1000+
push!(owned_mis, ci.def::MethodInstance)
9941001
end
9951002
end
9961003
filter!(code_instances) do ci
997-
return ci.owner !== nothing || in(ci.def, native_mis)
1004+
return ci.owner !== nothing || ci.def owned_mis
9981005
end
9991006
end
10001007

src/precompile.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
using PrecompileTools: @setup_workload, @compile_workload
22

3+
# Load REPL so that interactive use doesn't invalidate the precompiled compiler
4+
# pipeline (fixed on Julia 1.14, see JuliaLang/julia#61714).
5+
import REPL
6+
37
@setup_workload begin
48
precompile_module = @eval module $(gensym())
59
using ..GPUCompiler

test/native/precompile.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ precompile_test_harness("Inference caching") do load_path
2525
return x*x
2626
end
2727

28+
function checked_convert(x)
29+
return Int(x)
30+
end
31+
2832
let
2933
job, _ = NativeCompiler.Native.create_job(kernel, (Vector{Int}, Int))
3034
precompile(job)
@@ -48,6 +52,13 @@ precompile_test_harness("Inference caching") do load_path
4852
precompile(job)
4953
end
5054
end
55+
56+
@setup_workload begin
57+
job, _ = NativeCompiler.Native.create_job(checked_convert, (UInt,); validate=false)
58+
@compile_workload begin
59+
precompile(job)
60+
end
61+
end
5162
end) |> string)
5263

5364
Base.compilecache(Base.PkgId("NativeBackend"), stderr, stdout)
@@ -78,6 +89,21 @@ precompile_test_harness("Inference caching") do load_path
7889
# check that identity survived
7990
@test check_presence(identity_mi, token) broken=(v"1.12.0-DEV.1268" <= VERSION < v"1.12.5" || v"1.13.0-" <= VERSION < v"1.13.0-beta3"|| v"1.14.0-" <= VERSION < v"1.14.0-DEV.1843")
8091

92+
# Recompiling a foreign method after loading precompiled owner-token CIs
93+
# may also surface a native owner-less CI for the same MethodInstance.
94+
# GPUCompiler should prefer the owner-token CI instead of recording both.
95+
job, _ = NativeCompiler.Native.create_job(identity, (Int,))
96+
JuliaContext() do ctx
97+
_, meta = GPUCompiler.compile(:llvm, job)
98+
@test haskey(meta.compiled, job.source)
99+
end
100+
101+
job, _ = NativeCompiler.Native.create_job(NativeBackend.checked_convert, (UInt,); validate=false)
102+
JuliaContext() do ctx
103+
_, meta = GPUCompiler.compile(:llvm, job)
104+
@test haskey(meta.compiled, job.source)
105+
end
106+
81107
GPUCompiler.clear_disk_cache!()
82108
@test GPUCompiler.disk_cache_enabled() == false
83109

0 commit comments

Comments
 (0)