Skip to content

Commit d032ef0

Browse files
committed
Cache the runtime library in memory.
1 parent 046ceba commit d032ef0

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/rtlib.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ end
121121

122122
const runtime_lock = ReentrantLock()
123123

124+
const runtime_cache = Dict{String, Vector{UInt8}}()
125+
124126
@locked function load_runtime(@nospecialize(job::CompilerJob))
125127
global compile_cache
126128
if compile_cache === nothing # during precompilation
@@ -135,15 +137,14 @@ const runtime_lock = ReentrantLock()
135137
name = "runtime_$(slug).bc"
136138
path = joinpath(compile_cache, name)
137139

138-
lib = try
139-
if ispath(path)
140-
open(path) do io
141-
parse(LLVM.Module, read(io))
142-
end
140+
# cache the runtime library on disk and in memory
141+
lib = if haskey(runtime_cache, slug)
142+
parse(LLVM.Module, runtime_cache[slug])
143+
elseif ispath(path)
144+
runtime_cache[slug] = open(path) do io
145+
read(io)
143146
end
144-
catch ex
145-
@warn "Failed to load GPU runtime library at $path" exception=(ex, catch_backtrace())
146-
nothing
147+
parse(LLVM.Module, runtime_cache[slug])
147148
end
148149

149150
if lib === nothing

0 commit comments

Comments
 (0)