Last active
February 20, 2020 00:15
-
-
Save IanButterworth/9d8f6b3d53d8a887fc9719a5ff811b76 to your computer and use it in GitHub Desktop.
PackageCompiler.jl precompile statement failure bisector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using PackageCompiler, Random | |
function kfoldperm(N,k) | |
n,r = divrem(N,k) | |
b = collect(1:n:N+1) | |
for i in 1:length(b) | |
b[i] += i > r ? r : i-1 | |
end | |
p = randperm(N) | |
return [p[r] for r in [b[i]:b[i+1]-1 for i=1:k]] | |
end | |
numthreads = Threads.nthreads() | |
cd(@__DIR__) | |
!isdir(joinpath(@__DIR__, "sysimages")) && mkdir(joinpath(@__DIR__, "sysimages")) | |
original = joinpath(@__DIR__, "failing_precompile_statements.jl") | |
failures = readlines(original) | |
@show length(failures) | |
spinlocker = Threads.SpinLock() | |
while length(failures) >= numthreads | |
global failures | |
parts = kfoldperm(length(failures), numthreads) | |
nextids = Int[] | |
Threads.@threads for sect in 1:numthreads | |
sysimgfile = joinpath(@__DIR__, "sysimages", "SysImage_$(sect).so") | |
statefile = joinpath(@__DIR__, "$sect.jl") | |
open(statefile, "w") do io | |
map(i->println(io, failures[i]), parts[sect]) | |
end | |
try | |
create_sysimage(:PackageName, incremental = true, | |
sysimage_path=sysimgfile, | |
precompile_statements_file=joinpath(@__DIR__, "$sect.jl")) | |
# run(`julia --output-o=$ofile \ | |
# -g1 --startup-file=no --code-coverage=none \ | |
# --history-file=yes --inline=yes --math-mode=ieee --handle-signals=yes \ | |
# --startup-file=no --warn-overwrite=no --compile=yes --depwarn=yes \ | |
# --cpu-target=native --track-allocation=none --sysimage-native-code=yes \ | |
# --sysimage=/Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/sys.dylib \ | |
# --compiled-modules=yes --optimize=2 \ | |
# ./$sect.jl`) | |
@info "SysImage success: $sysimgfile" | |
catch | |
#If errors, append precompile statements to next.jl | |
lock(spinlocker) do | |
append!(nextids, parts[sect]) | |
end | |
end | |
isfile(sysimgfile) && rm(sysimgfile) | |
end | |
failures = failures[nextids] | |
@show length(failures) | |
end | |
@show failures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment