Skip to content

Commit df8afb8

Browse files
authored
Merge pull request NVIDIA#1359 from allisonvacanti/enh/pedantic_flags/gh.cub228
Enable more warning flags.
2 parents 5d1c0fd + f3e511f commit df8afb8

97 files changed

Lines changed: 725 additions & 663 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 3.15 is the minimum for including the project with add_subdirectory.
22
# 3.17 for building the project's standalone tests/examples/etc.
3-
# 3.18 for C++17 + CUDA.
3+
# 3.18.3 for C++17 + CUDA
44
cmake_minimum_required(VERSION 3.15)
55

66
# Remove this when we use the new CUDA_ARCHITECTURES properties with both

cmake/ThrustBuildCompilerTargets.cmake

Lines changed: 78 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,59 @@
66
# - Interface target providing compiler-specific options needed to build
77
# Thrust's tests, examples, etc.
88
#
9+
# thrust.compiler_interface_cpp11
10+
# thrust.compiler_interface_cpp14
11+
# thrust.compiler_interface_cpp17
12+
# - Interface targets providing compiler-specific options that should only be
13+
# applied to certain dialects of C++.
14+
#
915
# thrust.promote_cudafe_warnings
1016
# - Interface target that adds warning promotion for NVCC cudafe invocations.
1117
# - Only exists to work around github issue #1174 on tbb.cuda configurations.
1218
# - May be combined with thrust.compiler_interface when #1174 is fully resolved.
19+
#
20+
# thrust.silence_unreachable_code_warnings
21+
# - Interface target that silences unreachable code warnings.
22+
# - Used to selectively disable such warnings in unit tests caused by
23+
# unconditionally thrown exceptions.
1324

1425
function(thrust_build_compiler_targets)
1526
set(cxx_compile_definitions)
1627
set(cxx_compile_options)
1728

1829
thrust_update_system_found_flags()
1930

20-
if (THRUST_TBB_FOUND)
21-
# There's a ton of these in the TBB backend, even though the code is correct.
22-
# TODO: silence these warnings in code instead
23-
append_option_if_available("-Wno-unused-parameter" cxx_compile_options)
24-
endif()
25-
2631
if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
27-
# TODO Enable /Wall instead of W3
28-
append_option_if_available("/W3" cxx_compile_options)
32+
append_option_if_available("/W4" cxx_compile_options)
33+
34+
# Treat all warnings as errors. This is only supported on Release builds,
35+
# as `nv_exec_check_disable` doesn't seem to work with MSVC debug iterators
36+
# and spurious warnings are emitted.
37+
# See NVIDIA/thrust#1273, NVBug 3129879.
38+
if (CMAKE_BUILD_TYPE STREQUAL "Release")
39+
append_option_if_available("/WX" cxx_compile_options)
40+
endif()
2941

30-
# Treat all warnings as errors:
31-
append_option_if_available("/WX" cxx_compile_options)
42+
# Suppress overly-pedantic/unavoidable warnings brought in with /W4:
43+
# C4324: structure was padded due to alignment specifier
44+
append_option_if_available("/wd4324" cxx_compile_options)
45+
# C4505: unreferenced local function has been removed
46+
# The CUDA `host_runtime.h` header emits this for
47+
# `__cudaUnregisterBinaryUtil`.
48+
append_option_if_available("/wd4505" cxx_compile_options)
49+
# C4706: assignment within conditional expression
50+
# MSVC doesn't provide an opt-out for this warning when the assignment is
51+
# intentional. Clang will warn for these, but suppresses the warning when
52+
# double-parentheses are used around the assignment. We'll let Clang catch
53+
# unintentional assignments and suppress all such warnings on MSVC.
54+
append_option_if_available("/wd4706" cxx_compile_options)
3255

