Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
bitonicSort.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
19#include "shambackends/sycl.hpp"
20
22
23 template<class Tkey, class Tval>
24 void sort_by_key_bitonic_legacy(
25 sycl::queue &q, sycl::buffer<Tkey> &buf_key, sycl::buffer<Tval> &buf_values, u32 len);
26
27 template<class Tkey, class Tval, u32 MaxStencilSize>
28 void sort_by_key_bitonic_updated(
29 sycl::queue &q, sycl::buffer<Tkey> &buf_key, sycl::buffer<Tval> &buf_values, u32 len);
30
31 // implementation disabled since it exhibit the same performance as the normal one
32 template<class Tkey, class Tval, u32 MaxStencilSize>
33 void sort_by_key_bitonic_updated_xor_swap(
34 sycl::queue &q, sycl::buffer<Tkey> &buf_key, sycl::buffer<Tval> &buf_values, u32 len);
35
36 template<class Tkey, class Tval>
37 inline void sort_by_key_bitonic_fallback(
38 sycl::queue &q, sycl::buffer<Tkey> &buf_key, sycl::buffer<Tval> &buf_values, u32 len) {
39 std::vector<std::pair<Tkey, Tval>> v;
40 v.resize(len);
41
42 {
43 sycl::host_accessor key{buf_key, sycl::read_only};
44 sycl::host_accessor vals{buf_values, sycl::read_only};
45
46 for (u32 i = 0; i < len; i++) {
47 v[i] = {key[i], vals[i]};
48 }
49 }
50
51 std::sort(v.begin(), v.end());
52
53 {
54 sycl::host_accessor key{buf_key, sycl::write_only};
55 sycl::host_accessor vals{buf_values, sycl::write_only};
56
57 for (u32 i = 0; i < len; i++) {
58 key[i] = v[i].first;
59 vals[i] = v[i].second;
60 }
61 }
62 }
63
64} // namespace shamalgs::algorithm::details
std::uint32_t u32
32 bit unsigned integer
namespace to store algorithms implemented by shamalgs