Skip to content
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
4 changes: 2 additions & 2 deletions cmake/libs/libdiskann.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_definitions(-DKNOWHERE_WITH_DISKANN)
find_package(Boost REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIR})
find_package(Boost REQUIRED COMPONENTS program_options CONFIG)
include_directories(${Boost_INCLUDE_DIRS})
find_package(aio REQUIRED)
include_directories(${AIO_INCLUDE})
find_package(fmt REQUIRED)
Expand Down
46 changes: 46 additions & 0 deletions cmake/libs/libfaiss.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,49 @@ if(__PPC64)
knowhere_utils)
target_compile_definitions(faiss PRIVATE FINTEGER=int)
endif()

# GPU HNSW CUDA sources — compiled when WITH_CUVS is enabled.
#
# This `faiss_gpu_hnsw` OBJECT library is the ONLY place the faiss GPU sources
# are compiled in the knowhere build:
# * The main `faiss` STATIC target above is built from FAISS_SRCS, which globs
# only thirdparty/faiss/faiss/{*.cpp,impl,utils,...} — it deliberately does
# NOT include thirdparty/faiss/faiss/gpu/*, so none of the files below are
# also compiled into `faiss`.
# * Upstream faiss ships its own GPU build file
# (thirdparty/faiss/faiss/gpu/CMakeLists.txt → the `faiss_gpu_objs` target
# over FAISS_GPU_SRC). Knowhere assembles faiss manually via this .cmake and
# never `add_subdirectory()`s the vendored faiss tree, so that file (and
# `faiss_gpu_objs`) is never part of the knowhere build graph.
# Therefore the two GPU build paths are mutually exclusive here — there is no
# duplicate compilation or ODR hazard. Keep it that way: add GPU sources to the
# list below, NOT by pulling in the vendored gpu/CMakeLists.txt.
if(WITH_CUVS)
set(FAISS_GPU_HNSW_SRCS
thirdparty/faiss/faiss/gpu/GpuIndexHNSW.cu
thirdparty/faiss/faiss/gpu/GpuIndex.cu
thirdparty/faiss/faiss/gpu/GpuResources.cpp
thirdparty/faiss/faiss/gpu/StandardGpuResources.cpp
thirdparty/faiss/faiss/gpu/impl/GpuHnswTypes.cu
thirdparty/faiss/faiss/gpu/impl/IndexUtils.cu
thirdparty/faiss/faiss/gpu/utils/DeviceUtils.cu
thirdparty/faiss/faiss/gpu/utils/StackDeviceMemory.cpp
thirdparty/faiss/faiss/gpu/utils/Timer.cpp
)
add_library(faiss_gpu_hnsw OBJECT ${FAISS_GPU_HNSW_SRCS})
# These objects are linked into the STATIC `faiss` target which is in turn
# linked into the shared libknowhere.so. The global -fPIC in
# cmake/utils/compile_flags.cmake only reaches the C++ host compiler, not the
# CUDA (.cu) sources built by nvcc, so their objects are non-PIC and trigger
# `relocation R_X86_64_PC32 ... can not be used when making a shared object`
# (surfaces in clean/Debug test builds). Mirror upstream faiss_gpu_objs and
# mark the target PIC so CMake passes -Xcompiler -fPIC to nvcc.
set_target_properties(faiss_gpu_hnsw PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(faiss_gpu_hnsw PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/faiss
${Boost_INCLUDE_DIRS}
)
target_compile_definitions(faiss_gpu_hnsw PRIVATE FINTEGER=int)
target_link_libraries(faiss_gpu_hnsw PRIVATE CUDA::cudart)
target_link_libraries(faiss PUBLIC faiss_gpu_hnsw)
endif()
5 changes: 5 additions & 0 deletions include/knowhere/bitsetview.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class BitsetView {
return out_ids_ != nullptr;
}

size_t
id_offset() const {
return id_offset_;
}

void
set_out_ids(const uint32_t* out_ids, size_t num_internal_ids,
std::optional<size_t> num_filtered_out_ids = std::nullopt) {
Expand Down
2 changes: 2 additions & 0 deletions include/knowhere/comp/index_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ constexpr const char* INDEX_GPU_BRUTEFORCE = "GPU_BRUTE_FORCE";
constexpr const char* INDEX_GPU_IVFFLAT = "GPU_IVF_FLAT";
constexpr const char* INDEX_GPU_IVFPQ = "GPU_IVF_PQ";
constexpr const char* INDEX_GPU_CAGRA = "GPU_CAGRA";
constexpr const char* INDEX_GPU_HNSW = "GPU_HNSW";
constexpr const char* INDEX_GPU_HNSW_SQ = "GPU_HNSW_SQ";

constexpr const char* INDEX_HNSW = "HNSW";
constexpr const char* INDEX_HNSW_SQ = "HNSW_SQ";
Expand Down
17 changes: 16 additions & 1 deletion include/knowhere/index/index_static.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@
namespace knowhere {

struct Resource {
uint64_t memoryCost; // in bytes
uint64_t memoryCost; // retained host memory after load completes, in bytes
uint64_t diskCost; // in bytes
// Peak transient host memory required *during* load, in bytes. Defaults to 0
// so existing indexes are unaffected: consumers should fall back to their
// memoryCost-based heuristic when this is 0. Indexes whose peak load
// footprint differs from the retained footprint (e.g. GPU_HNSW frees its CPU
// copy after uploading to VRAM, so memoryCost≈0 but the peak covers the
// download buffer + deserialized CPU index + decode/graph staging) set this
// to the peak so the loader reserves enough host RAM and does not OOM.
uint64_t maxMemoryCost = 0;
// Device (GPU) memory retained after load, in bytes. Defaults to 0 so
// non-GPU indexes are unaffected and GPU consumers fall back to their prior
// heuristic when this is 0. GPU indexes that upload vectors/graph to VRAM
// set this to the per-segment device footprint so the loader's GPU
// admission reserves the actual VRAM growth, instead of (over-)charging the
// host transient maxMemoryCost against the device.
uint64_t gpuMemoryCost = 0;
};

#define DEFINE_HAS_STATIC_FUNC(func_name) \
Expand Down
8 changes: 8 additions & 0 deletions include/knowhere/index/index_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ static std::set<std::pair<std::string, VecType>> legal_knowhere_index = {
{IndexEnum::INDEX_GPU_CAGRA, VecType::VECTOR_FLOAT16},
{IndexEnum::INDEX_GPU_CAGRA, VecType::VECTOR_INT8},
{IndexEnum::INDEX_GPU_CAGRA, VecType::VECTOR_BINARY},
{IndexEnum::INDEX_GPU_HNSW, VecType::VECTOR_FLOAT},
{IndexEnum::INDEX_GPU_HNSW, VecType::VECTOR_FLOAT16},
{IndexEnum::INDEX_GPU_HNSW, VecType::VECTOR_BFLOAT16},
{IndexEnum::INDEX_GPU_HNSW, VecType::VECTOR_INT8},
{IndexEnum::INDEX_GPU_HNSW_SQ, VecType::VECTOR_FLOAT},
{IndexEnum::INDEX_GPU_HNSW_SQ, VecType::VECTOR_FLOAT16},
{IndexEnum::INDEX_GPU_HNSW_SQ, VecType::VECTOR_BFLOAT16},
{IndexEnum::INDEX_GPU_HNSW_SQ, VecType::VECTOR_INT8},

// hnsw
{IndexEnum::INDEX_HNSW, VecType::VECTOR_FLOAT},
Expand Down
Loading
Loading