41 static constexpr std::string_view variant_type_name =
"bitonic_sort";
56 static constexpr std::string_view variant_type_name =
"std_sort";
62 static constexpr std::string_view variant_type_name =
"lsd_radix_sort_basic";
70 return {{
"stencil_size",
static_cast<u32>(p.stencil_size)}};
74 if (j.contains(
"stencil_size")) {
76 j.at(
"stencil_size").get<u32>());
84 template<
class Tkey,
class Tval>
86 sycl::queue &q, sycl::buffer<Tkey> &buf_key, sycl::buffer<Tval> &buf_values,
u32 len) {
90 "Length must be a power of 2");
94 shamalgs::algorithm::details::sort_by_key_bitonic_fallback(q, buf_key, buf_values, len);
96 shamalgs::algorithm::details::sort_by_key_bitonic_updated<Tkey, Tval, 16>(
97 q, buf_key, buf_values, len);
108 sort_by_key_pow2_len_impl{[](
const sham::DeviceScheduler_ptr &dev_sched,
auto &self) {
109 if (dev_sched->ctx->device->prop.type == sham::DeviceType::GPU) {
121 template<
class Tkey,
class Tval>
123 const sham::DeviceScheduler_ptr &sched,
129 switch (stencil_size) {
142 case MaxStencilSize::Size16:
143 shamalgs::algorithm::details::sort_by_key_bitonic_updated_usm<Tkey, Tval, 16>(
144 sched, buf_key, buf_values, len);
146 case MaxStencilSize::Size32:
147 shamalgs::algorithm::details::sort_by_key_bitonic_updated_usm<Tkey, Tval, 32>(
148 sched, buf_key, buf_values, len);
157 template<
class Tkey,
class Tval>
159 const sham::DeviceScheduler_ptr &sched,
166 "Length must be a power of 2");
169 if (!impl::sort_by_key_pow2_len_impl.is_set()) {
177 sched, buf_key, buf_values, len, cfg.stencil_size);
183 if constexpr (std::is_unsigned_v<Tkey>) {
185 sched, buf_key, buf_values, len);
188 sched, buf_key, buf_values, len, impl::MaxStencilSize::Size16);
192 impl::sort_by_key_pow2_len_impl.get());
196 sycl::queue &q, sycl::buffer<u32> &buf_key, sycl::buffer<u32> &buf_values,
u32 len);
199 sycl::queue &q, sycl::buffer<u64> &buf_key, sycl::buffer<u32> &buf_values,
u32 len);
202 const sham::DeviceScheduler_ptr &sched,
208 const sham::DeviceScheduler_ptr &sched,
214 const sham::DeviceScheduler_ptr &sched,
220 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.
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.
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)
constexpr std::string_view sort_by_key_pow2_len_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_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.
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.
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.