Skip to content

Commit b1c3336

Browse files
committed
Temporarily revert NVIDIA#1334 "Add abstractions that use memory accessible from both
hosts and devices" to fix git blame authorship. This reverts commit b778e2a.
1 parent 999d268 commit b1c3336

59 files changed

Lines changed: 2801 additions & 1702 deletions

Some content is hidden

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

CHANGELOG.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ The new `thrust::shuffle` algorithm has been tweaked to improve the randomness
1212
of the output.
1313

1414
Our CMake package and build system continue to see improvements with
15-
better `add_subdirectory` support, installation rules, status messages, and
16-
other features that make Thrust easier to use from CMake projects.
15+
improved `add_subdirectory` support, installation rules, status messages, and
16+
other features that make CUB easier to use from CMake projects.
1717

1818
The release includes several other bugfixes and modernizations, and received
1919
updates from 12 contributors.
@@ -72,12 +72,11 @@ updates from 12 contributors.
7272
- Github's `thrust/cub` repository is now `NVIDIA/cub`
7373
- Development has moved from the `master` branch to the `main` branch.
7474

75-
# Thrust 1.10.0 (NVIDIA HPC SDK 20.9, CUDA Toolkit 11.2)
75+
# Thrust 1.10.0 (NVIDIA HPC SDK 20.9)
7676

7777
## Summary
7878

79-
Thrust 1.10.0 is the major release accompanying the NVIDIA HPC SDK 20.9 release
80-
and the CUDA Toolkit 11.2 release.
79+
Thrust 1.10.0 is the major release accompanying the NVIDIA HPC SDK 20.9 release.
8180
It drops support for C++03, GCC < 5, Clang < 6, and MSVC < 2017.
8281
It also overhauls CMake support.
8382
Finally, we now have a Code of Conduct for contributors:

examples/sorting_aos_vs_soa.cu

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <thrust/host_vector.h>
21
#include <thrust/device_vector.h>
32
#include <thrust/sort.h>
43
#include <thrust/random.h>
@@ -8,7 +7,7 @@
87

98
// This examples compares sorting performance using Array of Structures (AoS)
109
// and Structure of Arrays (SoA) data layout. Legacy applications will often
11-
// store data in C/C++ structs, such as MyStruct defined below. Although
10+
// store data in C/C++ structs, such as MyStruct defined below. Although
1211
// Thrust can process array of structs, it is typically less efficient than
1312
// the equivalent structure of arrays layout. In this particular example,
1413
// the optimized SoA approach is approximately *five times faster* than the
@@ -58,7 +57,7 @@ int main(void)
5857
{
5958
size_t N = 2 * 1024 * 1024;
6059

61-
// Sort Key-Value pairs using Array of Structures (AoS) storage
60+
// Sort Key-Value pairs using Array of Structures (AoS) storage
6261
{
6362
thrust::device_vector<MyStruct> structures(N);
6463

@@ -72,7 +71,7 @@ int main(void)
7271
std::cout << "AoS sort took " << 1e3 * t.elapsed() << " milliseconds" << std::endl;
7372
}
7473

75-
// Sort Key-Value pairs using Structure of Arrays (SoA) storage
74+
// Sort Key-Value pairs using Structure of Arrays (SoA) storage
7675
{
7776
thrust::device_vector<int> keys(N);
7877
thrust::device_vector<float> values(N);

examples/transform_input_output_iterator.cu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <thrust/host_vector.h>
21
#include <thrust/device_vector.h>
32
#include <thrust/functional.h>
43
#include <thrust/gather.h>
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#include <thrust/detail/config.h>
2+
3+
#if THRUST_CPP_DIALECT >= 2011
4+
5+
# include <unittest/unittest.h>
6+
7+
# include <thrust/allocate_unique.h>
8+
# include <thrust/memory/detail/device_system_resource.h>
9+
# include <thrust/mr/allocator.h>
10+
# include <thrust/type_traits/is_contiguous_iterator.h>
11+
12+
# include <numeric>
13+
# include <vector>
14+
15+
namespace
16+
{
17+
18+
template <typename T>
19+
using allocator =
20+
thrust::mr::stateless_resource_allocator<T, thrust::universal_memory_resource>;
21+
22+
// The managed_memory_pointer class should be identified as a
23+
// contiguous_iterator
24+
THRUST_STATIC_ASSERT(
25+
thrust::is_contiguous_iterator<allocator<int>::pointer>::value);
26+
27+
template <typename T>
28+
struct some_object {
29+
some_object(T data)
30+
: m_data(data)
31+
{}
32+
33+
void setter(T data) { m_data = data; }
34+
T getter() const { return m_data; }
35+
36+
private:
37+
T m_data;
38+
};
39+
40+
} // namespace
41+
42+
template <typename T>
43+
void TestAllocateUnique()
44+
{
45+
// Simple test to ensure that pointers created with universal_memory_resource
46+
// can be dereferenced and used with STL code. This is necessary as some
47+
// STL implementations break when using fancy references that overload
48+
// `operator&`, so universal_memory_resource uses a special pointer type that
49+
// returns regular C++ references that can be safely used host-side.
50+
51+
// These operations fail to compile with fancy references:
52+
auto pRaw = thrust::allocate_unique<T>(allocator<T>{}, 42);
53+
auto pObj =
54+
thrust::allocate_unique<some_object<T> >(allocator<some_object<T> >{}, 42);
55+
56+
static_assert(
57+
std::is_same<decltype(pRaw.get()),
58+
thrust::system::cuda::detail::managed_memory_pointer<T> >::value,
59+
"Unexpected pointer returned from unique_ptr::get.");
60+
static_assert(
61+
std::is_same<decltype(pObj.get()),
62+
thrust::system::cuda::detail::managed_memory_pointer<
63+
some_object<T> > >::value,
64+
"Unexpected pointer returned from unique_ptr::get.");
65+
66+
ASSERT_EQUAL(*pRaw, T(42));
67+
ASSERT_EQUAL(*pRaw.get(), T(42));
68+
ASSERT_EQUAL(pObj->getter(), T(42));
69+
ASSERT_EQUAL((*pObj).getter(), T(42));
70+
ASSERT_EQUAL(pObj.get()->getter(), T(42));
71+
ASSERT_EQUAL((*pObj.get()).getter(), T(42));
72+
}
73+
DECLARE_GENERIC_UNITTEST(TestAllocateUnique);
74+
75+
template <typename T>
76+
void TestIterationRaw()
77+
{
78+
auto array = thrust::allocate_unique_n<T>(allocator<T>{}, 6, 42);
79+
80+
static_assert(
81+
std::is_same<decltype(array.get()),
82+
thrust::system::cuda::detail::managed_memory_pointer<T> >::value,
83+
"Unexpected pointer returned from unique_ptr::get.");
84+
85+
for (auto iter = array.get(), end = array.get() + 6; iter < end; ++iter)
86+
{
87+
ASSERT_EQUAL(*iter, T(42));
88+
ASSERT_EQUAL(*iter.get(), T(42));
89+
}
90+
}
91+
DECLARE_GENERIC_UNITTEST(TestIterationRaw);
92+
93+
template <typename T>
94+
void TestIterationObj()
95+
{
96+
auto array =
97+
thrust::allocate_unique_n<some_object<T> >(allocator<some_object<T> >{},
98+
6,
99+
42);
100+
101+
static_assert(
102+
std::is_same<decltype(array.get()),
103+
thrust::system::cuda::detail::managed_memory_pointer<
104+
some_object<T> > >::value,
105+
"Unexpected pointer returned from unique_ptr::get.");
106+
107+
for (auto iter = array.get(), end = array.get() + 6; iter < end; ++iter)
108+
{
109+
ASSERT_EQUAL(iter->getter(), T(42));
110+
ASSERT_EQUAL((*iter).getter(), T(42));
111+
ASSERT_EQUAL(iter.get()->getter(), T(42));
112+
ASSERT_EQUAL((*iter.get()).getter(), T(42));
113+
}
114+
}
115+
DECLARE_GENERIC_UNITTEST(TestIterationObj);
116+
117+
template <typename T>
118+
void TestStdVector()
119+
{
120+
// Verify that a std::vector using the universal allocator will work with
121+
// STL algorithms.
122+
std::vector<T, allocator<T> > v0;
123+
124+
static_assert(
125+
std::is_same<typename std::decay<decltype(v0)>::type::pointer,
126+
thrust::system::cuda::detail::managed_memory_pointer<
127+
T > >::value,
128+
"Unexpected pointer returned from unique_ptr::get.");
129+
130+
v0.resize(6);
131+
std::iota(v0.begin(), v0.end(), 0);
132+
ASSERT_EQUAL(v0[0], T(0));
133+
ASSERT_EQUAL(v0[1], T(1));
134+
ASSERT_EQUAL(v0[2], T(2));
135+
ASSERT_EQUAL(v0[3], T(3));
136+
ASSERT_EQUAL(v0[4], T(4));
137+
ASSERT_EQUAL(v0[5], T(5));
138+
}
139+
DECLARE_GENERIC_UNITTEST(TestStdVector);
140+
141+
#endif // C++11

testing/functional_placeholders_bitwise.cu

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ template<typename T, typename U, typename Allocator>
2424
typename Allocator::template rebind<U>::other> type;
2525
};
2626

27-
template<typename T, typename U, typename Allocator>
28-
struct rebind_vector<thrust::universal_vector<T, Allocator>, U>
29-
{
30-
typedef thrust::universal_vector<U,
31-
typename Allocator::template rebind<U>::other> type;
32-
};
33-
3427
#define BINARY_FUNCTIONAL_PLACEHOLDERS_TEST(name, op, reference_functor, type_list) \
3528
template<typename Vector> \
3629
struct TestFunctionalPlaceholders##name \

testing/functional_placeholders_logical.cu

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ template<typename T, typename U, typename Allocator>
2323
typename Allocator::template rebind<U>::other> type;
2424
};
2525

26-
template<typename T, typename U, typename Allocator>
27-
struct rebind_vector<thrust::universal_vector<T, Allocator>, U>
28-
{
29-
typedef thrust::universal_vector<U,
30-
typename Allocator::template rebind<U>::other> type;
31-
};
32-
3326
#define BINARY_FUNCTIONAL_PLACEHOLDERS_TEST(name, reference_operator, functor) \
3427
template<typename Vector> \
3528
void TestFunctionalPlaceholders##name(void) \

testing/functional_placeholders_relational.cu

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ template<typename T, typename U, typename Allocator>
2323
typename Allocator::template rebind<U>::other> type;
2424
};
2525

26-
template<typename T, typename U, typename Allocator>
27-
struct rebind_vector<thrust::universal_vector<T, Allocator>, U>
28-
{
29-
typedef thrust::universal_vector<U,
30-
typename Allocator::template rebind<U>::other> type;
31-
};
32-
3326
#define BINARY_FUNCTIONAL_PLACEHOLDERS_TEST(name, reference_operator, functor) \
3427
template<typename Vector> \
3528
void TestFunctionalPlaceholdersBinary##name(void) \

0 commit comments

Comments
 (0)