Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
TreeReducedMortonCodes.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
20namespace shamrock::tree {
21
22 template<class u_morton>
24 public:
25 u32 tree_leaf_count;
26 std::unique_ptr<sycl::buffer<u32>> buf_reduc_index_map;
27 std::unique_ptr<sycl::buffer<u_morton>> buf_tree_morton; // size = leaf cnt
28
29 void build(
30 sycl::queue &queue,
31 u32 obj_cnt,
32 u32 reduc_level,
33 TreeMortonCodes<u_morton> &morton_codes,
34
35 bool &one_cell_mode);
36
37 [[nodiscard]] inline u64 memsize() const {
38 u64 sum = 0;
39
40 sum += sizeof(tree_leaf_count);
41
42 auto add_ptr = [&](auto &a) {
43 if (a) {
44 sum += a->byte_size();
45 }
46 };
47
48 add_ptr(buf_reduc_index_map);
49 add_ptr(buf_tree_morton);
50
51 return sum;
52 }
53
54 inline TreeReducedMortonCodes() = default;
55
57 : tree_leaf_count(other.tree_leaf_count),
58 buf_reduc_index_map(
59 shamalgs::memory::duplicate(
60 shamsys::instance::get_compute_queue(), other.buf_reduc_index_map)),
61 buf_tree_morton(
62 shamalgs::memory::duplicate(
63 shamsys::instance::get_compute_queue(), other.buf_tree_morton)) {}
64
65 inline TreeReducedMortonCodes &operator=(TreeReducedMortonCodes &&other) noexcept {
66 tree_leaf_count = std::move(other.tree_leaf_count);
67 buf_reduc_index_map = std::move(other.buf_reduc_index_map);
68 buf_tree_morton = std::move(other.buf_tree_morton);
69
70 return *this;
71 } // move assignment
72
73 bool operator==(const TreeReducedMortonCodes<u_morton> &rhs) const;
74
80 inline void serialize(shamalgs::SerializeHelper &serializer) {
81 StackEntry stack_loc{};
82
83 serializer.write(tree_leaf_count);
84 if (!buf_reduc_index_map) {
86 }
87 serializer.write<u32>(buf_reduc_index_map->size());
88 serializer.write_buf(*buf_reduc_index_map, buf_reduc_index_map->size());
89 if (!buf_tree_morton) {
91 }
92 serializer.write_buf(*buf_tree_morton, tree_leaf_count);
93 }
94
95 inline static TreeReducedMortonCodes deserialize(shamalgs::SerializeHelper &serializer) {
96 StackEntry stack_loc{};
97
98 TreeReducedMortonCodes ret;
99 serializer.load(ret.tree_leaf_count);
100
101 u32 tmp;
102 serializer.load(tmp);
103
104 ret.buf_reduc_index_map = std::make_unique<sycl::buffer<u32>>(tmp);
105 ret.buf_tree_morton = std::make_unique<sycl::buffer<u_morton>>(ret.tree_leaf_count);
106
107 serializer.load_buf(*ret.buf_reduc_index_map, tmp);
108 serializer.load_buf(*ret.buf_tree_morton, ret.tree_leaf_count);
109
110 return ret;
111 }
112
113 inline shamalgs::SerializeSize serialize_byte_size() {
114
116
117 return H::serialize_byte_size<u32>() * 2
118 + H::serialize_byte_size<u32>(buf_reduc_index_map->size())
119 + H::serialize_byte_size<u_morton>(tree_leaf_count);
120 }
121 };
122
123} // namespace shamrock::tree
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
void serialize(shamalgs::SerializeHelper &serializer)
serialize a TreeMortonCodes object
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.