CUB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
device_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 
83 {
84 
85  /******************************************************************/
89 
143  template <
144  typename KeyT,
145  typename ValueT>
146  CUB_RUNTIME_FUNCTION
147  static cudaError_t SortPairs(
148  void *d_temp_storage,
149  size_t &temp_storage_bytes,
150  KeyT *d_keys_in,
151  KeyT *d_keys_out,
152  ValueT *d_values_in,
153  ValueT *d_values_out,
154  int num_items,
155  int begin_bit = 0,
156  int end_bit = sizeof(KeyT) * 8,
157  cudaStream_t stream = 0,
158  bool debug_synchronous = false)
159  {
160  // Signed integer type for global offsets
161  typedef int OffsetT;
162 
163  DoubleBuffer<KeyT> d_keys(d_keys_in, d_keys_out);
164  DoubleBuffer<ValueT> d_values(d_values_in, d_values_out);
165 
166  return DispatchRadixSort<false, KeyT, ValueT, OffsetT>::Dispatch(
167  d_temp_storage,
168  temp_storage_bytes,
169  d_keys,
170  d_values,
171  num_items,
172  begin_bit,
173  end_bit,
174  false,
175  stream,
176  debug_synchronous);
177  }
178 
179 
244  template <
245  typename KeyT,
246  typename ValueT>
247  CUB_RUNTIME_FUNCTION
248  static cudaError_t SortPairs(
249  void *d_temp_storage,
250  size_t &temp_storage_bytes,
251  DoubleBuffer<KeyT> &d_keys,
252  DoubleBuffer<ValueT> &d_values,
253  int num_items,
254  int begin_bit = 0,
255  int end_bit = sizeof(KeyT) * 8,
256  cudaStream_t stream = 0,
257  bool debug_synchronous = false)
258  {
259  // Signed integer type for global offsets
260  typedef int OffsetT;
261 
262  return DispatchRadixSort<false, KeyT, ValueT, OffsetT>::Dispatch(
263  d_temp_storage,
264  temp_storage_bytes,
265  d_keys,
266  d_values,
267  num_items,
268  begin_bit,
269  end_bit,
270  true,
271  stream,
272  debug_synchronous);
273  }
274 
275 
324  template <
325  typename KeyT,
326  typename ValueT>
327  CUB_RUNTIME_FUNCTION
328  static cudaError_t SortPairsDescending(
329  void *d_temp_storage,
330  size_t &temp_storage_bytes,
331  KeyT *d_keys_in,
332  KeyT *d_keys_out,
333  ValueT *d_values_in,
334  ValueT *d_values_out,
335  int num_items,
336  int begin_bit = 0,
337  int end_bit = sizeof(KeyT) * 8,
338  cudaStream_t stream = 0,
339  bool debug_synchronous = false)
340  {
341  // Signed integer type for global offsets
342  typedef int OffsetT;
343 
344  DoubleBuffer<KeyT> d_keys(d_keys_in, d_keys_out);
345  DoubleBuffer<ValueT> d_values(d_values_in, d_values_out);
346 
347  return DispatchRadixSort<true, KeyT, ValueT, OffsetT>::Dispatch(
348  d_temp_storage,
349  temp_storage_bytes,
350  d_keys,
351  d_values,
352  num_items,
353  begin_bit,
354  end_bit,
355  false,
356  stream,
357  debug_synchronous);
358  }
359 
360 
420  template <
421  typename KeyT,
422  typename ValueT>
423  CUB_RUNTIME_FUNCTION
424  static cudaError_t SortPairsDescending(
425  void *d_temp_storage,
426  size_t &temp_storage_bytes,
427  DoubleBuffer<KeyT> &d_keys,
428  DoubleBuffer<ValueT> &d_values,
429  int num_items,
430  int begin_bit = 0,
431  int end_bit = sizeof(KeyT) * 8,
432  cudaStream_t stream = 0,
433  bool debug_synchronous = false)
434  {
435  // Signed integer type for global offsets
436  typedef int OffsetT;
437 
438  return DispatchRadixSort<true, KeyT, ValueT, OffsetT>::Dispatch(
439  d_temp_storage,
440  temp_storage_bytes,
441  d_keys,
442  d_values,
443  num_items,
444  begin_bit,
445  end_bit,
446  true,
447  stream,
448  debug_synchronous);
449  }
450 
451 
453  /******************************************************************/
457 
458 
504  template <typename KeyT>
505  CUB_RUNTIME_FUNCTION
506  static cudaError_t SortKeys(
507  void *d_temp_storage,
508  size_t &temp_storage_bytes,
509  KeyT *d_keys_in,
510  KeyT *d_keys_out,
511  int num_items,
512  int begin_bit = 0,
513  int end_bit = sizeof(KeyT) * 8,
514  cudaStream_t stream = 0,
515  bool debug_synchronous = false)
516  {
517  // Signed integer type for global offsets
518  typedef int OffsetT;
519 
520  // Null value type
521  DoubleBuffer<KeyT> d_keys(d_keys_in, d_keys_out);
522  DoubleBuffer<NullType> d_values;
523 
524  return DispatchRadixSort<false, KeyT, NullType, OffsetT>::Dispatch(
525  d_temp_storage,
526  temp_storage_bytes,
527  d_keys,
528  d_values,
529  num_items,
530  begin_bit,
531  end_bit,
532  false,
533  stream,
534  debug_synchronous);
535  }
536 
537 
593  template <typename KeyT>
594  CUB_RUNTIME_FUNCTION
595  static cudaError_t SortKeys(
596  void *d_temp_storage,
597  size_t &temp_storage_bytes,
598  DoubleBuffer<KeyT> &d_keys,
599  int num_items,
600  int begin_bit = 0,
601  int end_bit = sizeof(KeyT) * 8,
602  cudaStream_t stream = 0,
603  bool debug_synchronous = false)
604  {
605  // Signed integer type for global offsets
606  typedef int OffsetT;
607 
608  // Null value type
609  DoubleBuffer<NullType> d_values;
610 
611  return DispatchRadixSort<false, KeyT, NullType, OffsetT>::Dispatch(
612  d_temp_storage,
613  temp_storage_bytes,
614  d_keys,
615  d_values,
616  num_items,
617  begin_bit,
618  end_bit,
619  true,
620  stream,
621  debug_synchronous);
622  }
623 
668  template <typename KeyT>
669  CUB_RUNTIME_FUNCTION
670  static cudaError_t SortKeysDescending(
671  void *d_temp_storage,
672  size_t &temp_storage_bytes,
673  KeyT *d_keys_in,
674  KeyT *d_keys_out,
675  int num_items,
676  int begin_bit = 0,
677  int end_bit = sizeof(KeyT) * 8,
678  cudaStream_t stream = 0,
679  bool debug_synchronous = false)
680  {
681  // Signed integer type for global offsets
682  typedef int OffsetT;
683 
684  DoubleBuffer<KeyT> d_keys(d_keys_in, d_keys_out);
685  DoubleBuffer<NullType> d_values;
686 
687  return DispatchRadixSort<true, KeyT, NullType, OffsetT>::Dispatch(
688  d_temp_storage,
689  temp_storage_bytes,
690  d_keys,
691  d_values,
692  num_items,
693  begin_bit,
694  end_bit,
695  false,
696  stream,
697  debug_synchronous);
698  }
699 
700 
752  template <typename KeyT>
753  CUB_RUNTIME_FUNCTION
754  static cudaError_t SortKeysDescending(
755  void *d_temp_storage,
756  size_t &temp_storage_bytes,
757  DoubleBuffer<KeyT> &d_keys,
758  int num_items,
759  int begin_bit = 0,
760  int end_bit = sizeof(KeyT) * 8,
761  cudaStream_t stream = 0,
762  bool debug_synchronous = false)
763  {
764  // Signed integer type for global offsets
765  typedef int OffsetT;
766 
767  // Null value type
768  DoubleBuffer<NullType> d_values;
769 
770  return DispatchRadixSort<true, KeyT, NullType, OffsetT>::Dispatch(
771  d_temp_storage,
772  temp_storage_bytes,
773  d_keys,
774  d_values,
775  num_items,
776  begin_bit,
777  end_bit,
778  true,
779  stream,
780  debug_synchronous);
781  }
782 
783 
785 
786 
787 };
788 
793 } // CUB namespace
794 CUB_NS_POSTFIX // Optional outer namespace(s)
795 
796