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

Add end-to-end CUDA ann-benchmarks to raft #1304

Merged
merged 49 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b571ba9
Initial commit of cuann_benchmarks code. Squashed branch to remove IP.
cjnolet Feb 24, 2023
ccf251d
Merge branch 'branch-23.04' into fea-2304-cuann_benchmark
cjnolet Feb 24, 2023
72b265c
Merge branch 'branch-23.04' into fea-2304-cuann_benchmark
cjnolet Feb 25, 2023
b0a918c
Getting cuann benchmarks to build
cjnolet Feb 25, 2023
a344e50
Merge branch 'fea-2304-cuann_benchmark' of github.com:cjnolet/raft in…
cjnolet Feb 25, 2023
e7aca59
More cleanup
cjnolet Feb 25, 2023
f4c2282
Moving `cpp/cuann_bench` to `cpp/bench/ann` and `cpp/bench/prims`
cjnolet Feb 25, 2023
fc1c5e6
Cleaning up hnswlib cmake
cjnolet Feb 25, 2023
f34d6e8
Moving README.md from source code to docs
cjnolet Feb 25, 2023
30cc9f1
More docs upates
cjnolet Feb 25, 2023
5997e9a
Merge branch 'branch-23.04' into fea-2304-cuann_benchmark
cjnolet Feb 28, 2023
e93ede7
Breaking benchmarks apart to make them easier to maintain
cjnolet Feb 28, 2023
2b52598
Merge branch 'fea-2304-cuann_benchmark' of github.com:cjnolet/raft in…
cjnolet Feb 28, 2023
9ca1229
Renaming namespace benchmark -> raft::bench::ann everywhere
cjnolet Feb 28, 2023
6b8e25a
Getting new stuff to build. Now to test it...
cjnolet Feb 28, 2023
bb69daf
Merge branch 'branch-23.04' into fea-2304-cuann_benchmark
cjnolet Mar 6, 2023
2bd4ed9
Fixing ggnn
cjnolet Mar 7, 2023
7451ab4
Enabling all ann-benchmark variants
cjnolet Mar 7, 2023
e2a694a
Merge branch 'fea-2304-cuann_benchmark' of github.com:cjnolet/raft in…
cjnolet Mar 7, 2023
7b9bc95
Removing more headers. Consolidating ann bench cudart_util into RAFT'…
cjnolet Mar 7, 2023
59438fa
More cleanup
cjnolet Mar 7, 2023
52dde57
More cleanup
cjnolet Mar 7, 2023
fcb2e73
Fixing a few more stray macros
cjnolet Mar 7, 2023
5c734bd
Renaming cuann
cjnolet Mar 7, 2023
d6647bc
Doing some renaming
cjnolet Mar 9, 2023
e891924
Update cpp/bench/ann/conf/deep-100M.json
cjnolet Mar 16, 2023
697ecba
Merge remote-tracking branch 'rapidsai/branch-23.04' into fea-2304-cu…
cjnolet Mar 23, 2023
1228519
Updates based on review feedback
cjnolet Mar 23, 2023
2964fef
Reverting benchmark move
cjnolet Mar 23, 2023
a24ce8d
Using proper macro
cjnolet Mar 23, 2023
c399400
Replacing more instances
cjnolet Mar 23, 2023
d327bd1
CUDA_TRY
cjnolet Mar 23, 2023
ff724f3
Using proper return code
cjnolet Mar 23, 2023
5937d75
Adding conda generated file for ann benchmarks
cjnolet Mar 24, 2023
aeb448e
Adding actual conda dev file
cjnolet Mar 24, 2023
ed74608
Checking in
cjnolet Mar 24, 2023
94d0158
Making sure we find Threads even when googletest isn't installed
cjnolet Mar 24, 2023
7b770c6
Updating docs
cjnolet Mar 24, 2023
4140457
Merge remote-tracking branch 'rapidsai/branch-23.04' into fea-2304-cu…
cjnolet Mar 24, 2023
4f30b9b
Adding conda recipe
cjnolet Mar 24, 2023
8cd5c07
Adding h5py version
cjnolet Mar 24, 2023
b134133
Hnswlib recipe update
cjnolet Mar 24, 2023
d4d5fdd
Using proper filename
cjnolet Mar 24, 2023
5d093a3
Trying again
cjnolet Mar 24, 2023
d8cd9f7
Removing hnswlib from the conda recipe
cjnolet Mar 24, 2023
66f2b48
Adding FindAVX.cmake
cjnolet Mar 27, 2023
a739270
Adding copyrights and proper attribution for PyTorch copied cmake file
cjnolet Mar 28, 2023
9fe55ac
Addressing remaining review feedback
cjnolet Mar 28, 2023
fdb635e
Merge branch 'branch-23.04' into fea-2304-cuann_benchmark
cjnolet Mar 28, 2023
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
86 changes: 57 additions & 29 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

# Copyright (c) 2020-2023, NVIDIA CORPORATION.

# raft build script
# raft build scripts

# This script is used to build the component(s) in this repo from
# This scripts is used to build the component(s) in this repo from
# source, and can be called with various options to customize the
# build as needed (see the help output for details)

# Abort script on first error
# Abort scripts on first error
set -e

NUMARGS=$#
ARGS=$*

# NOTE: ensure all dir changes are relative to the location of this
# script, and that this script resides in the repo dir!
# scripts, and that this scripts 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"
HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<tool>] [--limit-tests=<targets>] [--limit-bench=<targets>]
VALIDARGS="clean libraft pylibraft raft-dask docs tests bench-prims bench-ann 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-prims=<targets>] [--limit-bench-ann=<targets>]
where <target> is:
clean - remove all existing build artifacts and configuration (start over)
libraft - build the raft C++ code only. Also builds the C-wrapper library
Expand All @@ -28,7 +28,8 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
raft-dask - build the raft-dask Python package. this also requires pylibraft.
docs - build the documentation
tests - build the tests
bench - build the benchmarks
bench-prims - build micro-benchmarks for primitives
bench-ann - build end-to-end ann benchmarks

and <flag> is:
-v - verbose build mode
Expand All @@ -43,7 +44,8 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
--minimal-deps - disables dependencies like thrust so they can be overridden.
can be useful for a pure header-only install
--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)
--limit-bench-prims - semicolon-separated list of prims benchmark executables to compute (e.g. NEIGHBORS_PRIMS_BENCH;CLUSTER_PRIMS_BENCH)
--limit-bench-ann - semicolon-separated list of ann benchmark executables to compute (e.g. HNSWLIB_ANN_BENCH;RAFT_IVF_PQ_ANN_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
Expand All @@ -62,13 +64,14 @@ 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
# Set defaults for vars modified by flags to this scripts
CMAKE_LOG_LEVEL=""
VERBOSE_FLAG=""
BUILD_ALL_GPU_ARCH=0
BUILD_TESTS=OFF
BUILD_TYPE=Release
BUILD_BENCH=OFF
BUILD_PRIMS_BENCH=OFF
BUILD_ANN_BENCH=OFF
BUILD_STATIC_FAISS=OFF
COMPILE_LIBRARIES=OFF
COMPILE_NN_LIBRARY=OFF
Expand All @@ -77,7 +80,7 @@ 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"
BENCH_TARGETS="CLUSTER_BENCH;NEIGHBORS_BENCH;DISTANCE_BENCH;LINALG_BENCH;MATRIX_BENCH;SPARSE_BENCH;RANDOM_BENCH"
PRIMS_BENCH_TARGETS="CLUSTER_PRIMS_BENCH;NEIGHBORS_PRIMS_BENCH;DISTANCE_PRIMS_BENCH;LINALG_PRIMS_BENCH;MATRIX_PRIMS_BENCH;SPARSE_PRIMS_BENCH;RANDOM_PRIMS_BENCH"
ENABLE_thrust_DEPENDENCY=ON

CACHE_ARGS=""
Expand Down Expand Up @@ -161,15 +164,30 @@ function limitTests {

function limitBench {
# Check for option to limit the set of test binaries to build
if [[ -n $(echo $ARGS | { grep -E "\-\-limit\-bench" || true; } ) ]]; then
if [[ -n $(echo $ARGS | { grep -E "\-\-limit\-bench-prims" || true; } ) ]]; then
# There are possible weird edge cases that may cause this regex filter to output nothing and fail silently
# the true pipe will catch any weird edge cases that may happen and will cause the program to fall back
# on the invalid option error
LIMIT_BENCH_TARGETS=$(echo $ARGS | sed -e 's/.*--limit-bench=//' -e 's/ .*//')
if [[ -n ${LIMIT_BENCH_TARGETS} ]]; then
LIMIT_PRIMS_BENCH_TARGETS=$(echo $ARGS | sed -e 's/.*--limit-bench-prims=//' -e 's/ .*//')
if [[ -n ${LIMIT_PRIMS_BENCH_TARGETS} ]]; then
# Remove the full LIMIT_PRIMS_BENCH_TARGETS argument from list of args so that it passes validArgs function
ARGS=${ARGS//--limit-bench-prims=$LIMIT_PRIMS_BENCH_TARGETS/}
PRIMS_BENCH_TARGETS=${LIMIT_PRIMS_BENCH_TARGETS}
fi
fi
}

function limitAnnBench {
# Check for option to limit the set of test binaries to build
if [[ -n $(echo $ARGS | { grep -E "\-\-limit\-bench-ann" || true; } ) ]]; then
# There are possible weird edge cases that may cause this regex filter to output nothing and fail silently
# the true pipe will catch any weird edge cases that may happen and will cause the program to fall back
# on the invalid option error
LIMIT_ANN_BENCH_TARGETS=$(echo $ARGS | sed -e 's/.*--limit-bench-ann=//' -e 's/ .*//')
if [[ -n ${LIMIT_ANN_BENCH_TARGETS} ]]; then
# Remove the full LIMIT_TEST_TARGETS argument from list of args so that it passes validArgs function
ARGS=${ARGS//--limit-bench=$LIMIT_BENCH_TARGETS/}
BENCH_TARGETS=${LIMIT_BENCH_TARGETS}
ARGS=${ARGS//--limit-bench-ann=$LIMIT_ANN_BENCH_TARGETS/}
ANN_BENCH_TARGETS=${LIMIT_ANN_BENCH_TARGETS}
fi
fi
}
Expand All @@ -185,6 +203,7 @@ if (( ${NUMARGS} != 0 )); then
cacheTool
limitTests
limitBench
limitAnnBench
for a in ${ARGS}; do
if ! (echo " ${VALIDARGS} " | grep -q " ${a} "); then
echo "Invalid option: ${a}"
Expand Down Expand Up @@ -315,27 +334,39 @@ if hasArg tests || (( ${NUMARGS} == 0 )); then
fi
fi

if hasArg bench || (( ${NUMARGS} == 0 )); then
BUILD_BENCH=ON
CMAKE_TARGET="${CMAKE_TARGET};${BENCH_TARGETS}"
if hasArg bench-prims || (( ${NUMARGS} == 0 )); then
BUILD_PRIMS_BENCH=ON
CMAKE_TARGET="${CMAKE_TARGET};${PRIMS_BENCH_TARGETS}"

# Force compile nn library when needed benchmark targets are specified
if [[ $CMAKE_TARGET == *"CLUSTER_BENCH"* || \
$CMAKE_TARGET == *"NEIGHBORS_BENCH"* ]]; then
if [[ $CMAKE_TARGET == *"CLUSTER_PRIMS_BENCH"* || \
$CMAKE_TARGET == *"NEIGHBORS_PRIMS_BENCH"* ]]; then
echo "-- Enabling nearest neighbors lib for benchmarks"
ENABLE_NN_DEPENDENCIES=ON
COMPILE_NN_LIBRARY=ON
fi

# Force compile distance library when needed benchmark targets are specified
if [[ $CMAKE_TARGET == *"CLUSTER_BENCH"* || \
$CMAKE_TARGET == *"NEIGHBORS_BENCH"* ]]; then
if [[ $CMAKE_TARGET == *"CLUSTER_PRIMS_BENCH"* || \
$CMAKE_TARGET == *"NEIGHBORS_PRIMS_BENCH"* ]]; then
echo "-- Enabling distance lib for benchmarks"
COMPILE_DIST_LIBRARY=ON
fi

fi

if hasArg bench-ann || (( ${NUMARGS} == 0 )); then
BUILD_ANN_BENCH=ON
CMAKE_TARGET="${CMAKE_TARGET};${ANN_BENCH_TARGETS}"

# Force compile nn library when needed benchmark targets are specified
if [[ $CMAKE_TARGET == *"_RAFT_"* ]]; then
ENABLE_NN_DEPENDENCIES=ON
COMPILE_DIST_LIBRARY=ON
COMPILE_NN_LIBRARY=ON
fi
fi

if hasArg --buildfaiss; then
BUILD_STATIC_FAISS=ON
fi
Expand All @@ -349,8 +380,6 @@ if hasArg clean; then
CLEAN=1
fi



if [[ ${CMAKE_TARGET} == "" ]]; then
CMAKE_TARGET="all"
fi
Expand Down Expand Up @@ -384,7 +413,7 @@ fi

################################################################################
# Configure for building all C++ targets
if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || hasArg bench; then
if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || hasArg bench-prims || hasArg bench-ann; then
if (( ${BUILD_ALL_GPU_ARCH} == 0 )); then
RAFT_CMAKE_CUDA_ARCHITECTURES="NATIVE"
echo "Building for the architecture of the GPU in the system..."
Expand All @@ -404,7 +433,8 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || has
-DRAFT_NVTX=${NVTX} \
-DDISABLE_DEPRECATION_WARNINGS=${DISABLE_DEPRECATION_WARNINGS} \
-DBUILD_TESTS=${BUILD_TESTS} \
-DBUILD_BENCH=${BUILD_BENCH} \
-DBUILD_PRIMS_BENCH=${BUILD_PRIMS_BENCH} \
-DBUILD_ANN_BENCH=${BUILD_ANN_BENCH} \
-DCMAKE_MESSAGE_LOG_LEVEL=${CMAKE_LOG_LEVEL} \
-DRAFT_COMPILE_NN_LIBRARY=${COMPILE_NN_LIBRARY} \
-DRAFT_COMPILE_DIST_LIBRARY=${COMPILE_DIST_LIBRARY} \
Expand All @@ -429,7 +459,6 @@ if (( ${NUMARGS} == 0 )) || hasArg raft-dask; then
if [[ "${EXTRA_CMAKE_ARGS}" != *"DFIND_RAFT_CPP"* ]]; then
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DFIND_RAFT_CPP=ON"
fi

cd ${REPODIR}/python/raft-dask
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
Expand All @@ -443,7 +472,6 @@ if (( ${NUMARGS} == 0 )) || hasArg pylibraft; then
if [[ "${EXTRA_CMAKE_ARGS}" != *"DFIND_RAFT_CPP"* ]]; then
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DFIND_RAFT_CPP=ON"
fi

cd ${REPODIR}/python/pylibraft
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
Expand Down
2 changes: 1 addition & 1 deletion conda/recipes/libraft/build_libraft_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Copyright (c) 2022-2023, NVIDIA CORPORATION.

./build.sh tests bench --allgpuarch --no-nvtx
./build.sh tests bench-prims --allgpuarch --no-nvtx
cmake --install cpp/build --component testing
24 changes: 16 additions & 8 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(BUILD_SHARED_LIBS "Build raft shared libraries" ON)
option(BUILD_TESTS "Build raft unit-tests" ON)
option(BUILD_BENCH "Build raft C++ benchmark tests" OFF)
option(BUILD_PRIMS_BENCH "Build raft C++ benchmark tests" OFF)
option(BUILD_ANN_BENCH "Build raft ann benchmarks" OFF)
option(CUDA_ENABLE_KERNELINFO "Enable kernel resource usage info" OFF)
option(CUDA_ENABLE_LINEINFO
"Enable the -lineinfo option for nvcc (useful for cuda-memcheck / profiler)" OFF
Expand All @@ -58,7 +59,7 @@ option(DISABLE_OPENMP "Disable OpenMP" OFF)
option(RAFT_NVTX "Enable nvtx markers" OFF)

set(RAFT_COMPILE_LIBRARIES_DEFAULT OFF)
if(BUILD_TESTS OR BUILD_BENCH)
if(BUILD_TESTS OR BUILD_PRIMS_BENCH)
set(RAFT_COMPILE_LIBRARIES_DEFAULT ON)
endif()
option(RAFT_COMPILE_LIBRARIES "Enable building raft shared library instantiations"
Expand All @@ -77,7 +78,7 @@ option(RAFT_ENABLE_NN_DEPENDENCIES "Search for raft::nn dependencies like faiss"

option(RAFT_ENABLE_thrust_DEPENDENCY "Enable Thrust dependency" ON)

if(BUILD_TESTS OR BUILD_BENCH)
if(BUILD_TESTS OR BUILD_PRIMS_BENCH)
# Needed because GoogleBenchmark changes the state of FindThreads.cmake, causing subsequent runs
# to have different values for the `Threads::Threads` target. Setting this flag ensures
# `Threads::Threads` is the same value in first run and subsequent runs.
Expand All @@ -102,7 +103,7 @@ cmake_dependent_option(

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}")
message(VERBOSE "RAFT: Building raft C++ benchmarks: ${BUILD_PRIMS_BENCH}")
message(VERBOSE "RAFT: Enable detection of conda environment for dependencies: ${DETECT_CONDA_ENV}")
message(VERBOSE "RAFT: Disable depreaction warnings " ${DISABLE_DEPRECATION_WARNINGS})
message(VERBOSE "RAFT: Disable OpenMP: ${DISABLE_OPENMP}")
Expand Down Expand Up @@ -197,7 +198,7 @@ if(BUILD_TESTS)
include(cmake/thirdparty/get_gtest.cmake)
endif()

if(BUILD_BENCH)
if(BUILD_PRIMS_BENCH)
include(${rapids-cmake-dir}/cpm/gbench.cmake)
rapids_cpm_gbench()
endif()
Expand Down Expand Up @@ -722,7 +723,7 @@ raft_export(
# ##################################################################################################
# * shared test/bench headers ------------------------------------------------

if(BUILD_TESTS OR BUILD_BENCH)
if(BUILD_TESTS OR BUILD_PRIMS_BENCH)
include(internal/CMakeLists.txt)
endif()

Expand All @@ -736,6 +737,13 @@ endif()
# ##################################################################################################
# * build benchmark executable -----------------------------------------------

if(BUILD_BENCH)
include(bench/CMakeLists.txt)
if(BUILD_PRIMS_BENCH)
include(bench/prims/CMakeLists.txt)
endif()

# ##################################################################################################
# * build ann benchmark executable -----------------------------------------------

if(BUILD_ANN_BENCH)
include(bench/ann/CMakeLists.txt)
endif()
Loading