16
16
#include < thrust/fill.h>
17
17
#include < thrust/scatter.h>
18
18
#include < thrust/execution_policy.h>
19
+ #include < thrust/iterator/counting_iterator.h>
20
+ #include < thrust/iterator/zip_iterator.h>
21
+ #include < thrust/tuple.h>
19
22
#include < loops/memory.hxx>
20
23
21
24
namespace loops {
@@ -25,81 +28,53 @@ using namespace memory;
25
28
/* *
26
29
* @brief Convert offsets to indices.
27
30
*
28
- * @tparam space The memory space of offsets.
29
- * @tparam index_t The type of indices.
30
- * @tparam offset_t The type of offsets.
31
+ * @tparam index_v_t The type of vector indices.
32
+ * @tparam offset_v_t The type of vector offsets.
31
33
* @param offsets The offsets.
32
- * @param size_of_offsets The size of offsets.
33
34
* @param indices The indices.
34
- * @param size_of_indices The size of indices.
35
- * @param stream The stream.
36
35
*/
37
- template <memory_space_t space, typename index_t , typename offset_t >
38
- void offsets_to_indices (const offset_t * offsets,
39
- const std::size_t size_of_offsets,
40
- index_t * indices,
41
- const std::size_t size_of_indices,
42
- cudaStream_t stream = 0 ) {
43
- // Execution policy (determines where to run the kernel).
44
- using execution_policy_t =
45
- std::conditional_t <(space == memory_space_t ::device),
46
- decltype (thrust::cuda::par.on (stream)),
47
- decltype (thrust::host)>;
48
-
49
- execution_policy_t exec;
36
+ template <typename index_v_t , typename offset_v_t >
37
+ void offsets_to_indices (const offset_v_t & offsets, index_v_t & indices) {
38
+ using offset_t = typename offset_v_t ::value_type;
39
+ using index_t = typename index_v_t ::value_type;
50
40
51
41
// Convert compressed offsets into uncompressed indices.
52
- thrust::fill (exec, indices + 0 , indices + size_of_indices , offset_t (0 ));
42
+ thrust::fill (indices. begin () , indices. end () , offset_t (0 ));
53
43
54
44
thrust::scatter_if (
55
- exec, // execution policy
56
45
thrust::counting_iterator<offset_t >(0 ), // begin iterator
57
- thrust::counting_iterator<offset_t >(size_of_offsets - 1 ), // end iterator
58
- offsets + 0 , // where to scatter
46
+ thrust::counting_iterator<offset_t >(offsets. size () - 1 ), // end iterator
47
+ offsets. begin () , // where to scatter
59
48
thrust::make_transform_iterator (
60
49
thrust::make_zip_iterator (
61
- thrust::make_tuple (offsets + 0 , offsets + 1 )),
50
+ thrust::make_tuple (offsets. begin () , offsets. begin () + 1 )),
62
51
[=] __host__ __device__ (const thrust::tuple<offset_t , offset_t >& t) {
63
52
thrust::not_equal_to<offset_t > comp;
64
53
return comp (thrust::get<0 >(t), thrust::get<1 >(t));
65
54
}),
66
- indices + 0 );
55
+ indices. begin () );
67
56
68
- thrust::inclusive_scan (exec , indices + 0 , indices + size_of_indices ,
69
- indices + 0 , thrust::maximum<offset_t >());
57
+ thrust::inclusive_scan (indices. begin () , indices. end () , indices. begin () ,
58
+ thrust::maximum<offset_t >());
70
59
}
71
60
72
61
/* *
73
62
* @brief Converts "indices"-based array to "offsets"-based array.
74
63
*
75
- * @tparam space The memory space of indices.
76
- * @tparam index_t The type of indices.
77
- * @tparam offset_t The type of offsets.
64
+ * @tparam index_v_t The type of vector indices.
65
+ * @tparam offset_v_t The type of vector offsets.
78
66
* @param indices The indices.
79
- * @param size_of_indices The size of indices.
80
67
* @param offsets The offsets.
81
- * @param size_of_offsets The size of offsets.
82
- * @param stream CUDA stream.
83
68
*/
84
- template <memory_space_t space, typename index_t , typename offset_t >
85
- void indices_to_offsets (index_t * indices,
86
- std::size_t size_of_indices,
87
- offset_t * offsets,
88
- std::size_t size_of_offsets,
89
- cudaStream_t stream = 0 ) {
90
- // Execution policy (determines where to run the kernel).
91
- using execution_policy_t =
92
- std::conditional_t <(space == memory_space_t ::device),
93
- decltype (thrust::cuda::par.on (stream)),
94
- decltype (thrust::host)>;
95
-
96
- execution_policy_t exec;
69
+ template <typename index_v_t , typename offset_v_t >
70
+ void indices_to_offsets (const index_v_t & indices, offset_v_t & offsets) {
71
+ using offset_t = typename offset_v_t ::value_type;
72
+ using index_t = typename index_v_t ::value_type;
97
73
98
74
// Convert uncompressed indices into compressed offsets.
99
- thrust::lower_bound (exec, indices, indices + size_of_indices,
100
- thrust::counting_iterator<offset_t >(0 ),
101
- thrust::counting_iterator<offset_t >(size_of_offsets),
102
- offsets + 0 );
75
+ thrust::lower_bound (
76
+ indices.begin (), indices.end (), thrust::counting_iterator<offset_t >(0 ),
77
+ thrust::counting_iterator<offset_t >(offsets.size ()), offsets.begin ());
103
78
}
104
79
105
80
} // namespace detail
0 commit comments