Skip to content
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
cmake-build-debug
cmake-build-debug
.idea
14 changes: 12 additions & 2 deletions src/allocator/allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,31 @@ int check_memory_type(CUdeviceptr address) {
int remove_chunk(allocated_list *a_list, CUdeviceptr dptr){
size_t t_size;
if (a_list->length==0) {
return -1;
LOG_ERROR("remove_chunk a_list length is 0 res=%d",a_list->length);
if (dptr != NULL){
//maybe some graph func, we can not hook the memory alloc
//try to free raw
return cuMemoryFree(dptr);
}
}
allocated_list_entry *val;
for (val=a_list->head;val!=NULL;val=val->next){
LOG_ERROR("remove_chunk remove list entry ");
if (val->entry->address==dptr){
t_size=val->entry->length;
cuMemoryFree(dptr);
LIST_REMOVE(a_list,val);

CUdevice dev;
cuCtxGetDevice(&dev);
rm_gpu_device_memory_usage(getpid(),dev,t_size,2);
return 0;
}
}
if (dptr != NULL){
//maybe some graph func, we can not hook the memory alloc
//try to free raw
return cuMemoryFree(dptr);
}
return -1;
}

Expand Down
6 changes: 6 additions & 0 deletions src/cuda/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ CUresult cuGraphAddMemcpyNode(CUgraphNode *phGraphNode, CUgraph hGraph, const CU
return CUDA_OVERRIDE_CALL(cuda_library_entry,cuGraphAddMemcpyNode,phGraphNode,hGraph,dependencies,numDependencies,copyParams,ctx);
}

CUresult cuGraphAddMemAllocNode(CUgraphNode *phGraphNode, CUgraph hGraph, const CUgraphNode *dependencies,
size_t numDependencies, CUDA_MEM_ALLOC_NODE_PARAMS *nodeParams) {
LOG_INFO("call in cuGraphAddMemAllocNode");
return CUDA_OVERRIDE_CALL(cuda_library_entry,cuGraphAddMemAllocNode,phGraphNode,hGraph,dependencies,numDependencies,nodeParams);
}

CUresult cuGraphMemcpyNodeGetParams(CUgraphNode hNode, CUDA_MEMCPY3D *nodeParams) {
LOG_DEBUG("cuGraphMemcpyNodeGetParams");
return CUDA_OVERRIDE_CALL(cuda_library_entry,cuGraphMemcpyNodeGetParams,hNode,nodeParams);
Expand Down
1 change: 1 addition & 0 deletions src/cuda/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ cuda_entry_t cuda_library_entry[] = {
{.name = "cuGraphMemcpyNodeGetParams"},
{.name = "cuGraphMemcpyNodeSetParams"},
{.name = "cuGraphAddMemsetNode"},
{.name = "cuGraphAddMemAllocNode"},
{.name = "cuGraphMemsetNodeGetParams"},
{.name = "cuGraphMemsetNodeSetParams"},
{.name = "cuGraphAddHostNode"},
Expand Down
1 change: 1 addition & 0 deletions src/include/libcuda_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ typedef enum {
CUDA_OVERRIDE_ENUM(cuGraphMemcpyNodeGetParams),
CUDA_OVERRIDE_ENUM(cuGraphMemcpyNodeSetParams),
CUDA_OVERRIDE_ENUM(cuGraphAddMemsetNode),
CUDA_OVERRIDE_ENUM(cuGraphAddMemAllocNode),
CUDA_OVERRIDE_ENUM(cuGraphMemsetNodeGetParams),
CUDA_OVERRIDE_ENUM(cuGraphMemsetNodeSetParams),
CUDA_OVERRIDE_ENUM(cuGraphAddHostNode),
Expand Down
1 change: 1 addition & 0 deletions src/libvgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ void* __dlsym_hook_section(void* handle, const char* symbol) {
DLSYM_HOOK_FUNC(cuGraphMemcpyNodeGetParams);
DLSYM_HOOK_FUNC(cuGraphMemcpyNodeSetParams);
DLSYM_HOOK_FUNC(cuGraphAddMemsetNode);
DLSYM_HOOK_FUNC(cuGraphAddMemAllocNode);
DLSYM_HOOK_FUNC(cuGraphMemsetNodeGetParams);
DLSYM_HOOK_FUNC(cuGraphMemsetNodeSetParams);
DLSYM_HOOK_FUNC(cuGraphAddHostNode);
Expand Down