-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RAFT skeleton project template (#1312)
This is a copy and modification of a user's project but I think this is going to be generally useful to users as the same types of challenges are going to come up again. In this case, the user wasn't able to build/link because they weren't using `rapids-cmake` to propagate important configuration settings. I think having a skeleton project available that we build in CI and keep up to date will help new users build more applications on RAFT. TODO: - [x] Make building the template optional - [x] Verify this can build in CMake and reuse already built/installed bits - [x] Add to docs / readme and reference in README.md - [x] Add a little example of invoking an API (maybe `pairwise_distances`?) to `main()` Authors: - Corey J. Nolet (https://github.com/cjnolet) - Ben Frederickson (https://github.com/benfred) Approvers: - Micka (https://github.com/lowener) - Dante Gama Dessavre (https://github.com/dantegd) - Divye Gala (https://github.com/divyegala) - AJ Schmidt (https://github.com/ajschmidt8) URL: #1312
- Loading branch information
Showing
14 changed files
with
409 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.