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

[REVIEW] install cmake config file with RMM #580

Merged
merged 19 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- PR #529 Add debug logging and fix multithreaded replay benchmark
- PR #560 Remove deprecated `get/set_default_resource` APIs
- PR #543 Add an arena-based memory resource
- PR #580 Install CMake config with RMM

## Improvements

Expand Down
43 changes: 32 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ option(CUDA_STATIC_RUNTIME "Statically link the CUDA runtime" OFF)

option(PER_THREAD_DEFAULT_STREAM "Build with per-thread default stream" OFF)

option(USE_NVTX "Build with NVTX support" OFF)

###################################################################################################
# find packages we depend on

Expand Down Expand Up @@ -91,18 +89,13 @@ endif(PER_THREAD_DEFAULT_STREAM)
# library targets

add_library(rmm INTERFACE)
add_library(rmm::rmm ALIAS rmm)

target_include_directories(rmm INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)

if(USE_NVTX)
message(STATUS "Using Nvidia Tools Extension")
else()
target_compile_definitions(rmm INTERFACE NVTX_DISABLE)
endif(USE_NVTX)

if(CUDA_STATIC_RUNTIME)
message(STATUS "Enabling static linking of cudart")
target_link_libraries(rmm INTERFACE CUDA::cudart_static)
Expand Down Expand Up @@ -140,12 +133,40 @@ endif(BUILD_BENCHMARKS)
###################################################################################################
# install targets

include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/rmm)

install(TARGETS rmm
DESTINATION lib)
EXPORT rmm-targets)

install(DIRECTORY include/rmm
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/rmm
DESTINATION include)
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/rmm-config.cmake.in
${RMM_BINARY_DIR}/rmm-config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)

write_basic_package_version_file(
${RMM_BINARY_DIR}/rmm-config-version.cmake
COMPATIBILITY SameMinorVersion
)

install(EXPORT rmm-targets
FILE rmm-targets.cmake
NAMESPACE rmm::
DESTINATION ${INSTALL_CONFIGDIR}
)

install(FILES
${RMM_BINARY_DIR}/rmm-config.cmake
${RMM_BINARY_DIR}/rmm-config-version.cmake
${RMM_SOURCE_DIR}/cmake/install/FindThrust.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)

###################################################################################################
# make documentation

Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,43 @@ $ pytest -v

Done! You are ready to develop for the RMM OSS project.

### Caching third-party dependencies

