Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
TreeMortonCodes.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
15
19
20namespace shamrock::tree {
21
22 template<class u_morton>
23 template<class T>
24 void TreeMortonCodes<u_morton>::build(
25 sycl::queue &queue,
26 shammath::CoordRange<T> coord_range,
27 u32 obj_cnt,
28 sycl::buffer<T> &pos_buf) {
29 StackEntry stack_loc{};
30
31 this->obj_cnt = obj_cnt;
32
33 using TProp = shambase::VectorProperties<T>;
34
36 queue,
37 {coord_range.lower, coord_range.upper},
38 pos_buf,
39 obj_cnt,
40 buf_morton,
41 buf_particle_index_map);
42 }
43
44 template<class u_morton>
45 template<class T>
46 void TreeMortonCodes<u_morton>::build(
47 sham::DeviceScheduler_ptr dev_sched,
48 shammath::CoordRange<T> coord_range,
49 u32 obj_cnt,
50 sham::DeviceBuffer<T> &pos_buf) {
51 StackEntry stack_loc{};
52
53 this->obj_cnt = obj_cnt;
54
55 using TProp = shambase::VectorProperties<T>;
56
58 dev_sched,
59 {coord_range.lower, coord_range.upper},
60 pos_buf,
61 obj_cnt,
62 buf_morton,
63 buf_particle_index_map);
64 }
65
66 template<class u_morton>
67 bool TreeMortonCodes<u_morton>::operator==(const TreeMortonCodes<u_morton> &rhs) const {
68 bool cmp = true;
69
70 cmp = cmp && (obj_cnt == rhs.obj_cnt);
71
72 using namespace shamalgs::primitives;
73
74 cmp = cmp
75 && equals(
76 shamsys::instance::get_compute_queue(), *buf_morton, *rhs.buf_morton, obj_cnt);
77 cmp = cmp
78 && equals(
79 shamsys::instance::get_compute_queue(),
80 *buf_particle_index_map,
81 *rhs.buf_particle_index_map,
82 obj_cnt);
83
84 return cmp;
85 }
86
87 template class TreeMortonCodes<u32>;
88 template class TreeMortonCodes<u64>;
89
90 // u32, f64_3
91 template void TreeMortonCodes<u32>::build<f64_3>(
92 sycl::queue &queue,
93 shammath::CoordRange<f64_3> coord_range,
94 u32 obj_cnt,
95 sycl::buffer<f64_3> &pos_buf);
96
97 template void TreeMortonCodes<u32>::build<f64_3>(
98 sham::DeviceScheduler_ptr dev_sched,
99 shammath::CoordRange<f64_3> coord_range,
100 u32 obj_cnt,
101 sham::DeviceBuffer<f64_3> &pos_buf);
102
103 // u32, f32_3
104 template void TreeMortonCodes<u32>::build<f32_3>(
105 sycl::queue &queue,
106 shammath::CoordRange<f32_3> coord_range,
107 u32 obj_cnt,
108 sycl::buffer<f32_3> &pos_buf);
109
110 template void TreeMortonCodes<u32>::build<f32_3>(
111 sham::DeviceScheduler_ptr dev_sched,
112 shammath::CoordRange<f32_3> coord_range,
113 u32 obj_cnt,
114 sham::DeviceBuffer<f32_3> &pos_buf);
115
116 // u32, u64_3
117 template void TreeMortonCodes<u32>::build<u64_3>(
118 sycl::queue &queue,
119 shammath::CoordRange<u64_3> coord_range,
120 u32 obj_cnt,
121 sycl::buffer<u64_3> &pos_buf);
122
123 template void TreeMortonCodes<u32>::build<u64_3>(
124 sham::DeviceScheduler_ptr dev_sched,
125 shammath::CoordRange<u64_3> coord_range,
126 u32 obj_cnt,
127 sham::DeviceBuffer<u64_3> &pos_buf);
128
129 // u64, f64_3
130 template void TreeMortonCodes<u64>::build<f64_3>(
131 sycl::queue &queue,
132 shammath::CoordRange<f64_3> coord_range,
133 u32 obj_cnt,
134 sycl::buffer<f64_3> &pos_buf);
135
136 template void TreeMortonCodes<u64>::build<f64_3>(
137 sham::DeviceScheduler_ptr dev_sched,
138 shammath::CoordRange<f64_3> coord_range,
139 u32 obj_cnt,
140 sham::DeviceBuffer<f64_3> &pos_buf);
141
142 // u64, f32_3
143 template void TreeMortonCodes<u64>::build<f32_3>(
144 sycl::queue &queue,
145 shammath::CoordRange<f32_3> coord_range,
146 u32 obj_cnt,
147 sycl::buffer<f32_3> &pos_buf);
148
149 template void TreeMortonCodes<u64>::build<f32_3>(
150 sham::DeviceScheduler_ptr dev_sched,
151 shammath::CoordRange<f32_3> coord_range,
152 u32 obj_cnt,
153 sham::DeviceBuffer<f32_3> &pos_buf);
154
155 // u64, u64_3
156 template void TreeMortonCodes<u64>::build<u64_3>(
157 sycl::queue &queue,
158 shammath::CoordRange<u64_3> coord_range,
159 u32 obj_cnt,
160 sycl::buffer<u64_3> &pos_buf);
161
162 template void TreeMortonCodes<u64>::build<u64_3>(
163 sham::DeviceScheduler_ptr dev_sched,
164 shammath::CoordRange<u64_3> coord_range,
165 u32 obj_cnt,
166 sham::DeviceBuffer<u64_3> &pos_buf);
167
168 // u64, u32_3
169 template void TreeMortonCodes<u64>::build<u32_3>(
170 sycl::queue &queue,
171 shammath::CoordRange<u32_3> coord_range,
172 u32 obj_cnt,
173 sycl::buffer<u32_3> &pos_buf);
174
175 template void TreeMortonCodes<u64>::build<u32_3>(
176 sham::DeviceScheduler_ptr dev_sched,
177 shammath::CoordRange<u32_3> coord_range,
178 u32 obj_cnt,
179 sham::DeviceBuffer<u32_3> &pos_buf);
180
181 // u64, i64_3
182 template void TreeMortonCodes<u64>::build<i64_3>(
183 sycl::queue &queue,
184 shammath::CoordRange<i64_3> coord_range,
185 u32 obj_cnt,
186 sycl::buffer<i64_3> &pos_buf);
187
188 template void TreeMortonCodes<u64>::build<i64_3>(
189 sham::DeviceScheduler_ptr dev_sched,
190 shammath::CoordRange<i64_3> coord_range,
191 u32 obj_cnt,
192 sham::DeviceBuffer<i64_3> &pos_buf);
193
194 // u32, i64_3
195 template void TreeMortonCodes<u32>::build<i64_3>(
196 sycl::queue &queue,
197 shammath::CoordRange<i64_3> coord_range,
198 u32 obj_cnt,
199 sycl::buffer<i64_3> &pos_buf);
200
201 template void TreeMortonCodes<u32>::build<i64_3>(
202 sham::DeviceScheduler_ptr dev_sched,
203 shammath::CoordRange<i64_3> coord_range,
204 u32 obj_cnt,
205 sham::DeviceBuffer<i64_3> &pos_buf);
206
207 // u32, u32_3
208 template void TreeMortonCodes<u32>::build<u32_3>(
209 sycl::queue &queue,
210 shammath::CoordRange<u32_3> coord_range,
211 u32 obj_cnt,
212 sycl::buffer<u32_3> &pos_buf);
213
214 template void TreeMortonCodes<u32>::build<u32_3>(
215 sham::DeviceScheduler_ptr dev_sched,
216 shammath::CoordRange<u32_3> coord_range,
217 u32 obj_cnt,
218 sham::DeviceBuffer<u32_3> &pos_buf);
219
220} // namespace shamrock::tree
Utility to build morton codes for the radix tree.
std::uint32_t u32
32 bit unsigned integer
static void build(sycl::queue &queue, std::tuple< pos_t, pos_t > bounding_box, sycl::buffer< pos_t > &pos_buf, u32 cnt_obj, std::unique_ptr< sycl::buffer< morton_t > > &out_buf_morton, std::unique_ptr< sycl::buffer< u32 > > &out_buf_particle_index_map)
build morton code table for the tree
Element-wise equality comparison algorithms for buffers.
bool equals(sycl::queue &q, sycl::buffer< T > &buf1, sycl::buffer< T > &buf2, u32 cnt)
Compare elements between two sycl::buffers for equality.
Definition equals.hpp:77
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.