Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Initial port to new monorepo build system. #704

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
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
29 changes: 8 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
# 3.15 is the minimum.
# 3.17 for NVC++.
# 3.18.3 for C++17 + CUDA.
# 3.15 is the minimum for including the project with add_subdirectory.
# 3.21 is the minimum for the developer build.
cmake_minimum_required(VERSION 3.15)

# Remove this when we use the new CUDA_ARCHITECTURES properties.
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
cmake_policy(SET CMP0104 OLD)
endif()

# CXX is only needed for AppendOptionIfAvailable.
project(CUB NONE)
project(CUB LANGUAGES NONE)

# Determine whether CUB is the top-level project or included into
# another project via add_subdirectory().
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
set(CUB_TOPLEVEL_PROJECT ON)
else()
set(CUB_TOPLEVEL_PROJECT OFF)
endif()
endif ()

# This must be done before any languages are enabled:
if (CUB_TOPLEVEL_PROJECT)
cmake_minimum_required(VERSION 3.21)
include(cmake/CubCompilerHacks.cmake)
endif()

Expand All @@ -30,15 +23,9 @@ endif()
# GNUInstallDirs CMake module.
enable_language(CXX)

# Thrust has its own copy of CUB install rules to handle packaging usecases
# where we want to install CUB headers but aren't actually building anything.
# In these cases the add_subdirectory(dependencies/cub) line in Thrust won't get
# called so we can't rely on CUB providing its own rules.
if (NOT CUB_IN_THRUST)
option(CUB_ENABLE_INSTALL_RULES "Enable installation of CUB" ${CUB_TOPLEVEL_PROJECT})
if (CUB_ENABLE_INSTALL_RULES)
include(cmake/CubInstallRules.cmake)
endif()
option(CUB_ENABLE_INSTALL_RULES "Enable installation of CUB" ${CUB_TOPLEVEL_PROJECT})
if (CUB_ENABLE_INSTALL_RULES)
include(cmake/CubInstallRules.cmake)
endif()

# Support adding CUB to a parent project via add_subdirectory.
Expand Down
44 changes: 11 additions & 33 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ The configuration options for CUB are:

- `CMAKE_BUILD_TYPE={Release, Debug, RelWithDebInfo, MinSizeRel}`
- Standard CMake build option. Default: `RelWithDebInfo`
- `CUB_ENABLE_INSTALL_RULES={ON, OFF}`
- If true, installation rules will be generated for CUB. Default is `ON` when
building CUB alone, and `OFF` when CUB is a subproject added via CMake's
`add_subdirectory`.
- `CUB_ENABLE_HEADER_TESTING={ON, OFF}`
- Whether to test compile public headers. Default is `ON`.
- `CUB_ENABLE_TESTING={ON, OFF}`
Expand All @@ -52,39 +56,13 @@ The configuration options for CUB are:
- Multiple dialects may be targeted in a single build.
- Possible values of `XX` are `{11, 14, 17}`.
- By default, only C++14 is enabled.
- `CUB_ENABLE_COMPUTE_XX={ON, OFF}`
- Setting this has no effect when building CUB as a component of Thrust.
See Thrust's architecture options, which CUB will inherit.
- Controls the targeted CUDA architecture(s)
- Multiple options may be selected when using NVCC as the CUDA compiler.
- Valid values of `XX` are:
`{35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, 80}`
- Default value depends on `CUB_DISABLE_ARCH_BY_DEFAULT`:
- `CUB_ENABLE_COMPUTE_FUTURE={ON, OFF}`
- Setting this has no effect when building CUB as a component of Thrust.
See Thrust's architecture options, which CUB will inherit.
- If enabled, CUDA objects will target the most recent virtual architecture
in addition to the real architectures specified by the
`CUB_ENABLE_COMPUTE_XX` options.
- Default value depends on `CUB_DISABLE_ARCH_BY_DEFAULT`:
- `CUB_DISABLE_ARCH_BY_DEFAULT={ON, OFF}`
- Setting this has no effect when building CUB as a component of Thrust.
See Thrust's architecture options, which CUB will inherit.
- When `ON`, all `CUB_ENABLE_COMPUTE_*` options are initially `OFF`.
- Default: `OFF` (meaning all architectures are enabled by default)
- `CUB_ENABLE_TESTS_WITH_RDC={ON, OFF}`
- Whether to enable Relocatable Device Code when building tests.
Default is `OFF`.
- `CUB_ENABLE_EXAMPLES_WITH_RDC={ON, OFF}`
- Whether to enable Relocatable Device Code when building examples.
Default is `OFF`.
- `CUB_ENABLE_INSTALL_RULES={ON, OFF}`
- Setting this has no effect when building CUB as a component of Thrust.
See Thrust's `THRUST_INSTALL_CUB_HEADERS` option, which controls this
behavior.
- If true, installation rules will be generated for CUB. Default is `ON` when
building CUB alone, and `OFF` when CUB is a subproject added via CMake's
`add_subdirectory`.
- `CUB_ENABLE_RDC_TESTS={ON, OFF}`
- Enable tests that require separable compilation.
- Default is `ON`.
- `CUB_FORCE_RDC={ON, OFF}`
- Enable separable compilation on all targets that are agnostic of RDC.
- Targets that explicitly require RDC to be enabled or disabled will ignore this setting.
- Default is `OFF`.

# Development Model

Expand Down
4 changes: 2 additions & 2 deletions cmake/CubBuildCompilerTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function(cub_build_compiler_targets)
endif()
endif()

if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
if ("NVHPC" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
list(APPEND cxx_compile_options -Mnodaz)
# TODO: Managed memory is currently not supported on windows with WSL
list(APPEND cxx_compile_options -gpu=nomanaged)
Expand All @@ -94,7 +94,7 @@ function(cub_build_compiler_targets)
foreach (cxx_option IN LISTS cxx_compile_options)
target_compile_options(cub.compiler_interface INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:${cxx_option}>
$<$<COMPILE_LANG_AND_ID:CUDA,NVCXX>:${cxx_option}>
$<$<COMPILE_LANG_AND_ID:CUDA,NVHPC>:${cxx_option}>
# Only use -Xcompiler with NVCC, not NVC++.
#
# CMake can't split genexs, so this can't be formatted better :(
Expand Down
17 changes: 1 addition & 16 deletions cmake/CubBuildTargetList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,6 @@ function(cub_set_target_properties target_name dialect prefix)
LIBRARY_OUTPUT_DIRECTORY "${CUB_LIBRARY_OUTPUT_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CUB_EXECUTABLE_OUTPUT_DIR}"
)

# CMake still emits errors about empty CUDA_ARCHITECTURES when CMP0104
# is set to OLD. This suppresses the errors for good.
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
set_target_properties(${target_name}
PROPERTIES
CUDA_ARCHITECTURES OFF
)
endif()

if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
set_target_properties(${target_name} PROPERTIES
CUDA_RESOLVE_DEVICE_SYMBOLS OFF
)
endif()
endif()
endfunction()

Expand Down Expand Up @@ -230,7 +215,7 @@ function(cub_build_target_list)
# Some of the iterators and unittests depend on thrust. We should break the
# cyclical dependency by migrating CUB's Thrust bits into Thrust.
find_package(Thrust ${CUB_VERSION} EXACT CONFIG
HINTS "../../" # Check if we are in thrust/dependencies/cub
HINTS "../thrust" # Monorepo path
)

if (Thrust_FOUND)
Expand Down
101 changes: 12 additions & 89 deletions cmake/CubCompilerHacks.cmake
Original file line number Diff line number Diff line change
@@ -1,93 +1,16 @@
# Set up compiler paths and apply temporary hacks to support NVC++.
# This file must be included before enabling any languages.

# Temporary hacks to make NVC++ work; this requires you to define
# `CMAKE_CUDA_COMPILER_ID=NVCXX` and `CMAKE_CUDA_COMPILER_FORCED=ON`.
if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
# If using NVC++, don't set CXX compiler
if (NOT "${CMAKE_CXX_COMPILER}" STREQUAL "")
unset(CMAKE_CXX_COMPILER CACHE)
message(FATAL_ERROR "You are using NVC++ as your CUDA C++ compiler, but have"
" specified a different ISO C++ compiler; NVC++ acts as both, so please"
" unset the CMAKE_CXX_COMPILER variable."
)
endif()

# We don't set CMAKE_CUDA_HOST_COMPILER for NVC++; if we do, CMake tries to
# pass `-ccbin ${CMAKE_CUDA_HOST_COMPILER}` to NVC++, which it doesn't
# understand.
if (NOT "${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "")
unset(CMAKE_CUDA_HOST_COMPILER CACHE)
message(FATAL_ERROR "You are using NVC++ as your CUDA C++ compiler, but have"
" specified a different host ISO C++ compiler; NVC++ acts as both, so"
" please unset the CMAKE_CUDA_HOST_COMPILER variable."
)
endif()

set(CMAKE_CXX_COMPILER "${CMAKE_CUDA_COMPILER}")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -cuda")
set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${CMAKE_CUDA_COMPILER}")
set(CMAKE_CUDA_LINK_EXECUTABLE
"<CMAKE_CUDA_HOST_LINK_LAUNCHER> <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
endif ()

# We don't set CMAKE_CUDA_HOST_COMPILER for NVC++; if we do, CMake tries to
# pass `-ccbin ${CMAKE_CUDA_HOST_COMPILER}` to NVC++, which it doesn't
# understand.
if ((NOT "NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}"))
if (NOT ("${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "" OR
"${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "${CMAKE_CXX_COMPILER}"))
set(tmp "${CMAKE_CUDA_HOST_COMPILER}")
unset(CMAKE_CUDA_HOST_COMPILER CACHE)
message(FATAL_ERROR
"For convenience, CUB's test harness uses CMAKE_CXX_COMPILER for the "
"CUDA host compiler. Refusing to overwrite specified "
"CMAKE_CUDA_HOST_COMPILER -- please reconfigure without setting this "
"variable. Currently:\n"
"CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\n"
"CMAKE_CUDA_HOST_COMPILER=${tmp}"
)
endif ()
set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}")
endif ()

# Temporary hacks to make NVC++ work; this requires you to define
# `CMAKE_CUDA_COMPILER_ID=NVCXX` and `CMAKE_CUDA_COMPILER_FORCED=ON`.
if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
# Need 3.17 for the properties used below.
cmake_minimum_required(VERSION 3.17)

set(CMAKE_CUDA_STANDARD_DEFAULT 03)

set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "-std=c++03")
set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "-std=c++03")
set(CMAKE_CUDA03_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA03_KNOWN_FEATURES)

set(CMAKE_CUDA11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "-std=c++11")
set(CMAKE_CUDA11_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA11_KNOWN_FEATURES)

set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14")
set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14")
set(CMAKE_CUDA14_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA14_KNOWN_FEATURES)

set(CMAKE_CUDA17_STANDARD_COMPILE_OPTION "-std=c++17")
set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17")
set(CMAKE_CUDA17_STANDARD__HAS_FULL_SUPPORT TRUE)
set_property(GLOBAL PROPERTY CMAKE_CUDA17_KNOWN_FEATURES)

include(Internal/FeatureTesting)
include(Compiler/CMakeCommonCompilerMacros)
cmake_record_cuda_compile_features()

set(CMAKE_CUDA_COMPILE_FEATURES
${CMAKE_CUDA03_COMPILE_FEATURES}
${CMAKE_CUDA11_COMPILE_FEATURES}
${CMAKE_CUDA14_COMPILE_FEATURES}
${CMAKE_CUDA17_COMPILE_FEATURES}
${CMAKE_CUDA20_COMPILE_FEATURES}
if (NOT ("${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "" OR
"${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "${CMAKE_CXX_COMPILER}"))
set(tmp "${CMAKE_CUDA_HOST_COMPILER}")
unset(CMAKE_CUDA_HOST_COMPILER CACHE)
message(FATAL_ERROR
"For convenience, CUB's test harness uses CMAKE_CXX_COMPILER for the "
"CUDA host compiler. Refusing to overwrite specified "
"CMAKE_CUDA_HOST_COMPILER -- please reconfigure without setting this "
"variable. Currently:\n"
"CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\n"
"CMAKE_CUDA_HOST_COMPILER=${tmp}"
)
endif ()
set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}")
95 changes: 21 additions & 74 deletions cmake/CubCudaConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,87 +1,34 @@
enable_language(CUDA)

if (NOT CUB_IN_THRUST)
message(FATAL_ERROR
"Building CUB as a standalone project is no longer supported. "
"Use the Thrust repo instead.")
endif()

set(CUB_CUDA_FLAGS_BASE "${THRUST_CUDA_FLAGS_BASE}")
set(CUB_CUDA_FLAGS_RDC "${THRUST_CUDA_FLAGS_RDC}")
set(CUB_CUDA_FLAGS_NO_RDC "${THRUST_CUDA_FLAGS_NO_RDC}")

# Update the enabled architectures list from thrust
foreach (arch IN LISTS THRUST_KNOWN_COMPUTE_ARCHS)
if (THRUST_ENABLE_COMPUTE_${arch})
set(CUB_ENABLE_COMPUTE_${arch} True)
string(APPEND arch_message " sm_${arch}")
else()
set(CUB_ENABLE_COMPUTE_${arch} False)
endif()
endforeach()

message(STATUS ${arch_message})

#
# RDC options:
# Architecture options:
#

# RDC is off by default in NVCC and on by default in NVC++. Turning off RDC
# isn't currently supported by NVC++. So, we default to RDC off for NVCC and
# RDC on for NVC++.
set(option_init OFF)
if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
set(option_init ON)
# Since we have to filter the arch list based on target features, we don't
# currently support the convenience arch flags:
if ("all" IN_LIST CMAKE_CUDA_ARCHITECTURES OR
"all-major" IN_LIST CMAKE_CUDA_ARCHITECTURES OR
"native" IN_LIST CMAKE_CUDA_ARCHITECTURES)
message(FATAL_ERROR
"The CUB dev build requires an explicit list of architectures in CMAKE_CUDA_ARCHITECTURES. "
"The convenience flags of 'all', 'all-major', and 'native' are not supported.\n"
"CMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES}")
endif()

option(CUB_ENABLE_TESTS_WITH_RDC
"Build all CUB tests with RDC; tests that require RDC are not affected by this option."
${option_init}
)

option(CUB_ENABLE_EXAMPLES_WITH_RDC
"Build all CUB examples with RDC; examples which require RDC are not affected by this option."
${option_init}
)
# Create a new arch list that only contains arches that support CDP:
set(CUB_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES})
set(CUB_CUDA_ARCHITECTURES_RDC ${CUB_CUDA_ARCHITECTURES})
list(FILTER CUB_CUDA_ARCHITECTURES_RDC EXCLUDE REGEX "53|62|72|90")
alliepiper marked this conversation as resolved.
Show resolved Hide resolved

# Check for RDC/SM compatibility and error/warn if necessary
set(rdc_supported True)
foreach (arch IN LISTS no_rdc_archs)
if (CUB_ENABLE_COMPUTE_${arch})
set(rdc_supported False)
break()
endif()
endforeach()
message(STATUS "CUB_CUDA_ARCHITECTURES: ${CUB_CUDA_ARCHITECTURES}")
message(STATUS "CUB_CUDA_ARCHITECTURES_RDC: ${CUB_CUDA_ARCHITECTURES_RDC}")

set(rdc_opts
CUB_ENABLE_TESTS_WITH_RDC
CUB_ENABLE_EXAMPLES_WITH_RDC
)
set(rdc_requested False)
foreach (rdc_opt IN LISTS rdc_opts)
if (${rdc_opt})
set(rdc_requested True)
break()
endif()
endforeach()
option(CUB_ENABLE_RDC_TESTS "Enable tests that require separable compilation." ON)
option(CUB_FORCE_RDC "Enable separable compilation on all targets that support it." OFF)

if (rdc_requested AND NOT rdc_supported)
string(JOIN ", " no_rdc ${no_rdc_archs})
string(JOIN "\n" opts ${rdc_opts})
message(FATAL_ERROR
"Architectures {${no_rdc}} do not support RDC and are incompatible with "
"these options:\n${opts}"
)
endif()


#
#
# Clang CUDA options
#
if ("Clang" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
set(CUB_CUDA_FLAGS_BASE "${CUB_CUDA_FLAGS_BASE} -Wno-unknown-cuda-version -Xclang=-fcuda-allow-variadic-functions")
endif()


# By default RDC is not used:
set(CMAKE_CUDA_FLAGS "${CUB_CUDA_FLAGS_BASE} ${CUB_CUDA_FLAGS_NO_RDC}")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-unknown-cuda-version -Xclang=-fcuda-allow-variadic-functions")
endif ()
1 change: 1 addition & 0 deletions cmake/CubHeaderTesting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function(cub_add_header_test label definitions)
target_link_libraries(${headertest_target} PUBLIC ${cub_target})
target_compile_definitions(${headertest_target} PRIVATE ${definitions})
cub_clone_target_properties(${headertest_target} ${cub_target})
cub_configure_cuda_target(${headertest_target} RDC ${CUB_FORCE_RDC})

if (CUB_IN_THRUST)
thrust_fix_clang_nvcc_build_for(${headertest_target})
Expand Down
6 changes: 0 additions & 6 deletions cmake/CubInstallRules.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Thrust manages its own copy of these rules. Update ThrustInstallRules.cmake
# if modifying this file.
if (CUB_IN_THRUST)
return()
endif()

# Bring in CMAKE_INSTALL_LIBDIR
include(GNUInstallDirs)

Expand Down
Loading