Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ValueLoader.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
16
20
22//
24template<class Tvec, class TgridVec, class T>
25void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_internal_block_xm(
26 u32 nobj, u32 nvar, sham::DeviceBuffer<T> &buf_src, sham::DeviceBuffer<T> &buf_dest) {
27
28 StackEntry stack_loc{};
29 using Block = typename Config::AMRBlock;
30
31 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
32
34 q,
35 sham::MultiRef{buf_src},
36 sham::MultiRef{buf_dest},
37 nobj * Block::block_size,
38 [](u32 id_a, const T *__restrict src, T *__restrict val_out) {
39 const u32 base_idx = id_a;
40 const u32 lid = id_a % Block::block_size;
41
42 static_assert(dim == 3, "implemented only in dim 3");
43 std::array<u32, 3> lid_coord = Block::get_coord(lid);
44
45 if (lid_coord[0] > 0) {
46 lid_coord[0] -= 1;
47 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
48 }
49 });
50}
51
52template<class Tvec, class TgridVec, class T>
53void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_internal_block_xp(
54 u32 nobj, u32 nvar, sham::DeviceBuffer<T> &buf_src, sham::DeviceBuffer<T> &buf_dest) {
55
56 StackEntry stack_loc{};
57 using Block = typename Config::AMRBlock;
58
59 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
60
62 q,
63 sham::MultiRef{buf_src},
64 sham::MultiRef{buf_dest},
65 nobj * Block::block_size,
66 [](u32 id_a, const T *__restrict src, T *__restrict val_out) {
67 const u32 base_idx = id_a;
68 const u32 lid = id_a % Block::block_size;
69
70 static_assert(dim == 3, "implemented only in dim 3");
71 std::array<u32, 3> lid_coord = Block::get_coord(lid);
72
73 if (lid_coord[0] < Block::Nside - 1) {
74 lid_coord[0] += 1;
75 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
76 }
77 });
78}
79
80template<class Tvec, class TgridVec, class T>
81void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_internal_block_ym(
82 u32 nobj, u32 nvar, sham::DeviceBuffer<T> &buf_src, sham::DeviceBuffer<T> &buf_dest) {
83
84 StackEntry stack_loc{};
85 using Block = typename Config::AMRBlock;
86
87 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
88
90 q,
91 sham::MultiRef{buf_src},
92 sham::MultiRef{buf_dest},
93 nobj * Block::block_size,
94 [](u32 id_a, const T *__restrict src, T *__restrict val_out) {
95 const u32 base_idx = id_a;
96 const u32 lid = id_a % Block::block_size;
97
98 static_assert(dim == 3, "implemented only in dim 3");
99 std::array<u32, 3> lid_coord = Block::get_coord(lid);
100
101 if (lid_coord[1] > 0) {
102 lid_coord[1] -= 1;
103 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
104 }
105 });
106}
107
108template<class Tvec, class TgridVec, class T>
109void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_internal_block_yp(
110 u32 nobj, u32 nvar, sham::DeviceBuffer<T> &buf_src, sham::DeviceBuffer<T> &buf_dest) {
111
112 StackEntry stack_loc{};
113 using Block = typename Config::AMRBlock;
114
115 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
116
118 q,
119 sham::MultiRef{buf_src},
120 sham::MultiRef{buf_dest},
121 nobj * Block::block_size,
122 [](u32 id_a, const T *__restrict src, T *__restrict val_out) {
123 const u32 base_idx = id_a;
124 const u32 lid = id_a % Block::block_size;
125
126 static_assert(dim == 3, "implemented only in dim 3");
127 std::array<u32, 3> lid_coord = Block::get_coord(lid);
128
129 if (lid_coord[1] < Block::Nside - 1) {
130 lid_coord[1] += 1;
131 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
132 }
133 });
134}
135
136template<class Tvec, class TgridVec, class T>
137void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_internal_block_zm(
138 u32 nobj, u32 nvar, sham::DeviceBuffer<T> &buf_src, sham::DeviceBuffer<T> &buf_dest) {
139
140 StackEntry stack_loc{};
141 using Block = typename Config::AMRBlock;
142
143 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
144
146 q,
147 sham::MultiRef{buf_src},
148 sham::MultiRef{buf_dest},
149 nobj * Block::block_size,
150 [](u32 id_a, const T *__restrict src, T *__restrict val_out) {
151 const u32 base_idx = id_a;
152 const u32 lid = id_a % Block::block_size;
153
154 static_assert(dim == 3, "implemented only in dim 3");
155 std::array<u32, 3> lid_coord = Block::get_coord(lid);
156
157 if (lid_coord[2] > 0) {
158 lid_coord[2] -= 1;
159 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
160 }
161 });
162}
163
164template<class Tvec, class TgridVec, class T>
165void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_internal_block_zp(
166 u32 nobj, u32 nvar, sham::DeviceBuffer<T> &buf_src, sham::DeviceBuffer<T> &buf_dest) {
167
168 StackEntry stack_loc{};
169 using Block = typename Config::AMRBlock;
170
171 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
172
174 q,
175 sham::MultiRef{buf_src},
176 sham::MultiRef{buf_dest},
177 nobj * Block::block_size,
178 [](u32 id_a, const T *__restrict src, T *__restrict val_out) {
179 const u32 base_idx = id_a;
180 const u32 lid = id_a % Block::block_size;
181
182 static_assert(dim == 3, "implemented only in dim 3");
183 std::array<u32, 3> lid_coord = Block::get_coord(lid);
184
185 if (lid_coord[2] < Block::Nside - 1) {
186 lid_coord[2] += 1;
187 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
188 }
189 });
190}
191
192template<class Tvec, class TgridVec, class T>
193void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_internal_block(
194 std::array<Tgridscal, dim> offset,
195 u32 nobj,
196 u32 nvar,
197 sham::DeviceBuffer<T> &buf_src,
198 sham::DeviceBuffer<T> &buf_dest) {
199
200 StackEntry stack_loc{};
201 using Block = typename Config::AMRBlock;
202
203 if constexpr (dim == 3) {
204 if (offset[0] == -1 && offset[1] == 0 && offset[2] == 0) {
205
206 load_patch_internal_block_xm(nobj, nvar, buf_src, buf_dest);
207
208 } else if (offset[0] == 0 && offset[1] == -1 && offset[2] == 0) {
209
210 load_patch_internal_block_ym(nobj, nvar, buf_src, buf_dest);
211
212 } else if (offset[0] == 0 && offset[1] == 0 && offset[2] == -1) {
213
214 load_patch_internal_block_zm(nobj, nvar, buf_src, buf_dest);
215
216 } else if (offset[0] == 1 && offset[1] == 0 && offset[2] == 0) {
217
218 load_patch_internal_block_xp(nobj, nvar, buf_src, buf_dest);
219
220 } else if (offset[0] == 0 && offset[1] == 1 && offset[2] == 0) {
221
222 load_patch_internal_block_yp(nobj, nvar, buf_src, buf_dest);
223
224 } else if (offset[0] == 0 && offset[1] == 0 && offset[2] == 1) {
225
226 load_patch_internal_block_zp(nobj, nvar, buf_src, buf_dest);
227
228 } else {
230 sham::format("offset : ({},{},{}) is invalid", offset[0], offset[1], offset[2]));
231 }
232 } else {
234 }
235}
236
238//
240
241template<class Tvec, class TgridVec, class T>
242void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_neigh_same_level_xm(
243
244 std::array<Tgridscal, dim> offset,
245 sham::DeviceBuffer<TgridVec> &buf_cell_min,
246 sham::DeviceBuffer<TgridVec> &buf_cell_max,
248 u32 nobj,
249 u32 nvar,
250 sham::DeviceBuffer<T> &buf_src,
251 sham::DeviceBuffer<T> &buf_dest
252
253) {
254 StackEntry stack_loc{};
255
256 using Block = typename Config::AMRBlock;
257 using namespace shamrock;
258
259 OrientedNeighFaceList<Tvec> &face_xm = face_lists.xm();
260
261 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
262
263 sham::EventList depends_list;
264 auto val_out = buf_dest.get_write_access(depends_list);
265 auto src = buf_src.get_read_access(depends_list);
266 auto cell_min = buf_cell_min.get_read_access(depends_list);
267 auto cell_max = buf_cell_max.get_read_access(depends_list);
268
269 auto fptr = face_xm.neigh_info.get_read_access(depends_list);
270
271 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
272 tree::ObjectCacheIterator faces_xm(fptr);
273
274 shambase::parallel_for(cgh, nobj * Block::block_size, "compute xm val (2)", [=](u64 id_a) {
275 const u32 base_idx = id_a;
276 const u32 block_id = id_a / Block::block_size;
277 const u32 lid = id_a % Block::block_size;
278
279 std::array<u32, 3> lid_coord = Block::get_coord(lid);
280
281 if (lid_coord[0] == 0) {
282 auto tmp = cell_max[block_id] - cell_min[block_id];
283 i32 Va = tmp.x() * tmp.y() * tmp.z();
284
285 static_assert(dim == 3, "implemented only in dim 3");
286 faces_xm.for_each_object(block_id, [&](u32 block_id_b) {
287 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
288 i32 nV = tmp.x() * tmp.y() * tmp.z();
289
290 if (nV == Va) { // same level
291 val_out[base_idx] = src
292 [block_id_b * Block::block_size
293 + Block::get_index({Block::Nside - 1, lid_coord[1], lid_coord[2]})];
294 }
295 });
296 }
297 });
298 });
299
300 buf_dest.complete_event_state(e);
301 buf_src.complete_event_state(e);
302 buf_cell_min.complete_event_state(e);
303 buf_cell_max.complete_event_state(e);
304
305 sham::EventList resulting_events;
306 resulting_events.add_event(e);
307 face_xm.neigh_info.complete_event_state(resulting_events);
308}
309
310template<class Tvec, class TgridVec, class T>
311void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_neigh_same_level_xp(
312
313 std::array<Tgridscal, dim> offset,
314 sham::DeviceBuffer<TgridVec> &buf_cell_min,
315 sham::DeviceBuffer<TgridVec> &buf_cell_max,
317 u32 nobj,
318 u32 nvar,
319 sham::DeviceBuffer<T> &buf_src,
320 sham::DeviceBuffer<T> &buf_dest
321
322) {
323 StackEntry stack_loc{};
324
325 using Block = typename Config::AMRBlock;
326 using namespace shamrock;
327
328 OrientedNeighFaceList<Tvec> &face_xp = face_lists.xp();
329
330 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
331
332 sham::EventList depends_list;
333 auto val_out = buf_dest.get_write_access(depends_list);
334 auto src = buf_src.get_read_access(depends_list);
335 auto cell_min = buf_cell_min.get_read_access(depends_list);
336 auto cell_max = buf_cell_max.get_read_access(depends_list);
337
338 auto fptr = face_xp.neigh_info.get_read_access(depends_list);
339
340 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
341 tree::ObjectCacheIterator faces_xp(fptr);
342
343 shambase::parallel_for(cgh, nobj * Block::block_size, "compute xm val (2)", [=](u64 id_a) {
344 const u32 base_idx = id_a;
345 const u32 block_id = id_a / Block::block_size;
346 const u32 lid = id_a % Block::block_size;
347
348 std::array<u32, 3> lid_coord = Block::get_coord(lid);
349
350 if (lid_coord[0] == Block::Nside - 1) {
351 auto tmp = cell_max[block_id] - cell_min[block_id];
352 i32 Va = tmp.x() * tmp.y() * tmp.z();
353
354 static_assert(dim == 3, "implemented only in dim 3");
355 faces_xp.for_each_object(block_id, [&](u32 block_id_b) {
356 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
357 i32 nV = tmp.x() * tmp.y() * tmp.z();
358
359 if (nV == Va) { // same level
360 auto val = src
361 [block_id_b * Block::block_size
362 + Block::get_index({0, lid_coord[1], lid_coord[2]})];
363
364 // if constexpr (std::is_same_v<T, Tvec>){
365 // sycl::ext::oneapi::experimental::printf("%d %f %f %f\n",block_id_b *
366 // Block::block_size +
367 // Block::get_index({0, lid_coord[1],
368 // lid_coord[2]}),val.x(),val.y(),val.z());
369 // }
370
371 val_out[base_idx] = val;
372 }
373 });
374 }
375 });
376 });
377
378 buf_dest.complete_event_state(e);
379 buf_src.complete_event_state(e);
380 buf_cell_min.complete_event_state(e);
381 buf_cell_max.complete_event_state(e);
382
383 sham::EventList resulting_events;
384 resulting_events.add_event(e);
385 face_xp.neigh_info.complete_event_state(resulting_events);
386}
387
388template<class Tvec, class TgridVec, class T>
389void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_neigh_same_level_ym(
390
391 std::array<Tgridscal, dim> offset,
392 sham::DeviceBuffer<TgridVec> &buf_cell_min,
393 sham::DeviceBuffer<TgridVec> &buf_cell_max,
395 u32 nobj,
396 u32 nvar,
397 sham::DeviceBuffer<T> &buf_src,
398 sham::DeviceBuffer<T> &buf_dest
399
400) {
401 StackEntry stack_loc{};
402
403 using Block = typename Config::AMRBlock;
404 using namespace shamrock;
405
406 OrientedNeighFaceList<Tvec> &face_ym = face_lists.ym();
407
408 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
409
410 sham::EventList depends_list;
411 auto val_out = buf_dest.get_write_access(depends_list);
412 auto src = buf_src.get_read_access(depends_list);
413 auto cell_min = buf_cell_min.get_read_access(depends_list);
414 auto cell_max = buf_cell_max.get_read_access(depends_list);
415
416 auto fptr = face_ym.neigh_info.get_read_access(depends_list);
417
418 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
419 tree::ObjectCacheIterator faces_ym(fptr);
420
421 shambase::parallel_for(cgh, nobj * Block::block_size, "compute ym val (2)", [=](u64 id_a) {
422 const u32 base_idx = id_a;
423 const u32 block_id = id_a / Block::block_size;
424 const u32 lid = id_a % Block::block_size;
425
426 std::array<u32, 3> lid_coord = Block::get_coord(lid);
427
428 if (lid_coord[1] == 0) {
429 auto tmp = cell_max[block_id] - cell_min[block_id];
430 i32 Va = tmp.x() * tmp.y() * tmp.z();
431
432 static_assert(dim == 3, "implemented only in dim 3");
433 faces_ym.for_each_object(block_id, [&](u32 block_id_b) {
434 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
435 i32 nV = tmp.x() * tmp.y() * tmp.z();
436
437 if (nV == Va) { // same level
438 val_out[base_idx] = src
439 [block_id_b * Block::block_size
440 + Block::get_index({lid_coord[0], Block::Nside - 1, lid_coord[2]})];
441 }
442 });
443 }
444 });
445 });
446
447 buf_dest.complete_event_state(e);
448 buf_src.complete_event_state(e);
449 buf_cell_min.complete_event_state(e);
450 buf_cell_max.complete_event_state(e);
451
452 sham::EventList resulting_events;
453 resulting_events.add_event(e);
454 face_ym.neigh_info.complete_event_state(resulting_events);
455}
456
457template<class Tvec, class TgridVec, class T>
458void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_neigh_same_level_yp(
459
460 std::array<Tgridscal, dim> offset,
461 sham::DeviceBuffer<TgridVec> &buf_cell_min,
462 sham::DeviceBuffer<TgridVec> &buf_cell_max,
464 u32 nobj,
465 u32 nvar,
466 sham::DeviceBuffer<T> &buf_src,
467 sham::DeviceBuffer<T> &buf_dest
468
469) {
470 StackEntry stack_loc{};
471
472 using Block = typename Config::AMRBlock;
473 using namespace shamrock;
474
475 OrientedNeighFaceList<Tvec> &face_yp = face_lists.yp();
476
477 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
478
479 sham::EventList depends_list;
480 auto val_out = buf_dest.get_write_access(depends_list);
481 auto src = buf_src.get_read_access(depends_list);
482 auto cell_min = buf_cell_min.get_read_access(depends_list);
483 auto cell_max = buf_cell_max.get_read_access(depends_list);
484
485 auto fptr = face_yp.neigh_info.get_read_access(depends_list);
486
487 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
488 tree::ObjectCacheIterator faces_yp(fptr);
489
490 shambase::parallel_for(cgh, nobj * Block::block_size, "compute ym val (2)", [=](u64 id_a) {
491 const u32 base_idx = id_a;
492 const u32 block_id = id_a / Block::block_size;
493 const u32 lid = id_a % Block::block_size;
494
495 std::array<u32, 3> lid_coord = Block::get_coord(lid);
496
497 if (lid_coord[1] == Block::Nside - 1) {
498 auto tmp = cell_max[block_id] - cell_min[block_id];
499 i32 Va = tmp.x() * tmp.y() * tmp.z();
500
501 static_assert(dim == 3, "implemented only in dim 3");
502 faces_yp.for_each_object(block_id, [&](u32 block_id_b) {
503 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
504 i32 nV = tmp.x() * tmp.y() * tmp.z();
505
506 if (nV == Va) { // same level
507 val_out[base_idx] = src
508 [block_id_b * Block::block_size
509 + Block::get_index({lid_coord[0], 0, lid_coord[2]})];
510 }
511 });
512 }
513 });
514 });
515
516 buf_dest.complete_event_state(e);
517 buf_src.complete_event_state(e);
518 buf_cell_min.complete_event_state(e);
519 buf_cell_max.complete_event_state(e);
520
521 sham::EventList resulting_events;
522 resulting_events.add_event(e);
523 face_yp.neigh_info.complete_event_state(resulting_events);
524}
525
526template<class Tvec, class TgridVec, class T>
527void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_neigh_same_level_zm(
528
529 std::array<Tgridscal, dim> offset,
530 sham::DeviceBuffer<TgridVec> &buf_cell_min,
531 sham::DeviceBuffer<TgridVec> &buf_cell_max,
533 u32 nobj,
534 u32 nvar,
535 sham::DeviceBuffer<T> &buf_src,
536 sham::DeviceBuffer<T> &buf_dest
537
538) {
539 StackEntry stack_loc{};
540
541 using Block = typename Config::AMRBlock;
542 using namespace shamrock;
543
544 OrientedNeighFaceList<Tvec> &face_zm = face_lists.zm();
545
546 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
547
548 sham::EventList depends_list;
549 auto val_out = buf_dest.get_write_access(depends_list);
550 auto src = buf_src.get_read_access(depends_list);
551 auto cell_min = buf_cell_min.get_read_access(depends_list);
552 auto cell_max = buf_cell_max.get_read_access(depends_list);
553
554 auto fptr = face_zm.neigh_info.get_read_access(depends_list);
555
556 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
557 tree::ObjectCacheIterator faces_zm(fptr);
558
559 shambase::parallel_for(cgh, nobj * Block::block_size, "compute zm val (2)", [=](u64 id_a) {
560 const u32 base_idx = id_a;
561 const u32 block_id = id_a / Block::block_size;
562 const u32 lid = id_a % Block::block_size;
563
564 std::array<u32, 3> lid_coord = Block::get_coord(lid);
565
566 if (lid_coord[2] == 0) {
567 auto tmp = cell_max[block_id] - cell_min[block_id];
568 i32 Va = tmp.x() * tmp.y() * tmp.z();
569
570 static_assert(dim == 3, "implemented only in dim 3");
571 faces_zm.for_each_object(block_id, [&](u32 block_id_b) {
572 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
573 i32 nV = tmp.x() * tmp.y() * tmp.z();
574
575 if (nV == Va) { // same level
576 val_out[base_idx] = src
577 [block_id_b * Block::block_size
578 + Block::get_index({lid_coord[0], lid_coord[1], Block::Nside - 1})];
579 }
580 });
581 }
582 });
583 });
584
585 buf_dest.complete_event_state(e);
586 buf_src.complete_event_state(e);
587 buf_cell_min.complete_event_state(e);
588 buf_cell_max.complete_event_state(e);
589
590 sham::EventList resulting_events;
591 resulting_events.add_event(e);
592 face_zm.neigh_info.complete_event_state(resulting_events);
593}
594
595template<class Tvec, class TgridVec, class T>
596void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_neigh_same_level_zp(
597
598 std::array<Tgridscal, dim> offset,
599 sham::DeviceBuffer<TgridVec> &buf_cell_min,
600 sham::DeviceBuffer<TgridVec> &buf_cell_max,
602 u32 nobj,
603 u32 nvar,
604 sham::DeviceBuffer<T> &buf_src,
605 sham::DeviceBuffer<T> &buf_dest
606
607) {
608 StackEntry stack_loc{};
609
610 using Block = typename Config::AMRBlock;
611 using namespace shamrock;
612
613 OrientedNeighFaceList<Tvec> &face_zp = face_lists.zp();
614
615 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
616
617 sham::EventList depends_list;
618 auto val_out = buf_dest.get_write_access(depends_list);
619 auto src = buf_src.get_read_access(depends_list);
620 auto cell_min = buf_cell_min.get_read_access(depends_list);
621 auto cell_max = buf_cell_max.get_read_access(depends_list);
622
623 auto fptr = face_zp.neigh_info.get_read_access(depends_list);
624
625 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
626 tree::ObjectCacheIterator faces_zp(fptr);
627
628 shambase::parallel_for(cgh, nobj * Block::block_size, "compute zm val (2)", [=](u64 id_a) {
629 const u32 base_idx = id_a;
630 const u32 block_id = id_a / Block::block_size;
631 const u32 lid = id_a % Block::block_size;
632
633 std::array<u32, 3> lid_coord = Block::get_coord(lid);
634
635 if (lid_coord[2] == Block::Nside - 1) {
636 auto tmp = cell_max[block_id] - cell_min[block_id];
637 i32 Va = tmp.x() * tmp.y() * tmp.z();
638
639 static_assert(dim == 3, "implemented only in dim 3");
640 faces_zp.for_each_object(block_id, [&](u32 block_id_b) {
641 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
642 i32 nV = tmp.x() * tmp.y() * tmp.z();
643
644 if (nV == Va) { // same level
645 val_out[base_idx] = src
646 [block_id_b * Block::block_size
647 + Block::get_index({lid_coord[0], lid_coord[1], 0})];
648 }
649 });
650 }
651 });
652 });
653
654 buf_dest.complete_event_state(e);
655 buf_src.complete_event_state(e);
656 buf_cell_min.complete_event_state(e);
657 buf_cell_max.complete_event_state(e);
658
659 sham::EventList resulting_events;
660 resulting_events.add_event(e);
661 face_zp.neigh_info.complete_event_state(resulting_events);
662}
663
664template<class Tvec, class TgridVec, class T>
665void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_neigh_same_level(
666
667 std::array<Tgridscal, dim> offset,
668 sham::DeviceBuffer<TgridVec> &buf_cell_min,
669 sham::DeviceBuffer<TgridVec> &buf_cell_max,
671 u32 nobj,
672 u32 nvar,
673 sham::DeviceBuffer<T> &buf_src,
674 sham::DeviceBuffer<T> &buf_dest
675
676) {
677 StackEntry stack_loc{};
678 using Block = typename Config::AMRBlock;
679
680 using namespace shamrock::patch;
681 using namespace shamrock;
682 using namespace shammath;
683 using MergedPDat = shamrock::MergedPatchData;
684
685 if constexpr (dim == 3) {
686 if (offset[0] == -1 && offset[1] == 0 && offset[2] == 0) {
687
688 load_patch_neigh_same_level_xm(
689 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
690
691 } else if (offset[0] == 0 && offset[1] == -1 && offset[2] == 0) {
692
693 load_patch_neigh_same_level_ym(
694 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
695
696 } else if (offset[0] == 0 && offset[1] == 0 && offset[2] == -1) {
697
698 load_patch_neigh_same_level_zm(
699 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
700
701 } else if (offset[0] == 1 && offset[1] == 0 && offset[2] == 0) {
702
703 load_patch_neigh_same_level_xp(
704 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
705
706 } else if (offset[0] == 0 && offset[1] == 1 && offset[2] == 0) {
707
708 load_patch_neigh_same_level_yp(
709 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
710
711 } else if (offset[0] == 0 && offset[1] == 0 && offset[2] == 1) {
712
713 load_patch_neigh_same_level_zp(
714 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
715
716 } else {
718 sham::format("offset : ({},{},{}) is invalid", offset[0], offset[1], offset[2]));
719 }
720 } else {
722 }
723}
724
726//
728
729template<class Tvec, class TgridVec, class T>
730void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_neigh_level_up(
731
732 std::array<Tgridscal, dim> offset,
733 sham::DeviceBuffer<TgridVec> &buf_cell_min,
734 sham::DeviceBuffer<TgridVec> &buf_cell_max,
736 u32 nobj,
737 u32 nvar,
738 sham::DeviceBuffer<T> &buf_src,
739 sham::DeviceBuffer<T> &buf_dest
740
741) {
742
743 StackEntry stack_loc{};
744 using Block = typename Config::AMRBlock;
745
746 using namespace shamrock::patch;
747 using namespace shamrock;
748 using namespace shammath;
749 using MergedPDat = shamrock::MergedPatchData;
750
751 if constexpr (dim == 3) {
752 if (offset[0] == -1 && offset[1] == 0 && offset[2] == 0) {
753
754 OrientedNeighFaceList<Tvec> &face_xm = face_lists.xm();
755
756 } else if (offset[0] == 0 && offset[1] == -1 && offset[2] == 0) {
757
758 OrientedNeighFaceList<Tvec> &face_ym = face_lists.ym();
759
760 } else if (offset[0] == 0 && offset[1] == 0 && offset[2] == -1) {
761
762 OrientedNeighFaceList<Tvec> &face_zm = face_lists.zm();
763
764 } else if (offset[0] == 1 && offset[1] == 0 && offset[2] == 0) {
765
766 OrientedNeighFaceList<Tvec> &face_xp = face_lists.xp();
767
768 } else if (offset[0] == 0 && offset[1] == 1 && offset[2] == 0) {
769
770 OrientedNeighFaceList<Tvec> &face_yp = face_lists.yp();
771
772 } else if (offset[0] == 0 && offset[1] == 0 && offset[2] == 1) {
773
774 OrientedNeighFaceList<Tvec> &face_zp = face_lists.zp();
775
776 } else {
778 sham::format("offset : ({},{},{}) is invalid", offset[0], offset[1], offset[2]));
779 }
780 } else {
782 }
783}
784
786//
788
789template<class Tvec, class TgridVec, class T>
790void shammodels::zeus::modules::ValueLoader<Tvec, TgridVec, T>::load_patch_neigh_level_down(
791
792 std::array<Tgridscal, dim> offset,
793 sham::DeviceBuffer<TgridVec> &buf_cell_min,
794 sham::DeviceBuffer<TgridVec> &buf_cell_max,
796 u32 nobj,
797 u32 nvar,
798 sham::DeviceBuffer<T> &buf_src,
799 sham::DeviceBuffer<T> &buf_dest
800
801) {
802 StackEntry stack_loc{};
803 using Block = typename Config::AMRBlock;
804
805 using namespace shamrock::patch;
806 using namespace shamrock;
807 using namespace shammath;
808 using MergedPDat = shamrock::MergedPatchData;
809
810 if constexpr (dim == 3) {
811 if (offset[0] == -1 && offset[1] == 0 && offset[2] == 0) {
812
813 OrientedNeighFaceList<Tvec> &face_xm = face_lists.xm();
814
815 } else if (offset[0] == 0 && offset[1] == -1 && offset[2] == 0) {
816
817 OrientedNeighFaceList<Tvec> &face_ym = face_lists.ym();
818
819 } else if (offset[0] == 0 && offset[1] == 0 && offset[2] == -1) {
820
821 OrientedNeighFaceList<Tvec> &face_zm = face_lists.zm();
822
823 } else if (offset[0] == 1 && offset[1] == 0 && offset[2] == 0) {
824
825 OrientedNeighFaceList<Tvec> &face_xp = face_lists.xp();
826
827 } else if (offset[0] == 0 && offset[1] == 1 && offset[2] == 0) {
828
829 OrientedNeighFaceList<Tvec> &face_yp = face_lists.yp();
830
831 } else if (offset[0] == 0 && offset[1] == 0 && offset[2] == 1) {
832
833 OrientedNeighFaceList<Tvec> &face_zp = face_lists.zp();
834
835 } else {
837 sham::format("offset : ({},{},{}) is invalid", offset[0], offset[1], offset[2]));
838 }
839 } else {
841 }
842}
843
845//
847
848template<class Tvec, class TgridVec, class T>
851 std::string field_name, std::array<Tgridscal, dim> offset, std::string result_name) {
852
853 StackEntry stack_loc{};
854
855 using namespace shamrock::patch;
856 using namespace shamrock;
857 using namespace shammath;
858 using MergedPDat = shamrock::MergedPatchData;
859 using Flagger = FaceFlagger<Tvec, TgridVec>;
860 using Block = typename Config::AMRBlock;
861
862 shamrock::SchedulerUtility utility(scheduler());
864 = utility.make_compute_field<T>(result_name, Block::block_size, [&](u64 id) {
865 return storage.merged_patchdata_ghost.get().get(id).total_elements;
866 });
867
869 = shambase::get_check_ref(storage.ghost_layout.get());
870 u32 ifield = ghost_layout.get_field_idx<T>(field_name);
871 u32 nvar = ghost_layout.get_field<T>(ifield).nvar;
872
873 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
874 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
875
876 sham::DeviceBuffer<T> &buf_src = mpdat.pdat.get_field_buf_ref<T>(ifield);
877 sham::DeviceBuffer<T> &buf_dest = tmp.get_buf_check(p.id_patch);
878
879 load_patch_internal_block(offset, mpdat.total_elements, nvar, buf_src, buf_dest);
880 });
881
882 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
883 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
884
885 sham::DeviceBuffer<TgridVec> &buf_cell_min = mpdat.pdat.get_field_buf_ref<TgridVec>(0);
886 sham::DeviceBuffer<TgridVec> &buf_cell_max = mpdat.pdat.get_field_buf_ref<TgridVec>(1);
887
888 sham::DeviceBuffer<T> &buf_src = mpdat.pdat.get_field_buf_ref<T>(ifield);
889 sham::DeviceBuffer<T> &buf_dest = tmp.get_buf_check(p.id_patch);
890
892 = storage.face_lists.get().get(p.id_patch);
893
894 load_patch_neigh_same_level(
895 offset,
896 buf_cell_min,
897 buf_cell_max,
898 face_lists,
899 mpdat.total_elements,
900 nvar,
901 buf_src,
902 buf_dest);
903 });
904
905 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
906 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
907
908 sham::DeviceBuffer<TgridVec> &buf_cell_min = mpdat.pdat.get_field_buf_ref<TgridVec>(0);
909 sham::DeviceBuffer<TgridVec> &buf_cell_max = mpdat.pdat.get_field_buf_ref<TgridVec>(1);
910
911 sham::DeviceBuffer<T> &buf_src = mpdat.pdat.get_field_buf_ref<T>(ifield);
912 sham::DeviceBuffer<T> &buf_dest = tmp.get_buf_check(p.id_patch);
913
915 = storage.face_lists.get().get(p.id_patch);
916
917 load_patch_neigh_level_up(
918 offset,
919 buf_cell_min,
920 buf_cell_max,
921 face_lists,
922 mpdat.total_elements,
923 nvar,
924 buf_src,
925 buf_dest);
926 });
927
928 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
929 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
930
931 sham::DeviceBuffer<TgridVec> &buf_cell_min = mpdat.pdat.get_field_buf_ref<TgridVec>(0);
932 sham::DeviceBuffer<TgridVec> &buf_cell_max = mpdat.pdat.get_field_buf_ref<TgridVec>(1);
933
934 sham::DeviceBuffer<T> &buf_src = mpdat.pdat.get_field_buf_ref<T>(ifield);
935 sham::DeviceBuffer<T> &buf_dest = tmp.get_buf_check(p.id_patch);
936
938 = storage.face_lists.get().get(p.id_patch);
939
940 load_patch_neigh_level_down(
941 offset,
942 buf_cell_min,
943 buf_cell_max,
944 face_lists,
945 mpdat.total_elements,
946 nvar,
947 buf_src,
948 buf_dest);
949 });
950
951 return tmp;
952}
953
954template<class Tvec, class TgridVec, class T>
957 shamrock::ComputeField<T> &compute_field,
958 std::array<Tgridscal, dim> offset,
959 std::string result_name) {
960
961 StackEntry stack_loc{};
962
963 using namespace shamrock::patch;
964 using namespace shamrock;
965 using namespace shammath;
966 using MergedPDat = shamrock::MergedPatchData;
967 using Flagger = FaceFlagger<Tvec, TgridVec>;
968 using Block = typename Config::AMRBlock;
969
970 shamrock::SchedulerUtility utility(scheduler());
972 = utility.make_compute_field<T>(result_name, Block::block_size, [&](u64 id) {
973 return storage.merged_patchdata_ghost.get().get(id).total_elements;
974 });
975
976 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
977 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
978
979 sham::DeviceBuffer<T> &buf_src = compute_field.get_buf_check(p.id_patch);
980 sham::DeviceBuffer<T> &buf_dest = tmp.get_buf_check(p.id_patch);
981
982 load_patch_internal_block(
983 offset,
984 mpdat.total_elements,
985 compute_field.get_field(p.id_patch).get_nvar(),
986 buf_src,
987 buf_dest);
988 });
989
990 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
991 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
992
993 sham::DeviceBuffer<TgridVec> &buf_cell_min = mpdat.pdat.get_field_buf_ref<TgridVec>(0);
994 sham::DeviceBuffer<TgridVec> &buf_cell_max = mpdat.pdat.get_field_buf_ref<TgridVec>(1);
995
996 sham::DeviceBuffer<T> &buf_src = compute_field.get_buf_check(p.id_patch);
997 sham::DeviceBuffer<T> &buf_dest = tmp.get_buf_check(p.id_patch);
998
1000 = storage.face_lists.get().get(p.id_patch);
1001
1002 load_patch_neigh_same_level(
1003 offset,
1004 buf_cell_min,
1005 buf_cell_max,
1006 face_lists,
1007 mpdat.total_elements,
1008 compute_field.get_field(p.id_patch).get_nvar(),
1009 buf_src,
1010 buf_dest);
1011 });
1012
1013 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
1014 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
1015
1016 sham::DeviceBuffer<TgridVec> &buf_cell_min = mpdat.pdat.get_field_buf_ref<TgridVec>(0);
1017 sham::DeviceBuffer<TgridVec> &buf_cell_max = mpdat.pdat.get_field_buf_ref<TgridVec>(1);
1018
1019 sham::DeviceBuffer<T> &buf_src = compute_field.get_buf_check(p.id_patch);
1020 sham::DeviceBuffer<T> &buf_dest = tmp.get_buf_check(p.id_patch);
1021
1023 = storage.face_lists.get().get(p.id_patch);
1024
1025 load_patch_neigh_level_up(
1026 offset,
1027 buf_cell_min,
1028 buf_cell_max,
1029 face_lists,
1030 mpdat.total_elements,
1031 compute_field.get_field(p.id_patch).get_nvar(),
1032 buf_src,
1033 buf_dest);
1034 });
1035
1036 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
1037 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
1038
1039 sham::DeviceBuffer<TgridVec> &buf_cell_min = mpdat.pdat.get_field_buf_ref<TgridVec>(0);
1040 sham::DeviceBuffer<TgridVec> &buf_cell_max = mpdat.pdat.get_field_buf_ref<TgridVec>(1);
1041
1042 sham::DeviceBuffer<T> &buf_src = compute_field.get_buf_check(p.id_patch);
1043 sham::DeviceBuffer<T> &buf_dest = tmp.get_buf_check(p.id_patch);
1044
1046 = storage.face_lists.get().get(p.id_patch);
1047
1048 load_patch_neigh_level_down(
1049 offset,
1050 buf_cell_min,
1051 buf_cell_max,
1052 face_lists,
1053 mpdat.total_elements,
1054 compute_field.get_field(p.id_patch).get_nvar(),
1055 buf_src,
1056 buf_dest);
1057 });
1058
1059 return tmp;
1060}
1061
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
std::int32_t i32
32 bit integer
A buffer allocated in USM (Unified Shared Memory).
void complete_event_state(sycl::event e) const
Complete the event state of the buffer.
T * get_write_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{})
Get a read-write pointer to the buffer's data.
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
A SYCL queue associated with a device and a context.
sycl::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
Class to manage a list of SYCL events.
Definition EventList.hpp:32
void add_event(sycl::event e)
Add an event to the list of events.
Definition EventList.hpp:88
flag faces with a lookup index for the orientation
shamrock::ComputeField< T > load_value_with_gz(std::string field_name, std::array< Tgridscal, dim > offset, std::string result_name)
ComputeField< T > make_compute_field(std::string new_name, u32 nvar)
create a compute field and init it to zeros
PatchDataLayer container class, the layout is described in patchdata_layout.
void kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, u32 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
Submit a kernel to a SYCL queue.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
Definition memory.hpp:112
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
namespace for math utility
Definition AABB.hpp:26
namespace for the main framework
Definition __init__.py:1
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
A class that references multiple buffers or similar objects.
Definition MultiRef.hpp:33
Patch object that contain generic patch information.
Definition Patch.hpp:33
u64 id_patch
unique key that identify the patch
Definition Patch.hpp:86