Skip to content

Commit

Permalink
Refactor allocation monitoring
Browse files Browse the repository at this point in the history
Update Project tomls
  • Loading branch information
charleskawczynski committed Jul 17, 2024
1 parent 8587938 commit 9f40d03
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*.png
*.svg
*.nc
*.html

# Docs
!docs/src/assets/*.svg
Expand Down
2 changes: 1 addition & 1 deletion perf/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
ProfileCanvas = "efd6af41-a80b-495e-886c-e51b0c7d77a3"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReportMetrics = "c1654acf-408b-4272-96ce-66c258df8a6c"
RootSolvers = "7181ea78-2dcb-4de3-ab41-2b8ab5a31e74"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
16 changes: 0 additions & 16 deletions perf/alloc_per_constructor.jl

This file was deleted.

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

dirs_to_monitor =
[".", pkgdir(Thermodynamics), pkgdir(RootSolvers), pkgdir(ClimaParams)]
include("common.jl")
output_dir = joinpath(pkgdir(Thermodynamics), "perf", "allocations_output")
mkpath(output_dir)
thermo_state_ρeq(param_set, ρ, e_int, q_tot)
Profile.Allocs.clear()
Profile.Allocs.@profile sample_rate = 1 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)

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_pθq(param_set, p, θ_liq_ice, q_tot)
Profile.Allocs.clear()
Profile.Allocs.@profile sample_rate = 1 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 = 1 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
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReportMetrics = "c1654acf-408b-4272-96ce-66c258df8a6c"
RootSolvers = "7181ea78-2dcb-4de3-ab41-2b8ab5a31e74"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
Expand Down

0 comments on commit 9f40d03

Please sign in to comment.