Skip to content

Commit e32c30f

Browse files
committed
add some docs
1 parent ff3085f commit e32c30f

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/execution.jl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,37 @@ end
6161

6262

6363
## cached compilation
64+
65+
### Disk cache notes
66+
# Julia uses package images (pkgimg) to cache both the result of inference,
67+
# and the result of native code emissions. Up until Julia v1.11 neither the
68+
# inferred nor the nativce code of foreign abstract interpreters was cached
69+
# across sessions. Julia v1.11 allows for caching of inference results across
70+
# sessions as long as those inference results are created during precompilation.
71+
#
72+
# Julia cache hierarchy is roughly as follows:
73+
# Function (name of a thing)
74+
# -> Method (particular piece of code to dispatch to with a signature)
75+
# -> MethodInstance (A particular Method + particular signature)
76+
# -> CodeInstance (A MethodInstance compiled for a world)
77+
#
78+
# In order to cache code across sessions we need to insert CodeInstance(owner=GPUCompilerCacheToken)
79+
# into the internal cache. Once we have done so we know that a particular CodeInstance is unique in
80+
# the system. (During pkgimg loading conflicts will be resolved).
81+
#
82+
# When a pkgimg is loaded we check it's validity, this means checking that all depdencies are the same,
83+
# the pkgimg was created for the right set of compiler flags, and that all source code that was used
84+
# to create this pkgimg is the same. When a CodeInstance is inside a pkgimg we can extend the chain of
85+
# validity even for GPU code, we cannot verify a "runtime" CodeInstance in the same way.
86+
#
87+
# Therefore when we see a compilation request for a CodeInstance that is originating from a pkgimg
88+
# we can use it as part of the hash for the on-disk cache. (see `cache_file`)
89+
90+
"""
91+
disk_cache()
92+
93+
Query if caching to disk is enabled.
94+
"""
6495
disk_cache() = parse(Bool, @load_preference("disk_cache", "false"))
6596

6697
"""
@@ -175,7 +206,10 @@ end
175206
ondisk_hit = false
176207
@static if VERSION >= v"1.11.0-"
177208
# Don't try to hit the disk cache if we are for a *compile* hook
178-
if ci !== nothing && obj === nothing && disk_cache() # TODO: (Should we allow backends to opt out?)
209+
# TODO:
210+
# - Sould we hit disk cache if Base.generating_output()
211+
# - Should we allow backend to opt out?
212+
if ci !== nothing && obj === nothing && disk_cache()
179213
path = cache_file(ci, cfg)
180214
@debug "Looking for on-disk cache" job path
181215
if path !== nothing && isfile(path)

0 commit comments

Comments
 (0)