Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b68d63e
Begin refactoring RAFT CMake configuration
wphicks Jul 21, 2023
10093d3
Correct RAFT CMake configuration
wphicks Jul 21, 2023
77a4971
Conditionally link to RAFT
wphicks Jul 26, 2023
a1aa366
Add configuration structs for RAFT indexes
wphicks Jul 26, 2023
bcef4c1
Add IVF index headers
wphicks Jul 31, 2023
2ebcf93
Provide initial update of tiered RAFT index
wphicks Aug 4, 2023
44d6b15
Update style
wphicks Aug 4, 2023
418ecaa
Merge branch 'main' into fea-raft_integration
wphicks Aug 7, 2023
1ed0cc9
Merge branch 'main' into fea-raft_integration
lowener Oct 9, 2023
4d66fe8
Rename ivf, add factory
lowener Oct 10, 2023
dbe8bea
Fix add and searches
lowener Oct 13, 2023
1d62824
Add size computation of tiered index
lowener Oct 18, 2023
32ce6cc
Update tiered index
lowener Oct 19, 2023
f3cd7b1
Add CUDA_ARCHITECTURE for half type
lowener Oct 20, 2023
28765de
Add Tiered index update and test
lowener Nov 2, 2023
54b895c
Separate cuda code and flat/pq
lowener Nov 8, 2023
1f99e55
Rework IVF, add stream manager, interface, benchmark
lowener Nov 14, 2023
6bab5e3
Update Tiered vector ingestion
lowener Nov 20, 2023
d072d3a
Update Tiered index. Add vector deletion code
lowener Nov 21, 2023
cfa190b
Add search bitset filter
lowener Nov 23, 2023
1726318
Add USE_CUDA guardrails for compilation
lowener Nov 24, 2023
8ba3767
Fix style
lowener Nov 24, 2023
2071218
Remaining USE_CUDA guards
lowener Nov 24, 2023
b735b20
Fix thread pool benchmark
lowener Dec 5, 2023
0790982
USE_CUDA fix
lowener Dec 5, 2023
4c90248
Fix compilation
lowener Dec 7, 2023
7805aa1
Add ivfpq bench
lowener Dec 22, 2023
f8c02ef
Add test for Cosine and IP
lowener Jan 8, 2024
45c510c
Update src/VecSim/algorithms/raft_ivf/ivf_tiered.h
lowener Apr 2, 2024
21a7d20
Separate index Size
lowener Jun 3, 2024
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
29 changes: 27 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
cmake_minimum_required(VERSION 3.10)
option(USE_CUDA "Build Cuda code" OFF)
if(USE_CUDA)
cmake_minimum_required(VERSION 3.26.4 FATAL_ERROR)
else()
cmake_minimum_required(VERSION 3.10)
endif()
cmake_policy(SET CMP0077 NEW)

set(CMAKE_CXX_STANDARD 20)
Expand All @@ -24,10 +29,30 @@ include(cmake/san.cmake)
# ----------------------------------------------------------------------------------------------
project(VectorSimilarity)

if (USE_CUDA)
# List of architectures to generate device code
set(CMAKE_CUDA_ARCHITECTURES "native")
# Enable CUDA compilation for this project
enable_language(CUDA)
# Add definition for conditional compilation of CUDA components
add_definitions(-DUSE_CUDA)
# Perform all RAFT-specific CMake setup
include(cmake/raft.cmake)
# Required flags for compiling RAFT
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda --expt-relaxed-constexpr")
set(CMAKE_CUDA_FLAGS_RELEASE "-O3")
set(CMAKE_CUDA_FLAGS_DEBUG "-g")
set(CMAKE_CUDA_STANDARD 17)
if(${CUDAToolkit_VERSION_MAJOR} GREATER 10)
# cuda11 support --threads for compile some large .cu more efficient
add_compile_options($<$<COMPILE_LANGUAGE:CUDA>:--threads=4>)
endif()
endif()

# Only do these if this is the main project, and not if it is included through add_subdirectory
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -fPIC ${CLANG_SAN_FLAGS} ${LLVM_CXX_FLAGS} ${COV_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -fPIC -pthread ${CLANG_SAN_FLAGS} ${LLVM_CXX_FLAGS} ${COV_CXX_FLAGS} -lrt")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${LLVM_LD_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${LLVM_LD_FLAGS}")

