Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Force the use of managed memory. #401

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/gpuarray_buffer_cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,10 @@ static int allocate(cuda_context *ctx, gpudata **res, gpudata **prev,

cuda_enter(ctx);

ctx->err = cuMemAlloc(&ptr, size);
if (1)
ctx->err = cuMemAllocManaged(&ptr, size, CU_MEM_ATTACH_GLOBAL);
else
ctx->err = cuMemAlloc(&ptr, size);
if (ctx->err != CUDA_SUCCESS) {
cuda_exit(ctx);
return GA_IMPL_ERROR;
Expand Down
1 change: 1 addition & 0 deletions src/loaders/libcuda.fn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DEF_PROC_V2(cuMemGetInfo, (size_t *free, size_t *total));
DEF_PROC_V2(cuMemAlloc, (CUdeviceptr *dptr, size_t bytesize));
DEF_PROC_V2(cuMemFree, (CUdeviceptr dptr));
DEF_PROC_V2(cuMemAllocHost, (void **pp, size_t bytesize));
DEF_PROC(cuMemAllocManaged, (CUdeviceptr* dptr, size_t bytesize, unsigned int flags));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use DEF_PROC_V2 here and it failed. Why? How this work? I followed the code but didn't understood.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found why.

DEF_PROC(cuMemFreeHost, (void *p));

DEF_PROC_V2(cuMemcpyHtoDAsync, (CUdeviceptr dstDevice, const void *srcHost, size_t ByteCount, CUstream hStream));
Expand Down
7 changes: 7 additions & 0 deletions src/loaders/libcuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef enum CUctx_flags_enum CUctx_flags;
typedef enum CUipcMem_flags_enum CUipcMem_flags;
typedef enum CUjit_option_enum CUjit_option;
typedef enum CUjitInputType_enum CUjitInputType;
typedef enum CUmemAttach_flags_enum CUmemAttach_flags;

#define CU_IPC_HANDLE_SIZE 64

Expand Down Expand Up @@ -187,6 +188,12 @@ enum CUipcMem_flags_enum {
CU_IPC_MEM_LAZY_ENABLE_PEER_ACCESS = 0x1
};

enum CUmemAttach_flags_enum {
CU_MEM_ATTACH_GLOBAL = 0x1,
CU_MEM_ATTACH_HOST = 0x2,
CU_MEM_ATTACH_SINGLE = 0x4
};

enum CUjit_option_enum {
CU_JIT_MAX_REGISTERS = 0,
CU_JIT_THREADS_PER_BLOCK,
Expand Down