From 391dee7e4b35148abe5508363759c73b29044476 Mon Sep 17 00:00:00 2001 From: marcelo-cjl Date: Mon, 27 Apr 2026 22:33:50 +0800 Subject: [PATCH] fix: resolve GPU build link failures (#49383) ## Summary - Set RAPIDS package dirs for GPU builds so local cuVS package resolution can find `raft::raft` and `rmm::rmm`. - Install cuVS runtime dependencies `librmm.so*` and `librapids_logger.so*` alongside Milvus core libraries. - Make the CUDA cgo GPU memory helper `static` to avoid duplicate global symbols during Go link. issue: #49368 ## Test plan - [ ] `make milvus-gpu > output.txt 2>&1` - [ ] Check `internal/core/output/lib/librmm.so*` and `internal/core/output/lib/librapids_logger.so*` exist after build. - [ ] Check `ldd internal/core/output/lib/libknowhere.so` does not report missing `librmm` or `librapids_logger`. Generated with Claude Code Signed-off-by: marcelo-cjl Co-authored-by: Claude Opus 4.7 (1M context) --- .../core/thirdparty/knowhere/CMakeLists.txt | 22 +++++++++++++++++++ pkg/util/hardware/gpu_mem_info_cuda.go | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/core/thirdparty/knowhere/CMakeLists.txt b/internal/core/thirdparty/knowhere/CMakeLists.txt index 1936c4dd2d..7cb0a498ba 100644 --- a/internal/core/thirdparty/knowhere/CMakeLists.txt +++ b/internal/core/thirdparty/knowhere/CMakeLists.txt @@ -37,6 +37,8 @@ endif() if ( MILVUS_GPU_VERSION STREQUAL "ON" ) set(WITH_CUVS ON CACHE BOOL "" FORCE ) + set(raft_DIR "${FETCHCONTENT_BASE_DIR}/raft-build" CACHE PATH "Path to raft build directory" FORCE) + set(rmm_DIR "${FETCHCONTENT_BASE_DIR}/rmm-build" CACHE PATH "Path to rmm build directory" FORCE) endif () if ( WITH_SVS STREQUAL "ON" ) @@ -80,6 +82,26 @@ if ( WITH_SVS STREQUAL "ON" ) endif() endif() +if ( WITH_CUVS STREQUAL "ON" ) + set( _RMM_LIB_DIR "${FETCHCONTENT_BASE_DIR}/rmm-build" ) + if ( EXISTS "${_RMM_LIB_DIR}" ) + install(DIRECTORY ${_RMM_LIB_DIR}/ + DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + FILES_MATCHING PATTERN "librmm.so*") + else() + message(WARNING "cuVS enabled but ${_RMM_LIB_DIR} not found \u2014 librmm.so will not be installed") + endif() + + set( _RAPIDS_LOGGER_LIB_DIR "${FETCHCONTENT_BASE_DIR}/rapids_logger-build" ) + if ( EXISTS "${_RAPIDS_LOGGER_LIB_DIR}" ) + install(DIRECTORY ${_RAPIDS_LOGGER_LIB_DIR}/ + DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + FILES_MATCHING PATTERN "librapids_logger.so*") + else() + message(WARNING "cuVS enabled but ${_RAPIDS_LOGGER_LIB_DIR} not found \u2014 librapids_logger.so will not be installed") + endif() +endif() + # get prometheus COMPILE_OPTIONS get_property( var DIRECTORY "${knowhere_SOURCE_DIR}" PROPERTY COMPILE_OPTIONS ) message( STATUS "knowhere src compile options: ${var}" ) diff --git a/pkg/util/hardware/gpu_mem_info_cuda.go b/pkg/util/hardware/gpu_mem_info_cuda.go index 5d797ccf28..0b6f9aec91 100644 --- a/pkg/util/hardware/gpu_mem_info_cuda.go +++ b/pkg/util/hardware/gpu_mem_info_cuda.go @@ -16,7 +16,7 @@ typedef struct { } GPUMemoryInfo; // Function to get memory info for all GPUs -int getAllGPUMemoryInfo(GPUMemoryInfo** infos) { +static int getAllGPUMemoryInfo(GPUMemoryInfo** infos) { int deviceCount = 0; cudaError_t err = cudaGetDeviceCount(&deviceCount); if (err != cudaSuccess || deviceCount == 0) {