Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEA] Add option to build faiss shared libs #345

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
07644ec
add option to build faiss shared libs
trxcllnt Sep 30, 2021
f3e1f09
add FAISS::FAISS to the list of global targets
trxcllnt Sep 30, 2021
e038644
update cuco
trxcllnt Sep 30, 2021
3fa9c94
create a faissTargets export-set
trxcllnt Sep 30, 2021
fc132ef
Merge branch 'fix/build-shared-faiss' into fix/node-rapids-21.10
trxcllnt Sep 30, 2021
85572d0
add faiss to raft-exports
trxcllnt Sep 30, 2021
b19a4b6
revert
trxcllnt Sep 30, 2021
6c74570
Merge branch 'fix/build-shared-faiss' into fix/node-rapids-21.10
trxcllnt Sep 30, 2021
14785ff
create a faiss-exports export-set
trxcllnt Sep 30, 2021
25b62e6
mark faiss to be found as part of resolving raft-exports dependencies
trxcllnt Sep 30, 2021
76edf36
create faiss-exports export set
trxcllnt Sep 30, 2021
92851b3
create faiss-exports export set
trxcllnt Sep 30, 2021
8e266ef
export faiss::faiss target to build export set
trxcllnt Oct 5, 2021
9d535fb
Merge branch 'fix/node-rapids-21.10' into fix/build-shared-faiss
trxcllnt Oct 5, 2021
7c990b1
Merge branch 'branch-21.10' of github.com:rapidsai/raft into fix/buil…
trxcllnt Oct 5, 2021
3a20c64
Merge branch 'branch-21.12' of github.com:rapidsai/raft into fix/buil…
trxcllnt Oct 5, 2021
83e3aa6
fix faiss GLOBAL_TARGETS
trxcllnt Oct 6, 2021
2773edc
update rapids-cmake version
trxcllnt Oct 6, 2021
3ff1c4d
fix naming for generated Findfaiss.cmake module so we find conda-inst…
trxcllnt Oct 6, 2021
cbb6f2d
ensure faiss::faiss target is available in build and install export sets
trxcllnt Oct 7, 2021
713a872
add gtest to raft-exports, remove dead code
trxcllnt Oct 7, 2021
ceb4d8b
update CMake faiss variable name
trxcllnt Oct 12, 2021
1d3ffab
make -v set cmake --log-level=VERBOSE
trxcllnt Oct 12, 2021
b48e393
update cuco hash to the commit that uses rapids-cmake v21.12
trxcllnt Oct 13, 2021
dc076ae
Merge branch 'branch-21.12' of github.com:rapidsai/raft into fix/buil…
trxcllnt Oct 14, 2021
e824384
Merge branch 'branch-21.12' of github.com:rapidsai/raft into fix/buil…
trxcllnt Nov 10, 2021
078e33c
Merge branch 'branch-21.12' of github.com:rapidsai/raft into fix/buil…
trxcllnt Nov 11, 2021
30dafb6
Merge branch 'branch-22.02' of github.com:rapidsai/raft into fix/buil…
trxcllnt Nov 18, 2021
aedc6d7
update cuco version
trxcllnt Nov 19, 2021
245ea3d
Merge branch 'branch-22.02' of github.com:rapidsai/raft into fix/buil…
trxcllnt Nov 20, 2021
2b99f1a
Merge branch 'branch-22.02' of github.com:rapidsai/raft into fix/buil…
trxcllnt Dec 1, 2021
bb4b7c7
move faiss into separate raft-faiss-exports export set, only include …
trxcllnt Dec 1, 2021
e798ab1
check for faiss in raft_FIND_COMPONENTS for build side export set too
trxcllnt Dec 2, 2021
2d5898d
pass EXCLUDE_FROM_ALL in get_faiss.cmake
trxcllnt Dec 2, 2021
2cb3c3a
enable CUDA language in code_string
trxcllnt Dec 2, 2021
23912f5
pass TRUE
trxcllnt Dec 2, 2021
fc306f6
drop CUDA from the list of global languages
trxcllnt Dec 2, 2021
61c263a
link raft to faiss if faiss component is requested
trxcllnt Dec 2, 2021
41bd51b
link raft to faiss if faiss component requested
trxcllnt Dec 8, 2021
4a95f2e
Merge branch 'branch-22.02' of github.com:rapidsai/raft into fix/buil…
trxcllnt Dec 15, 2021
082eea9
Merge branch 'branch-22.02' of github.com:rapidsai/raft into fix/buil…
trxcllnt Dec 16, 2021
ce8a005
fix FAISS::FAISS -> faiss::faiss
trxcllnt Dec 16, 2021
fb7ec4c
Merge branch 'branch-22.02' of github.com:rapidsai/raft into fix/buil…
trxcllnt Jan 6, 2022
99c009b
Merge branch 'fix/build-shared-faiss' of github.com:trxcllnt/raft int…
trxcllnt Jan 6, 2022
6cd76c7
remove LANGUAGES CUDA
trxcllnt Jan 7, 2022
745dd84
Merge branch 'branch-22.02' of github.com:rapidsai/raft into fix/buil…
trxcllnt Jan 11, 2022
c8e28fe
Merge branch 'branch-22.02' of github.com:rapidsai/raft into fix/buil…
trxcllnt Jan 13, 2022
31e7daf
Merge branch 'branch-22.02' of github.com:rapidsai/raft into fix/buil…
trxcllnt Jan 13, 2022
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
6 changes: 4 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ PYTHON_DEPS_CLONE=${REPODIR}/python/external_repositories
BUILD_DIRS="${CPP_RAFT_BUILD_DIR} ${PY_RAFT_BUILD_DIR} ${PYTHON_DEPS_CLONE}"

