Skip to content

Commit

Permalink
add chunk allocator posix_memalign return value check (PaddlePaddle#6…
Browse files Browse the repository at this point in the history
…0208) (PaddlePaddle#60495)

* fix chunk allocator posix_memalign return value check;test=develop

* fix chunk allocator posix_memalign return value check;test=develop

* fix chunk allocator posix_memalign return value check;test=develop
  • Loading branch information
danleifeng committed Jan 2, 2024
1 parent 203754e commit b065877
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit b065877

Please sign in to comment.