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

Improve CPUAllocator OOM message #20618

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions c10/core/CPUAllocator.cpp
Expand Up @@ -53,13 +53,24 @@ void* alloc_cpu(size_t nbytes) {
#elif defined(_MSC_VER)
data = _aligned_malloc(nbytes, gAlignment);
#else
CAFFE_ENFORCE_EQ(posix_memalign(&data, gAlignment, nbytes), 0);
int err = posix_memalign(&data, gAlignment, nbytes);
if (err != 0) {
CAFFE_THROW(
"DefaultCPUAllocator: can't allocate memory: you tried to allocate ",
nbytes,
" bytes. Error code ",
err,
" (",
strerror(err),
")");
}
#endif

CAFFE_ENFORCE(
data,
"DefaultCPUAllocator: not enough memory: you tried to allocate %dGB. Buy new RAM!",
nbytes / 1073741824);
"DefaultCPUAllocator: not enough memory: you tried to allocate ",
nbytes,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be simpler for the user to print the amount in MB or GB?

" bytes. Buy new RAM!");

// move data to a thread's NUMA node
NUMAMove(data, nbytes, GetCurrentNUMANode());
Expand Down