|
| 1 | +# compare two spreadtest executables at variety of dim, w{prec}. Barnett 6/17/24 |
| 2 | +using Printf |
| 3 | +using CairoMakie |
| 4 | +using JLD2 # for load/save arrays to file |
| 5 | +using UnPack |
| 6 | + |
| 7 | +fnam = "results/master-vs-svec2_gcc114_5700U_nthr8" # outfile head |
| 8 | +# locations of pair of FINUFFT repos to compare... |
| 9 | +repo1 = "/home/alex/numerics/finufft" |
| 10 | +repo2 = "/home/alex/numerics/nufft/finufft-svec2" |
| 11 | + |
| 12 | +# run spreadtestnd{f} for a list of tols at one prec |
| 13 | +# return spread & interp times as 2-by-ntols |
| 14 | +function run_spread(repo,dim,M,N,tols,nthr,prec) |
| 15 | + if prec==Float64 |
| 16 | + exec = "$repo/perftest/spreadtestnd" |
| 17 | + elseif prec==Float32 |
| 18 | + exec = "$repo/perftest/spreadtestndf" |
| 19 | + else error("prec not known!") |
| 20 | + end |
| 21 | + times = zeros(2,length(tols)) # spread col 1; interp col 2 |
| 22 | + for (i,tol) in enumerate(tols) |
| 23 | + nr = 3 # repetitions |
| 24 | + sptruns = zeros(nr) |
| 25 | + intruns = zeros(nr) |
| 26 | + for r=1:nr |
| 27 | + c = Cmd(`$exec $dim $M $N $tol`,env=("OMP_NUM_THREADS" => "$nthr",)) |
| 28 | + r==1 && println(c) # first run show entire Cmd not just strings |
| 29 | + o = read(c,String) # do the cmd (no shell launched, as SGJ likes) |
| 30 | + sptruns[r] = parse(Float64,split(split(o,"pts in")[2],"s")[1]) # get first timing (spread) in seconds |
| 31 | + intruns[r] = parse(Float64,split(split(o,"pts in")[3],"s")[1]) # get 2nd timing (interp) in seconds |
| 32 | + end |
| 33 | + times[:,i] = [minimum(sptruns), minimum(intruns)] |
| 34 | + end |
| 35 | + times |
| 36 | +end |
| 37 | +#ts = run_spread(repo2,1,1e7,1e6,[1e-2,1e-3,1e-5],1,Float32) # basic test |
| 38 | +#println(ts); stop |
| 39 | + |
| 40 | +# plots (and to PNG) all dims and w{prec} for both directions |
| 41 | +function plot_all(fnam,ts,wstr,dims,M,N,nthr) |
| 42 | + ntols = length(wstr) |
| 43 | + repos = stack([[1,2] for i=1:ntols]) # which repo each run was from |
| 44 | + for dir=1:2 |
| 45 | + dirstr = ["spread","interp"][dir] |
| 46 | + fig = Figure(fontsize=10, size=(1000,500)) # plot all 3 dims |
| 47 | + for (i,dim) in enumerate(dims) |
| 48 | + thrus = 1e-6 * M ./ ts[dir,i,:,:]' # slice for this dir, dim: interleave repo1, repo2, repo1,... |
| 49 | + ax = Axis(fig[1,i], title="$dirstr $(dim)d M=$M N=$N $(nthr)thr") # fnam too long |
| 50 | + barplot!(ax, kron(1:ntols, [1,1]), thrus[:], dodge=repos[:], color=repos[:]) |
| 51 | + ax.xticks=(1:ntols, wstr) |
| 52 | + ax.xlabel="w{prec}"; ax.ylabel=L"throughput ($10^6$ NU pt/s)" |
| 53 | + ax.limits=((0,ntols+1),(0,nothing)) |
| 54 | + yadd = maximum(thrus[:]) # what height to annotate % at |
| 55 | + for j=1:ntols # show % change |
| 56 | + text!(j+0.4, yadd, text=@sprintf("%.0f%%",100*(thrus[2,j]/thrus[1,j]-1.0)), rotation=pi/2) |
| 57 | + end |
| 58 | + end |
| 59 | + display(fig) |
| 60 | + save("$(fnam)_$(dirstr)_M$(M)_N$(N).png",fig) |
| 61 | + end |
| 62 | +end |
| 63 | + |
| 64 | +# main script........................................................................... |
| 65 | +nthr = 8; # 1: leave cpu freq at max (4.3GHz); for 8, lower to 2.7GHz since drops to this. |
| 66 | +# set freq lim with cpupower-gui |
| 67 | +# check with: watch -n 1 sort -nr /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq |
| 68 | +dims = 1:3 |
| 69 | +M=1e7; N=1e6 |
| 70 | +#tolsd = [1e-3,1e-6]; tolsf = [1e-2] # double then single prec tol lists |
| 71 | +tolsd = [10.0^-k for k=2:14]; tolsf = [10.0^-k for k=2:5]; |
| 72 | +compute = true #false |
| 73 | +if compute |
| 74 | + ntolsd = length(tolsd); ntolsf = length(tolsf) |
| 75 | + ntols = ntolsd+ntolsf |
| 76 | + ndims = length(dims) |
| 77 | + ts = NaN*zeros(2,ndims,ntols,2) # timings: 1st dim = spread,interp, 4th dim = repo# |
| 78 | + for (i,dim) in enumerate(dims) # do expensive runs... |
| 79 | + ts[:,i,1:ntolsd,1] = run_spread(repo1,dim,M,N,tolsd,nthr,Float64) |
| 80 | + ts[:,i,1:ntolsd,2] = run_spread(repo2,dim,M,N,tolsd,nthr,Float64) |
| 81 | + ts[:,i,ntolsd+1:end,1] = run_spread(repo1,dim,M,N,tolsf,nthr,Float32) |
| 82 | + ts[:,i,ntolsd+1:end,2] = run_spread(repo2,dim,M,N,tolsf,nthr,Float32) |
| 83 | + println(ts[:,i,:,:]) |
| 84 | + end |
| 85 | + #tolstr = [[@sprintf "%.0e" tol for tol=tolsd]; [@sprintf "%.0ef" tol for tol=tolsf]] |
| 86 | + # strings for w (nspread) for plotting... |
| 87 | + wstr = [[@sprintf "%d" -log10(tol)+1 for tol=tolsd]; [@sprintf "%df" -log10(tol)+1 for tol=tolsf]] |
| 88 | + jldsave("$(fnam).jld2"; fnam,ts,wstr,dims,M,N,tolsd,tolsf,nthr) # save all |
| 89 | + plot_all(fnam,ts,wstr,dims,M,N,nthr) |
| 90 | +else |
| 91 | + f = load("$(fnam).jld2"); # gives a dict |
| 92 | + @unpack fnam,ts,wstr,dims,M,N,nthr = f # not very easy way to get dict into globals |
| 93 | + plot_all(fnam,ts,wstr,dims,M,N,nthr) |
| 94 | +end |
0 commit comments