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

Initial build system updates for monorepo #1946

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
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
[submodule "cub"]
path = dependencies/cub
url = ../cub.git
[submodule "libcudacxx"]
path = dependencies/libcudacxx
url = ../libcudacxx.git
14 changes: 3 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
# 3.15 is the minimum for including the project with add_subdirectory.
# 3.17 for building the project's standalone tests/examples/etc.
# 3.18.3 for C++17 + CUDA
# 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 with both
# nvcc and nvc++.
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
cmake_policy(SET CMP0104 OLD)
endif()

project(Thrust NONE)
project(Thrust LANGUAGES NONE)

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

## thrust_fix_clang_nvcc_build_for
Expand All @@ -38,6 +29,7 @@ endfunction()

# This must be done before any languages are enabled:
if (THRUST_TOPLEVEL_PROJECT)
cmake_minimum_required(VERSION 3.21)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name ThrustCompilerHacks doesn't really make sense anymore. ThrustSetCUDAHostCompiler makes it clear what is being done.

include(cmake/ThrustCompilerHacks.cmake)
endif()

Expand Down
29 changes: 8 additions & 21 deletions cmake/ThrustBuildCompilerTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,18 @@ function(thrust_build_compiler_targets)
append_option_if_available("-diag-disable=11076" cxx_compile_options)
endif()

if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
# Today:
# * NVCC accepts CUDA C++ in .cu files but not .cpp files.
# * NVC++ accepts CUDA C++ in .cpp files but not .cu files.
# TODO: This won't be necessary in the future.
list(APPEND cxx_compile_options -cppsuffix=cu)
endif()

add_library(thrust.compiler_interface INTERFACE)

foreach (cxx_option IN LISTS cxx_compile_options)
target_compile_options(thrust.compiler_interface INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:${cxx_option}>
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID: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 :(
# This is:
# if (using CUDA and CUDA_COMPILER is NVCC) add -Xcompiler=opt:
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcompiler=${cxx_option}>
$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:-Xcompiler=${cxx_option}>
)
endforeach()

Expand All @@ -143,19 +135,14 @@ function(thrust_build_compiler_targets)
# Display warning numbers from nvcc cudafe errors:
target_compile_options(thrust.compiler_interface INTERFACE
# If using CUDA w/ NVCC...
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcudafe=--display_error_number>
)

# Tell NVCC to be quiet about deprecated GPU targets:
target_compile_options(thrust.compiler_interface INTERFACE
# If using CUDA w/ NVCC...
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Wno-deprecated-gpu-targets>
$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:-Xcudafe=--display_error_number>
$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:-Wno-deprecated-gpu-targets>
)

# This is kept separate for Github issue #1174.
add_library(thrust.promote_cudafe_warnings INTERFACE)
target_compile_options(thrust.promote_cudafe_warnings INTERFACE
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcudafe=--promote_warnings>
$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:-Xcudafe=--promote_warnings>
)

# Some of our unit tests unconditionally throw exceptions, and compilers will
Expand All @@ -166,7 +153,7 @@ function(thrust_build_compiler_targets)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(thrust.silence_unreachable_code_warnings INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:/wd4702>
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcompiler=/wd4702>
$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:-Xcompiler=/wd4702>
)
endif()

Expand All @@ -180,11 +167,11 @@ function(thrust_build_compiler_targets)
# THRUST_IF_CONSTEXPR to address these warnings.
target_compile_options(thrust.compiler_interface_cpp11 INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:/wd4127>
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcompiler=/wd4127>
$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:-Xcompiler=/wd4127>
)
target_compile_options(thrust.compiler_interface_cpp14 INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:/wd4127>
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcompiler=/wd4127>
$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:-Xcompiler=/wd4127>
)
endif()

Expand Down
16 changes: 0 additions & 16 deletions cmake/ThrustBuildTargetList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,6 @@ function(thrust_set_target_properties target_name host device dialect prefix)
LIBRARY_OUTPUT_DIRECTORY "${THRUST_LIBRARY_OUTPUT_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${THRUST_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 ("CUDA" STREQUAL "${device}" AND
"NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
set_target_properties(${target_name} PROPERTIES
CUDA_RESOLVE_DEVICE_SYMBOLS OFF
)
endif()
endif()
endfunction()

Expand Down
118 changes: 12 additions & 106 deletions cmake/ThrustCompilerHacks.cmake
Original file line number Diff line number Diff line change
@@ -1,110 +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} -stdpar")
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>")

# Setup CMAKE_CXX_LIBRARY_ARCHITECTURE on Debian/Ubuntu so that find_package
# works properly.
if (EXISTS /etc/debian_version)
if (NOT CMAKE_CXX_LIBRARY_ARCHITECTURE)
file(GLOB files_in_lib RELATIVE /lib /lib/*-linux-gnu* )
foreach (file ${files_in_lib})
if ("${file}" MATCHES "${CMAKE_LIBRARY_ARCHITECTURE_REGEX}")
set(CMAKE_CXX_LIBRARY_ARCHITECTURE ${file})
break()
endif()
endforeach()
endif()
if (NOT CMAKE_LIBRARY_ARCHITECTURE)
set(CMAKE_LIBRARY_ARCHITECTURE ${CMAKE_CXX_LIBRARY_ARCHITECTURE})
endif()
endif()
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
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, Thrust'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}
set(tmp "${CMAKE_CUDA_HOST_COMPILER}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this check from all projects.

unset(CMAKE_CUDA_HOST_COMPILER CACHE)
message(FATAL_ERROR
"For convenience, Thrust'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()
endif ()
set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}")
Loading