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

[cherrypick]add chunk allocator posix_memalign return value check #60495

Merged
merged 1 commit into from
Jan 2, 2024
Merged
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
14 changes: 11 additions & 3 deletions paddle/fluid/distributed/common/chunk_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once
#include <glog/logging.h>
#include "paddle/fluid/platform/enforce.h"

namespace paddle {
namespace distributed {
Expand Down Expand Up @@ -77,9 +78,16 @@ class ChunkAllocator {

void create_new_chunk() {
Chunk* chunk;
posix_memalign(reinterpret_cast<void**>(&chunk),
std::max<size_t>(sizeof(void*), alignof(Chunk)),
sizeof(Chunk) + sizeof(Node) * _chunk_size);
size_t alloc_size = sizeof(Chunk) + sizeof(Node) * _chunk_size;
int error = posix_memalign(reinterpret_cast<void**>(&chunk),
std::max<size_t>(sizeof(void*), alignof(Chunk)),
alloc_size);
PADDLE_ENFORCE_EQ(error,
0,
paddle::platform::errors::ResourceExhausted(
"Fail to alloc memory of %ld size, error code is %d.",
alloc_size,
error));
chunk->next = _chunks;
_chunks = chunk;

Expand Down