40 const u64_3 *cell_low_bound;
41 const u64_3 *cell_high_bound;
70 using buf_access_read = sycl::accessor<T, 1, sycl::access::mode::read, sycl::target::device>;
72 using buf_access_read_write
73 = sycl::accessor<T, 1, sycl::access::mode::read_write, sycl::target::device>;
81 auto &buf_field = pdat.get_field<
u32>(2).get_buf();
82 field = buf_field.get_write_access(depends_list);
86 auto &buf_field = pdat.get_field<
u32>(2).get_buf();
87 buf_field.complete_event_state(resulting_events);
91 inline void dump_patch(
u64 id) {
93 using namespace shamrock::patch;
98 std::vector<u64_3> mins = pdat.get_field<u64_3>(0).get_buf().copy_to_stdvec();
99 std::vector<u64_3> maxs = pdat.get_field<u64_3>(1).get_buf().copy_to_stdvec();
101 logger::raw_ln(
"----- dump");
102 for (
u32 i = 0; i < mins.size(); i++) {
103 logger::raw_ln(mins[i], maxs[i]);
105 logger::raw_ln(
"-----");
108 static constexpr u64 fact_p_len = 2;
119 u64_3 low_bound = acc.cell_low_bound[cell_id];
120 u64_3 high_bound = acc.cell_high_bound[cell_id];
126 low_bound, fact_p_len * u64_3{1, 1, 1}, fact_p_len * u64_3{4, 4, 4})
128 high_bound, fact_p_len * u64_3{1, 1, 1}, fact_p_len * u64_3{4, 4, 4});
130 should_refine = should_refine && (high_bound.x() - low_bound.x() > 1);
131 should_refine = should_refine && (high_bound.y() - low_bound.y() > 1);
132 should_refine = should_refine && (high_bound.z() - low_bound.z() > 1);
134 return should_refine;
142 std::array<u32, 8> new_cells,
143 std::array<Grid::CellCoord, 8> new_cells_coords,
145 u32 val = acc.field[cur_idx];
148 for (
u32 pid = 0; pid < 8; pid++) {
149 acc.field[new_cells[pid]] = val;
158 inline void derefine() {
159 auto merge = grid.gen_merge_list<RefineCritCellAccessor>(
160 [](
u32 cell_id, RefineCritCellAccessor acc) ->
u32 {
161 u64_3 low_bound = acc.cell_low_bound[cell_id];
162 u64_3 high_bound = acc.cell_high_bound[cell_id];
168 low_bound, fact_p_len * u64_3{1, 1, 1}, fact_p_len * u64_3{4, 4, 4})
170 high_bound, fact_p_len * u64_3{1, 1, 1}, fact_p_len * u64_3{4, 4, 4});
175 grid.apply_merge<RefineCellAccessor>(
178 [](std::array<u32, 8> old_cells,
179 std::array<Grid::CellCoord, 8> old_coords,
181 Grid::CellCoord new_coord,
183 RefineCellAccessor acc) {
187 for (
u32 pid = 0; pid < 8; pid++) {
188 accum += acc.field[old_cells[pid]];
191 acc.field[new_cell] = accum / 8;
200 using namespace shamrock::patch;
205 using namespace shamrock::patch;
211 shamsys::instance::get_compute_scheduler_ptr(),
213 pdat.get_field<u64_3>(0).get_buf(),
217 tree.compute_cell_ibounding_box(q.
q);
219 tree.convert_bounding_box(q.
q);
221 class WalkAccessors {
227 auto &buf_field = pdat.get_field<
u32>(2).get_buf();
228 field = buf_field.get_write_access(depends_list);
233 auto &buf_field = pdat.get_field<
u32>(2).get_buf();
234 buf_field.complete_event_state(resulting_events);
246 WalkAccessors uacc(depends_list, pdat);
248 auto cell_low_bound = pdat.get_field<u64_3>(0).get_buf().get_read_access(depends_list);
249 auto cell_high_bound = pdat.get_field<u64_3>(1).get_buf().get_read_access(depends_list);
251 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
253 Rta tree_acc(tree, cgh);
255 sycl::range range_npart{pdat.get_obj_cnt()};
257 cgh.parallel_for(range_npart, [=](sycl::item<1> item) {
258 u64_3 low_bound_a = cell_low_bound[item];
259 u64_3 high_bound_a = cell_high_bound[item];
266 u64_3 cur_pos_min_cell_b = tree_acc.pos_min_cell[node_id];
267 u64_3 cur_pos_max_cell_b = tree_acc.pos_max_cell[node_id];
270 low_bound_a, high_bound_a, cur_pos_min_cell_b, cur_pos_max_cell_b);
279 uacc.field[item] = sum;
284 uacc.finalize(resulting_events, pdat);
285 pdat.get_field<u64_3>(0).get_buf().complete_event_state(e);
286 pdat.get_field<u64_3>(1).get_buf().complete_event_state(e);
291 shamlog_debug_ln(
"AMR Test",
"walk time", t.
get_time_str());
293 class InteractionCrit {
300 sycl::buffer<u64_3> buf_cell_low_bound;
301 sycl::buffer<u64_3> buf_cell_high_bound;
305 sycl::accessor<u64_3, 1, sycl::access::mode::read> cell_low_bound;
306 sycl::accessor<u64_3, 1, sycl::access::mode::read> cell_high_bound;
308 sycl::accessor<u64_3, 1, sycl::access::mode::read> tree_cell_coordrange_min;
309 sycl::accessor<u64_3, 1, sycl::access::mode::read> tree_cell_coordrange_max;
311 Access(InteractionCrit crit, sycl::handler &cgh)
312 : cell_low_bound{crit.buf_cell_low_bound, cgh, sycl::read_only},
313 cell_high_bound{crit.buf_cell_high_bound, cgh, sycl::read_only},
314 tree_cell_coordrange_min{
315 *crit.tree.tree_cell_ranges.buf_pos_min_cell_flt,
318 tree_cell_coordrange_max{
319 *crit.tree.tree_cell_ranges.buf_pos_max_cell_flt,
325 u64_3 cell_low_bound;
326 u64_3 cell_high_bound;
327 ObjectValues(Access acc,
u32 index)
328 : cell_low_bound(acc.cell_low_bound[index]),
329 cell_high_bound(acc.cell_high_bound[index]) {}
333 static bool criterion(
334 u32 node_index, Access acc, Access::ObjectValues current_values) {
335 u64_3 cur_pos_min_cell_b = acc.tree_cell_coordrange_min[node_index];
336 u64_3 cur_pos_max_cell_b = acc.tree_cell_coordrange_max[node_index];
339 current_values.cell_low_bound,
340 current_values.cell_high_bound,
346 using Criterion = InteractionCrit;
347 using CriterionAcc =
typename Criterion::Access;
348 using CriterionVal =
typename CriterionAcc::ObjectValues;
359 pdat.get_field<u64_3>(0).get_buf().copy_to_sycl_buffer(),
360 pdat.get_field<u64_3>(1).get_buf().copy_to_sycl_buffer()});
362 q.
submit([&](sycl::handler &cgh) {
363 auto walker = walk.get_access(cgh);
364 auto leaf_iterator = tree.get_leaf_access(cgh);
366 cgh.parallel_for(walker.get_sycl_range(), [=](sycl::item<1> item) {
369 CriterionVal int_values{
370 walker.criterion(), static_cast<u32>(item.get_linear_id())};
372 walker.for_each_node(
375 [&](
u32 ,
u32 leaf_iterator_id) {
376 leaf_iterator.iter_object_in_leaf(
377 leaf_iterator_id, [&](
u32 ) {
381 [&](
u32 node_id) {});