29namespace shamalgs::primitives::details {
33 template<
class Tkey,
class Tval>
40 std::vector<Tkey> key_sub(key_stdvec.begin(), key_stdvec.begin() + len);
41 std::vector<Tval> val_sub(val_stdvec.begin(), val_stdvec.begin() + len);
45 std::copy(key_sub.begin(), key_sub.end(), key_stdvec.begin());
46 std::copy(val_sub.begin(), val_sub.end(), val_stdvec.begin());
61 static constexpr std::string_view variant_type_name =
"std_sort";
66 static constexpr std::string_view variant_type_name =
"batcher_odd_even_host_serial";
71 static constexpr std::string_view variant_type_name =
"batcher_odd_even";
77 static constexpr std::string_view variant_type_name =
"lsd_radix_sort_basic";
84 ImplVariantGlobal<StdSort, BatcherOddEvenHostSerial, BatcherOddEven, LsdRadixSortBasic>
85 sort_by_keys_impl{[](
const sham::DeviceScheduler_ptr &dev_sched,
auto &self) {
86 if (dev_sched->ctx->device->prop.type == sham::DeviceType::CPU) {
98 template<
class Tkey,
class Tval>
102 if (!impl::sort_by_keys_impl.is_set()) {
120 if constexpr (std::is_unsigned_v<Tkey>) {
128 impl::sort_by_keys_impl.get());
Generic std::variant-based implementation selector.
std::uint32_t u32
32 bit unsigned integer
Batcher odd-even mergesort, native for any length.
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::shared_ptr< DeviceScheduler > & get_dev_scheduler_ptr()
Gets the Device scheduler pointer corresponding to the held allocation.
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
This header file contains utility functions related to exception handling in the code.
Name-keyed registry of the implementation selectors (IImplVariant) of every algorithm.
#define SHAMALGS_REGISTER_IMPL(name, impl)
Register the implementation selector impl under name at static initialization.
void autoselect_impl(std::string_view alg, const sham::DeviceScheduler_ptr &sched)
Select the default implementation of alg for the device behind sched.
void sort_by_key_batcher_odd_even_host_reference(std::vector< Tkey > &keys, std::vector< Tval > &values)
Host reference of sort_by_key_batcher_odd_even.
void sort_by_key_batcher_odd_even(const sham::DeviceScheduler_ptr &sched, sham::DeviceBuffer< Tkey > &buf_key, sham::DeviceBuffer< Tval > &buf_values, u32 len)
Sort key-value pairs of any length using a Batcher odd-even merge network.
constexpr std::string_view sort_by_keys_impl_name
Registry name, shared by its registration and the dispatch site(s).
namespace for primitive algorithm (e.g. sort, scan, reductions, ...)
void sort_by_keys(sham::DeviceBuffer< Tkey > &buf_key, sham::DeviceBuffer< Tval > &buf_values, u32 len)
Sort key-value pairs using USM buffers (general length).
void sort_by_keys_batcher_odd_even_host_serial(sham::DeviceBuffer< Tkey > &buf_key, sham::DeviceBuffer< Tval > &buf_values, u32 len)
Portable LSD radix sort by keys, parallelized over chunks of the input.
void sort_by_keys_lsd_radix_sort_basic(const sham::DeviceScheduler_ptr &sched, sham::DeviceBuffer< Tkey > &buf_key, sham::DeviceBuffer< Tval > &buf_values, u32 len)
Stable LSD radix sort of (keys, values) on the first len elements (unsigned keys only).
std::sort based sort by keys implementation, shared by the sort by keys primitives
void sort_by_keys_std_sort(sham::DeviceBuffer< Tkey > &buf_key, sham::DeviceBuffer< Tval > &buf_values, u32 len)
Copy both buffers to host, std::sort the zipped key/value pairs, and copy back.
Copy the buffers to host, sort with Batcher's odd-even merge sort, and copy back.
Copy the buffers to host, sort with Batcher's odd-even merge sort, and copy back.
Copy the buffers to host, std::sort the zipped key/value pairs, and copy back.
Build an overload set out of several callables, for use with std::visit.