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

RMM now leverages rapids-cmake to reduce CMake boilerplate #800

Merged
merged 9 commits into from
Jun 22, 2021
161 changes: 70 additions & 91 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,56 @@
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================
cmake_minimum_required(VERSION 3.18...3.18 FATAL_ERROR)

# If `CMAKE_CUDA_ARCHITECTURES` is not defined, build for all supported architectures. If
# `CMAKE_CUDA_ARCHITECTURES` is set to an empty string (""), build for only the current
# architecture. If `CMAKE_CUDA_ARCHITECTURES` is specified by the user, use user setting.

# This needs to be run before enabling the CUDA language due to the default initialization behavior
# of `CMAKE_CUDA_ARCHITECTURES`, https://gitlab.kitware.com/cmake/cmake/-/issues/21302
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES OR CMAKE_CUDA_ARCHITECTURES STREQUAL "ALL")
set(RMM_BUILD_FOR_ALL_ARCHS TRUE)
elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "")
set(RMM_BUILD_FOR_DETECTED_ARCHS TRUE)
endif()

cmake_minimum_required(VERSION 3.20.1 FATAL_ERROR)

include(FetchContent)
FetchContent_Declare(
rapids-cmake
GIT_REPOSITORY https://github.com/rapidsai/rapids-cmake.git
GIT_TAG origin/branch-21.08
)
FetchContent_MakeAvailable(rapids-cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-export)
include(rapids-find)

project(
RMM
VERSION 21.08.00
LANGUAGES CXX)

include(cmake/Modules/CPM.cmake)
include(cmake/Modules/RMM_thirdparty.cmake)
include(cmake/Modules/Version.cmake)

# Write the version header
write_version()

# build type
rapids_cmake_write_version_file(include/rmm/version_config.hpp)

# Set a default build type if none was specified
set(DEFAULT_BUILD_TYPE "Release")

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "RMM: Setting build type to '${DEFAULT_BUILD_TYPE}' since none specified.")
set(CMAKE_BUILD_TYPE
"${DEFAULT_BUILD_TYPE}"
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel"
"RelWithDebInfo")
endif()
rapids_cmake_build_type(Release)

# build options

option(BUILD_TESTS "Configure CMake to build tests" ON)
option(BUILD_BENCHMARKS "Configure CMake to build (google) benchmarks" OFF)
set(RMM_LOGGING_LEVEL "INFO" CACHE STRING "Choose the logging level.")
set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR"
"CRITICAL" "OFF")

# Set logging level. Must go before including gtests and benchmarks.
# Set the possible values of build type for cmake-gui
message(STATUS "RMM: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'")

# cudart can be statically linked or dynamically linked the python ecosystem wants dynamic linking
option(CUDA_STATIC_RUNTIME "Statically link the CUDA runtime" OFF)

# find packages we depend on

find_package(CUDAToolkit REQUIRED)
rapids_find_package(CUDAToolkit REQUIRED
BUILD_EXPORT_SET rmm-exports
INSTALL_EXPORT_SET rmm-exports
)
rapids_cpm_init()
include(cmake/thirdparty/get_spdlog.cmake)
include(cmake/thirdparty/get_thrust.cmake)

# library targets

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

Expand All @@ -84,87 +79,71 @@ target_link_libraries(rmm INTERFACE spdlog::spdlog_header_only)
target_link_libraries(rmm INTERFACE dl)
target_compile_features(rmm INTERFACE cxx_std_17 $<BUILD_INTERFACE:cuda_std_17>)

# Set logging level. Must go before including gtests and benchmarks.

set(RMM_LOGGING_LEVEL
"INFO"
CACHE STRING "Choose the logging level.")
# Set the possible values of build type for cmake-gui
set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR"
"CRITICAL" "OFF")
message(STATUS "RMM: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'")

