Skip to content

Commit

Permalink
Support cuda pin memory in vineyard.
Browse files Browse the repository at this point in the history
Signed-off-by: Ye Cao <caoye.cao@alibaba-inc.com>
  • Loading branch information
dashanji committed Nov 19, 2024
1 parent 0f78867 commit ba07da0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/server/memory/malloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@

#include "common/util/logging.h" // IWYU pragma: keep

#if defined(ENABLE_CUDA)
#include <cuda_runtime.h>
#endif

namespace vineyard {

namespace memory {
Expand All @@ -60,6 +64,8 @@ constexpr int64_t kMmapRegionsGap = sizeof(size_t);
DEFINE_bool(reserve_memory, false,
"Reserving enough physical memory pages for vineyardd");

DEFINE_bool(cuda_pin_memory, false, "Pin memory for CUDA");

std::unordered_map<void*, MmapRecord> mmap_records;

static void* pointer_advance(void* p, ptrdiff_t n) {
Expand Down Expand Up @@ -266,6 +272,16 @@ void* mmap_buffer(int fd, int64_t size, bool gap, bool* is_committed,
return pointer;
}

if (FLAGS_cuda_pin_memory) {
#ifdef ENABLE_CUDA
cudaError_t status = cudaHostRegister(pointer, size, cudaHostRegisterDefault);
if (status != cudaSuccess) {
LOG(ERROR) << "cudaHostRegister failed with error: "
<< cudaGetErrorString(status);
}
#endif
}

MmapRecord& record = mmap_records[pointer];
record.fd = fd;
record.size = size;
Expand Down

0 comments on commit ba07da0

Please sign in to comment.