Skip to content

Commit cffea1c

Browse files
Merge pull request #294 from CliMA/ck/customize_hcrop
Add horizontal cropping to perf table
2 parents e141aff + a837eeb commit cffea1c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClimaTimeSteppers"
22
uuid = "595c0a79-7f3d-439a-bc5a-b232dc3bde79"
33
authors = ["Climate Modeling Alliance"]
4-
version = "0.7.30"
4+
version = "0.7.31"
55

66
[deps]
77
ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"

ext/ClimaTimeSteppersBenchmarkToolsExt.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const allowed_names =
5353
with_cu_prof::Symbol = :bfrofile, # [:bprofile, :profile]
5454
trace::Bool = false,
5555
crop::Bool = false,
56+
hcrop::Union{Nothing, Int} = nothing,
5657
only::Union{Nothing, Vector{String}} = nothing,
5758
)
5859
@@ -62,6 +63,7 @@ Benchmark a DistributedODEIntegrator given:
6263
- `with_cu_prof`, `:profile` or `:bprofile`, to call `CUDA.@profile` or `CUDA.@bprofile` respectively.
6364
- `trace`, Bool passed to `CUDA.@profile` (see CUDA docs)
6465
- `crop`, Bool indicating whether or not to crop the `CUDA.@profile` printed table.
66+
- `hcrop`, Number of horizontal characters to include in the table before cropping.
6567
- `only, list of functions to benchmarks (benchmark all by default)
6668
6769
`only` may contain:
@@ -81,6 +83,7 @@ function CTS.benchmark_step(
8183
with_cu_prof::Symbol = :bprofile,
8284
trace::Bool = false,
8385
crop::Bool = false,
86+
hcrop::Union{Nothing, Int} = nothing,
8487
only::Union{Nothing, Vector{String}} = nothing,
8588
)
8689
(; u, p, t, dt, sol, alg) = integrator
@@ -96,7 +99,7 @@ function CTS.benchmark_step(
9699
@. X = u
97100
@. Xlim = u
98101
trials₀ = OrderedCollections.OrderedDict()
99-
kwargs = (; device, with_cu_prof, trace, crop)
102+
kwargs = (; device, with_cu_prof, trace, crop, hcrop)
100103
#! format: off
101104
maybe_push!(trials₀, "Wfact", wfact_fun(integrator), (W, u, p, dt, t), kwargs, only)
102105
maybe_push!(trials₀, "ldiv!", LA.ldiv!, (X, W, u), kwargs, only)

ext/benchmark_utils.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ function tabulate_summary(summary; n_calls_per_step)
4848
)
4949
end
5050

51-
get_trial(f::Nothing, args, name; device, with_cu_prof = :bprofile, trace = false, crop = false) = nothing
52-
function get_trial(f, args, name; device, with_cu_prof = :bprofile, trace = false, crop = false)
51+
get_trial(f::Nothing, args, name; device, with_cu_prof = :bprofile, trace = false, crop = false, hcrop = nothing) =
52+
nothing
53+
function get_trial(f, args, name; device, with_cu_prof = :bprofile, trace = false, crop = false, hcrop = nothing)
5354
f(args...) # compile first
5455
b = if device isa ClimaComms.CUDADevice
5556
BenchmarkTools.@benchmarkable CUDA.@sync $f($(args)...)
@@ -68,8 +69,13 @@ function get_trial(f, args, name; device, with_cu_prof = :bprofile, trace = fals
6869
if crop
6970
println(p) # crops by default
7071
else
71-
io = IOContext(stdout, :crop => :horizontal)
72-
show(io, p)
72+
# use "COLUMNS" to set how many horizontal characters to crop:
73+
# See https://github.com/ronisbr/PrettyTables.jl/issues/11#issuecomment-2145550354
74+
envs = isnothing(hcrop) ? () : ("COLUMNS" => hcrop,)
75+
withenv(envs...) do
76+
io = IOContext(stdout, :crop => :horizontal, :limit => true, :displaysize => displaysize())
77+
show(io, p)
78+
end
7379
println()
7480
end
7581
end

0 commit comments

Comments
 (0)