RMM uses [CPM.cmake](https://github.com/TheLartians/CPM.cmake) to
handle third-party dependencies like spdlog, Thrust, GoogleTest,
GoogleBenchmark. In general you won't have to worry about it. If CMake
finds an appropriate version on your system, it uses it (you can
help it along by setting `CMAKE_PREFIX_PATH` to point to the
installed location). Otherwise those dependencies will be downloaded as
part of the build.

If you frequently start new builds from scratch, consider setting the
environment variable `CPM_SOURCE_CACHE` to an external download
directory to avoid repeated downloads of the third-party dependencies.

## Using RMM in a downstream CMake project

The installed RMM library provides a set of config files that makes it easy to
integrate RMM into your own CMake project. In your `CMakeLists.txt`, just add

```cmake
find_package(rmm [VERSION])
# ...
target_link_libraries(<your-target> (PRIVATE|PUBLIC) rmm::rmm)
```

Since RMM is a header-only library, this does not actually link RMM,
but it makes the headers available and pulls in transitive dependencies.
If RMM is not installed in a default location, use
`CMAKE_PREFIX_PATH` or `rmm_ROOT` to point to its location.

One of RMM's dependencies is the Thrust library, so the above
automatically pulls in `Thrust` by means of a dependency on the
`rmm::Thrust` target. By default it uses the standard configuration of
Thrust. If you want to customize it, you can set the variables
`THRUST_HOST_SYSTEM` and `THRUST_DEVICE_SYSTEM`; see
[Thrust's CMake documentation](https://github.com/NVIDIA/thrust/blob/main/thrust/cmake/README.md).

# Using RMM in C++

The first goal of RMM is to provide a common interface for device and host memory allocation.
Expand Down
14 changes: 13 additions & 1 deletion cmake/RMM_thirdparty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@ include(FetchContent)
###################################################################################################
# - spdlog ----------------------------------------------------------------------------------------

set(RMM_MIN_VERSION_spdlog 1.7.0)

CPMFindPackage(
NAME spdlog
GITHUB_REPOSITORY gabime/spdlog
VERSION 1.7.0
VERSION ${RMM_MIN_VERSION_spdlog}
GIT_SHALLOW TRUE
OPTIONS
# If there is no pre-installed spdlog we can use, we'll install our fetched copy
# together with RMM
"SPDLOG_INSTALL TRUE"
)

###################################################################################################
# - thrust/cub ------------------------------------------------------------------------------------

set(RMM_MIN_VERSION_Thrust 1.9.0)

CPMFindPackage(
NAME Thrust
GITHUB_REPOSITORY NVIDIA/thrust
GIT_TAG 1.10.0
VERSION 1.10.0
GIT_SHALLOW TRUE
OPTIONS
# If there is no pre-installed thrust we can use, we'll install our fetched copy
# together with RMM
"THRUST_INSTALL TRUE"
)

thrust_create_target(rmm::Thrust FROM_OPTIONS)
Expand Down
65 changes: 65 additions & 0 deletions cmake/install/FindThrust.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

# FindThrust
# ---------
#
# Try to find Thrust
#
# Uses Thrust_ROOT in the cache variables or in the environment as a hint
# where to search
#
# IMPORTED Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines a basic `thrust_create_target` function as provided
# otherwise by the newer Thrust >= 1.9.10 included configs.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables:
#
# ``Thrust_FOUND``
# system has Thrust
# ``Thrust_INCLUDE_DIRS``
# the Thrust include directories

include(FindPackageHandleStandardArgs)

# try to find Thrust via installed config first
find_package(Thrust QUIET CONFIG)
if (Thrust_FOUND)
find_package_handle_standard_args(Thrust CONFIG_MODE)
return()
endif()

cmake_minimum_required(VERSION 3.17..3.18 FATAL_ERROR)

find_dependency(CUDAToolkit)

find_path(Thrust_INCLUDE_DIRS
NAMES thrust/version.h
HINTS ${CUDAToolkit_INCLUDE_DIRS})

file(READ ${Thrust_INCLUDE_DIRS}/thrust/version.h _version_header)
string(REGEX MATCH "#define THRUST_VERSION ([0-9]*)" _match "${_version_header}")
math(EXPR major "${CMAKE_MATCH_1} / 100000")
math(EXPR minor "(${CMAKE_MATCH_1} / 100) % 1000")
math(EXPR subminor "${CMAKE_MATCH_1} % 100")
set(Thrust_VERSION "${major}.${minor}.${subminor}")

find_package_handle_standard_args(Thrust
REQUIRED_VARS Thrust_INCLUDE_DIRS
VERSION_VAR Thrust_VERSION)

if (Thrust_FOUND)
function(thrust_create_target tgt)
if(NOT TARGET ${tgt})
# can't use a regular IMPORTED INTERFACE target since that'll
# use -isystem, leading to the wrong search order with nvcc
add_library(thrust_internal INTERFACE)
set_target_properties(thrust_internal PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Thrust_INCLUDE_DIRS}")
add_library(${tgt} ALIAS thrust_internal)
endif()
endfunction()
endif()
30 changes: 30 additions & 0 deletions cmake/rmm-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

@PACKAGE_INIT@

cmake_minimum_required(VERSION 3.17)

# make the bundled find modules in this directory available
set(_save_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}")

include(CMakeFindDependencyMacro)

find_dependency(CUDAToolkit)

find_dependency(spdlog @RMM_MIN_VERSION_spdlog@)

find_dependency(Thrust @RMM_MIN_VERSION_Thrust@)
thrust_create_target(rmm::Thrust FROM_OPTIONS)

set(CMAKE_MODULE_PATH ${_save_CMAKE_MODULE_PATH})


include("${CMAKE_CURRENT_LIST_DIR}/rmm-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/rmm-config-version.cmake")

check_required_components(rmm)

set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${CMAKE_FIND_PACKAGE_NAME} CONFIG_MODE)