3356
# Disabled loss-of-data conversion warnings.
3457
# TODO Re-enable.
3558
append_option_if_available("/wd4244" cxx_compile_options)
36-
append_option_if_available("/wd4267" cxx_compile_options)
37-
38-
# Suppress numeric conversion-to-bool warnings.
39-
# TODO Re-enable.
40-
append_option_if_available("/wd4800" cxx_compile_options)
4159

4260
# Disable warning about applying unary operator- to unsigned type.
61+
# TODO Re-enable.
4362
append_option_if_available("/wd4146" cxx_compile_options)
4463

4564
# MSVC STL assumes that `allocator_traits`'s allocator will use raw pointers,
@@ -64,48 +83,29 @@ function(thrust_build_compiler_targets)
6483
append_option_if_available("-Winit-self" cxx_compile_options)
6584
append_option_if_available("-Woverloaded-virtual" cxx_compile_options)
6685
append_option_if_available("-Wcast-qual" cxx_compile_options)
67-
append_option_if_available("-Wno-cast-align" cxx_compile_options)
68-
append_option_if_available("-Wno-long-long" cxx_compile_options)
69-
append_option_if_available("-Wno-variadic-macros" cxx_compile_options)
86+
append_option_if_available("-Wpointer-arith" cxx_compile_options)
87+
append_option_if_available("-Wunused-local-typedef" cxx_compile_options)
88+
append_option_if_available("-Wvla" cxx_compile_options)
89+
90+
# Disable GNU extensions (flag is clang only)
91+
append_option_if_available("-Wgnu" cxx_compile_options)
92+
# Calling a variadic macro with zero args is a GNU extension until C++20,
93+
# but the THRUST_PP_ARITY macro is used with zero args. Need to see if this
94+
# is a real problem worth fixing.
95+
append_option_if_available("-Wno-gnu-zero-variadic-macro-arguments" cxx_compile_options)
96+
97+
# This complains about functions in CUDA system headers when used with nvcc.
7098
append_option_if_available("-Wno-unused-function" cxx_compile_options)
71-
append_option_if_available("-Wno-unused-variable" cxx_compile_options)
7299
endif()
73100

74101
if ("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
75-
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5)
76-
# In GCC 4.4, the CUDA backend's kernel launch templates cause
77-
# impossible-to-decipher "'<anonymous>' is used uninitialized in this
78-
# function" warnings, so we disable uninitialized variable warnings.
79-
append_option_if_available("-Wno-uninitialized" cxx_compile_options)
80-
endif()
81-
82-
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.5)
83-
# This isn't available until GCC 4.3, and misfires on TMP code until
84-
# GCC 4.5.
85-
append_option_if_available("-Wlogical-op" cxx_compile_options)
86-
endif()
87-
88102
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3)
89103
# GCC 7.3 complains about name mangling changes due to `noexcept`
90104
# becoming part of the type system; we don't care.
91105
append_option_if_available("-Wno-noexcept-type" cxx_compile_options)
92106
endif()
93107
endif()
94108

