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

Commit 862bc53

Browse files
committed
Backportable C++17 fixes.
Note that CMake won't support C++17 CUDA targets via the CUDA_STANDARD property until CMake 3.18. Until this, C++17 must be enabled explicitly by setting `--std=c++17` in CMAKE_CUDA_FLAGS. Once CMake 3.18 is released this can be fixed. - Address C++17 deprecated APIs in the allocator layers. Fixes #1214 Bug 200619424 Bug 3043659
1 parent d9d7b51 commit 862bc53

9 files changed

+55
-24
lines changed

testing/binary_search_vector.cu

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <unittest/unittest.h>
22
#include <thrust/binary_search.h>
33

4+
#include <thrust/detail/allocator/allocator_traits.h>
45
#include <thrust/sequence.h>
56
#include <thrust/sort.h>
67
#include <thrust/iterator/discard_iterator.h>
@@ -16,7 +17,8 @@ template <class ExampleVector, typename NewType>
1617
struct vector_like
1718
{
1819
typedef typename ExampleVector::allocator_type alloc;
19-
typedef typename alloc::template rebind<NewType>::other new_alloc;
20+
typedef typename thrust::detail::allocator_traits<alloc> alloc_traits;
21+
typedef typename alloc_traits::template rebind_alloc<NewType> new_alloc;
2022
typedef thrust::detail::vector_base<NewType, new_alloc> type;
2123
};
2224

testing/binary_search_vector_descending.cu

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <thrust/binary_search.h>
33
#include <thrust/functional.h>
44

5+
#include <thrust/detail/allocator/allocator_traits.h>
56
#include <thrust/sequence.h>
67
#include <thrust/sort.h>
78

@@ -14,7 +15,8 @@ template <class ExampleVector, typename NewType>
1415
struct vector_like
1516
{
1617
typedef typename ExampleVector::allocator_type alloc;
17-
typedef typename alloc::template rebind<NewType>::other new_alloc;
18+
typedef typename thrust::detail::allocator_traits<alloc> alloc_traits;
19+
typedef typename alloc_traits::template rebind_alloc<NewType> new_alloc;
1820
typedef thrust::detail::vector_base<NewType, new_alloc> type;
1921
};
2022

testing/functional_placeholders_bitwise.cu

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
#include <thrust/transform.h>
44
#include <thrust/iterator/constant_iterator.h>
55

6+
#include <thrust/detail/allocator/allocator_traits.h>
7+
68
static const size_t num_samples = 10000;
79

810
template<typename Vector, typename U> struct rebind_vector;
911

10-
// TODO: C++11: use rebind from allocator_traits
1112
template<typename T, typename U, typename Allocator>
1213
struct rebind_vector<thrust::host_vector<T, Allocator>, U>
1314
{
14-
typedef thrust::host_vector<U,
15-
typename Allocator::template rebind<U>::other> type;
15+
typedef typename thrust::detail::allocator_traits<Allocator> alloc_traits;
16+
typedef typename alloc_traits::template rebind_alloc<U> new_alloc;
17+
typedef thrust::host_vector<U, new_alloc> type;
1618
};
1719

1820
template<typename T, typename U, typename Allocator>

testing/functional_placeholders_logical.cu

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
#include <thrust/functional.h>
33
#include <thrust/transform.h>
44

5+
#include <thrust/detail/allocator/allocator_traits.h>
6+
57
static const size_t num_samples = 10000;
68

79
template<typename Vector, typename U> struct rebind_vector;
810

9-
// TODO: C++11: use rebind from allocator_traits
1011
template<typename T, typename U, typename Allocator>
1112
struct rebind_vector<thrust::host_vector<T, Allocator>, U>
1213
{
13-
typedef thrust::host_vector<U,
14-
typename Allocator::template rebind<U>::other> type;
14+
typedef typename thrust::detail::allocator_traits<Allocator> alloc_traits;
15+
typedef typename alloc_traits::template rebind_alloc<U> new_alloc;
16+
typedef thrust::host_vector<U, new_alloc> type;
1517
};
1618

1719
template<typename T, typename U, typename Allocator>

testing/functional_placeholders_relational.cu

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
#include <thrust/functional.h>
33
#include <thrust/transform.h>
44

5+
#include <thrust/detail/allocator/allocator_traits.h>
6+
57
static const size_t num_samples = 10000;
68

79
template<typename Vector, typename U> struct rebind_vector;
810

9-
// TODO: C++11: use rebind from allocator_traits
1011
template<typename T, typename U, typename Allocator>
1112
struct rebind_vector<thrust::host_vector<T, Allocator>, U>
1213
{
13-
typedef thrust::host_vector<U,
14-
typename Allocator::template rebind<U>::other> type;
14+
typedef typename thrust::detail::allocator_traits<Allocator> alloc_traits;
15+
typedef typename alloc_traits::template rebind_alloc<U> new_alloc;
16+
typedef thrust::host_vector<U, new_alloc> type;
1517
};
1618

1719
template<typename T, typename U, typename Allocator>

testing/vector_allocators.cu

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
template<typename BaseAlloc, bool PropagateOnSwap>
88
class stateful_allocator : public BaseAlloc
99
{
10+
typedef thrust::detail::allocator_traits<BaseAlloc> base_traits;
11+
1012
public:
1113
stateful_allocator(int i) : state(i)
1214
{
@@ -43,20 +45,35 @@ public:
4345
static int last_allocated;
4446
static int last_deallocated;
4547

46-
typedef
47-
typename thrust::detail::allocator_traits<BaseAlloc>::pointer
48-
pointer;
48+
typedef typename base_traits::pointer pointer;
49+
typedef typename base_traits::const_pointer const_pointer;
50+
typedef typename base_traits::reference reference;
51+
typedef typename base_traits::const_reference const_reference;
4952

5053
pointer allocate(std::size_t size)
5154
{
55+
BaseAlloc alloc;
5256
last_allocated = state;
53-
return BaseAlloc::allocate(size);
57+
return base_traits::allocate(alloc, size);
5458
}
5559

5660
void deallocate(pointer ptr, std::size_t size)
5761
{
62+
BaseAlloc alloc;
5863
last_deallocated = state;
59-
return BaseAlloc::deallocate(ptr, size);
64+
return base_traits::deallocate(alloc, ptr, size);
65+
}
66+
67+
static void construct(pointer ptr)
68+
{
69+
BaseAlloc alloc;
70+
return base_traits::construct(alloc, ptr);
71+
}
72+
73+
static void destroy(pointer ptr)
74+
{
75+
BaseAlloc alloc;
76+
return base_traits::destroy(alloc, ptr);
6077
}
6178

6279
bool operator==(const stateful_allocator &rhs) const

thrust/detail/allocator/allocator_traits.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ template<typename Alloc>
347347
};
348348
#endif
349349

350+
// Deprecated std::allocator typedefs that we need:
351+
typedef typename thrust::detail::pointer_traits<pointer>::reference reference;
352+
typedef typename thrust::detail::pointer_traits<const_pointer>::reference const_reference;
353+
350354
inline __host__ __device__
351355
static pointer allocate(allocator_type &a, size_type n);
352356

thrust/detail/allocator/allocator_traits.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public:
7070
is_empty<allocator_type>
7171
>::type;
7272

73+
// std::allocator_traits doesn't provide these, but
74+
// thrust::detail::allocator_traits does. These used to be part of the
75+
// std::allocator API but were deprecated in C++17.
76+
using reference = typename thrust::detail::pointer_traits<pointer>::reference;
77+
using const_reference = typename thrust::detail::pointer_traits<const_pointer>::reference;
78+
7379
template <typename U>
7480
using rebind_alloc = std::allocator<U>;
7581
template <typename U>

thrust/detail/contiguous_storage.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,8 @@ template<typename T, typename Alloc>
4343
typedef typename alloc_traits::const_pointer const_pointer;
4444
typedef typename alloc_traits::size_type size_type;
4545
typedef typename alloc_traits::difference_type difference_type;
46-
47-
// XXX we should bring reference & const_reference into allocator_traits
48-
// at the moment, it's unclear how -- we have nothing analogous to
49-
// rebind_pointer for references
50-
// we either need to add reference_traits or extend the existing
51-
// pointer_traits to support wrapped references
52-
typedef typename Alloc::reference reference;
53-
typedef typename Alloc::const_reference const_reference;
46+
typedef typename alloc_traits::reference reference;
47+
typedef typename alloc_traits::const_reference const_reference;
5448

5549
typedef thrust::detail::normal_iterator<pointer> iterator;
5650
typedef thrust::detail::normal_iterator<const_pointer> const_iterator;

0 commit comments

Comments
 (0)