Skip to content

Commit

Permalink
Removing FAISS from build (#1340)
Browse files Browse the repository at this point in the history
This depends on #1202 so those changes are also included here. This should also not be merged until that PR is merged.

Authors:
  - Corey J. Nolet (https://github.com/cjnolet)
  - Ben Frederickson (https://github.com/benfred)

Approvers:
  - Ben Frederickson (https://github.com/benfred)
  - Vyas Ramasubramani (https://github.com/vyasr)
  - Ray Douglass (https://github.com/raydouglass)

URL: #1340
  • Loading branch information
cjnolet authored Mar 18, 2023
1 parent 2586f80 commit c4671ed
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 152 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ find_and_configure_raft(VERSION ${RAFT_VERSION}.00

Several CMake targets can be made available by adding components in the table below to the `RAFT_COMPONENTS` list above, separated by spaces. The `raft::raft` target will always be available. RAFT headers require, at a minimum, the CUDA toolkit libraries and RMM dependencies.

| Component | Target | Description | Base Dependencies |
| --- | --- | --- | --- |
| Component | Target | Description | Base Dependencies |
| --- | --- | --- |------------------------------------------------------------------|
| n/a | `raft::raft` | Full RAFT header library | CUDA toolkit library, RMM, Thrust (optional), NVTools (optional) |
| distance | `raft::distance` | Pre-compiled template specializations for raft::distance | raft::raft, cuCollections (optional) |
| nn | `raft::nn` | Pre-compiled template specializations for raft::neighbors | raft::raft, FAISS (optional) |
| distributed | `raft::distributed` | No specializations | raft::raft, UCX, NCCL |
| distance | `raft::distance` | Pre-compiled template specializations for raft::distance | raft::raft, cuCollections (optional) |
| nn | `raft::nn` | Pre-compiled template specializations for raft::neighbors | raft::raft |
| distributed | `raft::distributed` | No specializations | raft::raft, UCX, NCCL |

### Source

Expand Down
13 changes: 1 addition & 12 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ARGS=$*
# script, and that this script resides in the repo dir!
REPODIR=$(cd $(dirname $0); pwd)

VALIDARGS="clean libraft pylibraft raft-dask docs tests bench clean --uninstall -v -g -n --compile-libs --compile-nn --compile-dist --allgpuarch --no-nvtx --show_depr_warn -h --buildfaiss --minimal-deps"
VALIDARGS="clean libraft pylibraft raft-dask docs tests bench clean --uninstall -v -g -n --compile-libs --compile-nn --compile-dist --allgpuarch --no-nvtx --show_depr_warn -h --minimal-deps"
HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<tool>] [--limit-tests=<targets>] [--limit-bench=<targets>]
where <target> is:
clean - remove all existing build artifacts and configuration (start over)
Expand All @@ -45,7 +45,6 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
--limit-tests - semicolon-separated list of test executables to compile (e.g. NEIGHBORS_TEST;CLUSTER_TEST)
--limit-bench - semicolon-separated list of benchmark executables to compute (e.g. NEIGHBORS_BENCH;CLUSTER_BENCH)
--allgpuarch - build for all supported GPU architectures
--buildfaiss - build faiss statically into raft
--no-nvtx - disable nvtx (profiling markers), but allow enabling it in downstream projects
--show_depr_warn - show cmake deprecation warnings
--cmake-args=\\\"<args>\\\" - pass arbitrary list of CMake configuration options (escape all quotes in argument)
Expand All @@ -69,11 +68,9 @@ BUILD_ALL_GPU_ARCH=0
BUILD_TESTS=OFF
BUILD_TYPE=Release
BUILD_BENCH=OFF
BUILD_STATIC_FAISS=OFF
COMPILE_LIBRARIES=OFF
COMPILE_NN_LIBRARY=OFF
COMPILE_DIST_LIBRARY=OFF
ENABLE_NN_DEPENDENCIES=OFF
INSTALL_TARGET=install

TEST_TARGETS="CLUSTER_TEST;CORE_TEST;DISTANCE_TEST;LABEL_TEST;LINALG_TEST;MATRIX_TEST;RANDOM_TEST;SOLVERS_TEST;SPARSE_TEST;SPARSE_DIST_TEST;SPARSE_NEIGHBORS_TEST;NEIGHBORS_TEST;STATS_TEST;UTILS_TEST"
Expand Down Expand Up @@ -278,7 +275,6 @@ if hasArg --compile-libs || (( ${NUMARGS} == 0 )); then
fi

if hasArg --compile-nn || hasArg --compile-libs || (( ${NUMARGS} == 0 )); then
ENABLE_NN_DEPENDENCIES=ON
COMPILE_NN_LIBRARY=ON
CMAKE_TARGET="${CMAKE_TARGET};raft_nn_lib"
fi
Expand All @@ -299,7 +295,6 @@ if hasArg tests || (( ${NUMARGS} == 0 )); then
$CMAKE_TARGET == *"NEIGHBORS_TEST"* || \
$CMAKE_TARGET == *"STATS_TEST"* ]]; then
echo "-- Enabling nearest neighbors lib for gtests"
ENABLE_NN_DEPENDENCIES=ON
COMPILE_NN_LIBRARY=ON
fi

Expand All @@ -324,7 +319,6 @@ if hasArg bench || (( ${NUMARGS} == 0 )); then
if [[ $CMAKE_TARGET == *"CLUSTER_BENCH"* || \
$CMAKE_TARGET == *"NEIGHBORS_BENCH"* ]]; then
echo "-- Enabling nearest neighbors lib for benchmarks"
ENABLE_NN_DEPENDENCIES=ON
COMPILE_NN_LIBRARY=ON
fi

Expand All @@ -338,9 +332,6 @@ if hasArg bench || (( ${NUMARGS} == 0 )); then

fi

if hasArg --buildfaiss; then
BUILD_STATIC_FAISS=ON
fi
if hasArg --no-nvtx; then
NVTX=OFF
fi
Expand Down Expand Up @@ -402,15 +393,13 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || has
-DCMAKE_CUDA_ARCHITECTURES=${RAFT_CMAKE_CUDA_ARCHITECTURES} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DRAFT_COMPILE_LIBRARIES=${COMPILE_LIBRARIES} \
-DRAFT_ENABLE_NN_DEPENDENCIES=${ENABLE_NN_DEPENDENCIES} \
-DRAFT_NVTX=${NVTX} \
-DDISABLE_DEPRECATION_WARNINGS=${DISABLE_DEPRECATION_WARNINGS} \
-DBUILD_TESTS=${BUILD_TESTS} \
-DBUILD_BENCH=${BUILD_BENCH} \
-DCMAKE_MESSAGE_LOG_LEVEL=${CMAKE_LOG_LEVEL} \
-DRAFT_COMPILE_NN_LIBRARY=${COMPILE_NN_LIBRARY} \
-DRAFT_COMPILE_DIST_LIBRARY=${COMPILE_DIST_LIBRARY} \
-DRAFT_USE_FAISS_STATIC=${BUILD_STATIC_FAISS} \
-DRAFT_ENABLE_thrust_DEPENDENCY=${ENABLE_thrust_DEPENDENCY} \
${CACHE_ARGS} \
${EXTRA_CMAKE_ARGS}
Expand Down
2 changes: 0 additions & 2 deletions conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dependencies:
- dask>=2023.1.1
- distributed>=2023.1.1
- doxygen>=1.8.20
- faiss-proc=*=cuda
- gcc_linux-64=11.*
- graphviz
- ipython
Expand All @@ -34,7 +33,6 @@ dependencies:
- libcusolver=11.4.1.48
- libcusparse-dev=11.7.5.86
- libcusparse=11.7.5.86
- libfaiss>=1.7.1=cuda*
- ninja
- numpydoc
- pydata-sphinx-theme
Expand Down
3 changes: 0 additions & 3 deletions conda/recipes/libraft/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ nccl_version:
gtest_version:
- "=1.10.0"

libfaiss_version:
- "1.7.2 *_cuda"

# The CTK libraries below are missing from the conda-forge::cudatoolkit
# package. The "*_host_*" version specifiers correspond to `11.8` packages and the
# "*_run_*" version specifiers correspond to `11.x` packages.
Expand Down
4 changes: 0 additions & 4 deletions conda/recipes/libraft/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ outputs:
host:
- {{ pin_subpackage('libraft-headers', exact=True) }}
- cuda-profiler-api {{ cuda_profiler_api_host_version }}
- faiss-proc=*=cuda
- lapack
- libcublas {{ libcublas_host_version }}
- libcublas-dev {{ libcublas_host_version }}
Expand All @@ -140,10 +139,7 @@ outputs:
- libcusolver-dev {{ libcusolver_host_version }}
- libcusparse {{ libcusparse_host_version }}
- libcusparse-dev {{ libcusparse_host_version }}
- libfaiss {{ libfaiss_version }}
run:
- faiss-proc=*=cuda
- libfaiss {{ libfaiss_version }}
- {{ pin_subpackage('libraft-headers', exact=True) }}
about:
home: https://rapids.ai/
Expand Down
23 changes: 1 addition & 22 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ option(
option(RAFT_COMPILE_DIST_LIBRARY "Enable building raft distant shared library instantiations"
${RAFT_COMPILE_LIBRARIES}
)
option(RAFT_ENABLE_NN_DEPENDENCIES "Search for raft::nn dependencies like faiss"
${RAFT_COMPILE_NN_LIBRARY}
)

option(RAFT_ENABLE_thrust_DEPENDENCY "Enable Thrust dependency" ON)

Expand All @@ -89,17 +86,6 @@ if(BUILD_TESTS AND NOT RAFT_ENABLE_thrust_DEPENDENCY)
set(RAFT_ENABLE_thrust_DEPENDENCY ON)
endif()

option(RAFT_EXCLUDE_FAISS_FROM_ALL "Exclude FAISS targets from RAFT's 'all' target" ON)

include(CMakeDependentOption)
cmake_dependent_option(
RAFT_USE_FAISS_STATIC
"Build and statically link the FAISS library for nearest neighbors search on GPU"
ON
RAFT_COMPILE_LIBRARIES
OFF
)

message(VERBOSE "RAFT: Building optional components: ${raft_FIND_COMPONENTS}")
message(VERBOSE "RAFT: Build RAFT unit-tests: ${BUILD_TESTS}")
message(VERBOSE "RAFT: Building raft C++ benchmarks: ${BUILD_BENCH}")
Expand Down Expand Up @@ -183,7 +169,6 @@ rapids_cpm_init()
# thrust before rmm/cuco so we get the right version of thrust/cub
include(cmake/thirdparty/get_thrust.cmake)
include(cmake/thirdparty/get_rmm.cmake)
include(cmake/thirdparty/get_faiss.cmake)
include(cmake/thirdparty/get_cutlass.cmake)

if(RAFT_ENABLE_cuco_DEPENDENCY)
Expand Down Expand Up @@ -502,7 +487,7 @@ if(RAFT_COMPILE_NN_LIBRARY)

target_link_libraries(
raft_nn_lib
PUBLIC faiss::faiss raft::raft
PUBLIC raft::raft
PRIVATE nvidia::cutlass::cutlass
)
target_compile_options(
Expand Down Expand Up @@ -710,12 +695,6 @@ endif()

if(nn IN_LIST raft_FIND_COMPONENTS)
enable_language(CUDA)

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()
endif()
]=]
)
Expand Down
89 changes: 0 additions & 89 deletions cpp/cmake/thirdparty/get_faiss.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ dependencies:
- ucx-py=0.31.*
- ucx-proc=*=gpu
- rmm=23.04
- libfaiss>=1.7.1=cuda*
- faiss-proc=*=cuda
- dask-cuda=23.04
test_python:
common:
Expand Down
19 changes: 6 additions & 13 deletions docs/source/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ In addition to the libraries included with cudatoolkit 11.0+, there are some oth
- [cuCollections](https://github.com/NVIDIA/cuCollections) - Used in `raft::sparse::distance` API.
- [Libcu++](https://github.com/NVIDIA/libcudacxx) v1.7.0 - Used by cuCollections
- [CUTLASS](https://github.com/NVIDIA/cutlass) v2.9.1 - Used in `raft::distance` API.
- [FAISS](https://github.com/facebookresearch/faiss) v1.7.0 - Used in `raft::neighbors` API.
- [NCCL](https://github.com/NVIDIA/nccl) - Used in `raft::comms` API and needed to build `raft-dask`.
- [UCX](https://github.com/openucx/ucx) - Used in `raft::comms` API and needed to build `raft-dask`.
- [Googletest](https://github.com/google/googletest) - Needed to build tests
Expand All @@ -60,14 +59,14 @@ The recommended way to build and install RAFT is to use the `build.sh` script in

### Header-only C++

`build.sh` uses [rapids-cmake](https://github.com/rapidsai/rapids-cmake), which will automatically download any dependencies which are not already installed. It's important to note that while all the headers will be installed and available, some parts of the RAFT API depend on libraries like `FAISS`, which will need to be explicitly enabled in `build.sh`.
`build.sh` uses [rapids-cmake](https://github.com/rapidsai/rapids-cmake), which will automatically download any dependencies which are not already installed. It's important to note that while all the headers will be installed and available, some parts of the RAFT API depend on libraries like CUTLASS, which will need to be explicitly enabled in `build.sh`.

The following example will download the needed dependencies and install the RAFT headers into `$INSTALL_PREFIX/include/raft`.
```bash
./build.sh libraft

```
The `-n` flag can be passed to just have the build download the needed dependencies. Since RAFT is primarily used at build-time, the dependencies will never be installed by the RAFT build, with the exception of building FAISS statically into the shared libraries.
The `-n` flag can be passed to just have the build download the needed dependencies. Since RAFT is primarily used at build-time, the dependencies will never be installed by the RAFT build.
```bash
./build.sh libraft -n
```
Expand Down Expand Up @@ -167,15 +166,13 @@ RAFT's cmake has the following configurable flags available:.
| RAFT_COMPILE_LIBRARIES | ON, OFF | ON if either BUILD_TESTS or BUILD_BENCH is ON; otherwise OFF | Compiles all `libraft` shared libraries (these are required for Googletests) |
| RAFT_COMPILE_NN_LIBRARY | ON, OFF | OFF | Compiles the `libraft-nn` shared library |
| RAFT_COMPILE_DIST_LIBRARY | ON, OFF | OFF | Compiles the `libraft-distance` shared library |
| RAFT_ENABLE_NN_DEPENDENCIES | ON, OFF | OFF | Searches for dependencies of nearest neighbors API, such as FAISS, and compiles them if not found. Needed for `raft::spatial::knn` |
| RAFT_USE_FAISS_STATIC | ON, OFF | OFF | Statically link FAISS into `libraft-nn` |
| DETECT_CONDA_ENV | ON, OFF | ON | Enable detection of conda environment for dependencies |
| RAFT_NVTX | ON, OFF | OFF | Enable NVTX Markers |
| CUDA_ENABLE_KERNELINFO | ON, OFF | OFF | Enables `kernelinfo` in nvcc. This is useful for `compute-sanitizer` |
| CUDA_ENABLE_LINEINFO | ON, OFF | OFF | Enable the -lineinfo option for nvcc |
| CUDA_STATIC_RUNTIME | ON, OFF | OFF | Statically link the CUDA runtime |

Currently, shared libraries are provided for the `libraft-nn` and `libraft-distance` components. The `libraft-nn` component depends upon [FAISS](https://github.com/facebookresearch/faiss) and the `RAFT_ENABLE_NN_DEPENDENCIES` option will build it from source if it is not already installed.
Currently, shared libraries are provided for the `libraft-nn` and `libraft-distance` components.

### Python

Expand Down Expand Up @@ -277,7 +274,7 @@ If RAFT has already been installed, such as by using the `build.sh` script, use

### Using C++ pre-compiled shared libraries

Use `find_package(raft COMPONENTS nn distance)` to enable the shared libraries and transitively pass dependencies through separate targets for each component. In this example, the `raft::distance` and `raft::nn` targets will be available for configuring linking paths in addition to `raft::raft`. These targets will also pass through any transitive dependencies (such as FAISS for the `nn` package).
Use `find_package(raft COMPONENTS nn distance)` to enable the shared libraries and transitively pass dependencies through separate targets for each component. In this example, the `raft::distance` and `raft::nn` targets will be available for configuring linking paths in addition to `raft::raft`. These targets will also pass through any transitive dependencies (such as CUTLASS for the `distance` package).

The pre-compiled libraries contain template specializations for commonly used types, such as single- and double-precision floating-point. In order to use the symbols in the pre-compiled libraries, the compiler needs to be told not to instantiate templates that are already contained in the shared libraries. By convention, these header files are named `specializations.cuh` and located in the base directory for the packages that contain specializations.

Expand All @@ -302,8 +299,8 @@ set(RAFT_FORK "rapidsai")
set(RAFT_PINNED_TAG "branch-${RAFT_VERSION}")
function(find_and_configure_raft)
set(oneValueArgs VERSION FORK PINNED_TAG USE_FAISS_STATIC
COMPILE_LIBRARIES ENABLE_NN_DEPENDENCIES CLONE_ON_PIN
set(oneValueArgs VERSION FORK PINNED_TAG
COMPILE_LIBRARIES CLONE_ON_PIN
USE_NN_LIBRARY USE_DISTANCE_LIBRARY
ENABLE_thrust_DEPENDENCY)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}"
Expand Down Expand Up @@ -346,8 +343,6 @@ function(find_and_configure_raft)
OPTIONS
"BUILD_TESTS OFF"
"BUILD_BENCH OFF"
"RAFT_ENABLE_NN_DEPENDENCIES ${PKG_ENABLE_NN_DEPENDENCIES}"
"RAFT_USE_FAISS_STATIC ${PKG_USE_FAISS_STATIC}"
"RAFT_COMPILE_LIBRARIES ${PKG_COMPILE_LIBRARIES}"
"RAFT_ENABLE_thrust_DEPENDENCY ${PKG_ENABLE_thrust_DEPENDENCY}"
)
Expand All @@ -369,8 +364,6 @@ find_and_configure_raft(VERSION ${RAFT_VERSION}.00
COMPILE_LIBRARIES NO
USE_NN_LIBRARY NO
USE_DISTANCE_LIBRARY NO
ENABLE_NN_DEPENDENCIES NO # This builds FAISS if not installed
USE_FAISS_STATIC NO
ENABLE_thrust_DEPENDENCY YES
)
```
Expand Down

0 comments on commit c4671ed

Please sign in to comment.