# Set defaults for vars modified by flags to this script
CMAKE_LOG_LEVEL=""
VERBOSE_FLAG=""
BUILD_ALL_GPU_ARCH=0
BUILD_GTEST=OFF
Expand Down Expand Up @@ -83,6 +84,7 @@ fi
# Process flags
if hasArg -v; then
VERBOSE_FLAG=-v
CMAKE_LOG_LEVEL="--log-level=VERBOSE"
set -x
fi
if hasArg -g; then
Expand Down Expand Up @@ -141,13 +143,13 @@ if (( ${NUMARGS} == 0 )) || hasArg cppraft; then
echo "Building for *ALL* supported GPU architectures..."
fi

cmake -S ${REPODIR}/cpp -B ${CPP_RAFT_BUILD_DIR} \
cmake -S ${REPODIR}/cpp -B ${CPP_RAFT_BUILD_DIR} ${CMAKE_LOG_LEVEL} \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DCMAKE_CUDA_ARCHITECTURES=${RAFT_CMAKE_CUDA_ARCHITECTURES} \
-DNVTX=${NVTX} \
-DDISABLE_DEPRECATION_WARNING=${BUILD_DISABLE_DEPRECATION_WARNING} \
-DBUILD_GTEST=${BUILD_GTEST} \
-DBUILD_STATIC_FAISS=${BUILD_STATIC_FAISS}
-DRAFT_USE_FAISS_STATIC=${BUILD_STATIC_FAISS}


# Run all c++ targets at once
Expand Down
23 changes: 19 additions & 4 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================

cmake_minimum_required(VERSION 3.20.1 FATAL_ERROR)
file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-21.10/RAPIDS.cmake
file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-21.12/RAPIDS.cmake
${CMAKE_BINARY_DIR}/RAPIDS.cmake)
include(${CMAKE_BINARY_DIR}/RAPIDS.cmake)
include(rapids-cmake)
Expand Down Expand Up @@ -49,6 +49,8 @@ option(DISABLE_DEPRECATION_WARNINGS "Disable depreaction warnings " ON)
option(DISABLE_OPENMP "Disable OpenMP" OFF)
option(NVTX "Enable nvtx markers" OFF)

option(RAFT_USE_FAISS_STATIC "Build and statically link the FAISS library for nearest neighbors search on GPU" ON)

message(VERBOSE "RAFT: Build RAFT unit-tests: ${BUILD_TESTS}")
message(VERBOSE "RAFT: Enable detection of conda environment for dependencies: ${DETECT_CONDA_ENV}")
message(VERBOSE "RAFT: Disable depreaction warnings " ${DISABLE_DEPRECATION_WARNINGS})
Expand Down Expand Up @@ -100,13 +102,14 @@ endif()
# add third party dependencies using CPM
rapids_cpm_init()

include(cmake/thirdparty/get_thrust.cmake)
include(cmake/thirdparty/get_rmm.cmake)
include(cmake/thirdparty/get_cuco.cmake)
# CPMFindPackage(faiss) so it's available for raft consumers to use
include(cmake/thirdparty/get_faiss.cmake)
# CPMFindPackage(GTest) so it's available for raft consumers to use
include(cmake/thirdparty/get_gtest.cmake)

if(BUILD_TESTS)
include(cmake/thirdparty/get_faiss.cmake)
include(cmake/thirdparty/get_gtest.cmake)
include(cmake/thirdparty/get_nccl.cmake)
include(cmake/thirdparty/get_ucx.cmake)
endif()
Expand Down Expand Up @@ -161,11 +164,22 @@ and common functions for the analytics components of RAPIDS.

]=])

set(raft_code_string
[=[
if(TARGET faiss AND (NOT TARGET faiss::faiss))
add_library(faiss::faiss ALIAS faiss)
elseif(TARGET faiss::faiss AND (NOT TARGET faiss))
add_library(faiss ALIAS faiss::faiss)
endif()
]=]
)

rapids_export(INSTALL raft
EXPORT_SET raft-exports
GLOBAL_TARGETS raft # since we can't hook into EXPORT SETS
NAMESPACE raft::
DOCUMENTATION doc_string
FINAL_CODE_BLOCK raft_code_string
)

##############################################################################
Expand All @@ -177,6 +191,7 @@ rapids_export(BUILD raft
LANGUAGES CUDA
DOCUMENTATION doc_string
NAMESPACE raft::
FINAL_CODE_BLOCK raft_code_string
)

