/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.2.3/hipcub/include/hipcub/backend/rocprim/block/block_histogram.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.2.3/hipcub/include/hipcub/backend/rocprim/block/block_histogram.hpp Source File#

hipCUB: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.2.3/hipcub/include/hipcub/backend/rocprim/block/block_histogram.hpp Source File
block_histogram.hpp
1 /******************************************************************************
2  * Copyright (c) 2010-2011, Duane Merrill. All rights reserved.
3  * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
4  * Modifications Copyright (c) 2017-2020, Advanced Micro Devices, Inc. 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 
30 #ifndef HIPCUB_ROCPRIM_BLOCK_BLOCK_HISTOGRAM_HPP_
31 #define HIPCUB_ROCPRIM_BLOCK_BLOCK_HISTOGRAM_HPP_
32 
33 #include <type_traits>
34 
35 #include <rocprim/block/block_histogram.hpp>
36 
37 BEGIN_HIPCUB_NAMESPACE
38 
39 namespace detail
40 {
41  inline constexpr
42  typename std::underlying_type<::rocprim::block_histogram_algorithm>::type
43  to_BlockHistogramAlgorithm_enum(::rocprim::block_histogram_algorithm v)
44  {
45  using utype = std::underlying_type<::rocprim::block_histogram_algorithm>::type;
46  return static_cast<utype>(v);
47  }
48 }
49 
50 enum BlockHistogramAlgorithm
51 {
52  BLOCK_HISTO_ATOMIC
53  = detail::to_BlockHistogramAlgorithm_enum(::rocprim::block_histogram_algorithm::using_atomic),
54  BLOCK_HISTO_SORT
55  = detail::to_BlockHistogramAlgorithm_enum(::rocprim::block_histogram_algorithm::using_sort)
56 };
57 
58 template<
59  typename T,
60  int BLOCK_DIM_X,
61  int ITEMS_PER_THREAD,
62  int BINS,
63  BlockHistogramAlgorithm ALGORITHM = BLOCK_HISTO_SORT,
64  int BLOCK_DIM_Y = 1,
65  int BLOCK_DIM_Z = 1,
66  int ARCH = HIPCUB_ARCH /* ignored */
67 >
69  : private ::rocprim::block_histogram<
70  T,
71  BLOCK_DIM_X,
72  ITEMS_PER_THREAD,
73  BINS,
74  static_cast<::rocprim::block_histogram_algorithm>(ALGORITHM),
75  BLOCK_DIM_Y,
76  BLOCK_DIM_Z
77  >
78 {
79  static_assert(
80  BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z > 0,
81  "BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z must be greater than 0"
82  );
83 
84  using base_type =
85  typename ::rocprim::block_histogram<
86  T,
87  BLOCK_DIM_X,
88  ITEMS_PER_THREAD,
89  BINS,
90  static_cast<::rocprim::block_histogram_algorithm>(ALGORITHM),
91  BLOCK_DIM_Y,
92  BLOCK_DIM_Z
93  >;
94 
95  // Reference to temporary storage (usually shared memory)
96  typename base_type::storage_type& temp_storage_;
97 
98 public:
99  using TempStorage = typename base_type::storage_type;
100 
101  HIPCUB_DEVICE inline
102  BlockHistogram() : temp_storage_(private_storage())
103  {
104  }
105 
106  HIPCUB_DEVICE inline
107  BlockHistogram(TempStorage& temp_storage) : temp_storage_(temp_storage)
108  {
109  }
110 
111  template<class CounterT>
112  HIPCUB_DEVICE inline
113  void InitHistogram(CounterT histogram[BINS])
114  {
115  base_type::init_histogram(histogram);
116  }
117 
118  template<class CounterT>
119  HIPCUB_DEVICE inline
120  void Composite(T (&items)[ITEMS_PER_THREAD],
121  CounterT histogram[BINS])
122  {
123  base_type::composite(items, histogram, temp_storage_);
124  }
125 
126  template<class CounterT>
127  HIPCUB_DEVICE inline
128  void Histogram(T (&items)[ITEMS_PER_THREAD],
129  CounterT histogram[BINS])
130  {
131  base_type::init_histogram(histogram);
132  CTA_SYNC();
133  base_type::composite(items, histogram, temp_storage_);
134  }
135 
136 private:
137  HIPCUB_DEVICE inline
138  TempStorage& private_storage()
139  {
140  HIPCUB_SHARED_MEMORY TempStorage private_storage;
141  return private_storage;
142  }
143 };
144 
145 END_HIPCUB_NAMESPACE
146 
147 #endif // HIPCUB_ROCPRIM_BLOCK_BLOCK_HISTOGRAM_HPP_
Definition: block_histogram.hpp:78