21 #ifndef ROCPRIM_DETAIL_TEMP_STORAGE_HPP_ 22 #define ROCPRIM_DETAIL_TEMP_STORAGE_HPP_ 26 #include "../config.hpp" 27 #include "../types.hpp" 28 #include "various.hpp" 30 BEGIN_ROCPRIM_NAMESPACE
34 namespace temp_storage
38 constexpr
size_t default_alignment = 256;
43 constexpr
size_t minimum_allocation_size = 4;
70 return this->storage_layout;
78 *this->dest = this->storage_layout.
size == 0 ? nullptr :
static_cast<T*
>(storage);
111 return make_partition(dest, elements *
sizeof(T),
alignof(T));
122 template<
typename... Ts>
134 size_t required_alignment = 1;
135 size_t required_size = 0;
137 for_each_in_tuple(this->sub_partitions,
138 [&](
auto& sub_partition)
140 const auto sub_layout = sub_partition.get_layout();
143 =
std::max(required_alignment, sub_layout.alignment);
145 if(sub_layout.size > 0)
146 required_size = align_size(required_size, sub_layout.alignment)
150 return {required_size, required_alignment};
159 for_each_in_tuple(this->sub_partitions,
160 [&](
auto& sub_partition)
162 const auto sub_layout = sub_partition.get_layout();
164 if(sub_layout.size > 0)
165 offset = align_size(offset, sub_layout.alignment);
167 sub_partition.set_storage(
168 static_cast<void*>(static_cast<char*>(storage) + offset));
169 offset += sub_layout.size;
177 template<
typename... Ts>
190 template<
typename... Ts>
202 size_t required_alignment = 1;
203 size_t required_size = 0;
205 for_each_in_tuple(this->sub_partitions,
206 [&](
auto& sub_partition)
208 const auto sub_layout = sub_partition.get_layout();
211 =
std::max(required_alignment, sub_layout.alignment);
212 required_size =
std::max(required_size, sub_layout.size);
215 return {required_size, required_alignment};
223 for_each_in_tuple(this->sub_partitions,
224 [&](
auto& sub_partition) { sub_partition.set_storage(storage); });
231 template<
typename... Ts>
263 template<
typename TempStoragePartition>
265 partition(
void*
const temporary_storage,
size_t& storage_size, TempStoragePartition
partition)
267 const auto layout = partition.get_layout();
271 if(temporary_storage ==
nullptr)
273 storage_size = required_size;
276 else if(storage_size < required_size)
278 return hipErrorInvalidValue;
281 partition.set_storage(temporary_storage);
288 END_ROCPRIM_NAMESPACE
290 #endif // ROCPRIM_DETAIL_TEMP_STORAGE_HPP_ A partition that represents a linear sequence of sub-partitions.
Definition: temp_storage.hpp:123
ROCPRIM_HOST_DEVICE constexpr T max(const T &a, const T &b)
Returns the maximum of its arguments.
Definition: functional.hpp:55
layout get_layout()
Compute the required layout for this type and return it.
Definition: temp_storage.hpp:200
This structure describes a single required partition of temporary global memory, as well as where to ...
Definition: temp_storage.hpp:60
hipError_t partition(void *temporary_storage, size_t &storage_size, InputIterator input, FlagIterator flags, OutputIterator output, SelectedCountOutputIterator selected_count_output, const size_t size, const hipStream_t stream=0, const bool debug_synchronous=false)
Parallel select primitive for device level using range of flags.
Definition: device_partition.hpp:721
T ** dest
The location to store the pointer to the partitioned memory.
Definition: temp_storage.hpp:63
layout get_layout()
Compute the required layout for this type and return it.
Definition: temp_storage.hpp:132
This value-structure describes the required layout of some piece of temporary memory, which includes the required size and the required alignment.
Definition: temp_storage.hpp:47
::rocprim::tuple< Ts... > sub_partitions
The sub-partitions in this union_partition.
Definition: temp_storage.hpp:194
layout storage_layout
The required memory layout of the memory that this partition should get.
Definition: temp_storage.hpp:65
A partition that represents a union of sub-partitions of temporary memories which are not used at the...
Definition: temp_storage.hpp:191
Deprecated: Configuration of device-level scan primitives.
Definition: block_histogram.hpp:62
void set_storage(void *const storage)
Assigns the final storage for this partition.
Definition: temp_storage.hpp:156
size_t size
The required size of the temporary memory, in bytes.
Definition: temp_storage.hpp:50
void set_storage(void *const storage)
Assigns the final storage for this partition.
Definition: temp_storage.hpp:221
void set_storage(void *const storage)
Assigns the final storage for this partition.
Definition: temp_storage.hpp:76
layout get_layout()
Compute the required layout for this type and return it.
Definition: temp_storage.hpp:68
linear_partition(Ts... sub_partitions)
Constructor.
Definition: temp_storage.hpp:129
size_t alignment
The required alignment of the temporary memory, in bytes. Defaults to default_alignment.
Definition: temp_storage.hpp:53
::rocprim::tuple< Ts... > sub_partitions
The sub-partitions in this linear_partition.
Definition: temp_storage.hpp:126
union_partition(Ts... sub_partitions)
Constructor.
Definition: temp_storage.hpp:197