CUB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
device_histogram.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_histogram_dispatch.cuh"
41 #include "../util_namespace.cuh"
42 
44 CUB_NS_PREFIX
45 
47 namespace cub {
48 
49 
67 {
68  /******************************************************************/
72 
73 
124  template <
125  int BINS,
126  typename InputIterator,
127  typename HistoCounter>
128  CUB_RUNTIME_FUNCTION
129  static cudaError_t SingleChannelSorting(
130  void *d_temp_storage,
131  size_t &temp_storage_bytes,
132  InputIterator d_samples,
133  HistoCounter* d_histogram,
134  int num_samples,
135  cudaStream_t stream = 0,
136  bool debug_synchronous = false)
137  {
138  // Signed integer type for global offsets
139  typedef int Offset;
140 
141  // Dispatch type
142  typedef DeviceHistogramDispatch<
143  DEVICE_HISTO_SORT,
144  BINS,
145  1,
146  1,
147  InputIterator,
148  HistoCounter,
149  Offset>
150  DeviceHistogramDispatch;
151 
152  return DeviceHistogramDispatch::Dispatch(
153  d_temp_storage,
154  temp_storage_bytes,
155  d_samples,
156  &d_histogram,
157  num_samples,
158  stream,
159  debug_synchronous);
160  }
161 
162 
212  template <
213  int BINS,
214  typename InputIterator,
215  typename HistoCounter>
216  CUB_RUNTIME_FUNCTION
217  static cudaError_t SingleChannelSharedAtomic(
218  void *d_temp_storage,
219  size_t &temp_storage_bytes,
220  InputIterator d_samples,
221  HistoCounter* d_histogram,
222  int num_samples,
223  cudaStream_t stream = 0,
224  bool debug_synchronous = false)
225  {
226  // Signed integer type for global offsets
227  typedef int Offset;
228 
229  // Dispatch type
230  typedef DeviceHistogramDispatch<
231  DEVICE_HISTO_SHARED_ATOMIC,
232  BINS,
233  1,
234  1,
235  InputIterator,
236  HistoCounter,
237  Offset>
238  DeviceHistogramDispatch;
239 
240  return DeviceHistogramDispatch::Dispatch(
241  d_temp_storage,
242  temp_storage_bytes,
243  d_samples,
244  &d_histogram,
245  num_samples,
246  stream,
247  debug_synchronous);
248  }
249 
250 
300  template <
301  int BINS,
302  typename InputIterator,
303  typename HistoCounter>
304  CUB_RUNTIME_FUNCTION
305  static cudaError_t SingleChannelGlobalAtomic(
306  void *d_temp_storage,
307  size_t &temp_storage_bytes,
308  InputIterator d_samples,
309  HistoCounter* d_histogram,
310  int num_samples,
311  cudaStream_t stream = 0,
312  bool debug_synchronous = false)
313  {
314  // Signed integer type for global offsets
315  typedef int Offset;
316 
317  // Dispatch type
318  typedef DeviceHistogramDispatch<
319  DEVICE_HISTO_GLOBAL_ATOMIC,
320  BINS,
321  1,
322  1,
323  InputIterator,
324  HistoCounter,
325  Offset>
326  DeviceHistogramDispatch;
327 
328  return DeviceHistogramDispatch::Dispatch(
329  d_temp_storage,
330  temp_storage_bytes,
331  d_samples,
332  &d_histogram,
333  num_samples,
334  stream,
335  debug_synchronous);
336  }
337 
338 
340  /******************************************************************/
344 
345 
405  template <
406  int BINS,
407  int CHANNELS,
408  int ACTIVE_CHANNELS,
409  typename InputIterator,
410  typename HistoCounter>
411  CUB_RUNTIME_FUNCTION
412  static cudaError_t MultiChannelSorting(
413  void *d_temp_storage,
414  size_t &temp_storage_bytes,
415  InputIterator d_samples,
416  HistoCounter *d_histograms[ACTIVE_CHANNELS],
417  int num_samples,
418  cudaStream_t stream = 0,
419  bool debug_synchronous = false)
420  {
421  // Signed integer type for global offsets
422  typedef int Offset;
423 
424  // Dispatch type
425  typedef DeviceHistogramDispatch<
426  DEVICE_HISTO_SORT,
427  BINS,
428  CHANNELS,
429  ACTIVE_CHANNELS,
430  InputIterator,
431  HistoCounter,
432  Offset> DeviceHistogramDispatch;
433 
434  return DeviceHistogramDispatch::Dispatch(
435  d_temp_storage,
436  temp_storage_bytes,
437  d_samples,
438  d_histograms,
439  num_samples,
440  stream,
441  debug_synchronous);
442  }
443 
444 
503  template <
504  int BINS,
505  int CHANNELS,
506  int ACTIVE_CHANNELS,
507  typename InputIterator,
508  typename HistoCounter>
509  CUB_RUNTIME_FUNCTION
510  static cudaError_t MultiChannelSharedAtomic(
511  void *d_temp_storage,
512  size_t &temp_storage_bytes,
513  InputIterator d_samples,
514  HistoCounter *d_histograms[ACTIVE_CHANNELS],
515  int num_samples,
516  cudaStream_t stream = 0,
517  bool debug_synchronous = false)
518  {
519  // Signed integer type for global offsets
520  typedef int Offset;
521 
522  // Dispatch type
523  typedef DeviceHistogramDispatch<
524  DEVICE_HISTO_SHARED_ATOMIC,
525  BINS,
526  CHANNELS,
527  ACTIVE_CHANNELS,
528  InputIterator,
529  HistoCounter,
530  Offset> DeviceHistogramDispatch;
531 
532  return DeviceHistogramDispatch::Dispatch(
533  d_temp_storage,
534  temp_storage_bytes,
535  d_samples,
536  d_histograms,
537  num_samples,
538  stream,
539  debug_synchronous);
540  }
541 
542 
602  template <
603  int BINS,
604  int CHANNELS,
605  int ACTIVE_CHANNELS,
606  typename InputIterator,
607  typename HistoCounter>
608  CUB_RUNTIME_FUNCTION
609  static cudaError_t MultiChannelGlobalAtomic(
610  void *d_temp_storage,
611  size_t &temp_storage_bytes,
612  InputIterator d_samples,
613  HistoCounter *d_histograms[ACTIVE_CHANNELS],
614  int num_samples,
615  cudaStream_t stream = 0,
616  bool debug_synchronous = false)
617  {
618  // Signed integer type for global offsets
619  typedef int Offset;
620 
621  // Dispatch type
622  typedef DeviceHistogramDispatch<
623  DEVICE_HISTO_GLOBAL_ATOMIC,
624  BINS,
625  CHANNELS,
626  ACTIVE_CHANNELS,
627  InputIterator,
628  HistoCounter,
629  Offset>
630  DeviceHistogramDispatch;
631 
632  return DeviceHistogramDispatch::Dispatch(
633  d_temp_storage,
634  temp_storage_bytes,
635  d_samples,
636  d_histograms,
637  num_samples,
638  stream,
639  debug_synchronous);
640  }
641 
643 
644 };
645 
650 } // CUB namespace
651 CUB_NS_POSTFIX // Optional outer namespace(s)
652 
653