CUB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
device_segmented_radix_sort.cuh
Go to the documentation of this file.
1 
2 /******************************************************************************
3  * Copyright (c) 2011, Duane Merrill. All rights reserved.
4  * Copyright (c) 2011-2016, NVIDIA CORPORATION. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  ******************************************************************************/
29 
35 #pragma once
36 
37 #include <stdio.h>
38 #include <iterator>
39 
40 #include "dispatch/dispatch_radix_sort.cuh"
41 #include "../util_arch.cuh"
42 #include "../util_namespace.cuh"
43 
45 CUB_NS_PREFIX
46 
48 namespace cub {
49 
50 
76 {
77 
78  /******************************************************************/
82 
136  template <
137  typename KeyT,
138  typename ValueT>
139  CUB_RUNTIME_FUNCTION
140  static cudaError_t SortPairs(
141  void *d_temp_storage,
142  size_t &temp_storage_bytes,
143  KeyT *d_keys_in,
144  KeyT *d_keys_out,
145  ValueT *d_values_in,
146  ValueT *d_values_out,
147  int num_items,
148  int num_segments,
149  int *d_begin_offsets,
150  int *d_end_offsets,
151  int begin_bit = 0,
152  int end_bit = sizeof(KeyT) * 8,
153  cudaStream_t stream = 0,
154  bool debug_synchronous = false)
155  {
156  // Signed integer type for global offsets
157  typedef int OffsetT;
158 
159  DoubleBuffer<KeyT> d_keys(d_keys_in, d_keys_out);
160  DoubleBuffer<ValueT> d_values(d_values_in, d_values_out);
161 
162  return DispatchSegmentedRadixSort<false, KeyT, ValueT, OffsetT>::Dispatch(
163  d_temp_storage,
164  temp_storage_bytes,
165  d_keys,
166  d_values,
167  num_items,
168  num_segments,
169  d_begin_offsets,
170  d_end_offsets,
171  begin_bit,
172  end_bit,
173  false,
174  stream,
175  debug_synchronous);
176  }
177 
178 
243  template <
244  typename KeyT,
245  typename ValueT>
246  CUB_RUNTIME_FUNCTION
247  static cudaError_t SortPairs(
248  void *d_temp_storage,
249  size_t &temp_storage_bytes,
250  DoubleBuffer<KeyT> &d_keys,
251  DoubleBuffer<ValueT> &d_values,
252  int num_items,
253  int num_segments,
254  int *d_begin_offsets,
255  int *d_end_offsets,
256  int begin_bit = 0,
257  int end_bit = sizeof(KeyT) * 8,
258  cudaStream_t stream = 0,
259  bool debug_synchronous = false)
260  {
261  // Signed integer type for global offsets
262  typedef int OffsetT;
263 
264  return DispatchSegmentedRadixSort<false, KeyT, ValueT, OffsetT>::Dispatch(
265  d_temp_storage,
266  temp_storage_bytes,
267  d_keys,
268  d_values,
269  num_items,
270  num_segments,
271  d_begin_offsets,
272  d_end_offsets,
273  begin_bit,
274  end_bit,
275  true,
276  stream,
277  debug_synchronous);
278  }
279 
280 
334  template <
335  typename KeyT,
336  typename ValueT>
337  CUB_RUNTIME_FUNCTION
338  static cudaError_t SortPairsDescending(
339  void *d_temp_storage,
340  size_t &temp_storage_bytes,
341  KeyT *d_keys_in,
342  KeyT *d_keys_out,
343  ValueT *d_values_in,
344  ValueT *d_values_out,
345  int num_items,
346  int num_segments,
347  int *d_begin_offsets,
348  int *d_end_offsets,
349  int begin_bit = 0,
350  int end_bit = sizeof(KeyT) * 8,
351  cudaStream_t stream = 0,
352  bool debug_synchronous = false)
353  {
354  // Signed integer type for global offsets
355  typedef int OffsetT;
356 
357  DoubleBuffer<KeyT> d_keys(d_keys_in, d_keys_out);
358  DoubleBuffer<ValueT> d_values(d_values_in, d_values_out);
359 
360  return DispatchSegmentedRadixSort<true, KeyT, ValueT, OffsetT>::Dispatch(
361  d_temp_storage,
362  temp_storage_bytes,
363  d_keys,
364  d_values,
365  num_items,
366  num_segments,
367  d_begin_offsets,
368  d_end_offsets,
369  begin_bit,
370  end_bit,
371  false,
372  stream,
373  debug_synchronous);
374  }
375 
376 
441  template <
442  typename KeyT,
443  typename ValueT>
444  CUB_RUNTIME_FUNCTION
445  static cudaError_t SortPairsDescending(
446  void *d_temp_storage,
447  size_t &temp_storage_bytes,
448  DoubleBuffer<KeyT> &d_keys,
449  DoubleBuffer<ValueT> &d_values,
450  int num_items,
451  int num_segments,
452  int *d_begin_offsets,
453  int *d_end_offsets,
454  int begin_bit = 0,
455  int end_bit = sizeof(KeyT) * 8,
456  cudaStream_t stream = 0,
457  bool debug_synchronous = false)
458  {
459  // Signed integer type for global offsets
460  typedef int OffsetT;
461 
462  return DispatchSegmentedRadixSort<true, KeyT, ValueT, OffsetT>::Dispatch(
463  d_temp_storage,
464  temp_storage_bytes,
465  d_keys,
466  d_values,
467  num_items,
468  num_segments,
469  d_begin_offsets,
470  d_end_offsets,
471  begin_bit,
472  end_bit,
473  true,
474  stream,
475  debug_synchronous);
476  }
477 
478 
480  /******************************************************************/
484 
485 
532  template <typename KeyT>
533  CUB_RUNTIME_FUNCTION
534  static cudaError_t SortKeys(
535  void *d_temp_storage,
536  size_t &temp_storage_bytes,
537  KeyT *d_keys_in,
538  KeyT *d_keys_out,
539  int num_items,
540  int num_segments,
541  int *d_begin_offsets,
542  int *d_end_offsets,
543  int begin_bit = 0,
544  int end_bit = sizeof(KeyT) * 8,
545  cudaStream_t stream = 0,
546  bool debug_synchronous = false)
547  {
548  // Signed integer type for global offsets
549  typedef int OffsetT;
550 
551  // Null value type
552  DoubleBuffer<KeyT> d_keys(d_keys_in, d_keys_out);
553  DoubleBuffer<NullType> d_values;
554 
555  return DispatchSegmentedRadixSort<false, KeyT, NullType, OffsetT>::Dispatch(
556  d_temp_storage,
557  temp_storage_bytes,
558  d_keys,
559  d_values,
560  num_items,
561  num_segments,
562  d_begin_offsets,
563  d_end_offsets,
564  begin_bit,
565  end_bit,
566  false,
567  stream,
568  debug_synchronous);
569  }
570 
571 
628  template <typename KeyT>
629  CUB_RUNTIME_FUNCTION
630  static cudaError_t SortKeys(
631  void *d_temp_storage,
632  size_t &temp_storage_bytes,
633  DoubleBuffer<KeyT> &d_keys,
634  int num_items,
635  int num_segments,
636  int *d_begin_offsets,
637  int *d_end_offsets,
638  int begin_bit = 0,
639  int end_bit = sizeof(KeyT) * 8,
640  cudaStream_t stream = 0,
641  bool debug_synchronous = false)
642  {
643  // Signed integer type for global offsets
644  typedef int OffsetT;
645 
646  // Null value type
647  DoubleBuffer<NullType> d_values;
648 
649  return DispatchSegmentedRadixSort<false, KeyT, NullType, OffsetT>::Dispatch(
650  d_temp_storage,
651  temp_storage_bytes,
652  d_keys,
653  d_values,
654  num_items,
655  num_segments,
656  d_begin_offsets,
657  d_end_offsets,
658  begin_bit,
659  end_bit,
660  true,
661  stream,
662  debug_synchronous);
663  }
664 
714  template <typename KeyT>
715  CUB_RUNTIME_FUNCTION
716  static cudaError_t SortKeysDescending(
717  void *d_temp_storage,
718  size_t &temp_storage_bytes,
719  KeyT *d_keys_in,
720  KeyT *d_keys_out,
721  int num_items,
722  int num_segments,
723  int *d_begin_offsets,
724  int *d_end_offsets,
725  int begin_bit = 0,
726  int end_bit = sizeof(KeyT) * 8,
727  cudaStream_t stream = 0,
728  bool debug_synchronous = false)
729  {
730  // Signed integer type for global offsets
731  typedef int OffsetT;
732 
733  DoubleBuffer<KeyT> d_keys(d_keys_in, d_keys_out);
734  DoubleBuffer<NullType> d_values;
735 
736  return DispatchSegmentedRadixSort<true, KeyT, NullType, OffsetT>::Dispatch(
737  d_temp_storage,
738  temp_storage_bytes,
739  d_keys,
740  d_values,
741  num_items,
742  num_segments,
743  d_begin_offsets,
744  d_end_offsets,
745  begin_bit,
746  end_bit,
747  false,
748  stream,
749  debug_synchronous);
750  }
751 
752 
809  template <typename KeyT>
810  CUB_RUNTIME_FUNCTION
811  static cudaError_t SortKeysDescending(
812  void *d_temp_storage,
813  size_t &temp_storage_bytes,
814  DoubleBuffer<KeyT> &d_keys,
815  int num_items,
816  int num_segments,
817  int *d_begin_offsets,
818  int *d_end_offsets,
819  int begin_bit = 0,
820  int end_bit = sizeof(KeyT) * 8,
821  cudaStream_t stream = 0,
822  bool debug_synchronous = false)
823  {
824  // Signed integer type for global offsets
825  typedef int OffsetT;
826 
827  // Null value type
828  DoubleBuffer<NullType> d_values;
829 
830  return DispatchSegmentedRadixSort<true, KeyT, NullType, OffsetT>::Dispatch(
831  d_temp_storage,
832  temp_storage_bytes,
833  d_keys,
834  d_values,
835  num_items,
836  num_segments,
837  d_begin_offsets,
838  d_end_offsets,
839  begin_bit,
840  end_bit,
841  true,
842  stream,
843  debug_synchronous);
844  }
845 
846 
848 
849 
850 };
851 
852 } // CUB namespace
853 CUB_NS_POSTFIX // Optional outer namespace(s)
854 
855