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

Commit

Permalink
Deprecate C++03, C++11, MSVC < 2017, GCC < 5.0
Browse files Browse the repository at this point in the history
Build infrastructure and static configuration fixes:

- Bump CMAKE_CXX_STANDARD to 14
- Add `-Werror all-warnings` to NVCC to promote warnings to errors
- Add `-Xcudafe --display_error_number` to get useful diagnositics from
    cudafe.
- Clean up cub include dir spec in CMake.
- Move THRUST_DEPRECATED logic out of compiler.h and into new header.
- Fix CPP dialect detection on newer MSVC.
- Remove raw `__cplusplus` checks.
- Use `_Pragma`/`__pragma` instead of `#pragma` in macro.
- Remove THRUST_BEGIN/END_NS macros.
  - These were used inconsistently, rendering them non-functional. Removing
    to prevent people from trying to use them.

Workarounds for msvc:

- MSVC isn't a fan of `decltype(...)::some_member` syntax.
  - WAR by aliasing the `decltype(...)` and doing `NewAlias::some_member`
- Missing `template` keyword when rebinding pointer in `async/reduce.h`
- Silence warning C4494 `declspec(allocator) used on non-pointer/ref type`
  - Bug in MSVC STL: microsoft/STL#696
- Disable async sort test on MSVC
  - Triage. Looks like a bug in cudafe? See #1098.
- Add pointer<T>::pointer_to(reference)
  - Required for C++11, hard compile error on MSVC.
- Bring a definition of `atanh` into scope for complex number impl
- Fix floating point literals be declared as floats instead of doubles
- Replace `std::remove_reference<T>::type&` with
  `std::add_lvalue_reference`.
  - Same behavior, and MSVC chokes on the other syntax when followed by
    `__host__`.
- Remove constexpr markup from defaulted functions.
  - These are constexpr by default when possible, and the compilers were
    complaining about the markup in places.
- Use `thrust::detail::integer_traits` instead of `std::numeric_limits`
  in device code.
- Avoid aligning beyond platform limits in alignment.cu.
- Pass /bigobj to MSVC so it can handle the async tests
- Work around MSVC compiler bug by replacing SFINAE with static dispatch

Bug 2865172
Bug 2880936
  • Loading branch information
alliepiper committed Apr 13, 2020
1 parent 8381aba commit 786457e
Show file tree
Hide file tree
Showing 142 changed files with 705 additions and 421 deletions.
31 changes: 24 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ endif ()
add_definitions(-DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_${THRUST_DEVICE_SYSTEM})

# Please note this also sets the default for the CUDA C++ version; see the comment below.
set(CMAKE_CXX_STANDARD 11 CACHE STRING "The C++ version to be used.")
set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ version to be used.")
set(CMAKE_CXX_EXTENSIONS OFF)

message("-- C++ Standard version: ${CMAKE_CXX_STANDARD}")

set(CUB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/dependencies/cub")

if ("CUDA" STREQUAL "${THRUST_DEVICE_SYSTEM}")
if (NOT "${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "")
unset(CMAKE_CUDA_HOST_COMPILER CACHE)
Expand Down Expand Up @@ -177,6 +179,19 @@ if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
# Disable warning about applying unary operator- to unsigned type.
append_option_if_available("/wd4146" THRUST_CXX_WARNINGS)

# MSVC STL assumes that `allocator_traits`'s allocator will use raw pointers,
# and the `__DECLSPEC_ALLOCATOR` macro causes issues with thrust's universal
# allocators:
# warning C4494: 'std::allocator_traits<_Alloc>::allocate' :
# Ignoring __declspec(allocator) because the function return type is not
# a pointer or reference
# See https://github.com/microsoft/STL/issues/696
append_option_if_available("/wd4494" THRUST_CXX_WARNINGS)

# Some of the async tests require /bigobj to fit all their sections into the
# object files:
append_option_if_available("/bigobj" THRUST_CXX_WARNINGS)

set(THRUST_TREAT_FILE_AS_CXX "/TP")
else ()
append_option_if_available("-Werror" THRUST_CXX_WARNINGS)
Expand Down Expand Up @@ -243,6 +258,8 @@ if ("CUDA" STREQUAL "${THRUST_DEVICE_SYSTEM}")
foreach (CXX_OPTION IN LISTS THRUST_CXX_WARNINGS)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=${CXX_OPTION}")
endforeach ()
set(CMAKE_CUDA_FLAGS
"${CMAKE_CUDA_FLAGS} -Werror all-warnings -Xcudafe --display_error_number")
endif ()

# For every public header, build a translation unit containing `#include <header>`
Expand Down Expand Up @@ -355,7 +372,7 @@ endforeach ()
add_library(header-test OBJECT ${THRUST_HEADER_TEST_SOURCES})
target_include_directories(
header-test
PUBLIC ${PROJECT_SOURCE_DIR}
PUBLIC ${PROJECT_SOURCE_DIR} ${CUB_INCLUDE_DIR}
)

include(CTest)
Expand Down Expand Up @@ -383,7 +400,7 @@ endif ()
add_library(thrust_testframework STATIC ${THRUST_TESTFRAMEWORK_FILES})
target_include_directories(
thrust_testframework
PUBLIC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies/cub
PUBLIC ${PROJECT_SOURCE_DIR} ${CUB_INCLUDE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/testing
)

Expand Down Expand Up @@ -491,7 +508,7 @@ foreach (THRUST_TEST_SOURCE IN LISTS THRUST_TESTS)

target_include_directories(
${THRUST_TEST}
PUBLIC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies/cub
PUBLIC ${PROJECT_SOURCE_DIR} ${CUB_INCLUDE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/testing
)

Expand All @@ -518,7 +535,7 @@ foreach (THRUST_TEST_SOURCE IN LISTS THRUST_TESTS)

target_include_directories(
${THRUST_TEST_RDC}
PUBLIC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies/cub
PUBLIC ${PROJECT_SOURCE_DIR} ${CUB_INCLUDE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/testing
)

Expand Down Expand Up @@ -617,7 +634,7 @@ foreach (THRUST_EXAMPLE_SOURCE IN LISTS THRUST_EXAMPLES)

target_include_directories(
${THRUST_EXAMPLE}
PUBLIC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies/cub
PUBLIC ${PROJECT_SOURCE_DIR} ${CUB_INCLUDE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/examples
)

Expand All @@ -640,7 +657,7 @@ foreach (THRUST_EXAMPLE_SOURCE IN LISTS THRUST_EXAMPLES)

target_include_directories(
${THRUST_EXAMPLE_RDC}
PUBLIC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dependencies/cub
PUBLIC ${PROJECT_SOURCE_DIR} ${CUB_INCLUDE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/examples
)

Expand Down
2 changes: 0 additions & 2 deletions doc/thrust.dox
Original file line number Diff line number Diff line change
Expand Up @@ -2063,8 +2063,6 @@ PREDEFINED = THRUST_NOEXCEPT=noexcept \
"THRUST_MR_DEFAULT_ALIGNMENT=alignof(max_align_t)" \
"THRUST_FINAL=final" \
"THRUST_OVERRIDE=" \
"THRUST_BEGIN_NS=namespace thrust {" \
"THRUST_END_NS=}" \
"cuda_cub=system::cuda"

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
Expand Down
5 changes: 3 additions & 2 deletions examples/cuda/async_reduce.cu
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <thrust/detail/config.h>
#include <thrust/device_vector.h>
#include <thrust/reduce.h>
#include <thrust/system/cuda/execution_policy.h>
#include <cassert>

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
#include <future>
#endif

Expand Down Expand Up @@ -52,7 +53,7 @@ int main()
// reset the result
result[0] = 0;

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
// method 2: use std::async to create asynchrony

// copy all the algorithm parameters
Expand Down
3 changes: 2 additions & 1 deletion examples/cuda/global_device_vector.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <thrust/detail/config.h>
#include <thrust/device_vector.h>

// If you create a global `thrust::device_vector` with the default allocator,
Expand All @@ -20,7 +21,7 @@ typedef thrust::system::cuda::detail::cuda_memory_resource<
thrust::cuda::pointer<void>
> device_ignore_shutdown_memory_resource;

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
template <typename T>
using device_ignore_shutdown_allocator =
thrust::mr::stateless_resource_allocator<
Expand Down
3 changes: 2 additions & 1 deletion internal/benchmark/bench.cu
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <thrust/sort.h>
#include <thrust/reduce.h>
#include <thrust/scan.h>
#include <thrust/detail/config.h>

#if THRUST_CPP_DIALECT >= 2011
#include <thrust/shuffle.h>
Expand Down Expand Up @@ -47,7 +48,7 @@

// We don't use THRUST_NOEXCEPT because it's new, and we want this benchmark to
// be backwards-compatible to older versions of Thrust.
#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
#define NOEXCEPT noexcept
#else
#define NOEXCEPT throw()
Expand Down
11 changes: 11 additions & 0 deletions internal/build/common_warnings.mk
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,16 @@ else ifeq ($(OS),win32)

# Disable warning about applying unary - to unsigned type.
CUDACC_FLAGS += -Xcompiler "/wd4146"

# Warning about declspec(allocator) on inappropriate function types
CUDACC_FLAGS += -Xcompiler "/wd4494"

# Allow tests to have lots and lots of sections in each translation unit:
CUDACC_FLAGS += -Xcompiler "/bigobj"
endif

# Promote all NVCC warnings into errors
CUDACC_FLAGS += -Werror all-warnings

# Print warning numbers with cudafe diagnostics
CUDACC_FLAGS += -Xcudafe --display_error_number
19 changes: 18 additions & 1 deletion testing/alignment.cu
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,31 @@ void test_aligned_type()
DECLARE_UNITTEST(test_aligned_type);

template <std::size_t Len, std::size_t Align>
void test_aligned_storage_instantiation()
void test_aligned_storage_instantiation(thrust::detail::true_type /* Align is valid */)
{
typedef typename thrust::detail::aligned_storage<Len, Align>::type type;
ASSERT_GEQUAL(sizeof(type), Len);
ASSERT_EQUAL(THRUST_ALIGNOF(type), Align);
ASSERT_EQUAL(thrust::detail::alignment_of<type>::value, Align);
}

template <std::size_t Len, std::size_t Align>
void test_aligned_storage_instantiation(thrust::detail::false_type /* Align is invalid */)
{
std::cerr << "Skipping test_aligned_storage_instantiation<Len=" << Len
<< ", Align=" << Align << "> (MaxAlign="
<< THRUST_ALIGNOF(thrust::detail::max_align_t) << ").\n";
}

template <std::size_t Len, std::size_t Align>
void test_aligned_storage_instantiation()
{
typedef thrust::detail::integral_constant<
bool, Align <= THRUST_ALIGNOF(thrust::detail::max_align_t)>
ValidAlign;
test_aligned_storage_instantiation<Len, Align>(ValidAlign());
}

template <std::size_t Len>
void test_aligned_storage_size()
{
Expand Down
5 changes: 3 additions & 2 deletions testing/allocator.cu
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <unittest/unittest.h>
#include <thrust/detail/config.h>
#include <thrust/device_malloc_allocator.h>
#include <thrust/system/cpp/vector.h>
#include <memory>
Expand Down Expand Up @@ -202,7 +203,7 @@ void TestAllocatorTraitsRebind()
}
DECLARE_UNITTEST(TestAllocatorTraitsRebind);

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
void TestAllocatorTraitsRebindCpp11()
{
ASSERT_EQUAL(
Expand Down Expand Up @@ -250,5 +251,5 @@ void TestAllocatorTraitsRebindCpp11()
);
}
DECLARE_UNITTEST(TestAllocatorTraitsRebindCpp11);
#endif
#endif // C++11

4 changes: 3 additions & 1 deletion testing/async_sort.cu
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <thrust/detail/config.h>

#if THRUST_CPP_DIALECT >= 2011 && !defined(THRUST_LEGACY_GCC)
// Disabled on MSVC for GH issue #1098
#if THRUST_CPP_DIALECT >= 2011 && !defined(THRUST_LEGACY_GCC) && \
THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC

#include <unittest/unittest.h>

Expand Down
4 changes: 3 additions & 1 deletion testing/complex.cu
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <unittest/unittest.h>

#include <thrust/complex.h>
#include <thrust/detail/config.h>

#include <complex>
#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -273,7 +275,7 @@ struct TestComplexTrigonometricFunctions
ASSERT_ALMOST_EQUAL(sinh(a),sinh(c));
ASSERT_ALMOST_EQUAL(tanh(a),tanh(c));

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011

ASSERT_ALMOST_EQUAL(acos(a),acos(c));
ASSERT_ALMOST_EQUAL(asin(a),asin(c));
Expand Down
7 changes: 4 additions & 3 deletions testing/dependencies_aware_policies.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <unittest/unittest.h>

#include <thrust/detail/config.h>
#include <thrust/detail/seq.h>
#include <thrust/system/cpp/detail/par.h>
#include <thrust/system/omp/detail/par.h>
Expand All @@ -9,7 +10,7 @@
# include <thrust/system/cuda/detail/par.h>
#endif

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011

template<typename T>
struct test_allocator_t
Expand Down Expand Up @@ -178,11 +179,11 @@ SimpleUnitTest<
>
> TestDependencyAttachmentInstance;

#else
#else // C++11

void TestDummy()
{
}
DECLARE_UNITTEST(TestDummy);

#endif
#endif // C++11
10 changes: 6 additions & 4 deletions testing/mr_disjoint_pool.cu
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <unittest/unittest.h>

#include <thrust/detail/config.h>
#include <thrust/mr/disjoint_pool.h>
#include <thrust/mr/new.h>

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
#include <thrust/mr/disjoint_sync_pool.h>
#endif

Expand Down Expand Up @@ -177,7 +179,7 @@ void TestDisjointUnsynchronizedPool()
}
DECLARE_UNITTEST(TestDisjointUnsynchronizedPool);

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
void TestDisjointSynchronizedPool()
{
TestDisjointPool<thrust::mr::disjoint_synchronized_pool_resource>();
Expand Down Expand Up @@ -260,7 +262,7 @@ void TestDisjointUnsynchronizedPoolCachingOversized()
}
DECLARE_UNITTEST(TestDisjointUnsynchronizedPoolCachingOversized);

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
void TestDisjointSynchronizedPoolCachingOversized()
{
TestDisjointPoolCachingOversized<thrust::mr::disjoint_synchronized_pool_resource>();
Expand All @@ -285,7 +287,7 @@ void TestUnsynchronizedDisjointGlobalPool()
}
DECLARE_UNITTEST(TestUnsynchronizedDisjointGlobalPool);

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
void TestSynchronizedDisjointGlobalPool()
{
TestDisjointGlobalPool<thrust::mr::disjoint_synchronized_pool_resource>();
Expand Down
10 changes: 6 additions & 4 deletions testing/mr_pool.cu
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <unittest/unittest.h>

#include <thrust/detail/config.h>
#include <thrust/mr/pool.h>
#include <thrust/mr/new.h>

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
#include <thrust/mr/sync_pool.h>
#endif

Expand Down Expand Up @@ -241,7 +243,7 @@ void TestUnsynchronizedPool()
}
DECLARE_UNITTEST(TestUnsynchronizedPool);

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
void TestSynchronizedPool()
{
TestPool<thrust::mr::synchronized_pool_resource>();
Expand Down Expand Up @@ -324,7 +326,7 @@ void TestUnsynchronizedPoolCachingOversized()
}
DECLARE_UNITTEST(TestUnsynchronizedPoolCachingOversized);

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
void TestSynchronizedPoolCachingOversized()
{
TestPoolCachingOversized<thrust::mr::synchronized_pool_resource>();
Expand All @@ -348,7 +350,7 @@ void TestUnsynchronizedGlobalPool()
}
DECLARE_UNITTEST(TestUnsynchronizedGlobalPool);

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
void TestSynchronizedGlobalPool()
{
TestGlobalPool<thrust::mr::synchronized_pool_resource>();
Expand Down
5 changes: 4 additions & 1 deletion testing/vector.cu
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <unittest/unittest.h>

#include <thrust/detail/config.h>
#include <thrust/sequence.h>
#include <thrust/device_malloc_allocator.h>

#include <vector>
#include <list>
#include <limits>
Expand Down Expand Up @@ -742,7 +745,7 @@ void TestVectorReversed(void)
}
DECLARE_VECTOR_UNITTEST(TestVectorReversed);

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
template <class Vector>
void TestVectorMove(void)
{
Expand Down
Loading

0 comments on commit 786457e

Please sign in to comment.