Skip to content

Commit d79c88f

Browse files
authored
Replace thrust::tuple with cuda::std::tuple (#2928)
Its an alias anyway and we should use the standard type Authors: - Michael Schellenberger Costa (https://github.com/miscco) Approvers: - Dante Gama Dessavre (https://github.com/dantegd) URL: #2928
1 parent e25de88 commit d79c88f

File tree

5 files changed

+39
-41
lines changed

5 files changed

+39
-41
lines changed

cpp/include/raft/linalg/detail/map.cuh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -16,7 +16,7 @@
1616

1717
#include <rmm/cuda_stream_view.hpp>
1818

19-
#include <thrust/tuple.h>
19+
#include <cuda/std/tuple>
2020

2121
namespace raft::linalg::detail {
2222

@@ -41,13 +41,13 @@ __device__ __forceinline__ void map_kernel_mainloop(
4141
OutT* out_ptr, IdxT offset, IdxT len, Func f, const InTs*... in_ptrs, std::index_sequence<Is...>)
4242
{
4343
TxN_t<OutT, R> wide;
44-
thrust::tuple<TxN_t<InTs, R>...> wide_args;
44+
cuda::std::tuple<TxN_t<InTs, R>...> wide_args;
4545
if (offset + R <= len) {
46-
(thrust::get<Is>(wide_args).load(in_ptrs, offset), ...);
46+
(cuda::std::get<Is>(wide_args).load(in_ptrs, offset), ...);
4747
#pragma unroll
4848
for (int j = 0; j < R; ++j) {
4949
wide.val.data[j] = map_apply<PassOffset, OutT, IdxT, Func, InTs...>(
50-
f, offset + j, thrust::get<Is>(wide_args).val.data[j]...);
50+
f, offset + j, cuda::std::get<Is>(wide_args).val.data[j]...);
5151
}
5252
wide.store(out_ptr, offset);
5353
}

cpp/include/raft/matrix/detail/linewise_op.cuh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2021-2024, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -11,7 +11,7 @@
1111
#include <raft/util/pow2_utils.cuh>
1212
#include <raft/util/vectorized.cuh>
1313

14-
#include <thrust/tuple.h>
14+
#include <cuda/std/tuple>
1515

1616
#include <algorithm>
1717

@@ -32,7 +32,7 @@ template <typename MatT, typename Lambda, class Tuple, size_t... Is>
3232
__device__ __forceinline__ MatT
3333
RunMatVecOp(Lambda op, MatT mat, Tuple&& args, std::index_sequence<Is...>)
3434
{
35-
return op(mat, (thrust::get<Is>(args))...);
35+
return op(mat, (cuda::std::get<Is>(args))...);
3636
}
3737

3838
template <typename Type, typename IdxType, std::size_t VecBytes, int BlockSize>
@@ -89,9 +89,7 @@ struct Linewise {
8989
{
9090
constexpr IdxType warpPad = (AlignWarp::Value - 1) * VecElems;
9191
constexpr auto index = std::index_sequence_for<Vecs...>();
92-
// todo(lsugy): switch to cuda::std::tuple from libcudacxx if we add it as a required
93-
// dependency. Note that thrust::tuple is limited to 10 elements.
94-
thrust::tuple<Vecs...> args;
92+
cuda::std::tuple<Vecs...> args;
9593
Vec v, w;
9694
bool update = true;
9795
for (; in < in_end; in += AlignWarp::Value, out += AlignWarp::Value, rowMod += warpPad) {
@@ -102,15 +100,15 @@ struct Linewise {
102100
update = true;
103101
}
104102
if (update) {
105-
args = thrust::make_tuple((vecs[rowDiv])...);
103+
args = cuda::std::make_tuple((vecs[rowDiv])...);
106104
update = false;
107105
}
108106
#pragma unroll VecElems
109107
for (int k = 0; k < VecElems; k++, rowMod++) {
110108
if (rowMod == rowLen) {
111109
rowMod = 0;
112110
rowDiv++;
113-
args = thrust::make_tuple((vecs[rowDiv])...);
111+
args = cuda::std::make_tuple((vecs[rowDiv])...);
114112
}
115113
w.val.data[k] = RunMatVecOp(op, v.val.data[k], args, index);
116114
}

cpp/include/raft/sparse/op/detail/sort.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2019-2024, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -13,12 +13,12 @@
1313

1414
#include <rmm/exec_policy.hpp>
1515

16+
#include <cuda/std/tuple>
1617
#include <cuda_runtime.h>
1718
#include <thrust/device_ptr.h>
1819
#include <thrust/iterator/zip_iterator.h>
1920
#include <thrust/scan.h>
2021
#include <thrust/sort.h>
21-
#include <thrust/tuple.h>
2222

2323
#include <cusparse_v2.h>
2424

@@ -37,11 +37,11 @@ struct TupleComp {
3737
operator()(const one& t1, const two& t2)
3838
{
3939
// sort first by each sample's color,
40-
if (thrust::get<0>(t1) < thrust::get<0>(t2)) return true;
41-
if (thrust::get<0>(t1) > thrust::get<0>(t2)) return false;
40+
if (cuda::std::get<0>(t1) < cuda::std::get<0>(t2)) return true;
41+
if (cuda::std::get<0>(t1) > cuda::std::get<0>(t2)) return false;
4242

4343
// then sort by value in descending order
44-
return thrust::get<1>(t1) < thrust::get<1>(t2);
44+
return cuda::std::get<1>(t1) < cuda::std::get<1>(t2);
4545
}
4646
};
4747

@@ -60,7 +60,7 @@ struct TupleComp {
6060
template <typename T, typename IdxT = int, typename nnz_t>
6161
void coo_sort(IdxT m, IdxT n, nnz_t nnz, IdxT* rows, IdxT* cols, T* vals, cudaStream_t stream)
6262
{
63-
auto coo_indices = thrust::make_zip_iterator(thrust::make_tuple(rows, cols));
63+
auto coo_indices = thrust::make_zip_iterator(cuda::std::make_tuple(rows, cols));
6464

6565
// get all the colors in contiguous locations so we can map them to warps.
6666
thrust::sort_by_key(rmm::exec_policy(stream), coo_indices, coo_indices + nnz, vals, TupleComp());
@@ -95,7 +95,7 @@ void coo_sort_by_weight(
9595
{
9696
thrust::device_ptr<value_t> t_data = thrust::device_pointer_cast(data);
9797

98-
auto first = thrust::make_zip_iterator(thrust::make_tuple(rows, cols));
98+
auto first = thrust::make_zip_iterator(cuda::std::make_tuple(rows, cols));
9999

100100
thrust::sort_by_key(rmm::exec_policy(stream), t_data, t_data + nnz, first);
101101
}

cpp/include/raft/sparse/solver/detail/mst_solver_inl.cuh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -14,6 +14,7 @@
1414
#include <rmm/device_scalar.hpp>
1515
#include <rmm/device_uvector.hpp>
1616

17+
#include <cuda/std/tuple>
1718
#include <thrust/copy.h>
1819
#include <thrust/device_ptr.h>
1920
#include <thrust/execution_policy.h>
@@ -26,7 +27,6 @@
2627
#include <thrust/sort.h>
2728
#include <thrust/transform.h>
2829
#include <thrust/transform_reduce.h>
29-
#include <thrust/tuple.h>
3030
#include <thrust/unique.h>
3131

3232
#include <curand.h>
@@ -169,10 +169,10 @@ Graph_COO<vertex_t, edge_t, weight_t> MST_solver<vertex_t, edge_t, weight_t, alt
169169
// ||y|-|x||
170170
template <typename weight_t>
171171
struct alteration_functor {
172-
__host__ __device__ weight_t operator()(const thrust::tuple<weight_t, weight_t>& t)
172+
__host__ __device__ weight_t operator()(const cuda::std::tuple<weight_t, weight_t>& t)
173173
{
174-
auto x = thrust::get<0>(t);
175-
auto y = thrust::get<1>(t);
174+
auto x = cuda::std::get<0>(t);
175+
auto y = cuda::std::get<1>(t);
176176
x = x < 0 ? -x : x;
177177
y = y < 0 ? -y : y;
178178
return x < y ? y - x : x - y;
@@ -194,8 +194,8 @@ alteration_t MST_solver<vertex_t, edge_t, weight_t, alteration_t>::alteration_ma
194194
auto new_end = thrust::unique(policy, tmp.begin(), tmp.end());
195195

196196
// min(a[i+1]-a[i])/2
197-
auto begin = thrust::make_zip_iterator(thrust::make_tuple(tmp.begin(), tmp.begin() + 1));
198-
auto end = thrust::make_zip_iterator(thrust::make_tuple(new_end - 1, new_end));
197+
auto begin = thrust::make_zip_iterator(cuda::std::make_tuple(tmp.begin(), tmp.begin() + 1));
198+
auto end = thrust::make_zip_iterator(cuda::std::make_tuple(new_end - 1, new_end));
199199
auto init = tmp.element(1, stream) - tmp.element(0, stream);
200200
auto max = thrust::transform_reduce(
201201
policy, begin, end, alteration_functor<weight_t>(), init, thrust::minimum<weight_t>());
@@ -365,9 +365,9 @@ void MST_solver<vertex_t, edge_t, weight_t, alteration_t>::check_termination()
365365

366366
template <typename vertex_t, typename weight_t>
367367
struct new_edges_functor {
368-
__host__ __device__ bool operator()(const thrust::tuple<vertex_t, vertex_t, weight_t>& t)
368+
__host__ __device__ bool operator()(const cuda::std::tuple<vertex_t, vertex_t, weight_t>& t)
369369
{
370-
auto src = thrust::get<0>(t);
370+
auto src = cuda::std::get<0>(t);
371371

372372
return src != std::numeric_limits<vertex_t>::max() ? true : false;
373373
}
@@ -383,15 +383,15 @@ void MST_solver<vertex_t, edge_t, weight_t, alteration_t>::append_src_dst_pair(
383383

384384
// iterator to end of mst edges added to final output in previous iteration
385385
auto src_dst_zip_end =
386-
thrust::make_zip_iterator(thrust::make_tuple(mst_src + curr_mst_edge_count,
387-
mst_dst + curr_mst_edge_count,
388-
mst_weights + curr_mst_edge_count));
386+
thrust::make_zip_iterator(cuda::std::make_tuple(mst_src + curr_mst_edge_count,
387+
mst_dst + curr_mst_edge_count,
388+
mst_weights + curr_mst_edge_count));
389389

390390
// iterator to new mst edges found
391391
auto temp_src_dst_zip_begin = thrust::make_zip_iterator(
392-
thrust::make_tuple(temp_src.begin(), temp_dst.begin(), temp_weights.begin()));
392+
cuda::std::make_tuple(temp_src.begin(), temp_dst.begin(), temp_weights.begin()));
393393
auto temp_src_dst_zip_end = thrust::make_zip_iterator(
394-
thrust::make_tuple(temp_src.end(), temp_dst.end(), temp_weights.end()));
394+
cuda::std::make_tuple(temp_src.end(), temp_dst.end(), temp_weights.end()));
395395

396396
// copy new mst edges to final output
397397
thrust::copy_if(policy,

cpp/include/raft/spectral/detail/spectral_util.cuh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -13,6 +13,7 @@
1313
#include <raft/spectral/matrix_wrappers.hpp>
1414
#include <raft/util/cudart_utils.hpp>
1515

16+
#include <cuda/std/tuple>
1617
#include <thrust/device_ptr.h>
1718
#include <thrust/fill.h>
1819
#include <thrust/for_each.h>
@@ -21,7 +22,6 @@
2122
#include <thrust/iterator/zip_iterator.h>
2223
#include <thrust/reduce.h>
2324
#include <thrust/transform.h>
24-
#include <thrust/tuple.h>
2525

2626
#include <algorithm>
2727

@@ -115,7 +115,7 @@ struct equal_to_i_op {
115115
template <typename Tuple_>
116116
__host__ __device__ void operator()(Tuple_ t)
117117
{
118-
thrust::get<1>(t) = (thrust::get<0>(t) == i) ? (value_type_t)1.0 : (value_type_t)0.0;
118+
cuda::std::get<1>(t) = (cuda::std::get<0>(t) == i) ? (value_type_t)1.0 : (value_type_t)0.0;
119119
}
120120
};
121121
} // namespace
@@ -140,10 +140,10 @@ bool construct_indicator(
140140

141141
thrust::for_each(
142142
thrust_exec_policy,
143-
thrust::make_zip_iterator(thrust::make_tuple(thrust::device_pointer_cast(clusters),
144-
thrust::device_pointer_cast(part_i.raw()))),
145-
thrust::make_zip_iterator(thrust::make_tuple(thrust::device_pointer_cast(clusters + n),
146-
thrust::device_pointer_cast(part_i.raw() + n))),
143+
thrust::make_zip_iterator(cuda::std::make_tuple(thrust::device_pointer_cast(clusters),
144+
thrust::device_pointer_cast(part_i.raw()))),
145+
thrust::make_zip_iterator(cuda::std::make_tuple(thrust::device_pointer_cast(clusters + n),
146+
thrust::device_pointer_cast(part_i.raw() + n))),
147147
equal_to_i_op<vertex_t, weight_t>(index));
148148
RAFT_CHECK_CUDA(stream);
149149

0 commit comments

Comments
 (0)