40 static constexpr std::string_view variant_type_name =
"bitonic_sort";
55 static constexpr std::string_view variant_type_name =
"std_sort";
63 return {{
"stencil_size",
static_cast<u32>(p.stencil_size)}};
67 if (j.contains(
"stencil_size")) {
69 j.at(
"stencil_size").get<u32>());
77 template<
class Tkey,
class Tval>
79 sycl::queue &q, sycl::buffer<Tkey> &buf_key, sycl::buffer<Tval> &buf_values,
u32 len) {
83 "Length must be a power of 2");
87 shamalgs::algorithm::details::sort_by_key_bitonic_fallback(q, buf_key, buf_values, len);
89 shamalgs::algorithm::details::sort_by_key_bitonic_updated<Tkey, Tval, 16>(
90 q, buf_key, buf_values, len);
98 [](
const sham::DeviceScheduler_ptr &,
auto &self) {
99 self.set(BitonicSort{});
104 return sort_by_key_pow2_len_impl.get_default_config_list();
109 return sort_by_key_pow2_len_impl.get_current_config();
118 "algs",
"setting sort by key (pow2 len) implementation to impl :",
impl);
119 sort_by_key_pow2_len_impl.set(
impl);
124 sort_by_key_pow2_len_impl.autoselect(dev_sched);
127 "defaulting sort by key (pow2 len) implementation to impl :",
133 template<
class Tkey,
class Tval>
135 const sham::DeviceScheduler_ptr &sched,
141 switch (stencil_size) {
154 case MaxStencilSize::Size16:
155 shamalgs::algorithm::details::sort_by_key_bitonic_updated_usm<Tkey, Tval, 16>(
156 sched, buf_key, buf_values, len);
158 case MaxStencilSize::Size32:
159 shamalgs::algorithm::details::sort_by_key_bitonic_updated_usm<Tkey, Tval, 32>(
160 sched, buf_key, buf_values, len);
169 template<
class Tkey,
class Tval>
171 const sham::DeviceScheduler_ptr &sched,
178 "Length must be a power of 2");
181 if (!impl::sort_by_key_pow2_len_impl.is_set()) {
189 sched, buf_key, buf_values, len, cfg.stencil_size);
195 impl::sort_by_key_pow2_len_impl.get());
199 sycl::queue &q, sycl::buffer<u32> &buf_key, sycl::buffer<u32> &buf_values,
u32 len);
202 sycl::queue &q, sycl::buffer<u64> &buf_key, sycl::buffer<u32> &buf_values,
u32 len);
205 const sham::DeviceScheduler_ptr &sched,
211 const sham::DeviceScheduler_ptr &sched,
217 const sham::DeviceScheduler_ptr &sched,
223 const sham::DeviceScheduler_ptr &sched,
Generic std::variant-based implementation selector.
std::uint32_t u32
32 bit unsigned integer
main include file for the shamalgs algorithms
A buffer allocated in USM (Unified Shared Memory).
Drop-in replacement for the hand-rolled "global variable + enum + name mapping.
This header file contains utility functions related to exception handling in the code.
namespace to control implementation behavior
void sort_by_key_pow2_len_bitonic_dispatch(const sham::DeviceScheduler_ptr &sched, sham::DeviceBuffer< Tkey > &buf_key, sham::DeviceBuffer< Tval > &buf_values, u32 len, MaxStencilSize stencil_size)
std::vector< std::string > get_default_impl_list_sort_by_key_pow2_len()
Get list of available sort by key pow2 len implementations, as config json strings.
void autoselect_impl_sort_by_key_pow2_len(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for sort by key pow2 len.
std::string get_current_impl_sort_by_key_pow2_len()
Get the current implementation for sort by key pow2 len, as a config json string.
bool is_impl_set_sort_by_key_pow2_len()
Check if an implementation has been selected for sort by key pow2 len.
void set_impl_sort_by_key_pow2_len(const std::string &impl)
Set the implementation for sort by key pow2 len, from a config json string.
namespace for primitive algorithm (e.g. sort, scan, reductions, ...)
void sort_by_key_pow2_len(sycl::queue &q, sycl::buffer< Tkey > &buf_key, sycl::buffer< Tval > &buf_values, u32 len)
Sort key-value pairs using sycl::buffers (power-of-2 optimized).
namespace to contain everything implemented by shamalgs
constexpr bool is_pow_of_two(T v) noexcept
determine if v is a power of two and check if v==0 Source : https://graphics.stanford....
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
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.
Customization point controlling how an alternative's fields (if any) are serialized to / parsed from ...
static Alt from_json(const nlohmann::json &)
Parse the alternative's fields back (default: no fields, ignored).
static nlohmann::json to_json(const Alt &)
Serialize the alternative's fields (default: no fields, empty object).
Bitonic sort, updated USM kernel (see bitonicSort_updated_usm.hpp).
static std::vector< BitonicSort > variant_custom_defaults()
Expose the stencil sizes worth benchmarking as separate default implementations.
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.