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

Move faiss_mr from raft #5281

Merged
merged 7 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions ci/checks/copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
]
FILES_TO_EXCLUDE = [
re.compile(r"cpp/src/tsne/cannylab/bh\.cu"),
re.compile(r"cpp/src/hdbscan/detail/faiss_mr\.hpp"),
]

# this will break starting at year 10000, which is probably OK :)
Expand Down
2 changes: 2 additions & 0 deletions conda/recipes/libcuml/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ requirements:
- libraft-headers ={{ minor_version }}
- libraft-nn ={{ minor_version }}
- treelite {{ treelite_version }}
- libfaiss>=1.7.1
- faiss-proc=*=cuda

outputs:
- name: libcuml
Expand Down
7 changes: 7 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ option(CUML_USE_FAISS_STATIC "Build and statically link the FAISS library for ne
option(CUML_USE_TREELITE_STATIC "Build and statically link the treelite library" OFF)
option(CUML_EXPORT_TREELITE_LINKAGE "Whether to publicly or privately link treelite to libcuml++" OFF)
option(CUML_USE_CUMLPRIMS_MG_STATIC "Build and statically link the cumlprims_mg library" OFF)
option(CUML_ENABLE_NN_DEPENDENCIES "Whether to enable FAISS dependency" ON)

# The options below allow incorporating libcuml into another build process
# without installing all its components. This is useful if total file size is
# at a premium and we do not expect other consumers to use any APIs of the
# dependency except those that are directly linked to by the dependent library.
option(CUML_EXCLUDE_FAISS_FROM_ALL "Exclude FAISS targets from RAFT's 'all' target" ON)
option(CUML_EXCLUDE_RAFT_FROM_ALL "Exclude RAFT targets from cuML's 'all' target" OFF)
option(CUML_EXCLUDE_TREELITE_FROM_ALL "Exclude Treelite targets from cuML's 'all' target" OFF)
option(CUML_EXCLUDE_CUMLPRIMS_MG_FROM_ALL "Exclude cumlprims_mg targets from cuML's 'all' target" OFF)
Expand Down Expand Up @@ -220,6 +223,10 @@ endif()

include(cmake/thirdparty/get_raft.cmake)

if(CUML_USE_RAFT_NN)
include(cmake/thirdparty/get_faiss.cmake)
endif()

if(LINK_TREELITE)
include(cmake/thirdparty/get_treelite.cmake)
endif()
Expand Down
89 changes: 89 additions & 0 deletions cpp/cmake/thirdparty/get_faiss.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#=============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

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

if(CUML_USE_RAFT_NN)
rapids_find_generate_module(faiss
HEADER_NAMES faiss/IndexFlat.h
LIBRARY_NAMES faiss
)

set(BUILD_SHARED_LIBS ON)
if (PKG_BUILD_STATIC_LIBS)
set(BUILD_SHARED_LIBS OFF)
set(CPM_DOWNLOAD_faiss ON)
endif()

rapids_cpm_find(faiss ${PKG_VERSION}
GLOBAL_TARGETS faiss::faiss
CPM_ARGS
GIT_REPOSITORY ${PKG_REPOSITORY}
GIT_TAG ${PKG_PINNED_TAG}
EXCLUDE_FROM_ALL ${PKG_EXCLUDE_FROM_ALL}
OPTIONS
"FAISS_ENABLE_PYTHON OFF"
"CUDAToolkit_ROOT ${CUDAToolkit_LIBRARY_DIR}"
"FAISS_ENABLE_GPU ON"
"BUILD_TESTING OFF"
"CMAKE_MESSAGE_LOG_LEVEL VERBOSE"
"FAISS_USE_CUDA_TOOLKIT_STATIC ${CUDA_STATIC_RUNTIME}"
)

if(TARGET faiss AND NOT TARGET faiss::faiss)
add_library(faiss::faiss ALIAS faiss)
endif()

if(faiss_ADDED)
rapids_export(BUILD faiss
EXPORT_SET faiss-targets
GLOBAL_TARGETS faiss
NAMESPACE faiss::)
endif()
endif()

# We generate the faiss-config files when we built faiss locally, so always do `find_dependency`
rapids_export_package(BUILD OpenMP cuml-exports) # faiss uses openMP but doesn't export a need for it
rapids_export_package(BUILD faiss cuml-exports GLOBAL_TARGETS faiss::faiss faiss)
rapids_export_package(INSTALL faiss cuml-exports GLOBAL_TARGETS faiss::faiss faiss)

# 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}]=] cuml-exports)
endfunction()

if(NOT CUML_FAISS_GIT_TAG)
# TODO: Remove this once faiss supports FAISS_USE_CUDA_TOOLKIT_STATIC
# (https://github.com/facebookresearch/faiss/pull/2446)
set(CUML_FAISS_GIT_TAG fea/statically-link-ctk-v1.7.0)
# set(RAFT_FAISS_GIT_TAG bde7c0027191f29c9dadafe4f6e68ca0ee31fb30)
endif()

if(NOT CUML_FAISS_GIT_REPOSITORY)
# TODO: Remove this once faiss supports FAISS_USE_CUDA_TOOLKIT_STATIC
# (https://github.com/facebookresearch/faiss/pull/2446)
set(CUML_FAISS_GIT_REPOSITORY https://github.com/trxcllnt/faiss.git)
# set(RAFT_FAISS_GIT_REPOSITORY https://github.com/facebookresearch/faiss.git)
endif()

find_and_configure_faiss(VERSION 1.7.0
REPOSITORY ${CUML_FAISS_GIT_REPOSITORY}
PINNED_TAG ${CUML_FAISS_GIT_TAG}
BUILD_STATIC_LIBS ${CUML_USE_FAISS_STATIC}
EXCLUDE_FROM_ALL ${CUML_EXCLUDE_FAISS_FROM_ALL})
3 changes: 2 additions & 1 deletion cpp/cmake/thirdparty/get_raft.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021-2022, NVIDIA CORPORATION.
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,6 +77,7 @@ function(find_and_configure_raft)
"RAFT_COMPILE_NN_LIBRARY ${PKG_USE_RAFT_NN}"
"RAFT_COMPILE_DIST_LIBRARY ${PKG_USE_RAFT_DIST}"
"RAFT_USE_FAISS_STATIC ${PKG_USE_FAISS_STATIC}"
"RAFT_ENABLE_NN_DEPENDENCIES NO"
)

if(raft_ADDED)
Expand Down
Loading