MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / ds_page_aligned_alloc

Function ds_page_aligned_alloc

csrc/pin_memory/page_alloc.cpp:14–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include <iostream>
13
14void* ds_page_aligned_alloc(const int64_t size, const bool lock)
15{
16 void* ptr;
17 int retval;
18
19 retval = posix_memalign(&ptr, (size_t)sysconf(_SC_PAGESIZE), size);
20 if (retval) { return nullptr; }
21
22 if (lock == false) { return ptr; }
23
24 auto mlock_ret = mlock(ptr, size);
25 if (mlock_ret != 0) {
26 auto mlock_error = errno;
27 std::cerr << "mlock failed to allocate " << size << " bytes with error no " << mlock_error
28 << " msg " << strerror(mlock_error) << std::endl;
29 free(ptr);
30 return nullptr;
31 }
32
33 return ptr;
34}

Callers 1

allocMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected