Skip to content

Commit

Permalink
Build infrastructure and static configuration fixes.
Browse files Browse the repository at this point in the history
- 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 from source code.
- Move the namespace macros/docs out of version.h.
- Remove raw `__cplusplus` checks.
- Use `_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 2015.

- 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 algo + test on MSVC
  - Triage. Looks like a bug in cudafe? See NVIDIA#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
- Fix `_Pragma` check for MSVC (MSVC uses `__pragma`)
- 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.

Other misc changes made for MSVC testing:

- Bump C++ standard to C++14 (prepare for deprecation)
- Add `-Xcudafe --display_error_number` to get useful diagnositics from
    cudafe.
  • Loading branch information
alliepiper committed Apr 8, 2020
1 parent ce9352a commit f18ef8b
Show file tree
Hide file tree
Showing 139 changed files with 538 additions and 394 deletions.
26 changes: 19 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,15 @@ 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)

set(THRUST_TREAT_FILE_AS_CXX "/TP")
else ()
append_option_if_available("-Werror" THRUST_CXX_WARNINGS)
Expand Down Expand Up @@ -243,6 +254,7 @@ 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} -Xcudafe --display_error_number")
endif ()

# For every public header, build a translation unit containing `#include <header>`
Expand Down Expand Up @@ -355,7 +367,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 +395,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 +503,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 +530,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 +629,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 +652,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: 1 addition & 1 deletion dependencies/cub
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>

#include <algorithm>
#include <numeric>
Expand Down Expand Up @@ -42,7 +43,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
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
8 changes: 5 additions & 3 deletions testing/vector_allocators.cu
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <unittest/unittest.h>

#include <thrust/detail/config.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>

Expand All @@ -23,7 +25,7 @@ public:
return *this;
}

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
stateful_allocator(stateful_allocator && other)
: BaseAlloc(std::move(other)), state(other.state)
{
Expand Down Expand Up @@ -129,7 +131,7 @@ void TestVectorAllocatorConstructors()
ASSERT_EQUAL(Alloc::last_allocated, 2);
Alloc::last_allocated = 0;

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
// FIXME: uncomment this after the vector_base(vector_base&&, const Alloc&)
// is fixed and implemented
// Vector v5(std::move(v3), alloc2);
Expand Down Expand Up @@ -188,7 +190,7 @@ void TestVectorAllocatorPropagateOnCopyAssignmentDevice()
}
DECLARE_UNITTEST(TestVectorAllocatorPropagateOnCopyAssignmentDevice);

#if __cplusplus >= 201103L
#if THRUST_CPP_DIALECT >= 2011
template<typename Vector>
void TestVectorAllocatorPropagateOnMoveAssignment()
{
Expand Down
5 changes: 3 additions & 2 deletions thrust/addressof.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# include <memory>
#endif

THRUST_BEGIN_NS
namespace thrust
{

///////////////////////////////////////////////////////////////////////////////

Expand All @@ -28,5 +29,5 @@ T* addressof(T& arg)

///////////////////////////////////////////////////////////////////////////////

THRUST_END_NS
} // end namespace thrust

Loading

0 comments on commit f18ef8b

Please sign in to comment.