Skip to content

Commit d519ea5

Browse files
committed
examples: Fix deprecation warnings with CUDA 13.1+
1 parent d1e6232 commit d519ea5

6 files changed

Lines changed: 61 additions & 7 deletions

File tree

examples/cuda/deque.cu

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ insert_neighbors_with_duplicates(const int* d_input, const stdgpu::index_t n, st
5757
}
5858
}
5959

60+
// thrust 3.1 (CUDA 13.1) encourages using C++ standard conforming functors
61+
#if THRUST_MAJOR_VERSION >= 3 && THRUST_MINOR_VERSION >= 1
62+
template <class T = void>
63+
using plus = cuda::std::plus<T>;
64+
#else
65+
template <class T = void>
66+
using plus = thrust::plus<T>;
67+
#endif
68+
6069
int
6170
main()
6271
{
@@ -87,7 +96,7 @@ main()
8796
// deq : 0, 1, 1, 2, 2, 2, 3, 3, 3, ..., 99, 99, 99, 100, 100, 101
8897

8998
auto range_deq = deq.device_range();
90-
int sum = thrust::reduce(range_deq.begin(), range_deq.end(), 0, thrust::plus<int>());
99+
int sum = thrust::reduce(range_deq.begin(), range_deq.end(), 0, plus<int>());
91100

92101
const int sum_closed_form = 3 * (n * (n + 1) / 2);
93102

examples/cuda/iterator.cu

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ struct is_odd
3232
}
3333
};
3434

35+
// thrust 3.1 (CUDA 13.1) encourages using C++ standard conforming functors
36+
#if THRUST_MAJOR_VERSION >= 3 && THRUST_MINOR_VERSION >= 1
37+
template <class T = void>
38+
using plus = cuda::std::plus<T>;
39+
#else
40+
template <class T = void>
41+
using plus = thrust::plus<T>;
42+
#endif
43+
3544
int
3645
main()
3746
{
@@ -54,7 +63,7 @@ main()
5463

5564
// vec : 1, 3, 5, ..., 99
5665

57-
int sum = thrust::reduce(stdgpu::device_cbegin(vec), stdgpu::device_cend(vec), 0, thrust::plus<int>());
66+
int sum = thrust::reduce(stdgpu::device_cbegin(vec), stdgpu::device_cend(vec), 0, plus<int>());
5867

5968
const int sum_closed_form = n * n / 4;
6069

examples/cuda/mutex_array.cu

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ try_partial_sum(const int* d_input, const stdgpu::index_t n, stdgpu::mutex_array
6464
}
6565
}
6666

67+
// thrust 3.1 (CUDA 13.1) encourages using C++ standard conforming functors
68+
#if THRUST_MAJOR_VERSION >= 3 && THRUST_MINOR_VERSION >= 1
69+
template <class T = void>
70+
using plus = cuda::std::plus<T>;
71+
#else
72+
template <class T = void>
73+
using plus = thrust::plus<T>;
74+
#endif
75+
6776
int
6877
main()
6978
{
@@ -94,7 +103,7 @@ main()
94103
d_result);
95104
cudaDeviceSynchronize();
96105

97-
int sum = thrust::reduce(stdgpu::device_cbegin(d_result), stdgpu::device_cend(d_result), 0, thrust::plus<int>());
106+
int sum = thrust::reduce(stdgpu::device_cbegin(d_result), stdgpu::device_cend(d_result), 0, plus<int>());
98107

99108
const int sum_closed_form = n * (n + 1) / 2;
100109

examples/cuda/ranges.cu

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ struct square_int
3333
}
3434
};
3535

36+
// thrust 3.1 (CUDA 13.1) encourages using C++ standard conforming functors
37+
#if THRUST_MAJOR_VERSION >= 3 && THRUST_MINOR_VERSION >= 1
38+
template <class T = void>
39+
using plus = cuda::std::plus<T>;
40+
#else
41+
template <class T = void>
42+
using plus = thrust::plus<T>;
43+
#endif
44+
3645
int
3746
main()
3847
{
@@ -70,14 +79,14 @@ main()
7079
// set : 1, 4, 9, ..., 10000
7180

7281
auto range_set = set.device_range();
73-
int sum = thrust::reduce(range_set.begin(), range_set.end(), 0, thrust::plus<int>());
82+
int sum = thrust::reduce(range_set.begin(), range_set.end(), 0, plus<int>());
7483

7584
// If thrust had a range interface (maybe in a future release), the above call could also be written in a shorter
7685
// form:
7786
//
7887
// int sum = thrust::reduce(set.device_range(),
7988
// 0,
80-
// thrust::plus<int>());
89+
// plus<int>());
8190
//
8291
// Or the call to device_range may also become an implicit operation in the future.
8392

examples/cuda/unordered_set.cu

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ insert_neighbors(const int* d_result, const stdgpu::index_t n, stdgpu::unordered
4949
}
5050
}
5151

52+
// thrust 3.1 (CUDA 13.1) encourages using C++ standard conforming functors
53+
#if THRUST_MAJOR_VERSION >= 3 && THRUST_MINOR_VERSION >= 1
54+
template <class T = void>
55+
using plus = cuda::std::plus<T>;
56+
#else
57+
template <class T = void>
58+
using plus = thrust::plus<T>;
59+
#endif
60+
5261
int
5362
main()
5463
{
@@ -83,7 +92,7 @@ main()
8392
// set : 0, 1, 2, 3, ..., 100
8493

8594
auto range_set = set.device_range();
86-
int sum = thrust::reduce(range_set.begin(), range_set.end(), 0, thrust::plus<int>());
95+
int sum = thrust::reduce(range_set.begin(), range_set.end(), 0, plus<int>());
8796

8897
const int sum_closed_form = n * (n + 1) / 2;
8998

examples/cuda/vector.cu

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ insert_neighbors_with_duplicates(const int* d_input, const stdgpu::index_t n, st
4040
}
4141
}
4242

43+
// thrust 3.1 (CUDA 13.1) encourages using C++ standard conforming functors
44+
#if THRUST_MAJOR_VERSION >= 3 && THRUST_MINOR_VERSION >= 1
45+
template <class T = void>
46+
using plus = cuda::std::plus<T>;
47+
#else
48+
template <class T = void>
49+
using plus = thrust::plus<T>;
50+
#endif
51+
4352
int
4453
main()
4554
{
@@ -69,7 +78,7 @@ main()
6978
// vec : 0, 1, 1, 2, 2, 2, 3, 3, 3, ..., 99, 99, 99, 100, 100, 101
7079

7180
auto range_vec = vec.device_range();
72-
int sum = thrust::reduce(range_vec.begin(), range_vec.end(), 0, thrust::plus<int>());
81+
int sum = thrust::reduce(range_vec.begin(), range_vec.end(), 0, plus<int>());
7382

7483
const int sum_closed_form = 3 * (n * (n + 1) / 2);
7584

0 commit comments

Comments
 (0)