From 9c8b76295c15c97e62e14f5ef5fb69ad0dd79ed4 Mon Sep 17 00:00:00 2001 From: "Corey J. Nolet" Date: Thu, 8 Dec 2022 09:56:06 -0500 Subject: [PATCH] Adding uninstall option to build.sh (#1075) As the name suggests, this feature was removed at some point quite awhile ago. I'm pulling over the logic that `cugraph` uses for uninstalling as that seems to work well for them. Authors: - Corey J. Nolet (https://github.com/cjnolet) Approvers: - Ben Frederickson (https://github.com/benfred) - Robert Maynard (https://github.com/robertmaynard) URL: https://github.com/rapidsai/raft/pull/1075 --- README.md | 2 +- build.sh | 77 +++++++++++++++++++++++++++++++---- docs/source/build.md | 59 +++++++++++++++++++++++++-- docs/source/cpp_api.rst | 6 +-- docs/source/pylibraft_api.rst | 6 +-- 5 files changed, 130 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b9f07595f5..bb268a896a 100755 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ pairwise_distance(in1, in2, out=output, metric="euclidean") ## Installing -RAFT itself can be installed through conda, [Cmake Package Manager (CPM)](https://github.com/cpm-cmake/CPM.cmake), pip, or by building the repository from source. Please refer to the [build instructions](docs/source/build.md) for more a comprehensive guide on building RAFT and using it in downstream projects. +RAFT itself can be installed through conda, [Cmake Package Manager (CPM)](https://github.com/cpm-cmake/CPM.cmake), pip, or by building the repository from source. Please refer to the [build instructions](docs/source/build.md) for more a comprehensive guide on installing and building RAFT and using it in downstream projects. ### Conda diff --git a/build.sh b/build.sh index 0708c1b89e..34dcd3a2db 100755 --- a/build.sh +++ b/build.sh @@ -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 -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 --buildfaiss --minimal-deps" HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool=] [--limit-tests=] [--limit-bench=] where is: clean - remove all existing build artifacts and configuration (start over) @@ -34,6 +34,7 @@ HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool=\"] [--cache-tool= /dev/null 2>&1 + fi + fi + + if hasArg pylibraft || (( ${NUMARGS} == 1 )); then + echo "Uninstalling pylibraft package..." + if [ -e ${PYLIBRAFT_BUILD_DIR}/install_manifest.txt ]; then + xargs rm -fv < ${PYLIBRAFT_BUILD_DIR}/install_manifest.txt > /dev/null 2>&1 + fi + + # Try to uninstall via pip if it is installed + if [ -x "$(command -v pip)" ]; then + echo "Using pip to uninstall pylibraft" + pip uninstall -y pylibraft + + # Otherwise, try to uninstall through conda if that's where things are installed + elif [ -x "$(command -v conda)" ] && [ "$INSTALL_PREFIX" == "$CONDA_PREFIX" ]; then + echo "Using conda to uninstall pylibraft" + conda uninstall -y pylibraft + + # Otherwise, fail + else + echo "Could not uninstall pylibraft from pip or conda. pylibraft package will need to be manually uninstalled" + fi + fi + + if hasArg raft-dask || (( ${NUMARGS} == 1 )); then + echo "Uninstalling raft-dask package..." + if [ -e ${RAFT_DASK_BUILD_DIR}/install_manifest.txt ]; then + xargs rm -fv < ${RAFT_DASK_BUILD_DIR}/install_manifest.txt > /dev/null 2>&1 + fi + + # Try to uninstall via pip if it is installed + if [ -x "$(command -v pip)" ]; then + echo "Using pip to uninstall raft-dask" + pip uninstall -y raft-dask + + # Otherwise, try to uninstall through conda if that's where things are installed + elif [ -x "$(command -v conda)" ] && [ "$INSTALL_PREFIX" == "$CONDA_PREFIX" ]; then + echo "Using conda to uninstall raft-dask" + conda uninstall -y raft-dask + + # Otherwise, fail + else + echo "Could not uninstall raft-dask from pip or conda. raft-dask package will need to be manually uninstalled." + fi + fi + exit 0 +fi + + # Process flags if hasArg -n; then INSTALL_TARGET="" @@ -286,9 +346,8 @@ fi if hasArg clean; then CLEAN=1 fi -if hasArg uninstall; then - UNINSTALL=1 -fi + + if [[ ${CMAKE_TARGET} == "" ]]; then CMAKE_TARGET="all" @@ -370,7 +429,7 @@ if (( ${NUMARGS} == 0 )) || hasArg raft-dask; then fi cd ${REPODIR}/python/raft-dask - python setup.py build_ext --inplace -- -DCMAKE_PREFIX_PATH="${LIBRAFT_BUILD_DIR};${INSTALL_PREFIX}" -DCMAKE_LIBRARY_PATH=${LIBRAFT_BUILD_DIR} ${EXTRA_CMAKE_ARGS} -- -j${PARALLEL_LEVEL:-1} + python setup.py build_ext --inplace -- -DCMAKE_PREFIX_PATH="${RAFT_DASK_BUILD_DIR};${INSTALL_PREFIX}" -DCMAKE_LIBRARY_PATH=${LIBRAFT_BUILD_DIR} ${EXTRA_CMAKE_ARGS} -- -j${PARALLEL_LEVEL:-1} if [[ ${INSTALL_TARGET} != "" ]]; then python setup.py install --single-version-externally-managed --record=record.txt -- -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} ${EXTRA_CMAKE_ARGS} fi @@ -384,7 +443,7 @@ if (( ${NUMARGS} == 0 )) || hasArg pylibraft; then fi cd ${REPODIR}/python/pylibraft - python setup.py build_ext --inplace -- -DCMAKE_PREFIX_PATH="${LIBRAFT_BUILD_DIR};${INSTALL_PREFIX}" -DCMAKE_LIBRARY_PATH=${LIBRAFT_BUILD_DIR} ${EXTRA_CMAKE_ARGS} -- -j${PARALLEL_LEVEL:-1} + python setup.py build_ext --inplace -- -DCMAKE_PREFIX_PATH="${RAFT_DASK_BUILD_DIR};${INSTALL_PREFIX}" -DCMAKE_LIBRARY_PATH=${LIBRAFT_BUILD_DIR} ${EXTRA_CMAKE_ARGS} -- -j${PARALLEL_LEVEL:-1} if [[ ${INSTALL_TARGET} != "" ]]; then python setup.py install --single-version-externally-managed --record=record.txt -- -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} ${EXTRA_CMAKE_ARGS} fi diff --git a/docs/source/build.md b/docs/source/build.md index d1b3ef7cd5..2eba3af450 100644 --- a/docs/source/build.md +++ b/docs/source/build.md @@ -1,4 +1,30 @@ -# Install Guide +# Installation + +### Conda + +The easiest way to install RAFT is through conda and several packages are provided. +- `libraft-headers` RAFT headers +- `libraft-nn` (optional) contains shared libraries for the nearest neighbors primitives. +- `libraft-distance` (optional) contains shared libraries for distance primitives. +- `pylibraft` (optional) Python wrappers around RAFT algorithms and primitives. +- `raft-dask` (optional) enables deployment of multi-node multi-GPU algorithms that use RAFT `raft::comms` in Dask clusters. + +Use the following command to install all of the RAFT packages with conda (replace `rapidsai` with `rapidsai-nightly` to install more up-to-date but less stable nightly packages). `mamba` is preferred over the `conda` command. +```bash +mamba install -c rapidsai -c conda-forge -c nvidia raft-dask pylibraft +``` + +You can also install the `libraft-*` conda packages individually using the `mamba` command above. + +After installing RAFT, `find_package(raft COMPONENTS nn distance)` can be used in your CUDA/C++ cmake build to compile and/or link against needed dependencies in your raft target. `COMPONENTS` are optional and will depend on the packages installed. + +### Pip + +pylibraft and raft-dask both have experimental packages that can be [installed through pip](https://rapids.ai/pip.html#install): +```bash +pip install pylibraft-cu11 --extra-index-url=https://pypi.ngc.nvidia.com +pip install raft-dask-cu11 --extra-index-url=https://pypi.ngc.nvidia.com +``` ## Building and installing RAFT @@ -46,6 +72,12 @@ The `-n` flag can be passed to just have the build download the needed dependenc ./build.sh libraft -n ``` +Once installed, `libraft` headers (and dependencies which were downloaded and installed using `rapids-cmake`) can be uninstalled also using `build.sh`: +```bash +./build.sh libraft --uninstall +``` + + ### C++ Shared Libraries (optional) For larger projects which make heavy use of the pairwise distances or nearest neighbors APIs, shared libraries can be built to speed up compile times. These shared libraries can also significantly improve re-compile times both while developing RAFT and developing against the APIs. Build all of the available shared libraries by passing `--compile-libs` flag to `build.sh`: @@ -60,6 +92,12 @@ Individual shared libraries have their own flags and multiple can be used (thoug In above example the shared libraries are installed by default into `$INSTALL_PREFIX/lib`. To disable this, pass `-n` flag. +Once installed, the shared libraries, headers (and any dependencies downloaded and installed via `rapids-cmake`) can be uninstalled using `build.sh`: +```bash +./build.sh libraft --uninstall +``` + + ### ccache and sccache `ccache` and `sccache` can be used to better cache parts of the build when rebuilding frequently, such as when working on a new feature. You can also use `ccache` or `sccache` with `build.sh`: @@ -108,7 +146,7 @@ It can take sometime to compile all of the benchmarks. You can build individual ./build.sh libraft bench --limit-bench=NEIGHBORS_BENCH;DISTANCE_BENCH;LINALG_BENCH ``` -### C++ Using Cmake +### C++ Using Cmake Directly Use `CMAKE_INSTALL_PREFIX` to install RAFT into a specific location. The snippet below will install it into the current conda environment: ```bash @@ -179,6 +217,11 @@ cd python/pylibraft py.test -s -v ``` +The Python packages can also be uninstalled using the `build.sh` script: +```bash +./build.sh pylibraft raft-dask --uninstall +``` + ### Documentation The documentation requires that the C++ headers and python packages have been built and installed. @@ -335,6 +378,14 @@ find_and_configure_raft(VERSION ${RAFT_VERSION}.00 If using the nearest neighbors APIs without the shared libraries, set `ENABLE_NN_DEPENDENCIES=ON` and keep `USE_NN_LIBRARY=OFF` -### Python/Cython Integration +## Uninstall + +Once built and installed, RAFT can be safely uninstalled using `build.sh` by specifying any or all of the installed components. Please note that since `pylibraft` depends on `libraft`, uninstalling `pylibraft` will also uninstall `libraft`: +```bash +./build.sh libraft pylibraft raft-dask --uninstall +``` -Once installed, RAFT's Python library can be added to downstream conda recipes, imported and used directly. +Leaving off the installed components will uninstall everything that's been installed: +```bash +./build.sh --uninstall +``` \ No newline at end of file diff --git a/docs/source/cpp_api.rst b/docs/source/cpp_api.rst index 337ed8d720..04656d5047 100644 --- a/docs/source/cpp_api.rst +++ b/docs/source/cpp_api.rst @@ -1,6 +1,6 @@ -~~~~~~~~~~~~~~~~~ -C++ API Reference -~~~~~~~~~~~~~~~~~ +~~~~~~~ +C++ API +~~~~~~~ .. _api: diff --git a/docs/source/pylibraft_api.rst b/docs/source/pylibraft_api.rst index 6d07c89311..d6bda89c21 100644 --- a/docs/source/pylibraft_api.rst +++ b/docs/source/pylibraft_api.rst @@ -1,6 +1,6 @@ -~~~~~~~~~~~~~~~~~~~~~~~ -PyLibRAFT API Reference -~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~ +PyLibRAFT API +~~~~~~~~~~~~~ .. _api: