diff --git a/BUILD.md b/BUILD.md index f572b11848..31af4984d1 100644 --- a/BUILD.md +++ b/BUILD.md @@ -7,6 +7,7 @@ - [C++ Shared Libraries](#shared_cpp_libs) - [Improving Rebuild Times](#ccache) - [Googletests](#gtests) + - [Googlebench](#gbench) - [C++ Using Cmake](#cpp_using_cmake) - [Python](#python) - [Using RAFT in downstream projects](#use_raft) @@ -102,17 +103,17 @@ It can take sometime to compile all of the tests. You can build individual tests ./build.sh libraft tests --limit-tests=SPATIAL_TEST;DISTANCE_TEST;MATRIX_TEST ``` -### Benchmarks +### Benchmarks -Compile the benchmarks using the `bench` target in `build.sh`: +The benchmarks are broken apart by algorithm category, so you will find several binaries in `cpp/build/` named `*_BENCH`. ```bash ./build.sh libraft bench ``` -To run the benchmarks: +It can take sometime to compile all of the tests. You can build individual tests by providing a semicolon-separated list to the `--limit-tests` option in `build.sh`: ```bash -./cpp/build/bench_raft +./build.sh libraft bench --limit-bench=SPATIAL_BENCH;DISTANCE_BENCH;LINALG_BENCH ``` ### C++ Using Cmake diff --git a/build.sh b/build.sh index 1f1169ade9..2b53ad2b69 100755 --- a/build.sh +++ b/build.sh @@ -19,7 +19,7 @@ ARGS=$* REPODIR=$(cd $(dirname $0); pwd) VALIDARGS="clean libraft pylibraft raft-dask docs tests bench clean -v -g --install --compile-libs --compile-nn --compile-dist --allgpuarch --no-nvtx --show_depr_warn -h --buildfaiss --minimal-deps" -HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool=] [--limit-tests=] +HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool=] [--limit-tests=] [--limit-bench=] where is: clean - remove all existing build artifacts and configuration (start over) libraft - build the raft C++ code only. Also builds the C-wrapper library @@ -41,6 +41,7 @@ HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool=:${RAFT_CXX_FLAGS}>" - "$<$:${RAFT_CUDA_FLAGS}>" -) - -target_include_directories(${RAFT_CPP_BENCH_TARGET} - PUBLIC "$" -) - -target_link_libraries(${RAFT_CPP_BENCH_TARGET} - PRIVATE - raft::raft - raft::distance - raft::nn - faiss::faiss - benchmark::benchmark - $ - $ -) +################################################################################################### +# - compiler function ----------------------------------------------------------------------------- + +function(ConfigureBench) + +set(options OPTIONAL DIST NN) +set(oneValueArgs NAME ) +set(multiValueArgs PATH TARGETS CONFIGURATIONS) + +cmake_parse_arguments(ConfigureBench "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN} ) + +set(BENCH_NAME ${ConfigureBench_NAME}) + +add_executable(${BENCH_NAME} ${ConfigureBench_PATH}) + +message("BENCH PATH: ${ConfigureBench_PATH}") + +target_link_libraries(${BENCH_NAME} + PRIVATE + raft::raft + $<$:raft::distance> + $<$:raft::nn> + benchmark::benchmark + Threads::Threads + $ + $ + ) + +set_target_properties(${BENCH_NAME} + PROPERTIES + # set target compile options + INSTALL_RPATH "\$ORIGIN/../../../lib" + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON + CUDA_STANDARD 17 + CUDA_STANDARD_REQUIRED ON + POSITION_INDEPENDENT_CODE ON + INTERFACE_POSITION_INDEPENDENT_CODE ON + ) + +target_compile_options(${BENCH_NAME} + PRIVATE "$<$:${RAFT_CXX_FLAGS}>" + "$<$:${RAFT_CUDA_FLAGS}>" + ) + +target_include_directories(${BENCH_NAME} + PUBLIC "$" + ) install( - TARGETS ${RAFT_CPP_BENCH_TARGET} - COMPONENT testing - DESTINATION bin/libraft/gbench - EXCLUDE_FROM_ALL -) + TARGETS ${BENCH_NAME} + COMPONENT testing + DESTINATION bin/gbench/libraft + EXCLUDE_FROM_ALL) + +endfunction() + +if(BUILD_BENCH) + ConfigureBench(NAME CLUSTER_BENCH + PATH + bench/cluster/kmeans_balanced.cu + bench/cluster/kmeans.cu + bench/main.cpp + OPTIONAL DIST NN + ) + + ConfigureBench(NAME DISTANCE_BENCH + PATH + bench/distance/distance_cosine.cu + bench/distance/distance_exp_l2.cu + bench/distance/distance_l1.cu + bench/distance/distance_unexp_l2.cu + bench/main.cpp + OPTIONAL DIST + ) + + ConfigureBench(NAME LINALG_BENCH + PATH + bench/linalg/add.cu + bench/linalg/map_then_reduce.cu + bench/linalg/matrix_vector_op.cu + bench/linalg/reduce.cu + bench/main.cpp + ) + + ConfigureBench(NAME RANDOM_BENCH + PATH + bench/random/make_blobs.cu + bench/random/permute.cu + bench/random/rng.cu + bench/main.cpp + ) + + ConfigureBench(NAME SPARSE_BENCH + PATH + bench/sparse/convert_csr.cu + bench/main.cpp + ) + + ConfigureBench(NAME SPATIAL_BENCH + PATH + bench/spatial/fused_l2_nn.cu + bench/spatial/knn/brute_force_float_int64_t.cu + bench/spatial/knn/brute_force_float_uint32_t.cu + bench/spatial/knn/ivf_flat_float_int64_t.cu + bench/spatial/knn/ivf_flat_float_uint32_t.cu + bench/spatial/knn/ivf_flat_int8_t_int64_t.cu + bench/spatial/knn/ivf_flat_uint8_t_uint32_t.cu + bench/spatial/knn/ivf_pq_float_int64_t.cu + bench/spatial/knn/ivf_pq_float_uint32_t.cu + bench/spatial/knn/ivf_pq_int8_t_int64_t.cu + bench/spatial/knn/ivf_pq_uint8_t_uint32_t.cu + bench/spatial/selection.cu + bench/main.cpp + OPTIONAL DIST NN + ) +endif() +