##############################################################################
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmake/thirdparty/get_cuco.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function(find_and_configure_cuco VERSION)
INSTALL_EXPORT_SET raft-exports
CPM_ARGS
GIT_REPOSITORY https://github.com/NVIDIA/cuCollections.git
GIT_TAG 729857a5698a0e8d8f812e0464f65f37854ae17b
GIT_TAG 23c9a1fdbc06c29687c54016f6bb0b503535032c
OPTIONS "BUILD_TESTS OFF"
"BUILD_BENCHMARKS OFF"
"BUILD_EXAMPLES OFF"
Expand Down
33 changes: 24 additions & 9 deletions cpp/cmake/thirdparty/get_faiss.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,54 @@
#=============================================================================

function(find_and_configure_faiss)
set(oneValueArgs VERSION PINNED_TAG)
set(oneValueArgs VERSION PINNED_TAG BUILD_STATIC_LIBS)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

rapids_find_generate_module(FAISS
rapids_find_generate_module(faiss
HEADER_NAMES faiss/IndexFlat.h
LIBRARY_NAMES faiss
)

rapids_cpm_find(FAISS ${PKG_VERSION}
GLOBAL_TARGETS faiss
set(BUILD_SHARED_LIBS OFF)
if (NOT BUILD_STATIC_LIBS)
set(BUILD_SHARED_LIBS ON)
endif()

rapids_cpm_find(faiss ${PKG_VERSION}
GLOBAL_TARGETS faiss::faiss
INSTALL_EXPORT_SET raft-exports
CPM_ARGS
GIT_REPOSITORY https://github.com/facebookresearch/faiss.git
GIT_TAG ${PKG_PINNED_TAG}
OPTIONS
"FAISS_ENABLE_PYTHON OFF"
"BUILD_SHARED_LIBS OFF"
"CUDAToolkit_ROOT ${CUDAToolkit_LIBRARY_DIR}"
"FAISS_ENABLE_GPU ON"
"BUILD_TESTING OFF"
"CMAKE_MESSAGE_LOG_LEVEL VERBOSE"
)

if(FAISS_ADDED)
set(FAISS_GPU_HEADERS ${FAISS_SOURCE_DIR} PARENT_SCOPE)
if(TARGET faiss AND NOT TARGET faiss::faiss)
add_library(faiss::faiss ALIAS faiss)
endif()

if(TARGET faiss AND NOT TARGET FAISS::FAISS)
add_library(FAISS::FAISS ALIAS faiss)
if(faiss_ADDED)
rapids_export(BUILD faiss
trxcllnt marked this conversation as resolved.
Show resolved Hide resolved
EXPORT_SET faiss-targets
GLOBAL_TARGETS faiss
trxcllnt marked this conversation as resolved.
Show resolved Hide resolved
NAMESPACE faiss::)
endif()

trxcllnt marked this conversation as resolved.
Show resolved Hide resolved
# We generate the faiss-config files when we built faiss locally, so always do `find_dependency`
rapids_export_package(BUILD faiss raft-exports)

# Tell cmake where it can find the generated faiss-config.cmake we wrote.
include("${rapids-cmake-dir}/export/find_package_root.cmake")
rapids_export_find_package_root(BUILD faiss [=[${CMAKE_CURRENT_LIST_DIR}]=] raft-exports)
endfunction()

find_and_configure_faiss(VERSION 1.7.0
PINNED_TAG bde7c0027191f29c9dadafe4f6e68ca0ee31fb30
BUILD_STATIC_LIBS ${RAFT_USE_FAISS_STATIC}
)
14 changes: 13 additions & 1 deletion cpp/cmake/thirdparty/get_gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@
function(find_and_configure_gtest )

include(${rapids-cmake-dir}/cpm/gtest.cmake)
rapids_cpm_gtest()
rapids_cpm_gtest(BUILD_EXPORT_SET raft-exports
INSTALL_EXPORT_SET raft-exports)

if(GTest_ADDED)
rapids_export(BUILD GTest
VERSION ${GTest_VERSION}
EXPORT_SET GTestTargets
GLOBAL_TARGETS gtest gmock gtest_main gmock_main
NAMESPACE GTest::)

include("${rapids-cmake-dir}/export/find_package_root.cmake")
rapids_export_find_package_root(BUILD GTest [=[${CMAKE_CURRENT_LIST_DIR}]=] raft-exports)
endif()

endfunction()

Expand Down
27 changes: 0 additions & 27 deletions cpp/cmake/thirdparty/get_thrust.cmake

This file was deleted.

12 changes: 3 additions & 9 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,14 @@ target_compile_options(test_raft
target_include_directories(test_raft
PUBLIC "$<BUILD_INTERFACE:${RAFT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${RAFT_SOURCE_DIR}/test>"
"${FAISS_GPU_HEADERS}"
)


target_link_libraries(test_raft
PRIVATE
CUDA::cublas
CUDA::curand
CUDA::cusolver
CUDA::cudart
CUDA::cusparse
rmm::rmm
cuco::cuco
FAISS::FAISS
raft::raft
NCCL::NCCL
faiss::faiss
GTest::gtest
GTest::gtest_main
Threads::Threads
Expand Down