Skip to content
Closed
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
Fix: avoid hooking cuMemGetInfo_v2 to prevent memory conflict with …
…total and limit memory.

Signed-off-by: yangshiqi <[email protected]>
  • Loading branch information
yangshiqi committed Jun 11, 2025
commit fcfc20ddd7563012e5f7186a8abc8fe3df87df1f
14 changes: 8 additions & 6 deletions src/cuda/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,21 @@ CUresult cuMemGetInfo_v2(size_t* free, size_t* total) {
size_t limit = get_current_device_memory_limit(dev);
if (limit == 0) {
CUDA_OVERRIDE_CALL(cuda_library_entry,cuMemGetInfo_v2, free, total);
//LOG_INFO("orig free=%ld total=%ld\n",*free,*total);
LOG_INFO("orig free=%ld total=%ld",*free,*total);
*free= *total - usage;
LOG_INFO("after free=%ld total=%ld",*free,*total);
LOG_MSG("orig free=%ld total=%ld",*free,*total);
*free = *total - usage;
LOG_MSG("after free=%ld total=%ld",*free,*total);
return CUDA_SUCCESS;
} else if (limit < usage) {
LOG_WARN("limit < usage; usage=%ld, limit=%ld",usage,limit);
return CUDA_ERROR_INVALID_VALUE;
} else {
CUDA_OVERRIDE_CALL(cuda_library_entry,cuMemGetInfo_v2, free, total);
LOG_MSG("orig free=%ld total=%ld limit=%ld usage=%ld",*free,*total,limit,usage);
*free = limit - usage;
*total = limit;
// Ensure total memory does not exceed the physical or imposed limit.
size_t actual_limit = (limit > *total) ? *total : limit;
*free = (actual_limit > usage) ? (actual_limit - usage) : 0;
*total = actual_limit;
LOG_MSG("after free=%ld total=%ld limit=%ld usage=%ld",*free,*total,limit,usage);
return CUDA_SUCCESS;
}
}
Expand Down