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

Function ds_page_aligned_alloc

csrc/aio/common/deepspeed_aio_utils.cpp:120–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120void* ds_page_aligned_alloc(const int64_t size, const bool lock)
121{
122 void* ptr;
123 int retval;
124
125 retval = posix_memalign(&ptr, (size_t)sysconf(_SC_PAGESIZE), size);
126 if (retval) { return nullptr; }
127
128 if (lock == false) { return ptr; }
129
130 auto mlock_ret = mlock(ptr, size);
131 if (mlock_ret != 0) {
132 auto mlock_error = errno;
133 std::cerr << "mlock failed to allocate " << size << " bytes with error no " << mlock_error
134 << " msg " << strerror(mlock_error) << std::endl;
135 free(ptr);
136 return nullptr;
137 }
138
139 return ptr;
140}

Callers 1

allocMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected