Skip to content

Commit aecc656

Browse files
authored
Merge pull request NVIDIA#1363 from allisonvacanti/enh/dialect_latest/gh.thrust1321
Add option to enable all supported standards in for multiconfig.
2 parents 41d1a12 + 809acfc commit aecc656

6 files changed

Lines changed: 163 additions & 59 deletions

File tree

CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# 3.15 is the minimum.
2-
# 3.17 for NVC++.
1+
# 3.15 is the minimum for including the project with add_subdirectory.
2+
# 3.17 for building the project's standalone tests/examples/etc.
33
# 3.18 for C++17 + CUDA.
44
cmake_minimum_required(VERSION 3.15)
55

@@ -43,6 +43,9 @@ if (NOT THRUST_TOPLEVEL_PROJECT)
4343
return()
4444
endif()
4545

46+
# We use 3.17 features when building our tests, etc.
47+
cmake_minimum_required(VERSION 3.17)
48+
4649
option(THRUST_ENABLE_HEADER_TESTING "Test that all public headers compile." "ON")
4750
option(THRUST_ENABLE_TESTING "Build Thrust testing suite." "ON")
4851
option(THRUST_ENABLE_EXAMPLES "Build Thrust examples." "ON")
@@ -61,6 +64,7 @@ endif()
6164
include(cmake/AppendOptionIfAvailable.cmake)
6265
include(cmake/ThrustBuildCompilerTargets.cmake)
6366
include(cmake/ThrustBuildTargetList.cmake)
67+
include(cmake/ThrustFindThrust.cmake)
6468
include(cmake/ThrustMultiConfig.cmake)
6569
include(cmake/ThrustUtilities.cmake)
6670

@@ -83,18 +87,19 @@ set(THRUST_LIBRARY_OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib")
8387
set(THRUST_EXECUTABLE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin")
8488

8589
thrust_configure_multiconfig()
90+
thrust_find_thrust()
91+
thrust_build_compiler_targets()
92+
thrust_update_system_found_flags()
93+
if (THRUST_CUDA_FOUND)
94+
include(cmake/ThrustCudaConfig.cmake)
95+
endif()
8696
thrust_build_target_list()
8797

88-
thrust_update_system_found_flags()
8998
message(STATUS "CPP system found? ${THRUST_CPP_FOUND}")
9099
message(STATUS "CUDA system found? ${THRUST_CUDA_FOUND}")
91100
message(STATUS "TBB system found? ${THRUST_TBB_FOUND}")
92101
message(STATUS "OMP system found? ${THRUST_OMP_FOUND}")
93102

94-
if (THRUST_CUDA_FOUND)
95-
include(cmake/ThrustCudaConfig.cmake)
96-
endif()
97-
98103
if (THRUST_ENABLE_HEADER_TESTING)
99104
include(cmake/ThrustHeaderTesting.cmake)
100105
endif()

ci/common/build.bash

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ fi
121121
case "${COVERAGE_PLAN}" in
122122
Exhaustive)
123123
append CMAKE_FLAGS "-DTHRUST_ENABLE_MULTICONFIG=ON"
124-
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP11=ON"
125124
append CMAKE_FLAGS "-DTHRUST_IGNORE_DEPRECATED_CPP_11=ON"
126-
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP14=ON"
127-
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP17=OFF"
125+
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_ALL=ON"
128126
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_SYSTEM_CPP=ON"
129127
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_SYSTEM_TBB=ON"
130128
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_SYSTEM_OMP=ON"
@@ -134,10 +132,8 @@ case "${COVERAGE_PLAN}" in
134132
;;
135133
Thorough)
136134
append CMAKE_FLAGS "-DTHRUST_ENABLE_MULTICONFIG=ON"
137-
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP11=ON"
138135
append CMAKE_FLAGS "-DTHRUST_IGNORE_DEPRECATED_CPP_11=ON"
139-
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP14=ON"
140-
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP17=OFF"
136+
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_ALL=ON"
141137
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_SYSTEM_CPP=ON"
142138
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_SYSTEM_TBB=ON"
143139
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_SYSTEM_OMP=ON"
@@ -155,9 +151,7 @@ case "${COVERAGE_PLAN}" in
155151
;;
156152
Minimal)
157153
append CMAKE_FLAGS "-DTHRUST_ENABLE_MULTICONFIG=ON"
158-
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP11=OFF"
159-
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP14=ON"
160-
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_CPP17=OFF"
154+
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_DIALECT_LATEST=ON"
161155
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_SYSTEM_CPP=ON"
162156
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_SYSTEM_TBB=OFF"
163157
append CMAKE_FLAGS "-DTHRUST_MULTICONFIG_ENABLE_SYSTEM_OMP=OFF"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Detect the langauge standards supported by the current compilers.
2+
#
3+
# Usage: detect_supported_cxx_standards(<var_prefix> <lang> <standards>)
4+
#
5+
# - var_prefix: Used to name result variables,
6+
# e.g. ${var_prefix}_${lang}_XX_SUPPORTED will be TRUE or FALSE. Defined for
7+
# each XX in ${standards}.
8+
# - lang: The language to test: C, CXX, or CUDA.
9+
# - standards: List of any standard versions.
10+
#
11+
# Example: detect_supported_cxx_standards(PROJ CXX 11 14 17)
12+
# - Sets the following variables in the parent scope to TRUE or FALSE:
13+
# - PROJ_CXX_11_SUPPORTED
14+
# - PROJ_CXX_14_SUPPORTED
15+
# - PROJ_CXX_17_SUPPORTED
16+
#
17+
function(detect_supported_standards prefix lang)
18+
string(TOLOWER "${lang}_std" feature_prefix)
19+
foreach(standard IN LISTS ARGN)
20+
set(var_name "${prefix}_${lang}_${standard}_SUPPORTED")
21+
if ("${feature_prefix}_${standard}" IN_LIST CMAKE_${lang}_COMPILE_FEATURES)
22+
set(${var_name} TRUE)
23+
else()
24+
set(${var_name} FALSE)
25+
endif()
26+
message(STATUS "Testing ${lang}${standard} Support: ${${var_name}}")
27+
set(${var_name} ${${var_name}} PARENT_SCOPE)
28+
endforeach()
29+
endfunction()

cmake/ThrustBuildTargetList.cmake

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -165,30 +165,73 @@ function(_thrust_add_target_to_target_list target_name host device dialect prefi
165165
endfunction()
166166

167167
function(_thrust_build_target_list_multiconfig)
168-
# Find thrust and all of the required systems:
169-
set(req_systems)
170-
if (THRUST_MULTICONFIG_ENABLE_SYSTEM_CUDA)
171-
list(APPEND req_systems CUDA)
172-
endif()
173-
if (THRUST_MULTICONFIG_ENABLE_SYSTEM_CPP)
174-
list(APPEND req_systems CPP)
175-
endif()
176-
if (THRUST_MULTICONFIG_ENABLE_SYSTEM_TBB)
177-
list(APPEND req_systems TBB)
178-
endif()
179-
if (THRUST_MULTICONFIG_ENABLE_SYSTEM_OMP)
180-
list(APPEND req_systems OMP)
181-
endif()
168+
# Detect supported dialects if requested -- this must happen after CUDA is
169+
# enabled, if it's going to be enabled.
170+
if (THRUST_MULTICONFIG_ENABLE_DIALECT_ALL OR
171+
THRUST_MULTICONFIG_ENABLE_DIALECT_LATEST)
172+
message(STATUS "Testing for supported language standards...")
173+
include("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/DetectSupportedStandards.cmake")
174+
detect_supported_standards(THRUST CXX ${THRUST_CPP_DIALECT_OPTIONS})
175+
if (THRUST_CUDA_FOUND)
176+
detect_supported_standards(THRUST CUDA ${THRUST_CPP_DIALECT_OPTIONS})
177+
endif()
182178

183-
find_package(Thrust REQUIRED CONFIG
184-
NO_DEFAULT_PATH # Only check the explicit path in HINTS:
185-
HINTS "${Thrust_SOURCE_DIR}"
186-
COMPONENTS ${req_systems}
187-
)
179+
# Take the union of supported standards in CXX and CUDA:
180+
set(supported_dialects)
181+
set(latest_dialect 11)
182+
foreach(standard IN LISTS THRUST_CPP_DIALECT_OPTIONS)
183+
if ((THRUST_CXX_${standard}_SUPPORTED) AND
184+
((NOT THRUST_CUDA_FOUND) OR THRUST_CUDA_${standard}_SUPPORTED))
188185

189-
# This must be called after backends are loaded but
190-
# before _thrust_add_target_to_target_list.
191-
thrust_build_compiler_targets()
186+
# MSVC silently promotes C++11 to C++14 -- skip it:
187+
if ((${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) AND (standard EQUAL 11))
188+
continue()
189+
endif()
190+
191+
list(APPEND supported_dialects ${standard})
192+
if (latest_dialect LESS standard)
193+
set(latest_dialect ${standard})
194+
endif()
195+
endif()
196+
endforeach()
197+
198+
if (THRUST_MULTICONFIG_ENABLE_DIALECT_ALL)
199+
foreach(standard IN LISTS THRUST_CPP_DIALECT_OPTIONS)
200+
if (standard IN_LIST supported_dialects)
201+
set(THRUST_MULTICONFIG_ENABLE_DIALECT_CPP${standard} ON CACHE BOOL
202+
"Generate C++${dialect} build configurations." FORCE
203+
)
204+
else()
205+
set(THRUST_MULTICONFIG_ENABLE_DIALECT_CPP${standard} OFF CACHE BOOL
206+
"Generate C++${dialect} build configurations." FORCE
207+
)
208+
endif()
209+
endforeach()
210+
elseif(THRUST_MULTICONFIG_ENABLE_DIALECT_LATEST)
211+
foreach(standard IN LISTS THRUST_CPP_DIALECT_OPTIONS)
212+
if (standard EQUAL latest_dialect)
213+
set(THRUST_MULTICONFIG_ENABLE_DIALECT_CPP${standard} ON CACHE BOOL
214+
"Generate C++${dialect} build configurations." FORCE
215+
)
216+
else()
217+
set(THRUST_MULTICONFIG_ENABLE_DIALECT_CPP${standard} OFF CACHE BOOL
218+
"Generate C++${dialect} build configurations." FORCE
219+
)
220+
endif()
221+
endforeach()
222+
endif()
223+
endif()
224+
225+
# Supported versions of MSVC do not distinguish between C++11 and C++14.
226+
# Warn the user that they may be generating a ton of redundant targets if
227+
# they explicitly requested this configuration.
228+
if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}" AND
229+
THRUST_MULTICONFIG_ENABLE_DIALECT_CPP11)
230+
message(WARNING
231+
"Supported versions of MSVC (2017+) do not distinguish between C++11 "
232+
"and C++14. The requested C++11 targets may be redundant."
233+
)
234+
endif()
192235

193236
# Build THRUST_TARGETS
194237
foreach(host IN LISTS THRUST_HOST_SYSTEM_OPTIONS)
@@ -225,22 +268,11 @@ function(_thrust_build_target_list_multiconfig)
225268
endfunction()
226269

227270
function(_thrust_build_target_list_singleconfig)
228-
find_package(Thrust REQUIRED CONFIG
229-
NO_DEFAULT_PATH # Only check the explicit path in HINTS:
230-
HINTS "${Thrust_SOURCE_DIR}"
231-
)
232-
thrust_create_target(thrust FROM_OPTIONS ${THRUST_TARGET_FLAGS})
233-
thrust_debug_target(thrust "${THRUST_VERSION}")
234-
235271
set(host ${THRUST_HOST_SYSTEM})
236272
set(device ${THRUST_DEVICE_SYSTEM})
237273
set(dialect ${THRUST_CPP_DIALECT})
238274
set(prefix "thrust") # single config
239275

240-
# This depends on the backends loaded by thrust_create_target, and must
241-
# be called before _thrust_add_target_to_target_list.
242-
thrust_build_compiler_targets()
243-
244276
_thrust_add_target_to_target_list(thrust ${host} ${device} ${dialect} ${prefix})
245277
endfunction()
246278

cmake/ThrustFindThrust.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function(_thrust_find_thrust_multiconfig)
2+
# Check which systems are enabled by multiconfig:
3+
set(req_systems)
4+
if (THRUST_MULTICONFIG_ENABLE_SYSTEM_CUDA)
5+
list(APPEND req_systems CUDA)
6+
endif()
7+
if (THRUST_MULTICONFIG_ENABLE_SYSTEM_CPP)
8+
list(APPEND req_systems CPP)
9+
endif()
10+
if (THRUST_MULTICONFIG_ENABLE_SYSTEM_TBB)
11+
list(APPEND req_systems TBB)
12+
endif()
13+
if (THRUST_MULTICONFIG_ENABLE_SYSTEM_OMP)
14+
list(APPEND req_systems OMP)
15+
endif()
16+
17+
find_package(Thrust REQUIRED CONFIG
18+
NO_DEFAULT_PATH # Only check the explicit path in HINTS:
19+
HINTS "${Thrust_SOURCE_DIR}"
20+
COMPONENTS ${req_systems}
21+
)
22+
endfunction()
23+
24+
function(_thrust_find_thrust_singleconfig)
25+
find_package(Thrust REQUIRED CONFIG
26+
NO_DEFAULT_PATH # Only check the explicit path in HINTS:
27+
HINTS "${Thrust_SOURCE_DIR}"
28+
)
29+
# Create target now to prepare system found flags:
30+
thrust_create_target(thrust FROM_OPTIONS ${THRUST_TARGET_FLAGS})
31+
thrust_debug_target(thrust "${THRUST_VERSION}")
32+
endfunction()
33+
34+
# Build a ${THRUST_TARGETS} list containing target names for all
35+
# requested configurations
36+
function(thrust_find_thrust)
37+
if (THRUST_ENABLE_MULTICONFIG)
38+
_thrust_find_thrust_multiconfig()
39+
else()
40+
_thrust_find_thrust_singleconfig()
41+
endif()
42+
endfunction()

