Blame view

tools/cub-1.8.0/cub/device/device_histogram.cuh 53.1 KB
8dcb6dfcb   Yannick Estève   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
  
  /******************************************************************************
   * Copyright (c) 2011, Duane Merrill.  All rights reserved.
   * Copyright (c) 2011-2018, NVIDIA CORPORATION.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met:
   *     * Redistributions of source code must retain the above copyright
   *       notice, this list of conditions and the following disclaimer.
   *     * Redistributions in binary form must reproduce the above copyright
   *       notice, this list of conditions and the following disclaimer in the
   *       documentation and/or other materials provided with the distribution.
   *     * Neither the name of the NVIDIA CORPORATION nor the
   *       names of its contributors may be used to endorse or promote products
   *       derived from this software without specific prior written permission.
   *
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   ******************************************************************************/
  
  /**
   * \file
   * cub::DeviceHistogram provides device-wide parallel operations for constructing histogram(s) from a sequence of samples data residing within device-accessible memory.
   */
  
  #pragma once
  
  #include <stdio.h>
  #include <iterator>
  #include <limits>
  
  #include "dispatch/dispatch_histogram.cuh"
  #include "../util_namespace.cuh"
  
  /// Optional outer namespace(s)
  CUB_NS_PREFIX
  
  /// CUB namespace
  namespace cub {
  
  
  /**
   * \brief DeviceHistogram provides device-wide parallel operations for constructing histogram(s) from a sequence of samples data residing within device-accessible memory. ![](histogram_logo.png)
   * \ingroup SingleModule
   *
   * \par Overview
   * A <a href="http://en.wikipedia.org/wiki/Histogram"><em>histogram</em></a>
   * counts the number of observations that fall into each of the disjoint categories (known as <em>bins</em>).
   *
   * \par Usage Considerations
   * \cdp_class{DeviceHistogram}
   *
   */
  struct DeviceHistogram
  {
      /******************************************************************//**
       * 
  ame Evenly-segmented bin ranges
       *********************************************************************/
      //@{
  
      /**
       * \brief Computes an intensity histogram from a sequence of data samples using equal-width bins.
       *
       * \par
       * - The number of histogram bins is (\p num_levels - 1)
       * - All bins comprise the same width of sample values: (\p upper_level - \p lower_level) / (\p num_levels - 1)
       * - \devicestorage
       *
       * \par Snippet
       * The code snippet below illustrates the computation of a six-bin histogram
       * from a sequence of float samples
       *
       * \par
       * \code
       * #include <cub/cub.cuh>   // or equivalently <cub/device/device_histogram.cuh>
       *
       * // Declare, allocate, and initialize device-accessible pointers for input samples and
       * // output histogram
       * int      num_samples;    // e.g., 10
       * float*   d_samples;      // e.g., [2.2, 6.0, 7.1, 2.9, 3.5, 0.3, 2.9, 2.0, 6.1, 999.5]
       * int*     d_histogram;    // e.g., [ -, -, -, -, -, -, -, -]
       * int      num_levels;     // e.g., 7       (seven level boundaries for six bins)
       * float    lower_level;    // e.g., 0.0     (lower sample value boundary of lowest bin)
       * float    upper_level;    // e.g., 12.0    (upper sample value boundary of upper bin)
       * ...
       *
       * // Determine temporary device storage requirements
       * void*    d_temp_storage = NULL;
       * size_t   temp_storage_bytes = 0;
       * cub::DeviceHistogram::HistogramEven(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, lower_level, upper_level, num_samples);
       *
       * // Allocate temporary storage
       * cudaMalloc(&d_temp_storage, temp_storage_bytes);
       *
       * // Compute histograms
       * cub::DeviceHistogram::HistogramEven(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, lower_level, upper_level, num_samples);
       *
       * // d_histogram   <-- [1, 0, 5, 0, 3, 0, 0, 0];
       *
       * \endcode
       *
       * \tparam SampleIteratorT          <b>[inferred]</b> Random-access input iterator type for reading input samples. \iterator
       * \tparam CounterT                 <b>[inferred]</b> Integer type for histogram bin counters
       * \tparam LevelT                   <b>[inferred]</b> Type for specifying boundaries (levels)
       * \tparam OffsetT                  <b>[inferred]</b> Signed integer type for sequence offsets, list lengths, pointer differences, etc.  \offset_size1
       */
      template <
          typename            SampleIteratorT,
          typename            CounterT,
          typename            LevelT,
          typename            OffsetT>
      CUB_RUNTIME_FUNCTION
      static cudaError_t HistogramEven(
          void*               d_temp_storage,                             ///< [in] %Device-accessible allocation of temporary storage.  When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done.
          size_t&             temp_storage_bytes,                        ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation
          SampleIteratorT     d_samples,                                  ///< [in] The pointer to the input sequence of data samples.
          CounterT*           d_histogram,                                ///< [out] The pointer to the histogram counter output array of length <tt>num_levels</tt> - 1.
          int                 num_levels,                                 ///< [in] The number of boundaries (levels) for delineating histogram samples.  Implies that the number of bins is <tt>num_levels</tt> - 1.
          LevelT              lower_level,                                ///< [in] The lower sample value bound (inclusive) for the lowest histogram bin.
          LevelT              upper_level,                                ///< [in] The upper sample value bound (exclusive) for the highest histogram bin.
          OffsetT             num_samples,                                ///< [in] The number of input samples (i.e., the length of \p d_samples)
          cudaStream_t        stream                  = 0,                ///< [in] <b>[optional]</b> CUDA stream to launch kernels within.  Default is stream<sub>0</sub>.
          bool                debug_synchronous       = false)            ///< [in] <b>[optional]</b> Whether or not to synchronize the stream after every kernel launch to check for errors.  May cause significant slowdown.  Default is \p false.
      {
          /// The sample value type of the input iterator
          typedef typename std::iterator_traits<SampleIteratorT>::value_type SampleT;
  
          CounterT*           d_histogram1[1]     = {d_histogram};
          int                 num_levels1[1]      = {num_levels};
          LevelT              lower_level1[1]     = {lower_level};
          LevelT              upper_level1[1]     = {upper_level};
  
          return MultiHistogramEven<1, 1>(
              d_temp_storage,
              temp_storage_bytes,
              d_samples,
              d_histogram1,
              num_levels1,
              lower_level1,
              upper_level1,
              num_samples,
              1,
              sizeof(SampleT) * num_samples,
              stream,
              debug_synchronous);
      }
  
  
      /**
       * \brief Computes an intensity histogram from a sequence of data samples using equal-width bins.
       *
       * \par
       * - A two-dimensional <em>region of interest</em> within \p d_samples can be specified
       *   using the \p num_row_samples, num_rows, and \p row_stride_bytes parameters.
       * - The row stride must be a whole multiple of the sample data type
       *   size, i.e., <tt>(row_stride_bytes % sizeof(SampleT)) == 0</tt>.
       * - The number of histogram bins is (\p num_levels - 1)
       * - All bins comprise the same width of sample values: (\p upper_level - \p lower_level) / (\p num_levels - 1)
       * - \devicestorage
       *
       * \par Snippet
       * The code snippet below illustrates the computation of a six-bin histogram
       * from a 2x5 region of interest within a flattened 2x7 array of float samples.
       *
       * \par
       * \code
       * #include <cub/cub.cuh>   // or equivalently <cub/device/device_histogram.cuh>
       *
       * // Declare, allocate, and initialize device-accessible pointers for input samples and
       * // output histogram
       * int      num_row_samples;    // e.g., 5
       * int      num_rows;           // e.g., 2;
       * size_t   row_stride_bytes;   // e.g., 7 * sizeof(float)
       * float*   d_samples;          // e.g., [2.2, 6.0, 7.1, 2.9, 3.5,   -, -,
       *                              //        0.3, 2.9, 2.0, 6.1, 999.5, -, -]
       * int*     d_histogram;        // e.g., [ -, -, -, -, -, -, -, -]
       * int      num_levels;         // e.g., 7       (seven level boundaries for six bins)
       * float    lower_level;        // e.g., 0.0     (lower sample value boundary of lowest bin)
       * float    upper_level;        // e.g., 12.0    (upper sample value boundary of upper bin)
       * ...
       *
       * // Determine temporary device storage requirements
       * void*    d_temp_storage  = NULL;
       * size_t   temp_storage_bytes = 0;
       * cub::DeviceHistogram::HistogramEven(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, lower_level, upper_level,
       *     num_row_samples, num_rows, row_stride_bytes);
       *
       * // Allocate temporary storage
       * cudaMalloc(&d_temp_storage, temp_storage_bytes);
       *
       * // Compute histograms
       * cub::DeviceHistogram::HistogramEven(d_temp_storage, temp_storage_bytes, d_samples, d_histogram,
       *     d_samples, d_histogram, num_levels, lower_level, upper_level,
       *     num_row_samples, num_rows, row_stride_bytes);
       *
       * // d_histogram   <-- [1, 0, 5, 0, 3, 0, 0, 0];
       *
       * \endcode
       *
       * \tparam SampleIteratorT          <b>[inferred]</b> Random-access input iterator type for reading input samples. \iterator
       * \tparam CounterT                 <b>[inferred]</b> Integer type for histogram bin counters
       * \tparam LevelT                   <b>[inferred]</b> Type for specifying boundaries (levels)
       * \tparam OffsetT                  <b>[inferred]</b> Signed integer type for sequence offsets, list lengths, pointer differences, etc.  \offset_size1
       */
      template <
          typename            SampleIteratorT,
          typename            CounterT,
          typename            LevelT,
          typename            OffsetT>
      CUB_RUNTIME_FUNCTION
      static cudaError_t HistogramEven(
          void*               d_temp_storage,                             ///< [in] %Device-accessible allocation of temporary storage.  When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done.
          size_t&             temp_storage_bytes,                        ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation
          SampleIteratorT     d_samples,                                  ///< [in] The pointer to the input sequence of data samples.
          CounterT*           d_histogram,                                ///< [out] The pointer to the histogram counter output array of length <tt>num_levels</tt> - 1.
          int                 num_levels,                                 ///< [in] The number of boundaries (levels) for delineating histogram samples.  Implies that the number of bins is <tt>num_levels</tt> - 1.
          LevelT              lower_level,                                ///< [in] The lower sample value bound (inclusive) for the lowest histogram bin.
          LevelT              upper_level,                                ///< [in] The upper sample value bound (exclusive) for the highest histogram bin.
          OffsetT             num_row_samples,                            ///< [in] The number of data samples per row in the region of interest
          OffsetT             num_rows,                                   ///< [in] The number of rows in the region of interest
          size_t              row_stride_bytes,                           ///< [in] The number of bytes between starts of consecutive rows in the region of interest
          cudaStream_t        stream                  = 0,                ///< [in] <b>[optional]</b> CUDA stream to launch kernels within.  Default is stream<sub>0</sub>.
          bool                debug_synchronous       = false)            ///< [in] <b>[optional]</b> Whether or not to synchronize the stream after every kernel launch to check for errors.  May cause significant slowdown.  Default is \p false.
      {
          CounterT*           d_histogram1[1]     = {d_histogram};
          int                 num_levels1[1]      = {num_levels};
          LevelT              lower_level1[1]     = {lower_level};
          LevelT              upper_level1[1]     = {upper_level};
  
          return MultiHistogramEven<1, 1>(
              d_temp_storage,
              temp_storage_bytes,
              d_samples,
              d_histogram1,
              num_levels1,
              lower_level1,
              upper_level1,
              num_row_samples,
              num_rows,
              row_stride_bytes,
              stream,
              debug_synchronous);
      }
  
      /**
       * \brief Computes per-channel intensity histograms from a sequence of multi-channel "pixel" data samples using equal-width bins.
       *
       * \par
       * - The input is a sequence of <em>pixel</em> structures, where each pixel comprises
       *   a record of \p NUM_CHANNELS consecutive data samples (e.g., an <em>RGBA</em> pixel).
       * - Of the \p NUM_CHANNELS specified, the function will only compute histograms
       *   for the first \p NUM_ACTIVE_CHANNELS (e.g., only <em>RGB</em> histograms from <em>RGBA</em>
       *   pixel samples).
       * - The number of histogram bins for channel<sub><em>i</em></sub> is <tt>num_levels[i]</tt> - 1.
       * - For channel<sub><em>i</em></sub>, the range of values for all histogram bins
       *   have the same width: (<tt>upper_level[i]</tt> - <tt>lower_level[i]</tt>) / (<tt> num_levels[i]</tt> - 1)
       * - \devicestorage
       *
       * \par Snippet
       * The code snippet below illustrates the computation of three 256-bin <em>RGB</em> histograms
       * from a quad-channel sequence of <em>RGBA</em> pixels (8 bits per channel per pixel)
       *
       * \par
       * \code
       * #include <cub/cub.cuh>   // or equivalently <cub/device/device_histogram.cuh>
       *
       * // Declare, allocate, and initialize device-accessible pointers for input samples
       * // and output histograms
       * int              num_pixels;         // e.g., 5
       * unsigned char*   d_samples;          // e.g., [(2, 6, 7, 5), (3, 0, 2, 1), (7, 0, 6, 2),
       *                                      //        (0, 6, 7, 5), (3, 0, 2, 6)]
       * int*             d_histogram[3];     // e.g., three device pointers to three device buffers,
       *                                      //       each allocated with 256 integer counters
       * int              num_levels[3];      // e.g., {257, 257, 257};
       * unsigned int     lower_level[3];     // e.g., {0, 0, 0};
       * unsigned int     upper_level[3];     // e.g., {256, 256, 256};
       * ...
       *
       * // Determine temporary device storage requirements
       * void*    d_temp_storage = NULL;
       * size_t   temp_storage_bytes = 0;
       * cub::DeviceHistogram::MultiHistogramEven<4, 3>(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, lower_level, upper_level, num_pixels);
       *
       * // Allocate temporary storage
       * cudaMalloc(&d_temp_storage, temp_storage_bytes);
       *
       * // Compute histograms
       * cub::DeviceHistogram::MultiHistogramEven<4, 3>(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, lower_level, upper_level, num_pixels);
       *
       * // d_histogram   <-- [ [1, 0, 1, 2, 0, 0, 0, 1, 0, 0, 0, ..., 0],
       * //                     [0, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, ..., 0],
       * //                     [0, 0, 2, 0, 0, 0, 1, 2, 0, 0, 0, ..., 0] ]
       *
       * \endcode
       *
       * \tparam NUM_CHANNELS             Number of channels interleaved in the input data (may be greater than the number of channels being actively histogrammed)
       * \tparam NUM_ACTIVE_CHANNELS      <b>[inferred]</b> Number of channels actively being histogrammed
       * \tparam SampleIteratorT          <b>[inferred]</b> Random-access input iterator type for reading input samples. \iterator
       * \tparam CounterT                 <b>[inferred]</b> Integer type for histogram bin counters
       * \tparam LevelT                   <b>[inferred]</b> Type for specifying boundaries (levels)
       * \tparam OffsetT                  <b>[inferred]</b> Signed integer type for sequence offsets, list lengths, pointer differences, etc.  \offset_size1
       */
      template <
          int                 NUM_CHANNELS,
          int                 NUM_ACTIVE_CHANNELS,
          typename            SampleIteratorT,
          typename            CounterT,
          typename            LevelT,
          typename            OffsetT>
      CUB_RUNTIME_FUNCTION
      static cudaError_t MultiHistogramEven(
          void*               d_temp_storage,                             ///< [in] %Device-accessible allocation of temporary storage.  When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done.
          size_t&             temp_storage_bytes,                        ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation
          SampleIteratorT     d_samples,                                  ///< [in] The pointer to the multi-channel input sequence of data samples. The samples from different channels are assumed to be interleaved (e.g., an array of 32-bit pixels where each pixel consists of four <em>RGBA</em> 8-bit samples).
          CounterT*           d_histogram[NUM_ACTIVE_CHANNELS],           ///< [out] The pointers to the histogram counter output arrays, one for each active channel.  For channel<sub><em>i</em></sub>, the allocation length of <tt>d_histogram[i]</tt> should be <tt>num_levels[i]</tt> - 1.
          int                 num_levels[NUM_ACTIVE_CHANNELS],            ///< [in] The number of boundaries (levels) for delineating histogram samples in each active channel.  Implies that the number of bins for channel<sub><em>i</em></sub> is <tt>num_levels[i]</tt> - 1.
          LevelT              lower_level[NUM_ACTIVE_CHANNELS],           ///< [in] The lower sample value bound (inclusive) for the lowest histogram bin in each active channel.
          LevelT              upper_level[NUM_ACTIVE_CHANNELS],           ///< [in] The upper sample value bound (exclusive) for the highest histogram bin in each active channel.
          OffsetT             num_pixels,                                 ///< [in] The number of multi-channel pixels (i.e., the length of \p d_samples / NUM_CHANNELS)
          cudaStream_t        stream                  = 0,                ///< [in] <b>[optional]</b> CUDA stream to launch kernels within.  Default is stream<sub>0</sub>.
          bool                debug_synchronous       = false)            ///< [in] <b>[optional]</b> Whether or not to synchronize the stream after every kernel launch to check for errors.  May cause significant slowdown.  Default is \p false.
      {
          /// The sample value type of the input iterator
          typedef typename std::iterator_traits<SampleIteratorT>::value_type SampleT;
  
          return MultiHistogramEven<NUM_CHANNELS, NUM_ACTIVE_CHANNELS>(
              d_temp_storage,
              temp_storage_bytes,
              d_samples,
              d_histogram,
              num_levels,
              lower_level,
              upper_level,
              num_pixels,
              1,
              sizeof(SampleT) * NUM_CHANNELS * num_pixels,
              stream,
              debug_synchronous);
      }
  
  
      /**
       * \brief Computes per-channel intensity histograms from a sequence of multi-channel "pixel" data samples using equal-width bins.
       *
       * \par
       * - The input is a sequence of <em>pixel</em> structures, where each pixel comprises
       *   a record of \p NUM_CHANNELS consecutive data samples (e.g., an <em>RGBA</em> pixel).
       * - Of the \p NUM_CHANNELS specified, the function will only compute histograms
       *   for the first \p NUM_ACTIVE_CHANNELS (e.g., only <em>RGB</em> histograms from <em>RGBA</em>
       *   pixel samples).
       * - A two-dimensional <em>region of interest</em> within \p d_samples can be specified
       *   using the \p num_row_samples, num_rows, and \p row_stride_bytes parameters.
       * - The row stride must be a whole multiple of the sample data type
       *   size, i.e., <tt>(row_stride_bytes % sizeof(SampleT)) == 0</tt>.
       * - The number of histogram bins for channel<sub><em>i</em></sub> is <tt>num_levels[i]</tt> - 1.
       * - For channel<sub><em>i</em></sub>, the range of values for all histogram bins
       *   have the same width: (<tt>upper_level[i]</tt> - <tt>lower_level[i]</tt>) / (<tt> num_levels[i]</tt> - 1)
       * - \devicestorage
       *
       * \par Snippet
       * The code snippet below illustrates the computation of three 256-bin <em>RGB</em> histograms from a 2x3 region of
       * interest of within a flattened 2x4 array of quad-channel <em>RGBA</em> pixels (8 bits per channel per pixel).
       *
       * \par
       * \code
       * #include <cub/cub.cuh>   // or equivalently <cub/device/device_histogram.cuh>
       *
       * // Declare, allocate, and initialize device-accessible pointers for input samples
       * // and output histograms
       * int              num_row_pixels;     // e.g., 3
       * int              num_rows;           // e.g., 2
       * size_t           row_stride_bytes;   // e.g., 4 * sizeof(unsigned char) * NUM_CHANNELS
       * unsigned char*   d_samples;          // e.g., [(2, 6, 7, 5), (3, 0, 2, 1), (7, 0, 6, 2), (-, -, -, -),
       *                                      //        (0, 6, 7, 5), (3, 0, 2, 6), (1, 1, 1, 1), (-, -, -, -)]
       * int*             d_histogram[3];     // e.g., three device pointers to three device buffers,
       *                                      //       each allocated with 256 integer counters
       * int              num_levels[3];      // e.g., {257, 257, 257};
       * unsigned int     lower_level[3];     // e.g., {0, 0, 0};
       * unsigned int     upper_level[3];     // e.g., {256, 256, 256};
       * ...
       *
       * // Determine temporary device storage requirements
       * void*    d_temp_storage = NULL;
       * size_t   temp_storage_bytes = 0;
       * cub::DeviceHistogram::MultiHistogramEven<4, 3>(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, lower_level, upper_level,
       *     num_row_pixels, num_rows, row_stride_bytes);
       *
       * // Allocate temporary storage
       * cudaMalloc(&d_temp_storage, temp_storage_bytes);
       *
       * // Compute histograms
       * cub::DeviceHistogram::MultiHistogramEven<4, 3>(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, lower_level, upper_level,
       *     num_row_pixels, num_rows, row_stride_bytes);
       *
       * // d_histogram   <-- [ [1, 1, 1, 2, 0, 0, 0, 1, 0, 0, 0, ..., 0],
       * //                     [0, 4, 0, 0, 0, 0, 2, 0, 0, 0, 0, ..., 0],
       * //                     [0, 1, 2, 0, 0, 0, 1, 2, 0, 0, 0, ..., 0] ]
       *
       * \endcode
       *
       * \tparam NUM_CHANNELS             Number of channels interleaved in the input data (may be greater than the number of channels being actively histogrammed)
       * \tparam NUM_ACTIVE_CHANNELS      <b>[inferred]</b> Number of channels actively being histogrammed
       * \tparam SampleIteratorT          <b>[inferred]</b> Random-access input iterator type for reading input samples. \iterator
       * \tparam CounterT                 <b>[inferred]</b> Integer type for histogram bin counters
       * \tparam LevelT                   <b>[inferred]</b> Type for specifying boundaries (levels)
       * \tparam OffsetT                  <b>[inferred]</b> Signed integer type for sequence offsets, list lengths, pointer differences, etc.  \offset_size1
       */
      template <
          int                 NUM_CHANNELS,
          int                 NUM_ACTIVE_CHANNELS,
          typename            SampleIteratorT,
          typename            CounterT,
          typename            LevelT,
          typename            OffsetT>
      CUB_RUNTIME_FUNCTION
      static cudaError_t MultiHistogramEven(
          void*               d_temp_storage,                             ///< [in] %Device-accessible allocation of temporary storage.  When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done.
          size_t&             temp_storage_bytes,                        ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation
          SampleIteratorT     d_samples,                                  ///< [in] The pointer to the multi-channel input sequence of data samples. The samples from different channels are assumed to be interleaved (e.g., an array of 32-bit pixels where each pixel consists of four <em>RGBA</em> 8-bit samples).
          CounterT*           d_histogram[NUM_ACTIVE_CHANNELS],           ///< [out] The pointers to the histogram counter output arrays, one for each active channel.  For channel<sub><em>i</em></sub>, the allocation length of <tt>d_histogram[i]</tt> should be <tt>num_levels[i]</tt> - 1.
          int                 num_levels[NUM_ACTIVE_CHANNELS],            ///< [in] The number of boundaries (levels) for delineating histogram samples in each active channel.  Implies that the number of bins for channel<sub><em>i</em></sub> is <tt>num_levels[i]</tt> - 1.
          LevelT              lower_level[NUM_ACTIVE_CHANNELS],           ///< [in] The lower sample value bound (inclusive) for the lowest histogram bin in each active channel.
          LevelT              upper_level[NUM_ACTIVE_CHANNELS],           ///< [in] The upper sample value bound (exclusive) for the highest histogram bin in each active channel.
          OffsetT             num_row_pixels,                             ///< [in] The number of multi-channel pixels per row in the region of interest
          OffsetT             num_rows,                                   ///< [in] The number of rows in the region of interest
          size_t              row_stride_bytes,                           ///< [in] The number of bytes between starts of consecutive rows in the region of interest
          cudaStream_t        stream                  = 0,                ///< [in] <b>[optional]</b> CUDA stream to launch kernels within.  Default is stream<sub>0</sub>.
          bool                debug_synchronous       = false)            ///< [in] <b>[optional]</b> Whether or not to synchronize the stream after every kernel launch to check for errors.  May cause significant slowdown.  Default is \p false.
      {
          /// The sample value type of the input iterator
          typedef typename std::iterator_traits<SampleIteratorT>::value_type SampleT;
          Int2Type<sizeof(SampleT) == 1> is_byte_sample;
  
          if ((sizeof(OffsetT) > sizeof(int)) &&
              ((unsigned long long) (num_rows * row_stride_bytes) < (unsigned long long) std::numeric_limits<int>::max()))
          {
              // Down-convert OffsetT data type
  
  
              return DipatchHistogram<NUM_CHANNELS, NUM_ACTIVE_CHANNELS, SampleIteratorT, CounterT, LevelT, int>::DispatchEven(
                  d_temp_storage, temp_storage_bytes, d_samples, d_histogram, num_levels, lower_level, upper_level,
                  (int) num_row_pixels, (int) num_rows, (int) (row_stride_bytes / sizeof(SampleT)),
                  stream, debug_synchronous, is_byte_sample);
          }
  
          return DipatchHistogram<NUM_CHANNELS, NUM_ACTIVE_CHANNELS, SampleIteratorT, CounterT, LevelT, OffsetT>::DispatchEven(
              d_temp_storage, temp_storage_bytes, d_samples, d_histogram, num_levels, lower_level, upper_level,
              num_row_pixels, num_rows, (OffsetT) (row_stride_bytes / sizeof(SampleT)),
              stream, debug_synchronous, is_byte_sample);
      }
  
  
      //@}  end member group
      /******************************************************************//**
       * 
  ame Custom bin ranges
       *********************************************************************/
      //@{
  
      /**
       * \brief Computes an intensity histogram from a sequence of data samples using the specified bin boundary levels.
       *
       * \par
       * - The number of histogram bins is (\p num_levels - 1)
       * - The value range for bin<sub><em>i</em></sub> is [<tt>level[i]</tt>, <tt>level[i+1]</tt>)
       * - \devicestorage
       *
       * \par Snippet
       * The code snippet below illustrates the computation of an six-bin histogram
       * from a sequence of float samples
       *
       * \par
       * \code
       * #include <cub/cub.cuh>   // or equivalently <cub/device/device_histogram.cuh>
       *
       * // Declare, allocate, and initialize device-accessible pointers for input samples and
       * // output histogram
       * int      num_samples;    // e.g., 10
       * float*   d_samples;      // e.g., [2.2, 6.0, 7.1, 2.9, 3.5, 0.3, 2.9, 2.0, 6.1, 999.5]
       * int*     d_histogram;    // e.g., [ -, -, -, -, -, -, -, -]
       * int      num_levels      // e.g., 7 (seven level boundaries for six bins)
       * float*   d_levels;       // e.g., [0.0, 2.0, 4.0, 6.0, 8.0, 12.0, 16.0]
       * ...
       *
       * // Determine temporary device storage requirements
       * void*    d_temp_storage = NULL;
       * size_t   temp_storage_bytes = 0;
       * cub::DeviceHistogram::HistogramRange(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, d_levels, num_samples);
       *
       * // Allocate temporary storage
       * cudaMalloc(&d_temp_storage, temp_storage_bytes);
       *
       * // Compute histograms
       * cub::DeviceHistogram::HistogramRange(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, d_levels, num_samples);
       *
       * // d_histogram   <-- [1, 0, 5, 0, 3, 0, 0, 0];
       *
       * \endcode
       *
       * \tparam SampleIteratorT          <b>[inferred]</b> Random-access input iterator type for reading input samples. \iterator
       * \tparam CounterT                 <b>[inferred]</b> Integer type for histogram bin counters
       * \tparam LevelT                   <b>[inferred]</b> Type for specifying boundaries (levels)
       * \tparam OffsetT                  <b>[inferred]</b> Signed integer type for sequence offsets, list lengths, pointer differences, etc.  \offset_size1
       */
      template <
          typename            SampleIteratorT,
          typename            CounterT,
          typename            LevelT,
          typename            OffsetT>
      CUB_RUNTIME_FUNCTION
      static cudaError_t HistogramRange(
          void*               d_temp_storage,                         ///< [in] %Device-accessible allocation of temporary storage.  When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done.
          size_t&             temp_storage_bytes,                    ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation
          SampleIteratorT     d_samples,                              ///< [in] The pointer to the input sequence of data samples.
          CounterT*           d_histogram,                            ///< [out] The pointer to the histogram counter output array of length <tt>num_levels</tt> - 1.
          int                 num_levels,                             ///< [in] The number of boundaries (levels) for delineating histogram samples.  Implies that the number of bins is <tt>num_levels</tt> - 1.
          LevelT*             d_levels,                               ///< [in] The pointer to the array of boundaries (levels).  Bin ranges are defined by consecutive boundary pairings: lower sample value boundaries are inclusive and upper sample value boundaries are exclusive.
          OffsetT             num_samples,                            ///< [in] The number of data samples per row in the region of interest
          cudaStream_t        stream              = 0,                ///< [in] <b>[optional]</b> CUDA stream to launch kernels within.  Default is stream<sub>0</sub>.
          bool                debug_synchronous   = false)            ///< [in] <b>[optional]</b> Whether or not to synchronize the stream after every kernel launch to check for errors.  May cause significant slowdown.  Default is \p false.
      {
          /// The sample value type of the input iterator
          typedef typename std::iterator_traits<SampleIteratorT>::value_type SampleT;
  
          CounterT*           d_histogram1[1] = {d_histogram};
          int                 num_levels1[1]  = {num_levels};
          LevelT*             d_levels1[1]    = {d_levels};
  
          return MultiHistogramRange<1, 1>(
              d_temp_storage,
              temp_storage_bytes,
              d_samples,
              d_histogram1,
              num_levels1,
              d_levels1,
              num_samples,
              1,
              sizeof(SampleT) * num_samples,
              stream,
              debug_synchronous);
      }
  
  
      /**
       * \brief Computes an intensity histogram from a sequence of data samples using the specified bin boundary levels.
       *
       * \par
       * - A two-dimensional <em>region of interest</em> within \p d_samples can be specified
       *   using the \p num_row_samples, num_rows, and \p row_stride_bytes parameters.
       * - The row stride must be a whole multiple of the sample data type
       *   size, i.e., <tt>(row_stride_bytes % sizeof(SampleT)) == 0</tt>.
       * - The number of histogram bins is (\p num_levels - 1)
       * - The value range for bin<sub><em>i</em></sub> is [<tt>level[i]</tt>, <tt>level[i+1]</tt>)
       * - \devicestorage
       *
       * \par Snippet
       * The code snippet below illustrates the computation of a six-bin histogram
       * from a 2x5 region of interest within a flattened 2x7 array of float samples.
       *
       * \par
       * \code
       * #include <cub/cub.cuh>   // or equivalently <cub/device/device_histogram.cuh>
       *
       * // Declare, allocate, and initialize device-accessible pointers for input samples and
       * // output histogram
       * int      num_row_samples;    // e.g., 5
       * int      num_rows;           // e.g., 2;
       * int      row_stride_bytes;   // e.g., 7 * sizeof(float)
       * float*   d_samples;          // e.g., [2.2, 6.0, 7.1, 2.9, 3.5,   -, -,
       *                              //        0.3, 2.9, 2.0, 6.1, 999.5, -, -]
       * int*     d_histogram;        // e.g., [ , , , , , , , ]
       * int      num_levels          // e.g., 7 (seven level boundaries for six bins)
       * float    *d_levels;          // e.g., [0.0, 2.0, 4.0, 6.0, 8.0, 12.0, 16.0]
       * ...
       *
       * // Determine temporary device storage requirements
       * void*    d_temp_storage = NULL;
       * size_t   temp_storage_bytes = 0;
       * cub::DeviceHistogram::HistogramRange(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, d_levels,
       *     num_row_samples, num_rows, row_stride_bytes);
       *
       * // Allocate temporary storage
       * cudaMalloc(&d_temp_storage, temp_storage_bytes);
       *
       * // Compute histograms
       * cub::DeviceHistogram::HistogramRange(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, d_levels,
       *     num_row_samples, num_rows, row_stride_bytes);
       *
       * // d_histogram   <-- [1, 0, 5, 0, 3, 0, 0, 0];
       *
       * \endcode
       *
       * \tparam SampleIteratorT          <b>[inferred]</b> Random-access input iterator type for reading input samples. \iterator
       * \tparam CounterT                 <b>[inferred]</b> Integer type for histogram bin counters
       * \tparam LevelT                   <b>[inferred]</b> Type for specifying boundaries (levels)
       * \tparam OffsetT                  <b>[inferred]</b> Signed integer type for sequence offsets, list lengths, pointer differences, etc.  \offset_size1
       */
      template <
          typename            SampleIteratorT,
          typename            CounterT,
          typename            LevelT,
          typename            OffsetT>
      CUB_RUNTIME_FUNCTION
      static cudaError_t HistogramRange(
          void*               d_temp_storage,                         ///< [in] %Device-accessible allocation of temporary storage.  When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done.
          size_t&             temp_storage_bytes,                    ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation
          SampleIteratorT     d_samples,                              ///< [in] The pointer to the input sequence of data samples.
          CounterT*           d_histogram,                            ///< [out] The pointer to the histogram counter output array of length <tt>num_levels</tt> - 1.
          int                 num_levels,                             ///< [in] The number of boundaries (levels) for delineating histogram samples.  Implies that the number of bins is <tt>num_levels</tt> - 1.
          LevelT*             d_levels,                               ///< [in] The pointer to the array of boundaries (levels).  Bin ranges are defined by consecutive boundary pairings: lower sample value boundaries are inclusive and upper sample value boundaries are exclusive.
          OffsetT             num_row_samples,                        ///< [in] The number of data samples per row in the region of interest
          OffsetT             num_rows,                               ///< [in] The number of rows in the region of interest
          size_t              row_stride_bytes,                       ///< [in] The number of bytes between starts of consecutive rows in the region of interest
          cudaStream_t        stream              = 0,                ///< [in] <b>[optional]</b> CUDA stream to launch kernels within.  Default is stream<sub>0</sub>.
          bool                debug_synchronous   = false)            ///< [in] <b>[optional]</b> Whether or not to synchronize the stream after every kernel launch to check for errors.  May cause significant slowdown.  Default is \p false.
      {
          CounterT*           d_histogram1[1]     = {d_histogram};
          int                 num_levels1[1]      = {num_levels};
          LevelT*             d_levels1[1]        = {d_levels};
  
          return MultiHistogramRange<1, 1>(
              d_temp_storage,
              temp_storage_bytes,
              d_samples,
              d_histogram1,
              num_levels1,
              d_levels1,
              num_row_samples,
              num_rows,
              row_stride_bytes,
              stream,
              debug_synchronous);
      }
  
      /**
       * \brief Computes per-channel intensity histograms from a sequence of multi-channel "pixel" data samples using the specified bin boundary levels.
       *
       * \par
       * - The input is a sequence of <em>pixel</em> structures, where each pixel comprises
       *   a record of \p NUM_CHANNELS consecutive data samples (e.g., an <em>RGBA</em> pixel).
       * - Of the \p NUM_CHANNELS specified, the function will only compute histograms
       *   for the first \p NUM_ACTIVE_CHANNELS (e.g., <em>RGB</em> histograms from <em>RGBA</em>
       *   pixel samples).
       * - The number of histogram bins for channel<sub><em>i</em></sub> is <tt>num_levels[i]</tt> - 1.
       * - For channel<sub><em>i</em></sub>, the range of values for all histogram bins
       *   have the same width: (<tt>upper_level[i]</tt> - <tt>lower_level[i]</tt>) / (<tt> num_levels[i]</tt> - 1)
       * - \devicestorage
       *
       * \par Snippet
       * The code snippet below illustrates the computation of three 4-bin <em>RGB</em> histograms
       * from a quad-channel sequence of <em>RGBA</em> pixels (8 bits per channel per pixel)
       *
       * \par
       * \code
       * #include <cub/cub.cuh>   // or equivalently <cub/device/device_histogram.cuh>
       *
       * // Declare, allocate, and initialize device-accessible pointers for input samples
       * // and output histograms
       * int            num_pixels;       // e.g., 5
       * unsigned char  *d_samples;       // e.g., [(2, 6, 7, 5),(3, 0, 2, 1),(7, 0, 6, 2),
       *                                  //        (0, 6, 7, 5),(3, 0, 2, 6)]
       * unsigned int   *d_histogram[3];  // e.g., [[ -, -, -, -],[ -, -, -, -],[ -, -, -, -]];
       * int            num_levels[3];    // e.g., {5, 5, 5};
       * unsigned int   *d_levels[3];     // e.g., [ [0, 2, 4, 6, 8],
       *                                  //         [0, 2, 4, 6, 8],
       *                                  //         [0, 2, 4, 6, 8] ];
       * ...
       *
       * // Determine temporary device storage requirements
       * void*    d_temp_storage = NULL;
       * size_t   temp_storage_bytes = 0;
       * cub::DeviceHistogram::MultiHistogramRange<4, 3>(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, d_levels, num_pixels);
       *
       * // Allocate temporary storage
       * cudaMalloc(&d_temp_storage, temp_storage_bytes);
       *
       * // Compute histograms
       * cub::DeviceHistogram::MultiHistogramRange<4, 3>(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, d_levels, num_pixels);
       *
       * // d_histogram   <-- [ [1, 3, 0, 1],
       * //                     [3, 0, 0, 2],
       * //                     [0, 2, 0, 3] ]
       *
       * \endcode
       *
       * \tparam NUM_CHANNELS             Number of channels interleaved in the input data (may be greater than the number of channels being actively histogrammed)
       * \tparam NUM_ACTIVE_CHANNELS      <b>[inferred]</b> Number of channels actively being histogrammed
       * \tparam SampleIteratorT          <b>[inferred]</b> Random-access input iterator type for reading input samples. \iterator
       * \tparam CounterT                 <b>[inferred]</b> Integer type for histogram bin counters
       * \tparam LevelT                   <b>[inferred]</b> Type for specifying boundaries (levels)
       * \tparam OffsetT                  <b>[inferred]</b> Signed integer type for sequence offsets, list lengths, pointer differences, etc.  \offset_size1
       */
      template <
          int                 NUM_CHANNELS,
          int                 NUM_ACTIVE_CHANNELS,
          typename            SampleIteratorT,
          typename            CounterT,
          typename            LevelT,
          typename            OffsetT>
      CUB_RUNTIME_FUNCTION
      static cudaError_t MultiHistogramRange(
          void*               d_temp_storage,                         ///< [in] %Device-accessible allocation of temporary storage.  When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done.
          size_t&             temp_storage_bytes,                    ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation
          SampleIteratorT     d_samples,                              ///< [in] The pointer to the multi-channel input sequence of data samples. The samples from different channels are assumed to be interleaved (e.g., an array of 32-bit pixels where each pixel consists of four <em>RGBA</em> 8-bit samples).
          CounterT*           d_histogram[NUM_ACTIVE_CHANNELS],       ///< [out] The pointers to the histogram counter output arrays, one for each active channel.  For channel<sub><em>i</em></sub>, the allocation length of <tt>d_histogram[i]</tt> should be <tt>num_levels[i]</tt> - 1.
          int                 num_levels[NUM_ACTIVE_CHANNELS],        ///< [in] The number of boundaries (levels) for delineating histogram samples in each active channel.  Implies that the number of bins for channel<sub><em>i</em></sub> is <tt>num_levels[i]</tt> - 1.
          LevelT*             d_levels[NUM_ACTIVE_CHANNELS],          ///< [in] The pointers to the arrays of boundaries (levels), one for each active channel.  Bin ranges are defined by consecutive boundary pairings: lower sample value boundaries are inclusive and upper sample value boundaries are exclusive.
          OffsetT             num_pixels,                             ///< [in] The number of multi-channel pixels (i.e., the length of \p d_samples / NUM_CHANNELS)
          cudaStream_t        stream              = 0,                ///< [in] <b>[optional]</b> CUDA stream to launch kernels within.  Default is stream<sub>0</sub>.
          bool                debug_synchronous   = false)            ///< [in] <b>[optional]</b> Whether or not to synchronize the stream after every kernel launch to check for errors.  May cause significant slowdown.  Default is \p false.
      {
          /// The sample value type of the input iterator
          typedef typename std::iterator_traits<SampleIteratorT>::value_type SampleT;
  
          return MultiHistogramRange<NUM_CHANNELS, NUM_ACTIVE_CHANNELS>(
              d_temp_storage,
              temp_storage_bytes,
              d_samples,
              d_histogram,
              num_levels,
              d_levels,
              num_pixels,
              1,
              sizeof(SampleT) * NUM_CHANNELS * num_pixels,
              stream,
              debug_synchronous);
      }
  
  
      /**
       * \brief Computes per-channel intensity histograms from a sequence of multi-channel "pixel" data samples using the specified bin boundary levels.
       *
       * \par
       * - The input is a sequence of <em>pixel</em> structures, where each pixel comprises
       *   a record of \p NUM_CHANNELS consecutive data samples (e.g., an <em>RGBA</em> pixel).
       * - Of the \p NUM_CHANNELS specified, the function will only compute histograms
       *   for the first \p NUM_ACTIVE_CHANNELS (e.g., <em>RGB</em> histograms from <em>RGBA</em>
       *   pixel samples).
       * - A two-dimensional <em>region of interest</em> within \p d_samples can be specified
       *   using the \p num_row_samples, num_rows, and \p row_stride_bytes parameters.
       * - The row stride must be a whole multiple of the sample data type
       *   size, i.e., <tt>(row_stride_bytes % sizeof(SampleT)) == 0</tt>.
       * - The number of histogram bins for channel<sub><em>i</em></sub> is <tt>num_levels[i]</tt> - 1.
       * - For channel<sub><em>i</em></sub>, the range of values for all histogram bins
       *   have the same width: (<tt>upper_level[i]</tt> - <tt>lower_level[i]</tt>) / (<tt> num_levels[i]</tt> - 1)
       * - \devicestorage
       *
       * \par Snippet
       * The code snippet below illustrates the computation of three 4-bin <em>RGB</em> histograms from a 2x3 region of
       * interest of within a flattened 2x4 array of quad-channel <em>RGBA</em> pixels (8 bits per channel per pixel).
       *
       * \par
       * \code
       * #include <cub/cub.cuh>   // or equivalently <cub/device/device_histogram.cuh>
       *
       * // Declare, allocate, and initialize device-accessible pointers for input samples
       * // and output histograms
       * int              num_row_pixels;     // e.g., 3
       * int              num_rows;           // e.g., 2
       * size_t           row_stride_bytes;   // e.g., 4 * sizeof(unsigned char) * NUM_CHANNELS
       * unsigned char*   d_samples;          // e.g., [(2, 6, 7, 5),(3, 0, 2, 1),(1, 1, 1, 1),(-, -, -, -),
       *                                      //        (7, 0, 6, 2),(0, 6, 7, 5),(3, 0, 2, 6),(-, -, -, -)]
       * int*             d_histogram[3];     // e.g., [[ -, -, -, -],[ -, -, -, -],[ -, -, -, -]];
       * int              num_levels[3];      // e.g., {5, 5, 5};
       * unsigned int*    d_levels[3];        // e.g., [ [0, 2, 4, 6, 8],
       *                                      //         [0, 2, 4, 6, 8],
       *                                      //         [0, 2, 4, 6, 8] ];
       * ...
       *
       * // Determine temporary device storage requirements
       * void*    d_temp_storage = NULL;
       * size_t   temp_storage_bytes = 0;
       * cub::DeviceHistogram::MultiHistogramRange<4, 3>(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, d_levels, num_row_pixels, num_rows, row_stride_bytes);
       *
       * // Allocate temporary storage
       * cudaMalloc(&d_temp_storage, temp_storage_bytes);
       *
       * // Compute histograms
       * cub::DeviceHistogram::MultiHistogramRange<4, 3>(d_temp_storage, temp_storage_bytes,
       *     d_samples, d_histogram, num_levels, d_levels, num_row_pixels, num_rows, row_stride_bytes);
       *
       * // d_histogram   <-- [ [2, 3, 0, 1],
       * //                     [3, 0, 0, 2],
       * //                     [1, 2, 0, 3] ]
       *
       * \endcode
       *
       * \tparam NUM_CHANNELS             Number of channels interleaved in the input data (may be greater than the number of channels being actively histogrammed)
       * \tparam NUM_ACTIVE_CHANNELS      <b>[inferred]</b> Number of channels actively being histogrammed
       * \tparam SampleIteratorT          <b>[inferred]</b> Random-access input iterator type for reading input samples. \iterator
       * \tparam CounterT                 <b>[inferred]</b> Integer type for histogram bin counters
       * \tparam LevelT                   <b>[inferred]</b> Type for specifying boundaries (levels)
       * \tparam OffsetT                  <b>[inferred]</b> Signed integer type for sequence offsets, list lengths, pointer differences, etc.  \offset_size1
       */
      template <
          int                 NUM_CHANNELS,
          int                 NUM_ACTIVE_CHANNELS,
          typename            SampleIteratorT,
          typename            CounterT,
          typename            LevelT,
          typename            OffsetT>
      CUB_RUNTIME_FUNCTION
      static cudaError_t MultiHistogramRange(
          void*               d_temp_storage,                         ///< [in] %Device-accessible allocation of temporary storage.  When NULL, the required allocation size is written to \p temp_storage_bytes and no work is done.
          size_t&             temp_storage_bytes,                    ///< [in,out] Reference to size in bytes of \p d_temp_storage allocation
          SampleIteratorT     d_samples,                              ///< [in] The pointer to the multi-channel input sequence of data samples. The samples from different channels are assumed to be interleaved (e.g., an array of 32-bit pixels where each pixel consists of four <em>RGBA</em> 8-bit samples).
          CounterT*           d_histogram[NUM_ACTIVE_CHANNELS],       ///< [out] The pointers to the histogram counter output arrays, one for each active channel.  For channel<sub><em>i</em></sub>, the allocation length of <tt>d_histogram[i]</tt> should be <tt>num_levels[i]</tt> - 1.
          int                 num_levels[NUM_ACTIVE_CHANNELS],        ///< [in] The number of boundaries (levels) for delineating histogram samples in each active channel.  Implies that the number of bins for channel<sub><em>i</em></sub> is <tt>num_levels[i]</tt> - 1.
          LevelT*             d_levels[NUM_ACTIVE_CHANNELS],          ///< [in] The pointers to the arrays of boundaries (levels), one for each active channel.  Bin ranges are defined by consecutive boundary pairings: lower sample value boundaries are inclusive and upper sample value boundaries are exclusive.
          OffsetT             num_row_pixels,                         ///< [in] The number of multi-channel pixels per row in the region of interest
          OffsetT             num_rows,                               ///< [in] The number of rows in the region of interest
          size_t              row_stride_bytes,                       ///< [in] The number of bytes between starts of consecutive rows in the region of interest
          cudaStream_t        stream              = 0,                ///< [in] <b>[optional]</b> CUDA stream to launch kernels within.  Default is stream<sub>0</sub>.
          bool                debug_synchronous   = false)            ///< [in] <b>[optional]</b> Whether or not to synchronize the stream after every kernel launch to check for errors.  May cause significant slowdown.  Default is \p false.
      {
          /// The sample value type of the input iterator
          typedef typename std::iterator_traits<SampleIteratorT>::value_type SampleT;
          Int2Type<sizeof(SampleT) == 1> is_byte_sample;
  
          if ((sizeof(OffsetT) > sizeof(int)) &&
              ((unsigned long long) (num_rows * row_stride_bytes) < (unsigned long long) std::numeric_limits<int>::max()))
          {
              // Down-convert OffsetT data type
              return DipatchHistogram<NUM_CHANNELS, NUM_ACTIVE_CHANNELS, SampleIteratorT, CounterT, LevelT, int>::DispatchRange(
                  d_temp_storage, temp_storage_bytes, d_samples, d_histogram, num_levels, d_levels,
                  (int) num_row_pixels, (int) num_rows, (int) (row_stride_bytes / sizeof(SampleT)),
                  stream, debug_synchronous, is_byte_sample);
          }
  
          return DipatchHistogram<NUM_CHANNELS, NUM_ACTIVE_CHANNELS, SampleIteratorT, CounterT, LevelT, OffsetT>::DispatchRange(
              d_temp_storage, temp_storage_bytes, d_samples, d_histogram, num_levels, d_levels,
              num_row_pixels, num_rows, (OffsetT) (row_stride_bytes / sizeof(SampleT)),
              stream, debug_synchronous, is_byte_sample);
      }
  
  
  
      //@}  end member group
  };
  
  }               // CUB namespace
  CUB_NS_POSTFIX  // Optional outer namespace(s)