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 all 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 @@ -43,6 +43,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 @@ -84,6 +85,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 @@ -147,13 +149,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
46 changes: 39 additions & 7 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
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,15 +102,15 @@ endif()
# add third party dependencies using CPM
rapids_cpm_init()

# thrust and libcudacxx need to be before cuco!
include(cmake/thirdparty/get_thrust.cmake)
include(cmake/thirdparty/get_rmm.cmake)
include(cmake/thirdparty/get_libcudacxx.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 @@ -152,7 +154,7 @@ set(RAFT_LINK_LIBRARIES

target_link_libraries(raft INTERFACE ${RAFT_LINK_LIBRARIES})
target_link_libraries(raft_distance PUBLIC ${RAFT_LINK_LIBRARIES})
target_link_libraries(raft_nn PUBLIC ${RAFT_LINK_LIBRARIES} FAISS::FAISS)
target_link_libraries(raft_nn PUBLIC ${RAFT_LINK_LIBRARIES} faiss::faiss)

set(RAFT_COMPILE_DEFINITIONS
$<$<BOOL:${NVTX}>:NVTX_ENABLED>
Expand Down Expand Up @@ -198,6 +200,12 @@ install(DIRECTORY include/raft/
install(FILES include/raft.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/raft)

include("${rapids-cmake-dir}/export/write_dependencies.cmake")
rapids_export_write_dependencies(
INSTALL raft-faiss-exports
"${PROJECT_BINARY_DIR}/rapids-cmake/raft/export/raft-faiss-dependencies.cmake"
)

##############################################################################
# - install export -----------------------------------------------------------
set(doc_string
Expand All @@ -209,11 +217,31 @@ mathematical computational primitives, and utilities that accelerate
building analytics and data science algorithms in the RAPIDS ecosystem.
]=])

rapids_export(INSTALL raft
set(code_string
[=[
if(faiss IN_LIST raft_FIND_COMPONENTS)
enable_language(CUDA)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/raft-faiss-dependencies.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/raft-faiss-dependencies.cmake")
endif()
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()
if(TARGET raft::raft)
target_link_libraries(raft::raft INTERFACE faiss::faiss)
endif()
endif()
]=]
)

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

##############################################################################
Expand All @@ -222,11 +250,15 @@ building analytics and data science algorithms in the RAPIDS ecosystem.
rapids_export(BUILD raft
EXPORT_SET raft-exports
GLOBAL_TARGETS raft raft_distance raft_nn# since we can't hook into EXPORT SETS
LANGUAGES CUDA
DOCUMENTATION doc_string
NAMESPACE raft::
FINAL_CODE_BLOCK code_string
)

rapids_export_write_dependencies(
BUILD raft-faiss-exports "${PROJECT_BINARY_DIR}/raft-faiss-dependencies.cmake"
)

##############################################################################
# - build test executable ----------------------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion cpp/cmake/thirdparty/get_cuco.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ function(find_and_configure_cuco VERSION)

endfunction()

find_and_configure_cuco(0.0.1)
# cuCollections doesn't have a version yet
find_and_configure_cuco(0.0)
38 changes: 27 additions & 11 deletions cpp/cmake/thirdparty/get_faiss.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,55 @@
#=============================================================================

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-faiss-exports
CPM_ARGS
GIT_REPOSITORY https://github.com/facebookresearch/faiss.git
GIT_TAG ${PKG_PINNED_TAG}
GIT_REPOSITORY https://github.com/facebookresearch/faiss.git
GIT_TAG ${PKG_PINNED_TAG}
EXCLUDE_FROM_ALL TRUE
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-faiss-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-faiss-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.

9 changes: 5 additions & 4 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ target_compile_options(test_raft

target_include_directories(test_raft
PUBLIC "$<BUILD_INTERFACE:${RAFT_SOURCE_DIR}/test>"
"${FAISS_GPU_HEADERS}"
)


target_link_libraries(test_raft
PRIVATE
raft # transitively links all CUDA libs, etc
raft_distance
raft_nn
raft::raft # transitively links all CUDA libs, etc
raft::raft_distance
raft::raft_nn
NCCL::NCCL
faiss::faiss
GTest::gtest
GTest::gtest_main
Threads::Threads
Expand Down