cmake/ThrustMultiConfig.cmake

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ function(thrust_configure_multiconfig)
2424
)
2525
endforeach()
2626

27-
# Supported versions of MSVC do not distinguish between C++11 and C++14.
28-
# Warn the user that they may be generating a ton of redundant targets.
29-
if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}" AND
30-
THRUST_MULTICONFIG_ENABLE_DIALECT_CPP11)
31-
message(WARNING
32-
"Supported versions of MSVC (2017+) do not distinguish between C++11 "
33-
"and C++14. The requested C++11 targets will be built with C++14."
34-
)
35-
endif()
27+
# Option to enable all standards supported by the CUDA and CXX compilers:
28+
option(THRUST_MULTICONFIG_ENABLE_DIALECT_ALL
29+
"Generate build configurations for all C++ standards supported by the configured compilers."
30+
OFF
31+
)
32+
33+
# Option to enable only the most recent supported dialect:
34+
option(THRUST_MULTICONFIG_ENABLE_DIALECT_LATEST
35+
"Generate a single build configuration for the most recent C++ standard supported by the configured compilers."
36+
OFF
37+
)
3638

3739
# Systems:
3840
option(THRUST_MULTICONFIG_ENABLE_SYSTEM_CPP "Generate build configurations that use CPP." ON)
@@ -89,7 +91,7 @@ function(thrust_configure_multiconfig)
8991
)
9092
set(THRUST_MULTICONFIG_WORKLOAD_FULL_CONFIGS
9193
${THRUST_MULTICONFIG_WORKLOAD_LARGE_CONFIGS}
92-
OMP_CPP TBB_CPP OMP_TBB TBB_OMP
94+
OMP_CPP TBB_CPP OMP_TBB TBB_OMP
9395
CACHE INTERNAL "Host/device combos enabled for FULL workloads." FORCE
9496
)
9597

0 commit comments

Comments
 (0)