Skip to content

Commit

Permalink
Refactor allocation monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Jul 17, 2024
1 parent 8587938 commit eba00e2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 41 deletions.
16 changes: 0 additions & 16 deletions perf/alloc_per_constructor.jl

This file was deleted.

52 changes: 40 additions & 12 deletions perf/allocs.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
import Thermodynamics
import RootSolvers
import ClimaParams
import ReportMetrics
import Profile, ProfileCanvas

dirs_to_monitor =
[".", pkgdir(Thermodynamics), pkgdir(RootSolvers), pkgdir(ClimaParams)]
include("common.jl")

for constructor in ["ρeq", "pθq", "pTq"]
ENV["ALLOCATION_CONSTRUCTOR"] = constructor
ReportMetrics.report_allocs(;
job_name = constructor,
run_cmd = `$(Base.julia_cmd()) --project=perf/ --track-allocation=all perf/alloc_per_constructor.jl`,
dirs_to_monitor = dirs_to_monitor,
process_filename = x -> last(split(x, "packages/")),
)
end
thermo_state_ρeq(param_set, ρ, e_int, q_tot)
Profile.Allocs.clear()
Profile.Allocs.@profile sample_rate = sampling_rate thermo_state_ρeq(
param_set,
ρ,
e_int,
q_tot,
)
results = Profile.Allocs.fetch()
Profile.Allocs.clear()
profile = ProfileCanvas.view_allocs(results)
ProfileCanvas.html_file(joinpath(output_dir, "allocs_ρeq.html"), profile)

thermo_state_pθq(param_set, p, θ_liq_ice, q_tot)
Profile.Allocs.clear()
Profile.Allocs.@profile sample_rate = sampling_rate thermo_state_pθq(
param_set,
p,
θ_liq_ice,
q_tot,
)
results = Profile.Allocs.fetch()
Profile.Allocs.clear()
profile = ProfileCanvas.view_allocs(results)
ProfileCanvas.html_file(joinpath(output_dir, "allocs_pθq.html"), profile)

thermo_state_pTq(param_set, p, T, q_tot)
Profile.Allocs.clear()
Profile.Allocs.@profile sample_rate = sampling_rate thermo_state_pTq(
param_set,
p,
T,
q_tot,
)
results = Profile.Allocs.fetch()
Profile.Allocs.clear()
profile = ProfileCanvas.view_allocs(results)
ProfileCanvas.html_file(joinpath(output_dir, "allocs_pTq.html"), profile)
17 changes: 14 additions & 3 deletions perf/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ include("common.jl")

@testset "Thermodynamics - Performance pθq constructor" begin

trial = BenchmarkTools.@benchmark $thermo_state_ρeq()
trial = BenchmarkTools.@benchmark thermo_state_ρeq(
$param_set,
$ρ,
$e_int,
$q_tot,
)
show(stdout, MIME("text/plain"), trial)
trial = BenchmarkTools.@benchmark $thermo_state_pθq()
trial = BenchmarkTools.@benchmark thermo_state_pθq(
$param_set,
$p,
$θ_liq_ice,
$q_tot,
)
show(stdout, MIME("text/plain"), trial)
trial = BenchmarkTools.@benchmark $thermo_state_pTq()
trial =
BenchmarkTools.@benchmark thermo_state_pTq($param_set, $p, $T, $q_tot)
show(stdout, MIME("text/plain"), trial)

end
29 changes: 19 additions & 10 deletions perf/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@ import ClimaParams as CP
const FT = Float64
const param_set = TP.ThermodynamicsParameters(FT)

ArrayType = Array{FT}
profiles = TD.TestedProfiles.PhaseEquilProfiles(param_set, ArrayType)
(; e_int, T, ρ, p, θ_liq_ice, q_tot) = profiles

function thermo_state_ρeq()
ts = TD.PhaseEquil_ρeq.(param_set, ρ, e_int, q_tot)
function thermo_state_ρeq(param_set, _ρ, _e_int, _q_tot)
for (ρ, e_int, q_tot) in zip(_ρ, _e_int, _q_tot)
ts = TD.PhaseEquil_ρeq(param_set, ρ, e_int, q_tot)
end
return nothing
end

function thermo_state_pθq()
ts = TD.PhaseEquil_pθq.(param_set, p, θ_liq_ice, q_tot)
function thermo_state_pθq(param_set, _p, _θ_liq_ice, _q_tot)
for (_p, _θ_liq_ice, _q_tot) in zip(p, θ_liq_ice, q_tot)
ts = TD.PhaseEquil_pθq(param_set, p, θ_liq_ice, q_tot)
end
return nothing
end

function thermo_state_pTq()
ts = TD.PhaseEquil_pTq.(param_set, p, T, q_tot)
function thermo_state_pTq(param_set, _p, _T, _q_tot)
for (_p, _T, _q_tot) in zip(p, T, q_tot)
ts = TD.PhaseEquil_pTq(param_set, p, T, q_tot)
end
return nothing
end

ArrayType = Array{FT}
profiles = TD.TestedProfiles.PhaseEquilProfiles(param_set, ArrayType)
(; e_int, T, ρ, p, θ_liq_ice, q_tot) = profiles

0 comments on commit eba00e2

Please sign in to comment.