diff options
Diffstat (limited to 'src/include/alloc.h')
-rw-r--r-- | src/include/alloc.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/include/alloc.h b/src/include/alloc.h index bcdbd18..27e206f 100644 --- a/src/include/alloc.h +++ b/src/include/alloc.h @@ -9,6 +9,7 @@ #include "nccl.h" #include "checks.h" +#include "align.h" #include <sys/mman.h> static inline ncclResult_t ncclCudaHostAlloc(void** ptr, void** devPtr, size_t size) { @@ -48,4 +49,18 @@ static ncclResult_t ncclCudaMemcpy(T* dst, T* src, size_t nelem) { return ncclSuccess; } +// Allocate memory to be potentially ibv_reg_mr'd. This needs to be +// allocated on separate pages as those pages will be marked DONTFORK +// and if they are shared, that could cause a crash in a child process +static ncclResult_t ncclIbMalloc(void** ptr, size_t size) { + size_t page_size = sysconf(_SC_PAGESIZE); + void* p; + int size_aligned = ROUNDUP(size, page_size); + int ret = posix_memalign(&p, page_size, size_aligned); + if (ret != 0) return ncclSystemError; + memset(p, 0, size); + *ptr = p; + return ncclSuccess; +} + #endif |