Skip to content

Commit

Permalink
Write out a cache header
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Apr 18, 2024
1 parent 088e62c commit 6bd0882
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ end
string(h, ".jls"))
end

struct OnDiskCacheEntry
src::MethodInstance
cfg::CompilerConfig
asm
end

@noinline function actual_compilation(cache::AbstractDict, src::MethodInstance, world::UInt,
cfg::CompilerConfig, compiler::Function, linker::Function)
job = CompilerJob(src, cfg, world)
Expand All @@ -176,7 +182,12 @@ end
ondisk_hit = true
try
@debug "Loading compiled kernel" job path
asm = deserialize(path)
entry = deserialize(path)::OnDiskCacheEntry
if entry.src == src && entry.cfg == cfg
asm = entry.asm
else
@warn "Cache missmatch" src cfg entry
end
catch ex
@warn "Failed to load compiled kernel" job path exception=(ex, catch_backtrace())
end
Expand All @@ -196,9 +207,9 @@ end
@static if VERSION >= v"1.11.0-"
if !ondisk_hit && path !== nothing && disk_cache()
@debug "Writing out on-disk cache" job path
# TODO: Do we want to serialize some more metadata to make sure the asm matches?
tmppath, io = mktemp(;cleanup=false)
serialize(io, asm)
entry = OnDiskCacheEntry(src, cfg, asm)
serialize(io, entry)
close(io)
# atomic move
mkpath(dirname(path))
Expand Down

0 comments on commit 6bd0882

Please sign in to comment.