if((BUILD_TESTS OR BUILD_BENCHMARKS) AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# Auto-detect available GPU compute architectures
include(${RMM_SOURCE_DIR}/cmake/Modules/SetGPUArchs.cmake)
# Enable the CUDA language after setting CMAKE_CUDA_ARCHITECTURES
include(rapids-cuda)
rapids_cuda_init_architectures(RMM)
enable_language(CUDA)

# Since RMM only enables CUDA optionally we need to manually
# include the file that rapids_cuda_init_architectures relies on `project` calling
include("${CMAKE_PROJECT_RMM_INCLUDE}")
message(STATUS "RMM: Building benchmarks with GPU Architectures: ${CMAKE_CUDA_ARCHITECTURES}")
endif()

# optionally build tests

if(BUILD_TESTS AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
enable_testing()
include(cmake/thirdparty/get_gtest.cmake)
harrism marked this conversation as resolved.
Show resolved Hide resolved
include(CTest) # calls enable_testing()

add_subdirectory(tests)
endif()

# add google benchmark

# optionally build benchmarks
if(BUILD_BENCHMARKS AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(cmake/thirdparty/get_gbench.cmake)
add_subdirectory(benchmarks)
endif()

# install targets

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

install(TARGETS rmm EXPORT rmm-targets)

install(DIRECTORY include/rmm DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# install export targets
install(TARGETS rmm EXPORT rmm-exports)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${RMM_BINARY_DIR}/include/rmm/version_config.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rmm)

include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/rmm-config.cmake.in ${RMM_BINARY_DIR}/cmake/rmm-config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR})
set(doc_string
[=[
Provide targets for RMM: RAPIDS Memory Manager.

write_basic_package_version_file(${RMM_BINARY_DIR}/cmake/rmm-config-version.cmake
COMPATIBILITY SameMinorVersion)
The goal of the [RMM](https://github.com/rapidsai/rmm) is to provide:

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

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

# build export targets

set(RMM_BUILD_DIR_EXPORT_SETTINGS
"list(PREPEND CMAKE_MODULE_PATH \"${RMM_SOURCE_DIR}/cmake/install/\")")
A common interface that allows customizing device and host memory allocation
A collection of implementations of the interface
A collection of data structures that use the interface for memory allocation
]=])

configure_package_config_file(cmake/rmm-config.cmake.in ${RMM_BINARY_DIR}/rmm-config.cmake
INSTALL_DESTINATION ${RMM_BINARY_DIR})
set(code_string
[=[
thrust_create_target(rmm::Thrust FROM_OPTIONS)
]=])

write_basic_package_version_file(${RMM_BINARY_DIR}/rmm-config-version.cmake
COMPATIBILITY SameMinorVersion)
rapids_export(INSTALL rmm
EXPORT_SET rmm-exports
GLOBAL_TARGETS rmm
NAMESPACE rmm::
DOCUMENTATION doc_string
FINAL_CODE_BLOCK code_string)

export(
TARGETS rmm
FILE ${RMM_BINARY_DIR}/rmm-targets.cmake
NAMESPACE rmm::)
# build export targets
rapids_export(BUILD rmm
EXPORT_SET rmm-exports
GLOBAL_TARGETS rmm
NAMESPACE rmm::
DOCUMENTATION doc_string
FINAL_CODE_BLOCK code_string
)

if(RMM_EXPORT_SPDLOG)
export(
APPEND
TARGETS spdlog_header_only
FILE ${RMM_BINARY_DIR}/rmm-targets.cmake)
endif()

# make documentation

Expand Down
10 changes: 0 additions & 10 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@
# the License.
# =============================================================================

# Fetch Google Benchmark

CPMFindPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
VERSION 1.5.2
GIT_SHALLOW TRUE
OPTIONS "BENCHMARK_ENABLE_TESTING OFF" "BENCHMARK_ENABLE_INSTALL OFF")

# Build options

option(DISABLE_DEPRECATION_WARNING "Disable warnings generated from deprecated declarations." OFF)
option(PER_THREAD_DEFAULT_STREAM "Build with per-thread default stream" OFF)

Expand Down
9 changes: 7 additions & 2 deletions ci/checks/style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,22 @@ CMAKE_FORMAT_RETVAL=0
CMAKE_LINTS=()
CMAKE_LINT_RETVAL=0

CURRENT_TAG=$(git tag --merged HEAD | grep -xE '^v.*' | sort --version-sort | tail -n 1 | tr -d 'v')
CURRENT_MAJOR=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[1]}')
CURRENT_MINOR=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[2]}')
CURRENT_SHORT_TAG=${CURRENT_MAJOR}.${CURRENT_MINOR}
gpuci_retry curl -s https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-${CURRENT_SHORT_TAG}/cmake-format-rapids-cmake.json -o cmake/rapids-cmake.json

for cmake_file in "${CMAKE_FILES[@]}"; do
cmake-format --in-place --config-files cmake/config.json -- ${cmake_file}
cmake-format --in-place --config-files cmake/config.json cmake/rapids-cmake.json -- ${cmake_file}
TMP_CMAKE_FORMAT=`git diff --color --exit-code -- ${cmake_file}`
TMP_CMAKE_FORMAT_RETVAL=$?
if [ "$TMP_CMAKE_FORMAT_RETVAL" != "0" ]; then
CMAKE_FORMAT_RETVAL=1
CMAKE_FORMATS+=("$TMP_CMAKE_FORMAT")
fi

TMP_CMAKE_LINT=`cmake-lint --config-files cmake/config.json -- ${cmake_file}`
TMP_CMAKE_LINT=`cmake-lint --config-files cmake/config.json cmake/rapids-cmake.json -- ${cmake_file}`
TMP_CMAKE_LINT_RETVAL=$?
if [ "$TMP_CMAKE_LINT_RETVAL" != "0" ]; then
CMAKE_LINT_RETVAL=1
Expand Down
21 changes: 0 additions & 21 deletions cmake/Modules/CPM.cmake

This file was deleted.

66 changes: 0 additions & 66 deletions cmake/Modules/EvalGPUArchs.cmake

This file was deleted.

33 changes: 0 additions & 33 deletions cmake/Modules/RMM_thirdparty.cmake

This file was deleted.

Loading