Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
MortonReducedSet.cpp
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
20#include <utility>
21
22namespace shamtree {
23
24 template<class Tmorton, class Tvec, u32 dim>
26 const sham::DeviceScheduler_ptr &dev_sched,
28 u32 reduction_level,
29 sham::DeviceBuffer<u32> &&cache_buf_reduc_index_map,
30 sham::DeviceBuffer<Tmorton> &&cache_reduced_morton_codes) {
31
32 // cache_buf_reduc_index_map is not yet recycled
33
35 dev_sched,
36 morton_codes_set.cnt_obj,
37 morton_codes_set.sorted_morton_codes,
38 reduction_level);
39
40 shamlog_debug_sycl_ln(
41 "RadixTree",
42 "reduction results : (before :",
43 morton_codes_set.cnt_obj,
44 " | after :",
45 res.morton_leaf_count,
46 ") ratio :",
48 "%2.2f", f32(morton_codes_set.cnt_obj) / f32(res.morton_leaf_count)));
49
50 if (res.morton_leaf_count == 0) {
51 throw shambase::make_except_with_loc<std::runtime_error>("0 leaf tree cannot exists");
52 }
53
54 // here the old "One cell mode" is not implemented as I want to get rid of this confusing
55 // mess, seriously this thing was giving me never ending headaches ...
56
57 sham::DeviceBuffer<Tmorton> buf_tree_morton
58 = std::forward<sham::DeviceBuffer<Tmorton>>(cache_reduced_morton_codes);
59 buf_tree_morton.resize(res.morton_leaf_count);
60
62 dev_sched->get_queue(),
63 res.morton_leaf_count,
64 res.buf_reduc_index_map,
65 morton_codes_set.sorted_morton_codes,
66 buf_tree_morton);
67
69 std::forward<MortonCodeSortedSet<Tmorton, Tvec, dim>>(morton_codes_set),
70 res.morton_leaf_count,
71 std::move(res.buf_reduc_index_map),
72 std::move(buf_tree_morton));
73 }
74
75 template<class Tmorton, class Tvec, u32 dim>
77 const sham::DeviceScheduler_ptr &dev_sched,
79 u32 reduction_level) {
80
81 return reduce_morton_set(
82 dev_sched,
83 std::forward<MortonCodeSortedSet<Tmorton, Tvec, dim>>(morton_codes_set),
84 reduction_level,
85 sham::DeviceBuffer<u32>(0, dev_sched),
86 sham::DeviceBuffer<Tmorton>(0, dev_sched));
87 }
88
89} // namespace shamtree
90
93
94template shamtree::MortonReducedSet<u32, f64_3, 3> shamtree::reduce_morton_set<u32, f64_3, 3>(
95 const sham::DeviceScheduler_ptr &dev_sched,
97 u32 reduction_level);
98template shamtree::MortonReducedSet<u64, f64_3, 3> shamtree::reduce_morton_set<u64, f64_3, 3>(
99 const sham::DeviceScheduler_ptr &dev_sched,
101 u32 reduction_level);
102
103template shamtree::MortonReducedSet<u32, f64_3, 3> shamtree::reduce_morton_set<u32, f64_3, 3>(
104 const sham::DeviceScheduler_ptr &dev_sched,
106 u32 reduction_level,
107 sham::DeviceBuffer<u32> &&cache_buf_reduc_index_map,
108 sham::DeviceBuffer<u32> &&cache_reduced_morton_codes);
109template shamtree::MortonReducedSet<u64, f64_3, 3> shamtree::reduce_morton_set<u64, f64_3, 3>(
110 const sham::DeviceScheduler_ptr &dev_sched,
112 u32 reduction_level,
113 sham::DeviceBuffer<u32> &&cache_buf_reduc_index_map,
114 sham::DeviceBuffer<u64> &&cache_reduced_morton_codes);
MortonReducedSet< Tmorton, Tvec, dim > reduce_morton_set(const sham::DeviceScheduler_ptr &dev_sched, MortonCodeSortedSet< Tmorton, Tvec, dim > &&morton_codes_set, u32 reduction_level)
Reduces the given Morton code set by grouping together Morton codes that are close to each other in t...
float f32
Alias for float.
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
void resize(size_t new_size, bool keep_data=true)
Resizes the buffer to a given size.
Class representing a set of Morton codes with associated bounding box and position data.
Class representing a set of Morton codes with associated bounding box and position data that was redu...
main include file for the shamalgs algorithms
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
void sycl_morton_remap_reduction(sycl::queue &queue, u32 morton_leaf_count, std::unique_ptr< sycl::buffer< u32 > > &buf_reduc_index_map, std::unique_ptr< sycl::buffer< u_morton > > &buf_morton, std::unique_ptr< sycl::buffer< u_morton > > &buf_leaf_morton)
Remaps a Morton tree on device using a reduction index map.
void reduction_alg(sycl::queue &queue, u32 morton_count, std::unique_ptr< sycl::buffer< u_morton > > &buf_morton, u32 reduction_level, std::unique_ptr< sycl::buffer< u32 > > &buf_reduc_index_map, u32 &morton_leaf_count)
Reduces a Morton tree on device.
Return type of reduction algorithms.