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

RAFT skeleton project template #1312

Merged
merged 159 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 158 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
57cfa20
Replace faiss bfKnn
benfred Jan 27, 2023
984c641
Merge branch 'branch-23.02' into bfknn
benfred Jan 27, 2023
805abc7
fix merge
benfred Jan 27, 2023
3e21478
Merge branch 'branch-23.02' into bfknn
cjnolet Jan 27, 2023
74bd44f
Fix bug with col_tiles < K
benfred Jan 27, 2023
c69054d
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred Jan 27, 2023
1d9581b
Include metric_arg in bfknn
benfred Jan 30, 2023
b4cf88c
speedup compile times
benfred Jan 30, 2023
98ffb70
Merge branch 'branch-23.02' into bfknn
benfred Jan 31, 2023
5442d31
Suggestions from code review
benfred Jan 31, 2023
0f5d206
fixes
benfred Jan 31, 2023
cb2b750
Merge branch 'branch-23.04' into bfknn
benfred Feb 3, 2023
e870eb3
use pairwise_distance specialization to speed up compile times
benfred Feb 7, 2023
cd84397
Merge branch 'branch-23.04' into bfknn
benfred Feb 7, 2023
8445aed
Use distance specializations
benfred Feb 7, 2023
e87633a
Merge branch 'branch-23.04' into bfknn
cjnolet Feb 9, 2023
52bf729
Merge branch 'branch-23.04' into bfknn
benfred Feb 11, 2023
d97ddb8
Merge branch 'branch-23.04' into bfknn
cjnolet Feb 11, 2023
5905b2d
use specializations in RBC code
benfred Feb 14, 2023
d905266
Merge branch 'branch-23.04' into bfknn
benfred Feb 14, 2023
8eaba84
use pw specializations in rbc
benfred Feb 14, 2023
fe728e9
use matrix::select_k in bfknn call
benfred Feb 14, 2023
96e05e1
expose bf detail specialization
benfred Feb 15, 2023
59060b2
Revert "use pw specializations in rbc"
benfred Feb 15, 2023
c734bac
Add tests for other metrics
benfred Feb 15, 2023
c65e4bb
Fix parameter order
benfred Feb 16, 2023
3830e53
Fix Lp distance
benfred Feb 17, 2023
3f0b9a7
Revert "use matrix::select_k in bfknn call"
benfred Feb 17, 2023
3900570
re-enable failing tests
benfred Feb 17, 2023
8e71915
fix cosine/innerproduct in bfknn
benfred Feb 17, 2023
f806bf6
Test JensenShannon distance
benfred Feb 17, 2023
3315dca
support k up to 2048 in faiss select
benfred Feb 18, 2023
1b6eda2
Merge remote-tracking branch 'origin/branch-23.04' into bfknn
benfred Feb 18, 2023
a83bef3
cmake format
benfred Feb 18, 2023
3b811a1
support k up to 2048 in faiss select
benfred Feb 18, 2023
9a19456
Merge branch 'branch-23.04' into faiss_largek
cjnolet Feb 18, 2023
c39dc65
style
benfred Feb 18, 2023
c60e17f
Merge branch 'faiss_largek' of github.com:benfred/raft into faiss_largek
benfred Feb 18, 2023
2752294
code review suggestions
benfred Feb 18, 2023
84f7a42
Merge remote-tracking branch 'bf/faiss_largek' into bfknn
benfred Feb 18, 2023
901b898
Merge branch 'branch-23.04' into bfknn
cjnolet Feb 20, 2023
1548a78
Remove ENABLE_NN_DEPENDENCIES option
benfred Feb 21, 2023
3fdc712
Merge branch 'branch-23.04' into bfknn
benfred Feb 21, 2023
642f87d
Adding brute-force knn api to pylibraft
cjnolet Feb 21, 2023
1ac42af
Merge branch 'branch-23.04' into fea-2304-bfknn
cjnolet Feb 21, 2023
31c9cf2
temporarily re-add faiss build targets
benfred Feb 21, 2023
f7fd6a7
couple more files to re-add faiss
benfred Feb 21, 2023
37d66d2
re-add faiss_mr
benfred Feb 22, 2023
a61c92f
explicitly include faiss_mr
benfred Feb 23, 2023
dbd31b2
Allow col_major input to bfknn
benfred Feb 24, 2023
fddecc3
fix faiss queryempty test
benfred Feb 24, 2023
4687144
exclude LP from fused
benfred Feb 27, 2023
bd3ff51
Merge branch 'branch-23.04' into bfknn
benfred Feb 27, 2023
06c8674
use metric processor for cosine/correlation
benfred Feb 27, 2023
b44d15c
exclude cosine
benfred Feb 28, 2023
5a582cd
Merge branch 'branch-23.04' into bfknn
benfred Mar 1, 2023
eb0271a
avoid l2expanded distance
benfred Mar 1, 2023
616455c
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred Mar 1, 2023
03a493b
Adding copyright
cjnolet Mar 1, 2023
fd6f1b1
Merge branch 'branch-23.04' into fea-2304-example_template
cjnolet Mar 1, 2023
f6a1f63
Checking in
cjnolet Mar 6, 2023
4d25620
Merge branch 'fea-2304-example_template' of github.com:cjnolet/raft i…
cjnolet Mar 6, 2023
4c41c63
Expanded L2 Changes
benfred Mar 6, 2023
cdf1962
correct for small instabilities in l2sqrtexpanded distance
benfred Mar 7, 2023
6a1e2d8
warp divergence
benfred Mar 7, 2023
1e2817c
clamp to 0
benfred Mar 7, 2023
4b56fac
threshold
benfred Mar 7, 2023
7acd1c9
Passing some more options through
cjnolet Mar 7, 2023
4b41e2c
Transpose for fusedl2knn as well
benfred Mar 8, 2023
455c952
fix
benfred Mar 8, 2023
df46b65
Fix stream handling on col-major inputs
benfred Mar 8, 2023
97a3c01
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred Mar 8, 2023
f628aab
Merge branch 'branch-23.04' into fea-2304-example_template
cjnolet Mar 8, 2023
105bc96
Merge branch 'branch-23.04' into bfknn
benfred Mar 9, 2023
2828c3b
Merge branch 'branch-23.04' into bfknn
benfred Mar 9, 2023
ae24aad
Merge branch 'branch-23.04' into fea-2304-example_template
cjnolet Mar 9, 2023
6e45267
Merge branch 'branch-23.04' into bfknn
benfred Mar 11, 2023
f426510
Merge branch 'branch-23.04' into fea-2304-bfknn
benfred Mar 11, 2023
11ede61
Merge branch 'branch-23.04' into fea-2304-example_template
cjnolet Mar 11, 2023
754ab9a
Merge remote-tracking branch 'ben/bfknn' into fea-2304-bfknn
cjnolet Mar 11, 2023
a35ec7b
Including specializations in bfknn runtime API
cjnolet Mar 11, 2023
63cf2ac
Start of PoC to remove NN lib
cjnolet Mar 11, 2023
2a7ff38
Removing faiss fully
cjnolet Mar 11, 2023
1280fb5
Removing pinned subpackage libraft-nn
cjnolet Mar 11, 2023
7f22d7f
Updating readme
cjnolet Mar 11, 2023
655e4db
libraft-distance -> libraft and raft::distance -> raft::compiled
cjnolet Mar 11, 2023
b6bd58e
Updating docs
cjnolet Mar 11, 2023
bc6938d
Fixing ci/* scripts
cjnolet Mar 11, 2023
0893d69
Removing raft::distance from remaining pylibraft cmakelists
cjnolet Mar 11, 2023
7c4f6c1
Unhooking brute_force from the ubild for now
cjnolet Mar 11, 2023
babd187
Changing all the compile conditionals in bench and test
cjnolet Mar 12, 2023
a936fe3
Exporting cutlass through raft-exports instead of just the compiled lib
cjnolet Mar 12, 2023
d9e8f62
Removing some more old and unsed cmake options
cjnolet Mar 12, 2023
8fa985c
Fixing typo
cjnolet Mar 12, 2023
7b4596b
Fixing build.sh
cjnolet Mar 12, 2023
420ca7c
Merge branch 'branch-23.04' into fea-2304-remove-nn-lib
cjnolet Mar 12, 2023
0127f99
Had one more to change
cjnolet Mar 12, 2023
ac74285
Merge branch 'fea-2304-remove-nn-lib' of github.com:cjnolet/raft into…
cjnolet Mar 12, 2023
d8e3191
Fixing build.sh
cjnolet Mar 12, 2023
5b4013f
Removing unneeded import
cjnolet Mar 12, 2023
28ebeef
fix build for missing symbols
benfred Mar 13, 2023
9917324
Merge branch 'branch-23.04' into bfknn
cjnolet Mar 13, 2023
65d7725
code review feedback
benfred Mar 14, 2023
e41ff88
matrix::fill and linalg::map_offset
benfred Mar 14, 2023
5eb7d22
build fix
benfred Mar 14, 2023
e36d089
fix
benfred Mar 14, 2023
50e366f
Merge branch 'branch-23.04' into bfknn
benfred Mar 14, 2023
bf6cdea
Small updates to docs
cjnolet Mar 14, 2023
e8f9c55
move faiss_select into raft::neighbors namespace
benfred Mar 14, 2023
a5d5865
Merge branch 'branch-23.04' into fea-2304-remove-nn-lib
cjnolet Mar 14, 2023
24004e3
Removing faiss from build
cjnolet Mar 14, 2023
6b01a17
Merge remote-tracking branch 'ben/bfknn' into build-2306-remove_faiss
cjnolet Mar 14, 2023
4d49ffd
Removing faissmr
cjnolet Mar 14, 2023
5ce9230
Removing faiss from docs
cjnolet Mar 14, 2023
6cf5c99
Merge branch 'build-2306-remove_faiss' into fea-2304-remove-nn-lib
cjnolet Mar 14, 2023
cc19b1b
Merge branch 'fea-2304-remove-nn-lib' of github.com:cjnolet/raft into…
cjnolet Mar 14, 2023
9f211a0
move knn_merge parts to its own file
benfred Mar 14, 2023
be4ca13
Removing faiss from conda recipe and dev env
cjnolet Mar 14, 2023
6b10ba6
Fixing typo
cjnolet Mar 14, 2023
9cbac3c
Merge branch 'branch-23.04' into bfknn
cjnolet Mar 14, 2023
0667526
Merge remote-tracking branch 'origin/branch-23.04' into bfknn
benfred Mar 15, 2023
9593ae1
Use stream pool
benfred Mar 15, 2023
76d2b19
Merge branch 'bfknn' of github.com:benfred/raft into bfknn
benfred Mar 15, 2023
01fb23b
Merge remote-tracking branch 'ben/bfknn' into build-2306-remove_faiss
cjnolet Mar 15, 2023
33dcc4a
Merge branch 'build-2306-remove_faiss' into fea-2304-remove-nn-lib
cjnolet Mar 15, 2023
7732118
Merge branch 'fea-2304-remove-nn-lib' into fea-2304-example_template
cjnolet Mar 15, 2023
8ace00b
Updating template for post-consolidated build artifacts
cjnolet Mar 15, 2023
70793f6
Merge branch 'fea-2304-example_template' of github.com:cjnolet/raft i…
cjnolet Mar 15, 2023
d5debc7
Merge branch 'branch-23.04' into build-2306-remove_faiss
cjnolet Mar 17, 2023
364dbd9
Merge branch 'build-2306-remove_faiss' into fea-2304-remove-nn-lib
cjnolet Mar 17, 2023
ebf7619
Adding raft.png
cjnolet Mar 17, 2023
44aa123
Adding raft.png
cjnolet Mar 17, 2023
65f6b05
Adding smaller image
cjnolet Mar 17, 2023
7cbd8f3
Trying a slightly larger version
cjnolet Mar 17, 2023
c66ecc0
making a little larger
cjnolet Mar 17, 2023
85d3159
Merge remote-tracking branch 'rapidsai/branch-23.04' into fea-2304-re…
cjnolet Mar 18, 2023
9ec9a9d
Merge branch 'doc-2304_readme_image' into fea-2304-remove-nn-lib
cjnolet Mar 18, 2023
febedc8
Smaller raft.png
cjnolet Mar 18, 2023
8d1169f
Merge branch 'doc-2304-doc_updates' into fea-2304-remove-nn-lib
cjnolet Mar 18, 2023
3d99afd
Using proper raft image
cjnolet Mar 18, 2023
a47938e
Merge branch 'fea-2304-remove-nn-lib' into fea-2304-example_template
cjnolet Mar 18, 2023
9ca1f2b
Merge branch 'branch-23.04' into fea-2304-example_template
cjnolet Mar 20, 2023
64cd29b
Merge branch 'branch-23.04' into fea-2304-example_template
cjnolet Mar 20, 2023
048e0ca
Fixing template
cjnolet Mar 21, 2023
ae8fc7f
Merge branch 'fea-2304-example_template' of github.com:cjnolet/raft i…
cjnolet Mar 21, 2023
17c2aab
Fixing build.sh
cjnolet Mar 21, 2023
49ec1b9
Making sure example works.
cjnolet Mar 21, 2023
478e2fa
Merge remote-tracking branch 'rapidsai/branch-23.04' into fea-2304-ex…
cjnolet Mar 21, 2023
abf45cc
Adding docs around new example template
cjnolet Mar 21, 2023
998a7c8
Merge branch 'branch-23.04' into fea-2304-example_template
cjnolet Mar 22, 2023
c9e6aeb
Building template
cjnolet Mar 23, 2023
42ca474
Not using ccache by default (since it's throwing an error in ci)
cjnolet Mar 23, 2023
55fc202
Apply suggestions from code review
cjnolet Mar 23, 2023
71e5ce5
Addressing review feedback
cjnolet Mar 23, 2023
5f0114d
Merge branch 'fea-2304-example_template' of github.com:cjnolet/raft i…
cjnolet Mar 23, 2023
905493f
Merge branch 'branch-23.04' into fea-2304-example_template
cjnolet Mar 23, 2023
b5ac84f
Rename FAISS_RAPIDS to RAFT_RAPIDS
cjnolet Mar 23, 2023
d865acc
Small comment
cjnolet Mar 23, 2023
d516c4a
Adding libraft-template as a conda package (which won't be uploaded).
cjnolet Mar 24, 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
61 changes: 12 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# <div align="left"><img src="https://rapids.ai/assets/images/rapids_logo.png" width="90px"/>&nbsp;RAFT: Reusable Accelerated Functions and Tools</div>


![Navigating the canyons of accelerated possibilities](img/raft.png)

## Resources
Expand Down Expand Up @@ -81,9 +80,9 @@ raft::device_resources handle;
int n_samples = 5000;
int n_features = 50;

auto input = raft::make_device_matrix<float>(handle, n_samples, n_features);
auto labels = raft::make_device_vector<int>(handle, n_samples);
auto output = raft::make_device_matrix<float>(handle, n_samples, n_samples);
auto input = raft::make_device_matrix<float, int>(handle, n_samples, n_features);
auto labels = raft::make_device_vector<int, int>(handle, n_samples);
auto output = raft::make_device_matrix<float, int>(handle, n_samples, n_samples);

raft::random::make_blobs(handle, input.view(), labels.view());

Expand Down Expand Up @@ -218,52 +217,15 @@ pip install raft-dask-cu11 --extra-index-url=https://pypi.ngc.nvidia.com

### CMake & CPM

RAFT uses the [RAPIDS-CMake](https://github.com/rapidsai/rapids-cmake) library, which makes it simple to include in downstream cmake projects. RAPIDS CMake provides a convenience layer around CPM.

After [installing](https://github.com/rapidsai/rapids-cmake#installation) rapids-cmake in your project, you can begin using RAFT by placing the code snippet below in a file named `get_raft.cmake` and including it in your cmake build with `include(get_raft.cmake)`. This will make available several targets to add to configure the link libraries for your artifacts.

```cmake

set(RAFT_VERSION "22.12")
set(RAFT_FORK "rapidsai")
set(RAFT_PINNED_TAG "branch-${RAFT_VERSION}")

function(find_and_configure_raft)
set(oneValueArgs VERSION FORK PINNED_TAG COMPILE_LIBRARIES)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

#-----------------------------------------------------
# Invoke CPM find_package()
#-----------------------------------------------------

rapids_cpm_find(raft ${PKG_VERSION}
GLOBAL_TARGETS raft::raft
BUILD_EXPORT_SET projname-exports
INSTALL_EXPORT_SET projname-exports
CPM_ARGS
GIT_REPOSITORY https://github.com/${PKG_FORK}/raft.git
GIT_TAG ${PKG_PINNED_TAG}
SOURCE_SUBDIR cpp
OPTIONS
"BUILD_TESTS OFF"
"BUILD_BENCH OFF"
"RAFT_COMPILE_LIBRARIES ${PKG_COMPILE_LIBRARIES}"
)

endfunction()

# Change pinned tag here to test a commit in CI
# To use a different RAFT locally, set the CMake variable
# CPM_raft_SOURCE=/path/to/local/raft
find_and_configure_raft(VERSION ${RAFT_VERSION}.00
FORK ${RAFT_FORK}
PINNED_TAG ${RAFT_PINNED_TAG}
COMPILE_LIBRARIES NO
)
```
RAFT uses the [RAPIDS-CMake](https://github.com/rapidsai/rapids-cmake) library, which makes it easy to include in downstream cmake projects. RAPIDS-CMake provides a convenience layer around CPM. Please refer to [these instructions](https://github.com/rapidsai/rapids-cmake#installation) to install and use rapids-cmake in your project.

#### Example Template Project

You can find an [example RAFT](cpp/template/README.md) project template in the `cpp/template` directory, which demonstrates how to build a new application with RAFT or incorporate RAFT into an existing cmake project.
cjnolet marked this conversation as resolved.
Show resolved Hide resolved

#### CMake Targets

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.
Additional 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 |
|-------------|---------------------|-----------------------------------------------------------|---------------------------------------|
Expand Down Expand Up @@ -317,6 +279,7 @@ The folder structure mirrors other RAPIDS repos, with the following folders:
- `internal`: A private header-only component that hosts the code shared between benchmarks and tests.
- `scripts`: Helpful scripts for development
- `src`: Compiled APIs and template specializations for the shared libraries
- `template`: A skeleton template containing the bare-bones file structure and cmake configuration for writing applications with RAFT.
- `test`: Googletests source code
- `docs`: Source code and scripts for building library documentation (Uses breath, doxygen, & pydocs)
- `python`: Source code for Python libraries.
Expand Down
15 changes: 12 additions & 3 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-lib --allgpuarch --no-nvtx --show_depr_warn -h"
VALIDARGS="clean libraft pylibraft raft-dask docs tests bench template clean --uninstall -v -g -n --compile-lib --allgpuarch --no-nvtx --show_depr_warn -h"
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 @@ -29,6 +29,7 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
docs - build the documentation
tests - build the tests
bench - build the benchmarks
template - build the example RAFT application template
and <flag> is:
-v - verbose build mode
Expand Down Expand Up @@ -354,13 +355,12 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || has
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DCMAKE_CUDA_ARCHITECTURES=${RAFT_CMAKE_CUDA_ARCHITECTURES} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DRAFT_COMPILE_LIBRARIES=${COMPILE_LIBRARIES} \
-DRAFT_COMPILE_LIBRARY=${COMPILE_LIBRARY} \
-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_LIBRARY=${COMPILE_LIBRARY} \
${CACHE_ARGS} \
${EXTRA_CMAKE_ARGS}

Expand Down Expand Up @@ -410,3 +410,12 @@ if hasArg docs; then
cd ${SPHINX_BUILD_DIR}
sphinx-build -b html source _html
fi

################################################################################
# Initiate build for example RAFT application template (if needed)

if hasArg template; then
pushd cpp/template
./build.sh
popd
fi
3 changes: 3 additions & 0 deletions conda/recipes/libraft/build_libraft_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash
# Copyright (c) 2022-2023, NVIDIA CORPORATION.

# Just building template so we verify it uses libraft.so and fail if it doesn't build
./build.sh template
cjnolet marked this conversation as resolved.
Show resolved Hide resolved

./build.sh tests bench --allgpuarch --no-nvtx
cmake --install cpp/build --component testing
38 changes: 38 additions & 0 deletions cpp/template/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# =============================================================================
# Copyright (c) 2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.

cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR)

# ------------- configure rapids-cmake --------------#

include(cmake/thirdparty/fetch_rapids.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-cuda)
include(rapids-export)
include(rapids-find)

# ------------- configure project --------------#

rapids_cuda_init_architectures(test_raft)

project(test_raft LANGUAGES CXX CUDA)

# ------------- configure raft -----------------#

rapids_cpm_init()
include(cmake/thirdparty/get_raft.cmake)

# -------------- compile tasks ----------------- #
add_executable(TEST_RAFT src/test_distance.cu)
target_link_libraries(TEST_RAFT PRIVATE raft::raft raft::compiled)
18 changes: 18 additions & 0 deletions cpp/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Example RAFT Project Template

This template project provides a drop-in sample to either start building a new application with, or using RAFT in an existing CMake project.

First, please refer to our [installation docs](https://docs.rapids.ai/api/raft/stable/build.html#cuda-gpu-requirements) for the minimum requirements to use RAFT.

Once the minimum requirements are satisfied, this example template application can be built with the provided `build.sh` script. This is a bash script that calls the appropriate CMake commands, so you can look into it to see the typical CMake based build workflow.

This directory (`RAFT_SOURCE/cpp/template`) can be copied directly in order to build a new application with RAFT.

RAFT can be integrated into an existing CMake project by copying the contents in the `configure rapids-cmake` and `configure raft` sections of the provided `CMakeLists.txt` into your project, along with `cmake/thirdparty/get_raft.cmake`.

Make sure to link against the appropriate Cmake targets. Use `raft::raft`to add make the headers available and `raft::compiled` when utilizing the shared library.

```cmake
target_link_libraries(your_app_target PRIVATE raft::raft raft::compiled)
```

41 changes: 41 additions & 0 deletions cpp/template/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Copyright (c) 2023, NVIDIA CORPORATION.

# raft empty project template build script

# Abort script on first error
set -e

PARALLEL_LEVEL=${PARALLEL_LEVEL:=`nproc`}

BUILD_TYPE=Release
BUILD_DIR=build/

RAFT_REPO_REL=""
EXTRA_CMAKE_ARGS=""
set -e


if [[ ${RAFT_REPO_REL} != "" ]]; then
RAFT_REPO_PATH="`readlink -f \"${RAFT_REPO_REL}\"`"
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DCPM_raft_SOURCE=${RAFT_REPO_PATH}"
fi

if [ "$1" == "clean" ]; then
rm -rf build
exit 0
fi

mkdir -p $BUILD_DIR
cd $BUILD_DIR

cmake \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DRAFT_NVTX=OFF \
-DCMAKE_CUDA_ARCHITECTURES="NATIVE" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
${EXTRA_CMAKE_ARGS} \
../

cmake --build . -j${PARALLEL_LEVEL}
21 changes: 21 additions & 0 deletions cpp/template/cmake/thirdparty/fetch_rapids.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# =============================================================================
# Copyright (c) 2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.

# Use this variable to update RAPIDS and RAFT versions
set(RAPIDS_VERSION "23.04")
cjnolet marked this conversation as resolved.
Show resolved Hide resolved

if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/RAFT_RAPIDS.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-${RAPIDS_VERSION}/RAPIDS.cmake
${CMAKE_CURRENT_BINARY_DIR}/RAFT_RAPIDS.cmake)
endif()
include(${CMAKE_CURRENT_BINARY_DIR}/RAFT_RAPIDS.cmake)
62 changes: 62 additions & 0 deletions cpp/template/cmake/thirdparty/get_raft.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# =============================================================================
# Copyright (c) 2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.

# Use RAPIDS_VERSION from cmake/thirdparty/fetch_rapids.cmake
set(RAFT_VERSION "${RAPIDS_VERSION}")
set(RAFT_FORK "rapidsai")
set(RAFT_PINNED_TAG "branch-${RAPIDS_VERSION}")

function(find_and_configure_raft)
set(oneValueArgs VERSION FORK PINNED_TAG COMPILE_LIBRARY ENABLE_NVTX ENABLE_MNMG_DEPENDENCIES)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

set(RAFT_COMPONENTS "")
if(PKG_COMPILE_LIBRARY)
string(APPEND RAFT_COMPONENTS " compiled")
endif()

if(PKG_ENABLE_MNMG_DEPENDENCIES)
string(APPEND RAFT_COMPONENTS " distributed")
endif()

#-----------------------------------------------------
# Invoke CPM find_package()
#-----------------------------------------------------
rapids_cpm_find(raft ${PKG_VERSION}
GLOBAL_TARGETS raft::raft
BUILD_EXPORT_SET raft-template-exports
INSTALL_EXPORT_SET raft-template-exports
COMPONENTS ${RAFT_COMPONENTS}
CPM_ARGS
GIT_REPOSITORY https://github.com/${PKG_FORK}/raft.git
GIT_TAG ${PKG_PINNED_TAG}
SOURCE_SUBDIR cpp
OPTIONS
"BUILD_TESTS OFF"
"BUILD_BENCH OFF"
"RAFT_NVTX ${ENABLE_NVTX}"
"RAFT_COMPILE_LIBRARY ${PKG_COMPILE_LIBRARY}"
)
endfunction()

# Change pinned tag here to test a commit in CI
# To use a different RAFT locally, set the CMake variable
# CPM_raft_SOURCE=/path/to/local/raft
find_and_configure_raft(VERSION ${RAFT_VERSION}.00
FORK ${RAFT_FORK}
PINNED_TAG ${RAFT_PINNED_TAG}
COMPILE_LIBRARY ON
ENABLE_MNMG_DEPENDENCIES OFF
ENABLE_NVTX OFF
)
42 changes: 42 additions & 0 deletions cpp/template/src/test_distance.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <cstdint>
#include <raft/core/device_mdarray.hpp>
#include <raft/core/device_resources.hpp>
#include <raft/distance/distance.cuh>
#include <raft/random/make_blobs.cuh>

#ifdef RAFT_COMPILED
#include <raft/distance/specializations.cuh>
#endif

int main()
{
raft::device_resources handle;

int n_samples = 5000;
int n_features = 50;

auto input = raft::make_device_matrix<float, int>(handle, n_samples, n_features);
auto labels = raft::make_device_vector<int, int>(handle, n_samples);
auto output = raft::make_device_matrix<float, int>(handle, n_samples, n_samples);

raft::random::make_blobs(handle, input.view(), labels.view());

auto metric = raft::distance::DistanceType::L2SqrtExpanded;
raft::distance::pairwise_distance(handle, input.view(), input.view(), output.view(), metric);
}
Loading