22namespace shamalgs::primitives::details {
24 template<
class T,
class Comp>
25 inline void segmented_sort_in_place_local_insertion_sort(
30 size_t interact_count = buf.
get_size();
31 size_t offsets_count = offsets.
get_size();
32 size_t N = offsets_count - 1;
40 comp](
u32 gid,
const u32 *__restrict__ offsets, T *__restrict__ in_out_sorted) {
41 u32 start_index = offsets[gid];
42 u32 end_index = offsets[gid + 1];
48 if (start_index == end_index) {
63 template<
class T,
class Comp>
64 inline void segmented_sort_in_place_multi_std_sort(
69 size_t interact_count = buf.
get_size();
70 size_t offsets_count = offsets.
get_size();
71 size_t N = offsets_count - 1;
76#pragma omp parallel for
77 for (
u32 i = 0; i < N; ++i) {
78 u32 start_index = offsets_stdvec[i];
79 u32 end_index = offsets_stdvec[i + 1];
85 if (start_index == end_index) {
96 std::sort(buf_stdvec.begin() + start_index, buf_stdvec.begin() + end_index, comp);
109 enum class SEGMENTED_SORT_IN_PLACE_IMPL :
u32 {
110 LOCAL_INSERTION_SORT,
114 SEGMENTED_SORT_IN_PLACE_IMPL get_default_segmented_sort_in_place_impl() {
115 return SEGMENTED_SORT_IN_PLACE_IMPL::MULTI_STD_SORT;
118 SEGMENTED_SORT_IN_PLACE_IMPL segmented_sort_in_place_impl
119 = get_default_segmented_sort_in_place_impl();
121 inline SEGMENTED_SORT_IN_PLACE_IMPL segmented_sort_in_place_impl_from_params(
122 const std::string &impl) {
123 if (impl ==
"local_insertion_sort") {
124 return SEGMENTED_SORT_IN_PLACE_IMPL::LOCAL_INSERTION_SORT;
125 }
else if (impl ==
"multi_std_sort") {
126 return SEGMENTED_SORT_IN_PLACE_IMPL::MULTI_STD_SORT;
129 "invalid implementation : {}, possible implementations : {}",
135 const SEGMENTED_SORT_IN_PLACE_IMPL &impl) {
136 if (impl == SEGMENTED_SORT_IN_PLACE_IMPL::LOCAL_INSERTION_SORT) {
137 return {
"local_insertion_sort",
""};
138 }
else if (impl == SEGMENTED_SORT_IN_PLACE_IMPL::MULTI_STD_SORT) {
139 return {
"multi_std_sort",
""};
142 shambase::format(
"unknown segmented sort in place implementation : {}",
u32(impl)));
148 {
"local_insertion_sort",
""},
149 {
"multi_std_sort",
""},
155 return segmented_sort_in_place_impl_to_params(segmented_sort_in_place_impl);
161 "tree",
"setting segmented sort in place implementation to impl :", impl);
162 segmented_sort_in_place_impl = segmented_sort_in_place_impl_from_params(impl);
167 template<
class T,
class Comp>
168 void internal_segmented_sort_in_place(
179 switch (impl::segmented_sort_in_place_impl) {
180 case impl::SEGMENTED_SORT_IN_PLACE_IMPL::LOCAL_INSERTION_SORT:
181 details::segmented_sort_in_place_local_insertion_sort(buf, offsets, comp);
184 case impl::SEGMENTED_SORT_IN_PLACE_IMPL::MULTI_STD_SORT:
185 details::segmented_sort_in_place_multi_std_sort(buf, offsets, comp);
189 "unimplemented case : {}",
u32(impl::segmented_sort_in_place_impl)));
194 void segmented_sort_in_place<u32_2>(
197 internal_segmented_sort_in_place(buf, offsets, [](u32_2 a, u32_2 b) {
198 return (a.x() == b.x()) ? (a.y() < b.y()) : (a.x() < b.x());
203 void segmented_sort_in_place<u32>(
205 internal_segmented_sort_in_place(buf, offsets, [](
u32 a,
u32 b) {
std::uint32_t u32
32 bit unsigned integer
Shamrock assertion utility.
#define SHAM_ASSERT(x)
Shorthand for SHAM_ASSERT_NAMED without a message.
A buffer allocated in USM (Unified Shared Memory)
void copy_from_stdvec(const std::vector< T > &vec)
Copy the content of a std::vector into the buffer.
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
size_t get_size() const
Gets the number of elements in the buffer.
DeviceScheduler & get_dev_scheduler() const
Gets the Device scheduler corresponding to the held allocation.
DeviceQueue & get_queue(u32 id=0)
Get a reference to a DeviceQueue.
void kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, u32 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
Submit a kernel to a SYCL queue.
std::vector< shamalgs::impl_param > get_default_impl_list_segmented_sort_in_place()
Get list of available segmented sort in place implementations.
void set_impl_segmented_sort_in_place(const std::string &impl, const std::string ¶m="")
Set the implementation for segmented sort in place.
shamalgs::impl_param get_current_impl_segmented_sort_in_place()
Get the current implementation for segmented sort in place.
namespace for primitive algorithm (e.g. sort, scan, reductions, ...)
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
void ptr_insert_sort(T *data, u32 start, u32 end, Comp &&comp)
Simple insertion sort on pointer range.
A class that references multiple buffers or similar objects.