-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
538: Update perf/allocations analysis tools r=charleskawczynski a=charleskawczynski Co-authored-by: Charles Kawczynski <[email protected]>
- Loading branch information
Showing
9 changed files
with
187 additions
and
42 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Launch with `julia --project --track-allocation=user` | ||
if !("." in LOAD_PATH) | ||
push!(LOAD_PATH, ".") | ||
end | ||
import Profile | ||
|
||
include("common.jl") | ||
case_name = ENV["ALLOCATION_CASE_NAME"] | ||
@info "Recording allocations for $case_name" | ||
sim = init_sim(case_name) | ||
update_n(sim, 1) # compile first | ||
Profile.clear_malloc_data() | ||
update_n(sim, 1) | ||
|
||
# Quit julia (which generates .mem files), then call | ||
#= | ||
import Coverage | ||
allocs = Coverage.analyze_malloc("src") | ||
=# |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
if !("." in LOAD_PATH) | ||
push!(LOAD_PATH, ".") | ||
end | ||
import Coverage | ||
import Plots | ||
|
||
# https://github.com/jheinen/GR.jl/issues/278#issuecomment-587090846 | ||
ENV["GKSwstype"] = "nul" | ||
|
||
all_cases = [ | ||
# "ARM_SGP", | ||
# "Bomex", | ||
# "DryBubble", | ||
# "DYCOMS_RF01", | ||
# "GABLS", | ||
# "GATE_III", | ||
# "life_cycle_Tan2018", | ||
# "Nieuwstadt", | ||
"Rico", | ||
# "Soares", | ||
# "SP", | ||
"TRMM_LBA", | ||
"LES_driven_SCM", | ||
] | ||
|
||
filter!(x -> x ≠ "GATE_III", all_cases) # no mse tables for GATE_III | ||
filter!(x -> x ≠ "SP", all_cases) # not currently running SP | ||
allocs = Dict() | ||
for case in all_cases | ||
ENV["ALLOCATION_CASE_NAME"] = case | ||
run(`julia --project=test/ --track-allocation=user perf/alloc_per_case.jl`) | ||
allocs[case] = Coverage.analyze_malloc(".") | ||
|
||
# Clean up files | ||
all_files = [joinpath(root, f) for (root, dirs, files) in Base.Filesystem.walkdir(".") for f in files] | ||
all_mem_files = filter(x -> endswith(x, ".mem"), all_files) | ||
for f in all_mem_files | ||
rm(f) | ||
end | ||
end | ||
|
||
@info "Post-processing allocations" | ||
|
||
function plot_allocs(case_name, allocs_per_case, n_unique_bytes) | ||
p = Plots.plot() | ||
case_bytes = getproperty.(allocs_per_case, :bytes)[end:-1:1] | ||
case_filename = getproperty.(allocs_per_case, :filename)[end:-1:1] | ||
case_linenumber = getproperty.(allocs_per_case, :linenumber)[end:-1:1] | ||
all_bytes = Int[] | ||
filenames = String[] | ||
linenumbers = Int[] | ||
loc_ids = String[] | ||
for (bytes, filename, linenumber) in zip(case_bytes, case_filename, case_linenumber) | ||
filename_only = first(split(filename, ".jl")) * ".jl" | ||
if endswith(filename_only, "TurbulenceConvection.jl") && linenumber == 1 | ||
continue # Skip loading module | ||
end | ||
loc_id = "$filename_only" * "$linenumber" | ||
if !(bytes in all_bytes) && !(loc_id in loc_ids) | ||
push!(all_bytes, bytes) | ||
push!(filenames, filename) | ||
push!(linenumbers, linenumber) | ||
push!(loc_ids, loc_id) | ||
if length(all_bytes) ≥ n_unique_bytes | ||
break | ||
end | ||
end | ||
end | ||
|
||
all_bytes = all_bytes ./ 10^3 | ||
max_bytes = maximum(all_bytes) | ||
@info "$case_name: $all_bytes" | ||
xtick_name(filename, linenumber) = "$filename, line number: $linenumber" | ||
markershape = (:circle, :star, :square, :hexagon) | ||
for (bytes, filename, linenumber) in zip(all_bytes, filenames, linenumbers) | ||
markershape = (markershape[end], markershape[1:(end - 1)]...) | ||
filename_only = first(split(filename, ".jl")) * ".jl" | ||
Plots.plot!( | ||
[0], | ||
[bytes]; | ||
seriestype = :scatter, | ||
label = xtick_name(filename_only, linenumber), | ||
markershape = markershape[1], | ||
markersize = 1 + bytes / max_bytes * 10, | ||
) | ||
end | ||
Plots.plot!(ylabel = "Number of allocations (KB)") | ||
Plots.savefig(joinpath(folder, "allocations_$case_name.png")) | ||
end | ||
|
||
folder = "perf/allocations_output" | ||
mkpath(folder) | ||
|
||
@info "Allocated bytes for single tendency per case:" | ||
for case in all_cases | ||
plot_allocs(case, allocs[case], 10) | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import TurbulenceConvection | ||
|
||
tc_dir = dirname(dirname(pathof(TurbulenceConvection))) | ||
include(joinpath(tc_dir, "integration_tests", "utils", "generate_namelist.jl")) | ||
include(joinpath(tc_dir, "integration_tests", "utils", "Cases.jl")) | ||
include(joinpath(tc_dir, "integration_tests", "utils", "parameter_set.jl")) | ||
include(joinpath(tc_dir, "integration_tests", "utils", "main.jl")) | ||
import .NameList | ||
|
||
TurbulenceConvection.initialize_io(sim::Simulation1d) = nothing | ||
TurbulenceConvection.io(sim::Simulation1d) = nothing | ||
|
||
update_n(sim, N::Int) = update_n(sim, Val(N)) | ||
|
||
function update_n(sim, ::Val{N}) where {N} | ||
for i in 1:N | ||
TC.update(sim.Turb, sim.grid, sim.state, sim.GMV, sim.Case, sim.TS) | ||
end | ||
return nothing | ||
end | ||
|
||
function init_sim(case_name) | ||
@info "Initializing $case_name for single timestep, with no IO." | ||
@info "call update_n(sim, n) to run update n-times" | ||
namelist = NameList.default_namelist(case_name) | ||
namelist["time_stepping"]["t_max"] = namelist["time_stepping"]["dt"] | ||
namelist["stats_io"]["frequency"] = 10.0e10 | ||
namelist["stats_io"]["skip"] = true | ||
namelist["meta"]["uuid"] = "01" | ||
sim = Simulation1d(namelist) | ||
|
||
Cases.initialize_profiles(sim.Case, sim.grid, sim.GMV, sim.state) | ||
TC.satadjust(sim.GMV, sim.grid, sim.state) | ||
|
||
Cases.initialize_surface(sim.Case, sim.grid, sim.state, sim.param_set) | ||
Cases.initialize_forcing(sim.Case, sim.grid, sim.state, sim.GMV, sim.param_set) | ||
Cases.initialize_radiation(sim.Case, sim.grid, sim.state, sim.GMV, sim.param_set) | ||
|
||
initialize_edmf(sim.Turb, sim.grid, sim.state, sim.Case, sim.GMV, sim.TS) | ||
return sim | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
include("common.jl") | ||
import BenchmarkTools | ||
|
||
sim = init_sim("Bomex") | ||
update_n(sim, 1) # compile first | ||
BenchmarkTools.@benchmark update_n($sim, 1) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
include("common.jl") | ||
import ProfileView | ||
import Profile | ||
|
||
Profile.@profile update_n(sim, 100) | ||
Profile.print() | ||
# Profile.print(; format = :flat, sortedby = :count) | ||
ProfileView.@profview update_n(sim, 1000) # compile first | ||
ProfileView.@profview update_n(sim, 1000) | ||
Profile.clear_malloc_data() |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.