Skip to content

Commit

Permalink
Merge branch 'INSTX-1947-16GB-message-macos' into 'master'
Browse files Browse the repository at this point in the history
[INSTX-1947] Log a warning message if running on Apple Silicon with less than 16GB RAM

Closes INSTX-1947

See merge request machine-learning/dorado!837
  • Loading branch information
blawrence-ont committed Feb 6, 2024
2 parents 00cac3d + f65a7cf commit d7defcc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
9 changes: 9 additions & 0 deletions dorado/basecall/MetalCaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "crf_utils.h"
#include "decode/beam_search.h"
#include "utils/math_utils.h"
#include "utils/memory_utils.h"
#include "utils/metal_utils.h"

#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -43,6 +44,14 @@ MetalCaller::MetalCaller(const CRFModelConfig &model_config, int chunk_size, int
: m_config(model_config) {
ScopedAutoReleasePool autorelease_pool;

// Our metal builds assume shared memory, so it's safe to check host.
if (auto total_mem = utils::total_host_memory_GB(); total_mem < 16) {
spdlog::warn(
"Less than 16GB of memory available: {}GB detected. "
"This is below minimum spec and may cause issues",
total_mem);
}

m_num_input_features = model_config.num_features;

m_device = get_mtl_device();
Expand Down
33 changes: 32 additions & 1 deletion dorado/utils/memory_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#include <sys/sysinfo.h>
#elif defined(__APPLE__)
#include <mach/mach.h>
#include <sys/sysctl.h>
#endif

#include <array>

namespace {
constexpr size_t BYTES_PER_GB{1024 * 1024 * 1024};
}
Expand Down Expand Up @@ -41,9 +44,37 @@ size_t available_host_memory_GB() {
unused_mem = static_cast<size_t>(vm_stats.free_count) * page_size / BYTES_PER_GB;
}
return unused_mem;

#else
// Unsupported
#error "Unsupported platform"
#endif
}

size_t total_host_memory_GB() {
#if defined(WIN32)
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
return static_cast<size_t>(status.ullTotalPhys) / BYTES_PER_GB;

#elif defined(__linux__)
struct sysinfo info;
if (sysinfo(&info) < 0) {
return 0;
}
return static_cast<size_t>(info.totalram) * info.mem_unit / BYTES_PER_GB;

#elif defined(__APPLE__)
std::array name{CTL_HW, HW_MEMSIZE};
uint64_t total_size = 0;
size_t length = sizeof(total_size);
if (sysctl(name.data(), name.size(), &total_size, &length, nullptr, 0) != -1) {
return total_size / BYTES_PER_GB;
}
return 0;

#else
#error "Unsupported platform"
#endif
}

Expand Down
1 change: 1 addition & 0 deletions dorado/utils/memory_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
namespace dorado::utils {

size_t available_host_memory_GB();
size_t total_host_memory_GB();

} // namespace dorado::utils

0 comments on commit d7defcc

Please sign in to comment.