95-
if (("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID}") OR
96-
("XL" STREQUAL "${CMAKE_CXX_COMPILER_ID}"))
97-
# xlC and Clang warn about unused parameters in uninstantiated templates.
98-
# This causes xlC to choke on the OMP backend, which is mostly #ifdef'd out
99-
# (and thus has unused parameters) when you aren't using it.
100-
append_option_if_available("-Wno-unused-parameters" cxx_compile_options)
101-
endif()
102-
103-
if ("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
104-
# -Wunneeded-internal-declaration misfires in the unit test framework
105-
# on older versions of Clang.
106-
append_option_if_available("-Wno-unneeded-internal-declaration" cxx_compile_options)
107-
endif()
108-
109109
if ("Intel" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
110110
# Disable warning that inlining is inhibited by compiler thresholds.
111111
append_option_if_available("-diag-disable=11074" cxx_compile_options)
@@ -159,4 +159,36 @@ function(thrust_build_compiler_targets)
159159
target_compile_options(thrust.promote_cudafe_warnings INTERFACE
160160
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcudafe=--promote_warnings>
161161
)
162+
163+
# Some of our unit tests unconditionally throw exceptions, and compilers will
164+
# detect that the following instructions are unreachable. This is intentional
165+
# and unavoidable in these cases. This target can be used to silence
166+
# unreachable code warnings.
167+
add_library(thrust.silence_unreachable_code_warnings INTERFACE)
168+
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
169+
target_compile_options(thrust.silence_unreachable_code_warnings INTERFACE
170+
$<$<COMPILE_LANGUAGE:CXX>:/wd4702>
171+
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcompiler=/wd4702>
172+
)
173+
endif()
174+
175+
# These targets are used for dialect-specific options:
176+
add_library(thrust.compiler_interface_cpp11 INTERFACE)
177+
add_library(thrust.compiler_interface_cpp14 INTERFACE)
178+
add_library(thrust.compiler_interface_cpp17 INTERFACE)
179+
180+
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
181+
# C4127: conditional expression is constant
182+
# Disable this MSVC warning for C++11/C++14. In C++17, we can use
183+
# THRUST_IF_CONSTEXPR to address these warnings.
184+
target_compile_options(thrust.compiler_interface_cpp11 INTERFACE
185+
$<$<COMPILE_LANGUAGE:CXX>:/wd4127>
186+
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcompiler=/wd4127>
187+
)
188+
target_compile_options(thrust.compiler_interface_cpp14 INTERFACE
189+
$<$<COMPILE_LANGUAGE:CXX>:/wd4127>
190+
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcompiler=/wd4127>
191+
)
192+
endif()
193+
162194
endfunction()

cmake/ThrustBuildTargetList.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ function(thrust_set_target_properties target_name host device dialect prefix)
6161
)
6262

6363
get_target_property(type ${target_name} TYPE)
64-
if (NOT ${type} STREQUAL "INTERFACE_LIBRARY")
64+
if (${type} STREQUAL "INTERFACE_LIBRARY")
65+
target_compile_features(${target_name} INTERFACE
66+
cxx_std_${dialect}
67+
cuda_std_${dialect}
68+
)
69+
else()
70+
target_compile_features(${target_name} PUBLIC
71+
cxx_std_${dialect}
72+
cuda_std_${dialect}
73+
)
6574
set_target_properties(${target_name}
6675
PROPERTIES
6776
CXX_STANDARD ${dialect}
@@ -147,6 +156,7 @@ function(_thrust_add_target_to_target_list target_name host device dialect prefi
147156

148157
target_link_libraries(${target_name} INTERFACE
149158
thrust.compiler_interface
159+
thrust.compiler_interface_cpp${dialect}
150160
)
151161

152162
# Workaround Github issue #1174. cudafe promote TBB header warnings to

cmake/ThrustMultiConfig.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ function(thrust_configure_multiconfig)
4242
option(THRUST_MULTICONFIG_ENABLE_SYSTEM_OMP "Generate build configurations that use OpenMP." OFF)
4343
option(THRUST_MULTICONFIG_ENABLE_SYSTEM_TBB "Generate build configurations that use TBB." OFF)
4444

45-
# CMake added C++17 support for CUDA targets in 3.18:
45+
# CMake fixed C++17 support for NVCC + MSVC targets in 3.18.3:
4646
if (THRUST_MULTICONFIG_ENABLE_DIALECT_CPP17 AND
4747
THRUST_MULTICONFIG_ENABLE_SYSTEM_CUDA)
48-
cmake_minimum_required(VERSION 3.18)
48+
cmake_minimum_required(VERSION 3.18.3)
4949
endif()
5050

5151
# Workload:
@@ -120,10 +120,10 @@ function(thrust_configure_multiconfig)
120120
${THRUST_CPP_DIALECT_OPTIONS}
121121
)
122122

123-
# CMake added C++17 support for CUDA targets in 3.18:
123+
# CMake fixed C++17 support for NVCC + MSVC targets in 3.18.3:
124124
if (THRUST_CPP_DIALECT EQUAL 17 AND
125125
THRUST_DEVICE_SYSTEM STREQUAL "CUDA")
126-
cmake_minimum_required(VERSION 3.18)
126+
cmake_minimum_required(VERSION 3.18.3)
127127
endif()
128128
endif()
129129
endfunction()

dependencies/cub

Submodule cub updated from f5ef160 to b229817

doc/thrust.dox

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,12 +2057,8 @@ INCLUDE_FILE_PATTERNS =
20572057
# recursively expanded use the := operator instead of the = operator.
20582058
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
20592059

2060-
PREDEFINED = THRUST_NOEXCEPT=noexcept \
2061-
"THRUST_DEFAULT={}" \
2062-
"THRUST_NODISCARD=[[nodiscard]]" \
2060+
PREDEFINED = "THRUST_NODISCARD=[[nodiscard]]" \
20632061
"THRUST_MR_DEFAULT_ALIGNMENT=alignof(max_align_t)" \
2064-
"THRUST_FINAL=final" \
2065-
"THRUST_OVERRIDE=" \
20662062
"cuda_cub=system::cuda"
20672063

20682064
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this

examples/cuda/range_view.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ int main()
226226

227227
// print values from original device_vector<float> Z
228228
// to ensure that range view was mapped to this vector
229-
for (int i = 0, n = Z.size(); i < n; ++i)
229+
for (std::size_t i = 0, n = Z.size(); i < n; ++i)
230230
{
231231
cout << "z[" << i << "]= " << Z[i] << endl;
232232
}

examples/raw_reference_cast.cu

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ int main(void)
8484
typedef Vector::iterator Iterator;
8585
typedef thrust::device_system_tag System;
8686

87-
size_t N = 5;
88-
8987
// allocate device memory
90-
Vector A(N);
91-
Vector B(N);
88+
Vector A(5);
89+
Vector B(5);
9290

9391
// initialize A and B
9492
thrust::sequence(A.begin(), A.end());
@@ -100,7 +98,7 @@ int main(void)
10098

10199
// note: we must specify the System to ensure correct execution
102100
thrust::for_each(thrust::counting_iterator<int,System>(0),
103-
thrust::counting_iterator<int,System>(N),
101+
thrust::counting_iterator<int,System>(5),
104102
copy_iterators<Iterator,Iterator>(A.begin(), B.begin()));
105103

106104
std::cout << "After A->B Copy" << std::endl;

examples/sort.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void initialize(thrust::device_vector<int>& v1, thrust::device_vector<int>& v2)
4141
for(size_t i = 0; i < v1.size(); i++)
4242
{
4343
v1[i] = dist(rng);
44-
v2[i] = i;
44+
v2[i] = static_cast<int>(i);
4545
}
4646
}
4747

testing/CMakeLists.txt

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,29 @@ endif()
1717
# Generate testing framework libraries:
1818
add_subdirectory(unittest)
1919

20-
# List of tests that aren't implemented for all backends, but are implemented for CUDA.
21-
set(partially_implemented_CUDA
22-
async_copy
23-
async_for_each
24-
async_reduce
25-
async_reduce_into
26-
async_sort
27-
async_transform
28-
event
29-
future
30-
31-
# This test is incompatible with TBB and OMP, since it requires special per-device
32-
# handling to process exceptions in a device function, which is only implemented
33-
# for CUDA.
34-
unittest_static_assert
35-
)
36-
37-
# List of tests that aren't implemented for all backends, but are implemented for CPP.
38-
set(partially_implemented_CPP
39-
)
40-
41-
# List of tests that aren't implemented for all backends, but are implemented for TBB.
42-
set(partially_implemented_TBB
43-
)
44-
45-
# List of tests that aren't implemented for all backends, but are implemented for OMP.
46-
set(partially_implemented_OMP
47-
)
48-
49-
# List of all partially implemented tests.
50-
set(partially_implemented
51-
${partially_implemented_CUDA}
52-
${partially_implemented_CPP}
53-
${partially_implemented_TBB}
54-
${partially_implemented_OMP}
55-
)
56-
list(REMOVE_DUPLICATES partially_implemented)
20+
# Some tests only support certain host.device configurations. Use this macro to
21+
# declare allowed configurations. If not specified, all host.device config are
22+
# used.
23+
set(restricted_tests)
24+
macro(thrust_declare_test_restrictions test_name)
25+
list(APPEND restricted_tests ${test_name})
26+
list(APPEND ${test_name}_host.device_allowed ${ARGN})
27+
endmacro()
28+
29+
# Async/future/event tests only support the CUDA backend:
30+
thrust_declare_test_restrictions(async_copy CPP.CUDA OMP.CUDA TBB.CUDA)
31+
thrust_declare_test_restrictions(async_for_each CPP.CUDA OMP.CUDA TBB.CUDA)
32+
thrust_declare_test_restrictions(async_reduce CPP.CUDA OMP.CUDA TBB.CUDA)
33+
thrust_declare_test_restrictions(async_reduce_into CPP.CUDA OMP.CUDA TBB.CUDA)
34+
thrust_declare_test_restrictions(async_sort CPP.CUDA OMP.CUDA TBB.CUDA)
35+
thrust_declare_test_restrictions(async_transform CPP.CUDA OMP.CUDA TBB.CUDA)
36+
thrust_declare_test_restrictions(event CPP.CUDA OMP.CUDA TBB.CUDA)
37+
thrust_declare_test_restrictions(future CPP.CUDA OMP.CUDA TBB.CUDA)
38+
39+
# This test is incompatible with TBB and OMP, since it requires special per-device
40+
# handling to process exceptions in a device function, which is only implemented
41+
# for CUDA.
42+
thrust_declare_test_restrictions(unittest_static_assert CPP.CPP CPP.CUDA)
5743

5844
## thrust_add_test
5945
#
@@ -89,7 +75,7 @@ function(thrust_add_test target_name_var test_name test_src thrust_target)
8975
set(test_meta_target thrust.all.test.${test_name})
9076

9177
add_executable(${test_target} "${real_test_src}")
92-
target_link_libraries(${test_target} ${config_framework_target})
78+
target_link_libraries(${test_target} PRIVATE ${config_framework_target})
9379
target_include_directories(${test_target} PRIVATE "${Thrust_SOURCE_DIR}/testing")
9480
thrust_clone_target_properties(${test_target} ${thrust_target})
9581

@@ -140,15 +126,18 @@ file(GLOB test_srcs
140126

141127
# Add common tests to all configs:
142128
foreach(thrust_target IN LISTS THRUST_TARGETS)
129+
thrust_get_target_property(config_host ${thrust_target} HOST)
143130
thrust_get_target_property(config_device ${thrust_target} DEVICE)
144131
thrust_get_target_property(config_prefix ${thrust_target} PREFIX)
145132

146133
foreach(test_src IN LISTS test_srcs)
147134
get_filename_component(test_name "${test_src}" NAME_WLE)
148-
if ("${test_name}" IN_LIST partially_implemented)
149-
# This test is partially implemented on _some_ backends...
150-
if (NOT "${test_name}" IN_LIST partially_implemented_${config_device})
151-
# ...but not on the current one.
135+
136+
# Is this test restricted to only certain host/device combinations?
137+
if(${test_name} IN_LIST restricted_tests)
138+
# Is the current host/device combination supported?
139+
if (NOT "${config_host}.${config_device}" IN_LIST
140+
${test_name}_host.device_allowed)
152141
continue()
153142
endif()
154143
endif()

0 commit comments

Comments
 (0)