From bad4ef7483fdbdf6de9795971e409efd04882a2c Mon Sep 17 00:00:00 2001 From: Julia Sloan Date: Mon, 18 Mar 2024 08:52:20 -0700 Subject: [PATCH] move show_mem to driver --- Project.toml | 2 -- docs/src/utilities.md | 1 - experiments/AMIP/coupler_driver.jl | 31 +++++++++++++++++++++++++++++- src/Utilities.jl | 30 ----------------------------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Project.toml b/Project.toml index 96f3435efa..4c27e6cad8 100644 --- a/Project.toml +++ b/Project.toml @@ -4,7 +4,6 @@ authors = ["CliMA Contributors "] version = "0.1.0" [deps] -CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" ClimaAtmos = "b2c96348-7fb7-4fe0-8da9-78d88439e717" ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d" ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884" @@ -25,7 +24,6 @@ TempestRemap_jll = "8573a8c5-1df0-515e-a024-abad257ee284" Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c" [compat] -CUDA = "5.2" ClimaAtmos = "0.22" ClimaComms = "0.5.6" ClimaCore = "0.13" diff --git a/docs/src/utilities.md b/docs/src/utilities.md index a38e2825b9..c87b83f5f1 100644 --- a/docs/src/utilities.md +++ b/docs/src/utilities.md @@ -10,5 +10,4 @@ modules in the coupler. ClimaCoupler.Utilities.swap_space! ClimaCoupler.Utilities.get_comms_context ClimaCoupler.Utilities.get_device -ClimaCoupler.Utilities.show_memory_usage ``` diff --git a/experiments/AMIP/coupler_driver.jl b/experiments/AMIP/coupler_driver.jl index 53f0093c5a..c99cfdbd5d 100644 --- a/experiments/AMIP/coupler_driver.jl +++ b/experiments/AMIP/coupler_driver.jl @@ -25,6 +25,35 @@ so we force abbreviated stacktraces even in non-interactive runs. =# using CUDA +""" + show_memory_usage(comms_ctx, objects) + +Display the current memory footprint of the simulation, using an appropriate +method based on the device being used. + +In the GPU case, show the memory usage of the GPU. +In the CPU case, show the memory footprint of the provided object(s). +Note that these two cases provide different information, and should not be +directly compared. + +# Arguments +`comms_ctx`: the communication context being used to run the model +`objects`: Dict mapping objects whose memory footprint is displayed in the CPU case to their names +""" +function show_memory_usage(comms_ctx, objects) + if comms_ctx.device isa ClimaComms.CUDADevice + @info "Memory usage: $(CUDA.memory_status())" + elseif comms_ctx.device isa ClimaComms.AbstractCPUDevice + if ClimaComms.iamroot(comms_ctx) + for (obj, name) in objects + @info "Memory footprint of `$(name)` in bytes: $(Base.summarysize(obj))" + end + end + else + @warn "Invalid device type $device; cannot show memory usage." + end +end + redirect_stderr(IOContext(stderr, :stacktrace_types_limited => Ref(false))) #= @@ -65,7 +94,7 @@ using ClimaCoupler.Regridder using ClimaCoupler.Regridder: update_surface_fractions!, combine_surfaces!, binary_mask using ClimaCoupler.TimeManager: current_date, Monthly, EveryTimestep, HourlyCallback, MonthlyCallback, update_firstdayofmonth!, trigger_callback! -import ClimaCoupler.Utilities: get_comms_context, show_memory_usage +import ClimaCoupler.Utilities: get_comms_context pkg_dir = pkgdir(ClimaCoupler) diff --git a/src/Utilities.jl b/src/Utilities.jl index f0df98ad8c..df44b054b1 100644 --- a/src/Utilities.jl +++ b/src/Utilities.jl @@ -8,7 +8,6 @@ module Utilities import ClimaComms using ClimaCore: Fields, Spaces -using CUDA export swap_space! @@ -70,33 +69,4 @@ function get_comms_context(parsed_args) return comms_ctx end -""" - show_memory_usage(comms_ctx, objects) - -Display the current memory footprint of the simulation, using an appropriate -method based on the device being used. - -In the GPU case, show the memory usage of the GPU. -In the CPU case, show the memory footprint of the provided object(s). -Note that these two cases provide different information, and should not be -directly compared. - -# Arguments -`comms_ctx`: the communication context being used to run the model -`objects`: Dict mapping objects whose memory footprint is displayed in the CPU case to their names -""" -function show_memory_usage(comms_ctx, objects) - if comms_ctx.device isa ClimaComms.CUDADevice - @info "Memory usage: $(CUDA.memory_status())" - elseif comms_ctx.device isa ClimaComms.AbstractCPUDevice - if ClimaComms.iamroot(comms_ctx) - for (obj, name) in objects - @info "Memory footprint of `$(name)` in bytes: $(Base.summarysize(obj))" - end - end - else - @warn "Invalid device type $device; cannot show memory usage." - end -end - end # module