Skip to content

Commit

Permalink
Adding uninstall option to build.sh (#1075)
Browse files Browse the repository at this point in the history
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: #1075
  • Loading branch information
cjnolet authored Dec 8, 2022
1 parent de24a94 commit 9c8b762
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
77 changes: 68 additions & 9 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 -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 [<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 @@ -34,6 +34,7 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
-v - verbose build mode
-g - build for debug
-n - no install step
--uninstall - uninstall files for specified targets which were built and installed prior
--compile-libs - compile shared libraries for all components
--compile-nn - compile shared library for nn component
--compile-dist - compile shared library for distance and current random components
Expand All @@ -56,9 +57,9 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
"
LIBRAFT_BUILD_DIR=${LIBRAFT_BUILD_DIR:=${REPODIR}/cpp/build}
SPHINX_BUILD_DIR=${REPODIR}/docs
PY_RAFT_BUILD_DIR=${REPODIR}/python/raft/build
PY_LIBRAFT_BUILD_DIR=${REPODIR}/python/pylibraft/_skbuild
BUILD_DIRS="${LIBRAFT_BUILD_DIR} ${PY_RAFT_BUILD_DIR} ${PY_LIBRAFT_BUILD_DIR}"
RAFT_DASK_BUILD_DIR=${REPODIR}/python/raft-dask/_skbuild
PYLIBRAFT_BUILD_DIR=${REPODIR}/python/pylibraft/_skbuild
BUILD_DIRS="${LIBRAFT_BUILD_DIR} ${PYLIBRAFT_BUILD_DIR} ${RAFT_DASK_BUILD_DIR}"

# Set defaults for vars modified by flags to this script
CMAKE_LOG_LEVEL=""
Expand Down Expand Up @@ -190,6 +191,65 @@ if (( ${NUMARGS} != 0 )); then
done
fi

# This should run before build/install
if hasArg --uninstall; then
UNINSTALL=1

if hasArg pylibraft || hasArg libraft || (( ${NUMARGS} == 1 )); then

echo "Removing libraft files..."
if [ -e ${LIBRAFT_BUILD_DIR}/install_manifest.txt ]; then
xargs rm -fv < ${LIBRAFT_BUILD_DIR}/install_manifest.txt > /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=""
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
59 changes: 55 additions & 4 deletions docs/source/build.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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`:
Expand All @@ -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`:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
```
6 changes: 3 additions & 3 deletions docs/source/cpp_api.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
~~~~~~~~~~~~~~~~~
C++ API Reference
~~~~~~~~~~~~~~~~~
~~~~~~~
C++ API
~~~~~~~

.. _api:

Expand Down
6 changes: 3 additions & 3 deletions docs/source/pylibraft_api.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
~~~~~~~~~~~~~~~~~~~~~~~
PyLibRAFT API Reference
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
PyLibRAFT API
~~~~~~~~~~~~~

.. _api:

Expand Down

0 comments on commit 9c8b762

Please sign in to comment.