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-2015, 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_namespace.cuh"
42 
44 CUB_NS_PREFIX
45 
47 namespace cub {
48 
49 
82 {
83 
84  /******************************************************************/
88 
143  template <
144  typename Key,
145  typename Value>
146  CUB_RUNTIME_FUNCTION
147  static cudaError_t SortPairs(
148  void* d_temp_storage,
149  size_t& temp_storage_bytes,
150  Key *d_keys_in,
151  Key *d_keys_out,
152  Value *d_values_in,
153  Value *d_values_out,
154  int num_items,
155  int begin_bit = 0,
156  int end_bit = sizeof(Key) * 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<Key> d_keys(d_keys_in, d_keys_out);
164  DoubleBuffer<Value> d_values(d_values_in, d_values_out);
165 
166  return DispatchRadixSort<false, true, Key, Value, 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  stream,
175  debug_synchronous);
176  }
177 
178 
244  template <
245  typename Key,
246  typename Value>
247  CUB_RUNTIME_FUNCTION
248  static cudaError_t SortPairs(
249  void* d_temp_storage,
250  size_t& temp_storage_bytes,
251  DoubleBuffer<Key> &d_keys,
252  DoubleBuffer<Value> &d_values,
253  int num_items,
254  int begin_bit = 0,
255  int end_bit = sizeof(Key) * 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, false, Key, Value, 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  stream,
271  debug_synchronous);
272  }
273 
274 
324  template <
325  typename Key,
326  typename Value>
327  CUB_RUNTIME_FUNCTION
328  static cudaError_t SortPairsDescending(
329  void* d_temp_storage,
330  size_t& temp_storage_bytes,
331  Key *d_keys_in,
332  Key *d_keys_out,
333  Value *d_values_in,
334  Value *d_values_out,
335  int num_items,
336  int begin_bit = 0,
337  int end_bit = sizeof(Key) * 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<Key> d_keys(d_keys_in, d_keys_out);
345  DoubleBuffer<Value> d_values(d_values_in, d_values_out);
346 
347  return DispatchRadixSort<true, true, Key, Value, 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  stream,
356  debug_synchronous);
357  }
358 
359 
420  template <
421  typename Key,
422  typename Value>
423  CUB_RUNTIME_FUNCTION
424  static cudaError_t SortPairsDescending(
425  void* d_temp_storage,
426  size_t& temp_storage_bytes,
427  DoubleBuffer<Key> &d_keys,
428  DoubleBuffer<Value> &d_values,
429  int num_items,
430  int begin_bit = 0,
431  int end_bit = sizeof(Key) * 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, false, Key, Value, 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  stream,
447  debug_synchronous);
448  }
449 
450 
452  /******************************************************************/
456 
457 
504  template <typename Key>
505  CUB_RUNTIME_FUNCTION
506  static cudaError_t SortKeys(
507  void* d_temp_storage,
508  size_t& temp_storage_bytes,
509  Key *d_keys_in,
510  Key *d_keys_out,
511  int num_items,
512  int begin_bit = 0,
513  int end_bit = sizeof(Key) * 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<Key> d_keys(d_keys_in, d_keys_out);
522  DoubleBuffer<NullType> d_values;
523 
524  return DispatchRadixSort<false, true, Key, 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  stream,
533  debug_synchronous);
534  }
535 
536 
593  template <typename Key>
594  CUB_RUNTIME_FUNCTION
595  static cudaError_t SortKeys(
596  void* d_temp_storage,
597  size_t& temp_storage_bytes,
598  DoubleBuffer<Key> &d_keys,
599  int num_items,
600  int begin_bit = 0,
601  int end_bit = sizeof(Key) * 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, false, Key, 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  stream,
620  debug_synchronous);
621  }
622 
668  template <typename Key>
669  CUB_RUNTIME_FUNCTION
670  static cudaError_t SortKeysDescending(
671  void* d_temp_storage,
672  size_t& temp_storage_bytes,
673  Key *d_keys_in,
674  Key *d_keys_out,
675  int num_items,
676  int begin_bit = 0,
677  int end_bit = sizeof(Key) * 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<Key> d_keys(d_keys_in, d_keys_out);
685  DoubleBuffer<NullType> d_values;
686 
687  return DispatchRadixSort<true, false, Key, 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  stream,
696  debug_synchronous);
697  }
698 
699 
752  template <typename Key>
753  CUB_RUNTIME_FUNCTION
754  static cudaError_t SortKeysDescending(
755  void* d_temp_storage,
756  size_t& temp_storage_bytes,
757  DoubleBuffer<Key> &d_keys,
758  int num_items,
759  int begin_bit = 0,
760  int end_bit = sizeof(Key) * 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, false, Key, 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  stream,
779  debug_synchronous);
780  }
781 
782 
784 
785 
786 };
787 
792 } // CUB namespace
793 CUB_NS_POSTFIX // Optional outer namespace(s)
794 
795