Expand Down
4 changes: 2 additions & 2 deletions check-format.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
CLANG_FMT_SRCS=$(find ./src/ \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hh' -o -name '*.hpp' \))
CLANG_FMT_TESTS="$(find ./tests/ -type d \( -path ./tests/unit/build \) -prune -false -o \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hh' -o -name '*.hpp' \))"
CLANG_FMT_SRCS=$(find ./src/ \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hh' -o -name '*.hpp' -o -name '*.cuh' -o -name '*.cu' \))
CLANG_FMT_TESTS="$(find ./tests/ -type d \( -path ./tests/unit/build \) -prune -false -o \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hh' -o -name '*.hpp' -o -name '*.cuh' -o -name '*.cu' \))"

E=0
for filename in $CLANG_FMT_SRCS $CLANG_FMT_TESTS; do
Expand Down
81 changes: 81 additions & 0 deletions cmake/raft.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
if(USE_CUDA)
# Set which version of RAPIDS to use
set(RAPIDS_VERSION 23.12)
# Set which version of RAFT to use (defined separately for testing
# minimal dependency changes if necessary)
set(RAFT_VERSION "${RAPIDS_VERSION}")
set(RAFT_FORK "rapidsai")
set(RAFT_PINNED_TAG "branch-${RAPIDS_VERSION}")

# Download CMake file for bootstrapping RAPIDS-CMake, a utility that
# simplifies handling of complex RAPIDS dependencies
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/RAPIDS.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-${RAPIDS_VERSION}/RAPIDS.cmake
${CMAKE_CURRENT_BINARY_DIR}/RAPIDS.cmake)
endif()
include(${CMAKE_CURRENT_BINARY_DIR}/RAPIDS.cmake)

# General tool for orchestrating RAPIDS dependencies
include(rapids-cmake)
# CPM helper functions with dependency tracking
include(rapids-cpm)
rapids_cpm_init()
# Common CMake CUDA logic
include(rapids-cuda)
# Include required dependencies in Project-Config.cmake modules
# include(rapids-export) TODO(wphicks)
# Functions to find system dependencies with dependency tracking
include(rapids-find)

# Correctly handle supported CUDA architectures
# (From rapids-cuda)
rapids_cuda_init_architectures(VectorSimilarity)

# Find system CUDA toolkit
rapids_find_package(CUDAToolkit REQUIRED)

set(RAFT_VERSION "${RAPIDS_VERSION}")
set(RAFT_FORK "rapidsai")
set(RAFT_PINNED_TAG "branch-${RAPIDS_VERSION}")

function(find_and_configure_raft)
set(oneValueArgs VERSION FORK PINNED_TAG COMPILE_LIBRARY)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

set(RAFT_COMPONENTS "")
if(PKG_COMPILE_LIBRARY)
string(APPEND RAFT_COMPONENTS " compiled")
endif()
# Invoke CPM find_package()
# (From rapids-cpm)
rapids_cpm_find(raft ${PKG_VERSION}
GLOBAL_TARGETS raft::raft
BUILD_EXPORT_SET VectorSimilarity-exports
INSTALL_EXPORT_SET VectorSimilarity-exports
COMPONENTS ${RAFT_COMPONENTS}
CPM_ARGS
GIT_REPOSITORY https://github.com/${PKG_FORK}/raft.git
GIT_TAG ${PKG_PINNED_TAG}
SOURCE_SUBDIR cpp
OPTIONS
"BUILD_TESTS OFF"
"BUILD_BENCH OFF"
"RAFT_COMPILE_LIBRARY ${PKG_COMPILE_LIBRARY}"
)
if(raft_ADDED)
message(VERBOSE "VectorSimilarity: Using RAFT located in ${raft_SOURCE_DIR}")
else()
message(VERBOSE "VectorSimilarity: Using RAFT located in ${raft_DIR}")
endif()
endfunction()

# Change pinned tag here to test a commit in CI
# To use a different RAFT locally, set the CMake variable
# CPM_raft_SOURCE=/path/to/local/raft
find_and_configure_raft(VERSION ${RAFT_VERSION}.00
FORK ${RAFT_FORK}
PINNED_TAG ${RAFT_PINNED_TAG}
COMPILE_LIBRARY OFF
)
endif()
16 changes: 14 additions & 2 deletions src/VecSim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ add_library(VectorSimilarity ${VECSIM_LIBTYPE}
index_factories/hnsw_factory.cpp
index_factories/tiered_factory.cpp
index_factories/index_factory.cpp
$<$<BOOL:${USE_CUDA}>:index_factories/raft_ivf_factory.cu>
$<$<BOOL:${USE_CUDA}>:index_factories/raft_ivf_tiered_factory.cpp>
algorithms/hnsw/visited_nodes_handler.cpp
vec_sim.cpp
vec_sim_interface.cpp
Expand All @@ -31,9 +33,19 @@ add_library(VectorSimilarity ${VECSIM_LIBTYPE}
${HEADER_LIST}
)

target_link_libraries(VectorSimilarity VectorSimilaritySpaces)

if(VECSIM_BUILD_TESTS)
add_library(VectorSimilaritySerializer utils/serializer.cpp)
target_link_libraries(VectorSimilarity VectorSimilaritySerializer)
endif()

target_link_libraries(VectorSimilarity
PUBLIC
VectorSimilaritySpaces
$<$<BOOL:${VECSIM_BUILD_TESTS}>:VectorSimilaritySerializer>
PRIVATE
$<$<BOOL:${USE_CUDA}>:raft::raft>
$<$<BOOL:${USE_CUDA}>:CUDA::cusolver>
$<$<BOOL:${USE_CUDA}>:CUDA::cublas>
$<$<BOOL:${USE_CUDA}>:CUDA::curand>
$<$<BOOL:${USE_CUDA}>:CUDA::cusparse>
)
2 changes: 2 additions & 0 deletions src/VecSim/algorithms/brute_force/brute_force.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class BruteForceIndex : public VecSimIndexAbstract<DistType> {
public:
BruteForceIndex(const BFParams *params, const AbstractIndexInitParams &abstractInitParams);

virtual void clear() = 0;
size_t indexSize() const override;
size_t indexCapacity() const override;
vecsim_stl::vector<DistType> computeBlockScores(const DataBlock &block, const void *queryBlob,
Expand All @@ -54,6 +55,7 @@ class BruteForceIndex : public VecSimIndexAbstract<DistType> {
VecSimQueryParams *queryParams) const override;
bool preferAdHocSearch(size_t subsetSize, size_t k, bool initial_check) const override;
inline labelType getVectorLabel(idType id) const { return idToLabelMapping.at(id); }
inline vecsim_stl::vector<labelType> getLabels() const { return idToLabelMapping; }

inline const vecsim_stl::vector<DataBlock> &getVectorBlocks() const { return vectorBlocks; }
inline const labelType getLabelByInternalId(idType internal_id) const {
Expand Down
8 changes: 8 additions & 0 deletions src/VecSim/algorithms/brute_force/brute_force_multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class BruteForceIndex_Multi : public BruteForceIndex<DataType, DistType> {

~BruteForceIndex_Multi() {}

void clear() override {
this->labelToIdsLookup.clear();
this->idToLabelMapping.clear();
this->idToLabelMapping.shrink_to_fit();
this->vectorBlocks.clear();
this->vectorBlocks.shrink_to_fit();
this->count = idType{};
Copy link
Collaborator

Choose a reason for hiding this comment

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

this->count = 0 ?

}
int addVector(const void *vector_data, labelType label, void *auxiliaryCtx = nullptr) override;
int deleteVector(labelType labelType) override;
int deleteVectorById(labelType label, idType id) override;
Expand Down
8 changes: 8 additions & 0 deletions src/VecSim/algorithms/brute_force/brute_force_single.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class BruteForceIndex_Single : public BruteForceIndex<DataType, DistType> {
const AbstractIndexInitParams &abstractInitParams);
~BruteForceIndex_Single();

void clear() override {
this->labelToIdLookup.clear();
this->idToLabelMapping.clear();
this->idToLabelMapping.shrink_to_fit();
this->vectorBlocks.clear();
this->vectorBlocks.shrink_to_fit();
this->count = idType{};
Copy link
Collaborator

Choose a reason for hiding this comment

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

this->count = 0 ?

}
int addVector(const void *vector_data, labelType label, void *auxiliaryCtx = nullptr) override;
int deleteVector(labelType label) override;
int deleteVectorById(labelType label, idType id) override;
Expand Down
Loading