|
16 | 16 |
|
17 | 17 | #pragma once |
18 | 18 |
|
19 | | -#include <cuco/detail/storage/aow_storage_base.cuh> |
| 19 | +#include <cuco/detail/storage/bucket_storage_base.cuh> |
20 | 20 | #include <cuco/extent.cuh> |
21 | 21 | #include <cuco/utility/allocator.hpp> |
22 | 22 |
|
|
29 | 29 | #include <memory> |
30 | 30 |
|
31 | 31 | namespace cuco { |
| 32 | +/// Bucket type alias |
| 33 | +template <typename T, int32_t BucketSize> |
| 34 | +using bucket = detail::bucket<T, BucketSize>; |
32 | 35 |
|
33 | | -/// Window type alias |
34 | | -template <typename T, int32_t WindowSize> |
35 | | -using window = detail::window<T, WindowSize>; |
36 | | - |
37 | | -/// forward declaration |
38 | | -template <typename T, int32_t WindowSize, typename Extent> |
39 | | -class aow_storage_ref; |
| 36 | +/// Alias for bucket |
| 37 | +template <typename T, int32_t BucketSize> |
| 38 | +using window = bucket<T, BucketSize>; |
40 | 39 |
|
41 | 40 | /** |
42 | | - * @brief Array of Window open addressing storage class. |
| 41 | + * @brief Non-owning array of buckets storage reference type. |
43 | 42 | * |
44 | | - * @tparam T Slot type |
45 | | - * @tparam WindowSize Number of slots in each window |
46 | | - * @tparam Extent Type of extent denoting number of windows |
47 | | - * @tparam Allocator Type of allocator used for device storage (de)allocation |
| 43 | + * @tparam T Storage element type |
| 44 | + * @tparam BucketSize Number of slots in each bucket |
| 45 | + * @tparam Extent Type of extent denoting storage capacity |
48 | 46 | */ |
49 | | -template <typename T, |
50 | | - int32_t WindowSize, |
51 | | - typename Extent = cuco::extent<std::size_t>, |
52 | | - typename Allocator = cuco::cuda_allocator<cuco::window<T, WindowSize>>> |
53 | | -class aow_storage : public detail::aow_storage_base<T, WindowSize, Extent> { |
| 47 | +template <typename T, int32_t BucketSize, typename Extent = cuco::extent<std::size_t>> |
| 48 | +class bucket_storage_ref : public detail::bucket_storage_base<T, BucketSize, Extent> { |
54 | 49 | public: |
55 | | - using base_type = detail::aow_storage_base<T, WindowSize, Extent>; ///< AoW base class type |
| 50 | + /// Array of buckets base class type |
| 51 | + using base_type = detail::bucket_storage_base<T, BucketSize, Extent>; |
56 | 52 |
|
57 | | - using base_type::window_size; ///< Number of elements processed per window |
| 53 | + using base_type::bucket_size; ///< Number of elements processed per bucket |
58 | 54 |
|
59 | 55 | using extent_type = typename base_type::extent_type; ///< Storage extent type |
60 | 56 | using size_type = typename base_type::size_type; ///< Storage size type |
61 | 57 | using value_type = typename base_type::value_type; ///< Slot type |
62 | | - using window_type = typename base_type::window_type; ///< Slot window type |
| 58 | + using bucket_type = typename base_type::bucket_type; ///< Slot bucket type |
63 | 59 |
|
64 | 60 | using base_type::capacity; |
65 | | - using base_type::num_windows; |
66 | | - |
67 | | - /// Type of the allocator to (de)allocate windows |
68 | | - using allocator_type = |
69 | | - typename std::allocator_traits<Allocator>::template rebind_alloc<window_type>; |
70 | | - using window_deleter_type = |
71 | | - detail::custom_deleter<size_type, allocator_type>; ///< Type of window deleter |
72 | | - using ref_type = aow_storage_ref<value_type, window_size, extent_type>; ///< Storage ref type |
| 61 | + using base_type::num_buckets; |
73 | 62 |
|
74 | 63 | /** |
75 | | - * @brief Constructor of AoW storage. |
76 | | - * |
77 | | - * @note The input `size` should be exclusively determined by the return value of |
78 | | - * `make_window_extent` since it depends on the requested low-bound value, the probing scheme, and |
79 | | - * the storage. |
| 64 | + * @brief Constructor of AoS storage ref. |
80 | 65 | * |
81 | | - * @param size Number of windows to (de)allocate |
82 | | - * @param allocator Allocator used for (de)allocating device storage |
| 66 | + * @param size Number of buckets |
| 67 | + * @param buckets Pointer to the buckets array |
83 | 68 | */ |
84 | | - explicit constexpr aow_storage(Extent size, Allocator const& allocator = {}); |
| 69 | + __host__ __device__ explicit constexpr bucket_storage_ref(Extent size, |
| 70 | + bucket_type* buckets) noexcept; |
85 | 71 |
|
86 | | - aow_storage(aow_storage&&) = default; ///< Move constructor |
87 | 72 | /** |
88 | | - * @brief Replaces the contents of the storage with another storage. |
| 73 | + * @brief Custom un-incrementable input iterator for the convenience of `find` operations. |
89 | 74 | * |
90 | | - * @return Reference of the current storage object |
| 75 | + * @note This iterator is for read only and NOT incrementable. |
91 | 76 | */ |
92 | | - aow_storage& operator=(aow_storage&&) = default; |
93 | | - ~aow_storage() = default; ///< Destructor |
94 | | - |
95 | | - aow_storage(aow_storage const&) = delete; |
96 | | - aow_storage& operator=(aow_storage const&) = delete; |
| 77 | + struct iterator; |
| 78 | + using const_iterator = iterator const; ///< Const forward iterator type |
97 | 79 |
|
98 | 80 | /** |
99 | | - * @brief Gets windows array. |
| 81 | + * @brief Returns an iterator to one past the last slot. |
| 82 | + * |
| 83 | + * This is provided for convenience for those familiar with checking |
| 84 | + * an iterator returned from `find()` against the `end()` iterator. |
100 | 85 | * |
101 | | - * @return Pointer to the first window |
| 86 | + * @return An iterator to one past the last slot |
102 | 87 | */ |
103 | | - [[nodiscard]] constexpr window_type* data() const noexcept; |
| 88 | + [[nodiscard]] __device__ constexpr iterator end() noexcept; |
104 | 89 |
|
105 | 90 | /** |
106 | | - * @brief Gets the storage allocator. |
| 91 | + * @brief Returns a const_iterator to one past the last slot. |
107 | 92 | * |
108 | | - * @return The storage allocator |
| 93 | + * This is provided for convenience for those familiar with checking |
| 94 | + * an iterator returned from `find()` against the `end()` iterator. |
| 95 | + * |
| 96 | + * @return A const_iterator to one past the last slot |
109 | 97 | */ |
110 | | - [[nodiscard]] constexpr allocator_type allocator() const noexcept; |
| 98 | + [[nodiscard]] __device__ constexpr const_iterator end() const noexcept; |
111 | 99 |
|
112 | 100 | /** |
113 | | - * @brief Gets window storage reference. |
| 101 | + * @brief Gets buckets array. |
114 | 102 | * |
115 | | - * @return Reference of window storage |
| 103 | + * @return Pointer to the first bucket |
116 | 104 | */ |
117 | | - [[nodiscard]] constexpr ref_type ref() const noexcept; |
| 105 | + [[nodiscard]] __device__ constexpr bucket_type* data() noexcept; |
118 | 106 |
|
119 | 107 | /** |
120 | | - * @brief Initializes each slot in the AoW storage to contain `key`. |
| 108 | + * @brief Gets bucket array. |
121 | 109 | * |
122 | | - * @param key Key to which all keys in `slots` are initialized |
123 | | - * @param stream Stream used for executing the kernel |
| 110 | + * @return Pointer to the first bucket |
124 | 111 | */ |
125 | | - void initialize(value_type key, cuda::stream_ref stream = {}); |
| 112 | + [[nodiscard]] __device__ constexpr bucket_type* data() const noexcept; |
126 | 113 |
|
127 | 114 | /** |
128 | | - * @brief Asynchronously initializes each slot in the AoW storage to contain `key`. |
| 115 | + * @brief Returns an array of slots (or a bucket) for a given index. |
129 | 116 | * |
130 | | - * @param key Key to which all keys in `slots` are initialized |
131 | | - * @param stream Stream used for executing the kernel |
| 117 | + * @param index Index of the bucket |
| 118 | + * @return An array of slots |
132 | 119 | */ |
133 | | - void initialize_async(value_type key, cuda::stream_ref stream = {}) noexcept; |
| 120 | + [[nodiscard]] __device__ constexpr bucket_type operator[](size_type index) const noexcept; |
134 | 121 |
|
135 | 122 | private: |
136 | | - allocator_type allocator_; ///< Allocator used to (de)allocate windows |
137 | | - window_deleter_type window_deleter_; ///< Custom windows deleter |
138 | | - std::unique_ptr<window_type, window_deleter_type> windows_; ///< Pointer to AoW storage |
| 123 | + bucket_type* buckets_; ///< Pointer to the buckets array |
139 | 124 | }; |
140 | 125 |
|
141 | 126 | /** |
142 | | - * @brief Non-owning AoW storage reference type. |
| 127 | + * @brief Array of buckets open addressing storage class. |
143 | 128 | * |
144 | | - * @tparam T Storage element type |
145 | | - * @tparam WindowSize Number of slots in each window |
146 | | - * @tparam Extent Type of extent denoting storage capacity |
| 129 | + * @tparam T Slot type |
| 130 | + * @tparam BucketSize Number of slots in each bucket |
| 131 | + * @tparam Extent Type of extent denoting number of buckets |
| 132 | + * @tparam Allocator Type of allocator used for device storage (de)allocation |
147 | 133 | */ |
148 | | -template <typename T, int32_t WindowSize, typename Extent = cuco::extent<std::size_t>> |
149 | | -class aow_storage_ref : public detail::aow_storage_base<T, WindowSize, Extent> { |
| 134 | +template <typename T, |
| 135 | + int32_t BucketSize, |
| 136 | + typename Extent = cuco::extent<std::size_t>, |
| 137 | + typename Allocator = cuco::cuda_allocator<cuco::bucket<T, BucketSize>>> |
| 138 | +class bucket_storage : public detail::bucket_storage_base<T, BucketSize, Extent> { |
150 | 139 | public: |
151 | | - using base_type = detail::aow_storage_base<T, WindowSize, Extent>; ///< AoW base class type |
| 140 | + /// Array of buckets base class type |
| 141 | + using base_type = detail::bucket_storage_base<T, BucketSize, Extent>; |
152 | 142 |
|
153 | | - using base_type::window_size; ///< Number of elements processed per window |
| 143 | + using base_type::bucket_size; ///< Number of elements processed per bucket |
154 | 144 |
|
155 | 145 | using extent_type = typename base_type::extent_type; ///< Storage extent type |
156 | 146 | using size_type = typename base_type::size_type; ///< Storage size type |
157 | 147 | using value_type = typename base_type::value_type; ///< Slot type |
158 | | - using window_type = typename base_type::window_type; ///< Slot window type |
| 148 | + using bucket_type = typename base_type::bucket_type; ///< Slot bucket type |
159 | 149 |
|
160 | 150 | using base_type::capacity; |
161 | | - using base_type::num_windows; |
| 151 | + using base_type::num_buckets; |
| 152 | + |
| 153 | + /// Type of the allocator to (de)allocate buckets |
| 154 | + using allocator_type = |
| 155 | + typename std::allocator_traits<Allocator>::template rebind_alloc<bucket_type>; |
| 156 | + using bucket_deleter_type = |
| 157 | + detail::custom_deleter<size_type, allocator_type>; ///< Type of bucket deleter |
| 158 | + using ref_type = bucket_storage_ref<value_type, bucket_size, extent_type>; ///< Storage ref type |
162 | 159 |
|
163 | 160 | /** |
164 | | - * @brief Constructor of AoS storage ref. |
| 161 | + * @brief Constructor of bucket storage. |
| 162 | + * |
| 163 | + * @note The input `size` should be exclusively determined by the return value of |
| 164 | + * `make_bucket_extent` since it depends on the requested low-bound value, the probing scheme, and |
| 165 | + * the storage. |
165 | 166 | * |
166 | | - * @param size Number of windows |
167 | | - * @param windows Pointer to the windows array |
| 167 | + * @param size Number of buckets to (de)allocate |
| 168 | + * @param allocator Allocator used for (de)allocating device storage |
168 | 169 | */ |
169 | | - __host__ __device__ explicit constexpr aow_storage_ref(Extent size, |
170 | | - window_type* windows) noexcept; |
| 170 | + explicit constexpr bucket_storage(Extent size, Allocator const& allocator = {}); |
171 | 171 |
|
| 172 | + bucket_storage(bucket_storage&&) = default; ///< Move constructor |
172 | 173 | /** |
173 | | - * @brief Custom un-incrementable input iterator for the convenience of `find` operations. |
| 174 | + * @brief Replaces the contents of the storage with another storage. |
174 | 175 | * |
175 | | - * @note This iterator is for read only and NOT incrementable. |
| 176 | + * @return Reference of the current storage object |
176 | 177 | */ |
177 | | - struct iterator; |
178 | | - using const_iterator = iterator const; ///< Const forward iterator type |
| 178 | + bucket_storage& operator=(bucket_storage&&) = default; |
| 179 | + ~bucket_storage() = default; ///< Destructor |
| 180 | + |
| 181 | + bucket_storage(bucket_storage const&) = delete; |
| 182 | + bucket_storage& operator=(bucket_storage const&) = delete; |
179 | 183 |
|
180 | 184 | /** |
181 | | - * @brief Returns an iterator to one past the last slot. |
| 185 | + * @brief Gets buckets array. |
182 | 186 | * |
183 | | - * This is provided for convenience for those familiar with checking |
184 | | - * an iterator returned from `find()` against the `end()` iterator. |
185 | | - * |
186 | | - * @return An iterator to one past the last slot |
| 187 | + * @return Pointer to the first bucket |
187 | 188 | */ |
188 | | - [[nodiscard]] __device__ constexpr iterator end() noexcept; |
| 189 | + [[nodiscard]] constexpr bucket_type* data() const noexcept; |
189 | 190 |
|
190 | 191 | /** |
191 | | - * @brief Returns a const_iterator to one past the last slot. |
192 | | - * |
193 | | - * This is provided for convenience for those familiar with checking |
194 | | - * an iterator returned from `find()` against the `end()` iterator. |
| 192 | + * @brief Gets the storage allocator. |
195 | 193 | * |
196 | | - * @return A const_iterator to one past the last slot |
| 194 | + * @return The storage allocator |
197 | 195 | */ |
198 | | - [[nodiscard]] __device__ constexpr const_iterator end() const noexcept; |
| 196 | + [[nodiscard]] constexpr allocator_type allocator() const noexcept; |
199 | 197 |
|
200 | 198 | /** |
201 | | - * @brief Gets windows array. |
| 199 | + * @brief Gets bucket storage reference. |
202 | 200 | * |
203 | | - * @return Pointer to the first window |
| 201 | + * @return Reference of bucket storage |
204 | 202 | */ |
205 | | - [[nodiscard]] __device__ constexpr window_type* data() noexcept; |
| 203 | + [[nodiscard]] constexpr ref_type ref() const noexcept; |
206 | 204 |
|
207 | 205 | /** |
208 | | - * @brief Gets windows array. |
| 206 | + * @brief Initializes each slot in the bucket storage to contain `key`. |
209 | 207 | * |
210 | | - * @return Pointer to the first window |
| 208 | + * @param key Key to which all keys in `slots` are initialized |
| 209 | + * @param stream Stream used for executing the kernel |
211 | 210 | */ |
212 | | - [[nodiscard]] __device__ constexpr window_type* data() const noexcept; |
| 211 | + void initialize(value_type key, cuda::stream_ref stream = {}); |
213 | 212 |
|
214 | 213 | /** |
215 | | - * @brief Returns an array of slots (or a window) for a given index. |
| 214 | + * @brief Asynchronously initializes each slot in the bucket storage to contain `key`. |
216 | 215 | * |
217 | | - * @param index Index of the window |
218 | | - * @return An array of slots |
| 216 | + * @param key Key to which all keys in `slots` are initialized |
| 217 | + * @param stream Stream used for executing the kernel |
219 | 218 | */ |
220 | | - [[nodiscard]] __device__ constexpr window_type operator[](size_type index) const noexcept; |
| 219 | + void initialize_async(value_type key, cuda::stream_ref stream = {}) noexcept; |
221 | 220 |
|
222 | 221 | private: |
223 | | - window_type* windows_; ///< Pointer to the windows array |
| 222 | + allocator_type allocator_; ///< Allocator used to (de)allocate buckets |
| 223 | + bucket_deleter_type bucket_deleter_; ///< Custom buckets deleter |
| 224 | + /// Pointer to the bucket storage |
| 225 | + std::unique_ptr<bucket_type, bucket_deleter_type> buckets_; |
224 | 226 | }; |
225 | 227 |
|
| 228 | +/// Alias for bucket_storage_ref |
| 229 | +template <typename T, int32_t BucketSize, typename Extent = cuco::extent<std::size_t>> |
| 230 | +using aow_storage_ref = bucket_storage_ref<T, BucketSize, Extent>; |
| 231 | + |
| 232 | +/// Alias for bucket_storage |
| 233 | +template <typename T, |
| 234 | + int32_t BucketSize, |
| 235 | + typename Extent = cuco::extent<std::size_t>, |
| 236 | + typename Allocator = cuco::cuda_allocator<cuco::bucket<T, BucketSize>>> |
| 237 | +using aow_storage = bucket_storage<T, BucketSize, Extent, Allocator>; |
| 238 | + |
226 | 239 | } // namespace cuco |
227 | 240 |
|
228 | | -#include <cuco/detail/storage/aow_storage.inl> |
| 241 | +#include <cuco/detail/storage/bucket_storage.inl> |
0 commit comments