Skip to content

Commit

Permalink
Add horizontal cropping to perf table
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Jun 3, 2024
1 parent b3dbb71 commit a837eeb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaTimeSteppers"
uuid = "595c0a79-7f3d-439a-bc5a-b232dc3bde79"
authors = ["Climate Modeling Alliance"]
version = "0.7.30"
version = "0.7.31"

[deps]
ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"
Expand Down
5 changes: 4 additions & 1 deletion ext/ClimaTimeSteppersBenchmarkToolsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const allowed_names =
with_cu_prof::Symbol = :bfrofile, # [:bprofile, :profile]
trace::Bool = false,
crop::Bool = false,
hcrop::Union{Nothing, Int} = nothing,
only::Union{Nothing, Vector{String}} = nothing,
)
Expand All @@ -62,6 +63,7 @@ Benchmark a DistributedODEIntegrator given:
- `with_cu_prof`, `:profile` or `:bprofile`, to call `CUDA.@profile` or `CUDA.@bprofile` respectively.
- `trace`, Bool passed to `CUDA.@profile` (see CUDA docs)
- `crop`, Bool indicating whether or not to crop the `CUDA.@profile` printed table.
- `hcrop`, Number of horizontal characters to include in the table before cropping.
- `only, list of functions to benchmarks (benchmark all by default)
`only` may contain:
Expand All @@ -81,6 +83,7 @@ function CTS.benchmark_step(
with_cu_prof::Symbol = :bprofile,
trace::Bool = false,
crop::Bool = false,
hcrop::Union{Nothing, Int} = nothing,
only::Union{Nothing, Vector{String}} = nothing,
)
(; u, p, t, dt, sol, alg) = integrator
Expand All @@ -96,7 +99,7 @@ function CTS.benchmark_step(
@. X = u
@. Xlim = u
trials₀ = OrderedCollections.OrderedDict()
kwargs = (; device, with_cu_prof, trace, crop)
kwargs = (; device, with_cu_prof, trace, crop, hcrop)
#! format: off
maybe_push!(trials₀, "Wfact", wfact_fun(integrator), (W, u, p, dt, t), kwargs, only)
maybe_push!(trials₀, "ldiv!", LA.ldiv!, (X, W, u), kwargs, only)
Expand Down
14 changes: 10 additions & 4 deletions ext/benchmark_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ function tabulate_summary(summary; n_calls_per_step)
)
end

get_trial(f::Nothing, args, name; device, with_cu_prof = :bprofile, trace = false, crop = false) = nothing
function get_trial(f, args, name; device, with_cu_prof = :bprofile, trace = false, crop = false)
get_trial(f::Nothing, args, name; device, with_cu_prof = :bprofile, trace = false, crop = false, hcrop = nothing) =
nothing
function get_trial(f, args, name; device, with_cu_prof = :bprofile, trace = false, crop = false, hcrop = nothing)
f(args...) # compile first
b = if device isa ClimaComms.CUDADevice
BenchmarkTools.@benchmarkable CUDA.@sync $f($(args)...)
Expand All @@ -68,8 +69,13 @@ function get_trial(f, args, name; device, with_cu_prof = :bprofile, trace = fals
if crop
println(p) # crops by default
else
io = IOContext(stdout, :crop => :horizontal)
show(io, p)
# use "COLUMNS" to set how many horizontal characters to crop:
# See https://github.com/ronisbr/PrettyTables.jl/issues/11#issuecomment-2145550354
envs = isnothing(hcrop) ? () : ("COLUMNS" => hcrop,)
withenv(envs...) do
io = IOContext(stdout, :crop => :horizontal, :limit => true, :displaysize => displaysize())
show(io, p)
end
println()
end
end
Expand Down

0 comments on commit a837eeb

Please sign in to comment.