15
15
# GPU run-time library
16
16
#
17
17
18
- # get the path to a directory where we can put cache files (machine-specific, ephemeral)
19
- # NOTE: maybe we should use XDG_CACHE_PATH/%LOCALAPPDATA%, but other Julia cache files
20
- # are put in .julia anyway so let's just follow suit for now.
21
- function cachedir (depot= DEPOT_PATH [1 ])
22
- # this mimicks Base.compilecache. we can't just call the function, or we might actually
23
- # _generate_ a cache file, e.g., when running with `--compiled-modules=no`.
24
- entrypath, entryfile = Base. cache_file_entry (Base. PkgId (GPUCompiler))
25
- abspath (depot, entrypath, entryfile)
26
- end
27
-
28
18
29
19
# # higher-level functionality to work with runtime functions
30
20
@@ -125,30 +115,9 @@ const runtime_lock = ReentrantLock()
125
115
126
116
@locked function load_runtime (@nospecialize (job:: CompilerJob ); ctx)
127
117
lock (runtime_lock) do
128
- # find the first existing cache directory (for when dealing with layered depots)
129
- cachedirs = [cachedir (depot) for depot in DEPOT_PATH ]
130
- filter! (isdir, cachedirs)
131
- input_dir = if isempty (cachedirs)
132
- nothing
133
- else
134
- first (cachedirs)
135
- end
136
-
137
- # we are only guaranteed to be able to write in the current depot
138
- output_dir = cachedir ()
139
-
140
- # if both aren't equal, copy pregenerated runtime libraries to our depot
141
- # NOTE: we don't just lazily read from the one and write to the other, because
142
- # once we generate additional runtimes in the output dir we don't know if
143
- # it's safe to load from other layers (since those could have been invalidated)
144
- if input_dir != = nothing && input_dir != output_dir
145
- mkpath (dirname (output_dir))
146
- cp (input_dir, output_dir)
147
- end
148
-
149
118
slug = runtime_slug (job)
150
119
name = " runtime_$(slug) .bc"
151
- path = joinpath (output_dir , name)
120
+ path = joinpath (compile_cache , name)
152
121
153
122
lib = try
154
123
if ispath (path)
@@ -163,7 +132,7 @@ const runtime_lock = ReentrantLock()
163
132
164
133
if lib === nothing
165
134
@debug " Building the GPU runtime library at $path "
166
- mkpath (output_dir )
135
+ mkpath (compile_cache )
167
136
lib = build_runtime (job; ctx)
168
137
169
138
# atomic write to disk
181
150
# NOTE: call this function from global scope, so any change triggers recompilation.
182
151
function reset_runtime ()
183
152
lock (runtime_lock) do
184
- rm (cachedir (); recursive= true , force= true )
185
- # create an empty cache directory. since we only ever load from the first existing cachedir,
186
- # this effectively invalidates preexisting caches in lower layers of the depot.
187
- mkpath (cachedir ())
153
+ rm (compile_cache; recursive= true , force= true )
188
154
end
189
155
190
156
return
0 commit comments