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-2014, 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/device_radix_sort_dispatch.cuh"
41 #include "../util_namespace.cuh"
42 
44 CUB_NS_PREFIX
45 
47 namespace cub {
48 
49 
82 {
140  template <
141  typename Key,
142  typename Value>
143  CUB_RUNTIME_FUNCTION
144  static cudaError_t SortPairs(
145  void *d_temp_storage,
146  size_t &temp_storage_bytes,
147  DoubleBuffer<Key> &d_keys,
148  DoubleBuffer<Value> &d_values,
149  int num_items,
150  int begin_bit = 0,
151  int end_bit = sizeof(Key) * 8,
152  cudaStream_t stream = 0,
153  bool debug_synchronous = false)
154  {
155  // Signed integer type for global offsets
156  typedef int Offset;
157 
158  return DeviceRadixSortDispatch<false, Key, Value, Offset>::Dispatch(
159  d_temp_storage,
160  temp_storage_bytes,
161  d_keys,
162  d_values,
163  num_items,
164  begin_bit,
165  end_bit,
166  stream,
167  debug_synchronous);
168  }
169 
170 
223  template <
224  typename Key,
225  typename Value>
226  CUB_RUNTIME_FUNCTION
227  static cudaError_t SortPairsDescending(
228  void *d_temp_storage,
229  size_t &temp_storage_bytes,
230  DoubleBuffer<Key> &d_keys,
231  DoubleBuffer<Value> &d_values,
232  int num_items,
233  int begin_bit = 0,
234  int end_bit = sizeof(Key) * 8,
235  cudaStream_t stream = 0,
236  bool debug_synchronous = false)
237  {
238  // Signed integer type for global offsets
239  typedef int Offset;
240 
241  return DeviceRadixSortDispatch<true, Key, Value, Offset>::Dispatch(
242  d_temp_storage,
243  temp_storage_bytes,
244  d_keys,
245  d_values,
246  num_items,
247  begin_bit,
248  end_bit,
249  stream,
250  debug_synchronous);
251  }
252 
253 
304  template <typename Key>
305  CUB_RUNTIME_FUNCTION
306  static cudaError_t SortKeys(
307  void *d_temp_storage,
308  size_t &temp_storage_bytes,
309  DoubleBuffer<Key> &d_keys,
310  int num_items,
311  int begin_bit = 0,
312  int end_bit = sizeof(Key) * 8,
313  cudaStream_t stream = 0,
314  bool debug_synchronous = false)
315  {
316  // Signed integer type for global offsets
317  typedef int Offset;
318 
319  // Null value type
320  DoubleBuffer<NullType> d_values;
321 
322  return DeviceRadixSortDispatch<false, Key, NullType, Offset>::Dispatch(
323  d_temp_storage,
324  temp_storage_bytes,
325  d_keys,
326  d_values,
327  num_items,
328  begin_bit,
329  end_bit,
330  stream,
331  debug_synchronous);
332  }
333 
334 
381  template <typename Key>
382  CUB_RUNTIME_FUNCTION
383  static cudaError_t SortKeysDescending(
384  void *d_temp_storage,
385  size_t &temp_storage_bytes,
386  DoubleBuffer<Key> &d_keys,
387  int num_items,
388  int begin_bit = 0,
389  int end_bit = sizeof(Key) * 8,
390  cudaStream_t stream = 0,
391  bool debug_synchronous = false)
392  {
393  // Signed integer type for global offsets
394  typedef int Offset;
395 
396  // Null value type
397  DoubleBuffer<NullType> d_values;
398 
399  return DeviceRadixSortDispatch<true, Key, NullType, Offset>::Dispatch(
400  d_temp_storage,
401  temp_storage_bytes,
402  d_keys,
403  d_values,
404  num_items,
405  begin_bit,
406  end_bit,
407  stream,
408  debug_synchronous);
409  }
410 
411 };
412 
417 } // CUB namespace
418 CUB_NS_POSTFIX // Optional outer namespace(s)
419 
420