Skip to content

Commit b065877

Browse files
authoredJan 2, 2024
add chunk allocator posix_memalign return value check (#60208) (#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
1 parent 203754e commit b065877

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed
 

‎paddle/fluid/distributed/common/chunk_allocator.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#pragma once
1616
#include <glog/logging.h>
17+
#include "paddle/fluid/platform/enforce.h"
1718

1819
namespace paddle {
1920
namespace distributed {
@@ -77,9 +78,16 @@ class ChunkAllocator {
7778

7879
void create_new_chunk() {
7980
Chunk* chunk;
80-
posix_memalign(reinterpret_cast<void**>(&chunk),
81-
std::max<size_t>(sizeof(void*), alignof(Chunk)),
82-
sizeof(Chunk) + sizeof(Node) * _chunk_size);
81+
size_t alloc_size = sizeof(Chunk) + sizeof(Node) * _chunk_size;
82+
int error = posix_memalign(reinterpret_cast<void**>(&chunk),
83+
std::max<size_t>(sizeof(void*), alignof(Chunk)),
84+
alloc_size);
85+
PADDLE_ENFORCE_EQ(error,
86+
0,
87+
paddle::platform::errors::ResourceExhausted(
88+
"Fail to alloc memory of %ld size, error code is %d.",
89+
alloc_size,
90+
error));
8391
chunk->next = _chunks;
8492
_chunks = chunk;
8593

0 commit comments

Comments
 (0)
Please sign in to comment.