30 #ifndef HIPCUB_ROCPRIM_DEVICE_DEVICE_SEGMENTED_SORT_HPP_
31 #define HIPCUB_ROCPRIM_DEVICE_DEVICE_SEGMENTED_SORT_HPP_
33 #include "../../../config.hpp"
35 #include "../util_type.hpp"
37 #include <rocprim/device/device_segmented_radix_sort.hpp>
39 BEGIN_HIPCUB_NAMESPACE
41 struct DeviceSegmentedSort
43 template<
typename KeyT,
typename ValueT,
typename OffsetIteratorT>
44 HIPCUB_RUNTIME_FUNCTION
static
45 hipError_t SortPairs(
void * d_temp_storage,
46 size_t& temp_storage_bytes,
47 const KeyT * d_keys_in,
49 const ValueT * d_values_in,
50 ValueT * d_values_out,
53 OffsetIteratorT d_begin_offsets,
54 OffsetIteratorT d_end_offsets,
55 hipStream_t stream = 0,
56 bool debug_synchronous =
false)
58 return ::rocprim::segmented_radix_sort_pairs(
59 d_temp_storage, temp_storage_bytes,
60 d_keys_in, d_keys_out, d_values_in, d_values_out, num_items,
61 num_segments, d_begin_offsets, d_end_offsets,
63 stream, debug_synchronous
67 template<
typename KeyT,
typename ValueT,
typename OffsetIteratorT>
68 HIPCUB_RUNTIME_FUNCTION
static
69 hipError_t SortPairs(
void * d_temp_storage,
70 size_t& temp_storage_bytes,
71 DoubleBuffer<KeyT>& d_keys,
72 DoubleBuffer<ValueT>& d_values,
75 OffsetIteratorT d_begin_offsets,
76 OffsetIteratorT d_end_offsets,
77 hipStream_t stream = 0,
78 bool debug_synchronous =
false)
80 ::rocprim::double_buffer<KeyT> d_keys_db = detail::to_double_buffer(d_keys);
81 ::rocprim::double_buffer<ValueT> d_values_db = detail::to_double_buffer(d_values);
82 hipError_t error = ::rocprim::segmented_radix_sort_pairs(
83 d_temp_storage, temp_storage_bytes,
84 d_keys_db, d_values_db, num_items,
85 num_segments, d_begin_offsets, d_end_offsets,
87 stream, debug_synchronous
89 detail::update_double_buffer(d_keys, d_keys_db);
90 detail::update_double_buffer(d_values, d_values_db);
94 template<
typename KeyT,
typename ValueT,
typename OffsetIteratorT>
95 HIPCUB_RUNTIME_FUNCTION
static
96 hipError_t SortPairsDescending(
void * d_temp_storage,
97 size_t& temp_storage_bytes,
98 const KeyT * d_keys_in,
100 const ValueT * d_values_in,
101 ValueT * d_values_out,
104 OffsetIteratorT d_begin_offsets,
105 OffsetIteratorT d_end_offsets,
106 hipStream_t stream = 0,
107 bool debug_synchronous =
false)
109 return ::rocprim::segmented_radix_sort_pairs_desc(
110 d_temp_storage, temp_storage_bytes,
111 d_keys_in, d_keys_out, d_values_in, d_values_out, num_items,
112 num_segments, d_begin_offsets, d_end_offsets,
114 stream, debug_synchronous
118 template<
typename KeyT,
typename ValueT,
typename OffsetIteratorT>
119 HIPCUB_RUNTIME_FUNCTION
static
120 hipError_t SortPairsDescending(
void * d_temp_storage,
121 size_t& temp_storage_bytes,
122 DoubleBuffer<KeyT>& d_keys,
123 DoubleBuffer<ValueT>& d_values,
126 OffsetIteratorT d_begin_offsets,
127 OffsetIteratorT d_end_offsets,
128 hipStream_t stream = 0,
129 bool debug_synchronous =
false)
131 ::rocprim::double_buffer<KeyT> d_keys_db = detail::to_double_buffer(d_keys);
132 ::rocprim::double_buffer<ValueT> d_values_db = detail::to_double_buffer(d_values);
133 hipError_t error = ::rocprim::segmented_radix_sort_pairs_desc(
134 d_temp_storage, temp_storage_bytes,
135 d_keys_db, d_values_db, num_items,
136 num_segments, d_begin_offsets, d_end_offsets,
138 stream, debug_synchronous
140 detail::update_double_buffer(d_keys, d_keys_db);
141 detail::update_double_buffer(d_values, d_values_db);
145 template<
typename KeyT,
typename OffsetIteratorT>
146 HIPCUB_RUNTIME_FUNCTION
static
147 hipError_t SortKeys(
void * d_temp_storage,
148 size_t& temp_storage_bytes,
149 const KeyT * d_keys_in,
153 OffsetIteratorT d_begin_offsets,
154 OffsetIteratorT d_end_offsets,
155 hipStream_t stream = 0,
156 bool debug_synchronous =
false)
158 return ::rocprim::segmented_radix_sort_keys(
159 d_temp_storage, temp_storage_bytes,
160 d_keys_in, d_keys_out, num_items,
161 num_segments, d_begin_offsets, d_end_offsets,
163 stream, debug_synchronous
167 template<
typename KeyT,
typename OffsetIteratorT>
168 HIPCUB_RUNTIME_FUNCTION
static
169 hipError_t SortKeys(
void * d_temp_storage,
170 size_t& temp_storage_bytes,
171 DoubleBuffer<KeyT>& d_keys,
174 OffsetIteratorT d_begin_offsets,
175 OffsetIteratorT d_end_offsets,
176 hipStream_t stream = 0,
177 bool debug_synchronous =
false)
179 ::rocprim::double_buffer<KeyT> d_keys_db = detail::to_double_buffer(d_keys);
180 hipError_t error = ::rocprim::segmented_radix_sort_keys(
181 d_temp_storage, temp_storage_bytes,
182 d_keys_db, num_items,
183 num_segments, d_begin_offsets, d_end_offsets,
185 stream, debug_synchronous
187 detail::update_double_buffer(d_keys, d_keys_db);
191 template<
typename KeyT,
typename OffsetIteratorT>
192 HIPCUB_RUNTIME_FUNCTION
static
193 hipError_t SortKeysDescending(
void * d_temp_storage,
194 size_t& temp_storage_bytes,
195 const KeyT * d_keys_in,
199 OffsetIteratorT d_begin_offsets,
200 OffsetIteratorT d_end_offsets,
201 hipStream_t stream = 0,
202 bool debug_synchronous =
false)
204 return ::rocprim::segmented_radix_sort_keys_desc(
205 d_temp_storage, temp_storage_bytes,
206 d_keys_in, d_keys_out, num_items,
207 num_segments, d_begin_offsets, d_end_offsets,
209 stream, debug_synchronous
213 template<
typename KeyT,
typename OffsetIteratorT>
214 HIPCUB_RUNTIME_FUNCTION
static
215 hipError_t SortKeysDescending(
void * d_temp_storage,
216 size_t& temp_storage_bytes,
217 DoubleBuffer<KeyT>& d_keys,
220 OffsetIteratorT d_begin_offsets,
221 OffsetIteratorT d_end_offsets,
222 hipStream_t stream = 0,
223 bool debug_synchronous =
false)
225 ::rocprim::double_buffer<KeyT> d_keys_db = detail::to_double_buffer(d_keys);
226 hipError_t error = ::rocprim::segmented_radix_sort_keys_desc(
227 d_temp_storage, temp_storage_bytes,
228 d_keys_db, num_items,
229 num_segments, d_begin_offsets, d_end_offsets,
231 stream, debug_synchronous
233 detail::update_double_buffer(d_keys, d_keys_db);
237 template<
typename KeyT,
typename ValueT,
typename OffsetIteratorT>
238 HIPCUB_RUNTIME_FUNCTION
static
239 hipError_t StableSortPairs(
void * d_temp_storage,
240 size_t& temp_storage_bytes,
241 const KeyT * d_keys_in,
243 const ValueT * d_values_in,
244 ValueT * d_values_out,
247 OffsetIteratorT d_begin_offsets,
248 OffsetIteratorT d_end_offsets,
249 hipStream_t stream = 0,
250 bool debug_synchronous =
false)
253 d_temp_storage, temp_storage_bytes,
254 d_keys_in, d_keys_out, d_values_in, d_values_out, num_items,
255 num_segments, d_begin_offsets, d_end_offsets,
256 stream, debug_synchronous
260 template<
typename KeyT,
typename ValueT,
typename OffsetIteratorT>
261 HIPCUB_RUNTIME_FUNCTION
static
262 hipError_t StableSortPairs(
void * d_temp_storage,
263 size_t& temp_storage_bytes,
264 DoubleBuffer<KeyT>& d_keys,
265 DoubleBuffer<ValueT>& d_values,
268 OffsetIteratorT d_begin_offsets,
269 OffsetIteratorT d_end_offsets,
270 hipStream_t stream = 0,
271 bool debug_synchronous =
false)
274 d_temp_storage, temp_storage_bytes,
275 d_keys, d_values, num_items,
276 num_segments, d_begin_offsets, d_end_offsets,
277 stream, debug_synchronous
281 template<
typename KeyT,
typename ValueT,
typename OffsetIteratorT>
282 HIPCUB_RUNTIME_FUNCTION
static
283 hipError_t StableSortPairsDescending(
void * d_temp_storage,
284 size_t& temp_storage_bytes,
285 const KeyT * d_keys_in,
287 const ValueT * d_values_in,
288 ValueT * d_values_out,
291 OffsetIteratorT d_begin_offsets,
292 OffsetIteratorT d_end_offsets,
293 hipStream_t stream = 0,
294 bool debug_synchronous =
false)
296 return SortPairsDescending(
297 d_temp_storage, temp_storage_bytes,
298 d_keys_in, d_keys_out, d_values_in, d_values_out, num_items,
299 num_segments, d_begin_offsets, d_end_offsets,
300 stream, debug_synchronous
304 template<
typename KeyT,
typename ValueT,
typename OffsetIteratorT>
305 HIPCUB_RUNTIME_FUNCTION
static
306 hipError_t StableSortPairsDescending(
void * d_temp_storage,
307 size_t& temp_storage_bytes,
308 DoubleBuffer<KeyT>& d_keys,
309 DoubleBuffer<ValueT>& d_values,
312 OffsetIteratorT d_begin_offsets,
313 OffsetIteratorT d_end_offsets,
314 hipStream_t stream = 0,
315 bool debug_synchronous =
false)
317 return SortPairsDescending(
318 d_temp_storage, temp_storage_bytes,
319 d_keys, d_values, num_items,
320 num_segments, d_begin_offsets, d_end_offsets,
321 stream, debug_synchronous
325 template<
typename KeyT,
typename OffsetIteratorT>
326 HIPCUB_RUNTIME_FUNCTION
static
327 hipError_t StableSortKeys(
void * d_temp_storage,
328 size_t& temp_storage_bytes,
329 const KeyT * d_keys_in,
333 OffsetIteratorT d_begin_offsets,
334 OffsetIteratorT d_end_offsets,
335 hipStream_t stream = 0,
336 bool debug_synchronous =
false)
339 d_temp_storage, temp_storage_bytes,
340 d_keys_in, d_keys_out, num_items,
341 num_segments, d_begin_offsets, d_end_offsets,
342 stream, debug_synchronous
346 template<
typename KeyT,
typename OffsetIteratorT>
347 HIPCUB_RUNTIME_FUNCTION
static
348 hipError_t StableSortKeys(
void * d_temp_storage,
349 size_t& temp_storage_bytes,
350 DoubleBuffer<KeyT>& d_keys,
353 OffsetIteratorT d_begin_offsets,
354 OffsetIteratorT d_end_offsets,
355 hipStream_t stream = 0,
356 bool debug_synchronous =
false)
359 d_temp_storage, temp_storage_bytes,
361 num_segments, d_begin_offsets, d_end_offsets,
362 stream, debug_synchronous
366 template<
typename KeyT,
typename OffsetIteratorT>
367 HIPCUB_RUNTIME_FUNCTION
static
368 hipError_t StableSortKeysDescending(
void * d_temp_storage,
369 size_t& temp_storage_bytes,
370 const KeyT * d_keys_in,
374 OffsetIteratorT d_begin_offsets,
375 OffsetIteratorT d_end_offsets,
376 hipStream_t stream = 0,
377 bool debug_synchronous =
false)
379 return SortKeysDescending(
380 d_temp_storage, temp_storage_bytes,
381 d_keys_in, d_keys_out, num_items,
382 num_segments, d_begin_offsets, d_end_offsets,
383 stream, debug_synchronous
387 template<
typename KeyT,
typename OffsetIteratorT>
388 HIPCUB_RUNTIME_FUNCTION
static
389 hipError_t StableSortKeysDescending(
void * d_temp_storage,
390 size_t& temp_storage_bytes,
391 DoubleBuffer<KeyT>& d_keys,
394 OffsetIteratorT d_begin_offsets,
395 OffsetIteratorT d_end_offsets,
396 hipStream_t stream = 0,
397 bool debug_synchronous =
false)
399 return SortKeysDescending(
400 d_temp_storage, temp_storage_bytes,
402 num_segments, d_begin_offsets, d_end_offsets,
403 stream, debug_synchronous