Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DiHydrogen for memory profiler information #2356

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/callbacks/gpu_memory_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <iomanip>
#include <sstream>

#ifdef LBANN_HAS_GPU
#include <h2/gpu/memory_utils.hpp>
#endif

#include "lbann/proto/callbacks.pb.h"

namespace {
Expand Down Expand Up @@ -79,13 +83,7 @@ void gpu_memory_usage::write_specific_proto(lbann_data::Callback& proto) const
void gpu_memory_usage::on_epoch_begin(model* m)
{
#ifdef LBANN_HAS_GPU
size_t available;
size_t total;
#ifdef LBANN_HAS_CUDA
FORCE_CHECK_CUDA(cudaMemGetInfo(&available, &total));
#elif defined(LBANN_HAS_ROCM)
FORCE_CHECK_ROCM(hipMemGetInfo(&available, &total));
#endif
auto const [available, total] = h2::gpu::mem_info();
size_t used = total - available;
auto comm = m->get_comm();
if (comm->am_trainer_master()) {
Expand Down
22 changes: 7 additions & 15 deletions src/callbacks/memory_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include <algorithm>
#include <string>

#ifdef LBANN_HAS_GPU
#include <h2/gpu/memory_utils.hpp>
#endif

namespace lbann {
namespace callback {
namespace {
Expand Down Expand Up @@ -169,17 +173,12 @@ size_t get_activation_and_error_signal_size(Layer const& x, std::ostream& os)
/**
* @brief Returns the currently used memory, or 0 if LBANN was not compiled with
* GPU support.
* TODO(later): Gather across all ranks?
*/
size_t get_used_gpu_memory()
{
#ifdef LBANN_HAS_GPU
size_t available;
size_t total;
#ifdef LBANN_HAS_CUDA
FORCE_CHECK_CUDA(cudaMemGetInfo(&available, &total));
#elif defined(LBANN_HAS_ROCM)
FORCE_CHECK_ROCM(hipMemGetInfo(&available, &total));
#endif
auto const [available, total] = h2::gpu::mem_info();
// TODO(later): Might be nicer to return a struct with gathered information
// (min, max, median across ranks)
return total - available;
Expand All @@ -195,14 +194,7 @@ size_t get_used_gpu_memory()
static inline size_t get_total_gpu_memory()
{
#ifdef LBANN_HAS_GPU
size_t available;
size_t total;
#ifdef LBANN_HAS_CUDA
FORCE_CHECK_CUDA(cudaMemGetInfo(&available, &total));
#elif defined(LBANN_HAS_ROCM)
FORCE_CHECK_ROCM(hipMemGetInfo(&available, &total));
#endif
return total;
return h2::gpu::mem_info().total;
#else
return 0;
#endif
Expand Down