24template<
class Tvec,
class Tgr
idVec,
class T>
29 using Block =
typename Config::AMRBlock;
37 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
38 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute xm val (1)", [=](
u64 id_a) {
39 const u32 base_idx = id_a;
40 const u32 lid = id_a % Block::block_size;
42 static_assert(dim == 3,
"implemented only in dim 3");
43 std::array<u32, 3> lid_coord = Block::get_coord(lid);
45 if (lid_coord[0] > 0) {
47 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
56template<
class Tvec,
class Tgr
idVec,
class T>
61 using Block =
typename Config::AMRBlock;
69 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
70 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute xp val (1)", [=](
u64 id_a) {
71 const u32 base_idx = id_a;
72 const u32 lid = id_a % Block::block_size;
74 static_assert(dim == 3,
"implemented only in dim 3");
75 std::array<u32, 3> lid_coord = Block::get_coord(lid);
77 if (lid_coord[0] < Block::Nside - 1) {
79 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
88template<
class Tvec,
class Tgr
idVec,
class T>
93 using Block =
typename Config::AMRBlock;
101 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
102 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute ym val (1)", [=](
u64 id_a) {
103 const u32 base_idx = id_a;
104 const u32 lid = id_a % Block::block_size;
106 static_assert(dim == 3,
"implemented only in dim 3");
107 std::array<u32, 3> lid_coord = Block::get_coord(lid);
109 if (lid_coord[1] > 0) {
111 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
120template<
class Tvec,
class Tgr
idVec,
class T>
125 using Block =
typename Config::AMRBlock;
133 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
134 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute yp val (1)", [=](
u64 id_a) {
135 const u32 base_idx = id_a;
136 const u32 lid = id_a % Block::block_size;
138 static_assert(dim == 3,
"implemented only in dim 3");
139 std::array<u32, 3> lid_coord = Block::get_coord(lid);
141 if (lid_coord[1] < Block::Nside - 1) {
143 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
152template<
class Tvec,
class Tgr
idVec,
class T>
157 using Block =
typename Config::AMRBlock;
165 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
166 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute ym val (1)", [=](
u64 id_a) {
167 const u32 base_idx = id_a;
168 const u32 lid = id_a % Block::block_size;
170 static_assert(dim == 3,
"implemented only in dim 3");
171 std::array<u32, 3> lid_coord = Block::get_coord(lid);
173 if (lid_coord[2] > 0) {
175 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
184template<
class Tvec,
class Tgr
idVec,
class T>
189 using Block =
typename Config::AMRBlock;
197 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
198 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute ym val (1)", [=](
u64 id_a) {
199 const u32 base_idx = id_a;
200 const u32 lid = id_a % Block::block_size;
202 static_assert(dim == 3,
"implemented only in dim 3");
203 std::array<u32, 3> lid_coord = Block::get_coord(lid);
205 if (lid_coord[2] < Block::Nside - 1) {
207 val_out[base_idx] = src[base_idx - lid + Block::get_index(lid_coord)];
216template<
class Tvec,
class Tgr
idVec,
class T>
218 std::array<Tgridscal, dim> offset,
225 using Block =
typename Config::AMRBlock;
227 if constexpr (dim == 3) {
228 if (offset[0] == -1 && offset[1] == 0 && offset[2] == 0) {
230 load_patch_internal_block_xm(nobj, nvar, buf_src, buf_dest);
232 }
else if (offset[0] == 0 && offset[1] == -1 && offset[2] == 0) {
234 load_patch_internal_block_ym(nobj, nvar, buf_src, buf_dest);
236 }
else if (offset[0] == 0 && offset[1] == 0 && offset[2] == -1) {
238 load_patch_internal_block_zm(nobj, nvar, buf_src, buf_dest);
240 }
else if (offset[0] == 1 && offset[1] == 0 && offset[2] == 0) {
242 load_patch_internal_block_xp(nobj, nvar, buf_src, buf_dest);
244 }
else if (offset[0] == 0 && offset[1] == 1 && offset[2] == 0) {
246 load_patch_internal_block_yp(nobj, nvar, buf_src, buf_dest);
248 }
else if (offset[0] == 0 && offset[1] == 0 && offset[2] == 1) {
250 load_patch_internal_block_zp(nobj, nvar, buf_src, buf_dest);
254 "offset : ({},{},{}) is invalid", offset[0], offset[1], offset[2]));
265template<
class Tvec,
class Tgr
idVec,
class T>
268 std::array<Tgridscal, dim> offset,
280 using Block =
typename Config::AMRBlock;
283 OrientedNeighFaceList<Tvec> &face_xm = face_lists.xm();
293 auto fptr = face_xm.neigh_info.get_read_access(depends_list);
295 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
298 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute xm val (2)", [=](
u64 id_a) {
299 const u32 base_idx = id_a;
300 const u32 block_id = id_a / Block::block_size;
301 const u32 lid = id_a % Block::block_size;
303 std::array<u32, 3> lid_coord = Block::get_coord(lid);
305 if (lid_coord[0] == 0) {
306 auto tmp = cell_max[block_id] - cell_min[block_id];
307 i32 Va = tmp.x() * tmp.y() * tmp.z();
309 static_assert(dim == 3,
"implemented only in dim 3");
310 faces_xm.for_each_object(block_id, [&](
u32 block_id_b) {
311 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
312 i32 nV = tmp.x() * tmp.y() * tmp.z();
315 val_out[base_idx] = src
316 [block_id_b * Block::block_size
317 + Block::get_index({Block::Nside - 1, lid_coord[1], lid_coord[2]})];
331 face_xm.neigh_info.complete_event_state(resulting_events);
334template<
class Tvec,
class Tgr
idVec,
class T>
337 std::array<Tgridscal, dim> offset,
349 using Block =
typename Config::AMRBlock;
352 OrientedNeighFaceList<Tvec> &face_xp = face_lists.xp();
362 auto fptr = face_xp.neigh_info.get_read_access(depends_list);
364 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
367 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute xm val (2)", [=](
u64 id_a) {
368 const u32 base_idx = id_a;
369 const u32 block_id = id_a / Block::block_size;
370 const u32 lid = id_a % Block::block_size;
372 std::array<u32, 3> lid_coord = Block::get_coord(lid);
374 if (lid_coord[0] == Block::Nside - 1) {
375 auto tmp = cell_max[block_id] - cell_min[block_id];
376 i32 Va = tmp.x() * tmp.y() * tmp.z();
378 static_assert(dim == 3,
"implemented only in dim 3");
379 faces_xp.for_each_object(block_id, [&](
u32 block_id_b) {
380 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
381 i32 nV = tmp.x() * tmp.y() * tmp.z();
385 [block_id_b * Block::block_size
386 + Block::get_index({0, lid_coord[1], lid_coord[2]})];
395 val_out[base_idx] = val;
409 face_xp.neigh_info.complete_event_state(resulting_events);
412template<
class Tvec,
class Tgr
idVec,
class T>
415 std::array<Tgridscal, dim> offset,
427 using Block =
typename Config::AMRBlock;
430 OrientedNeighFaceList<Tvec> &face_ym = face_lists.ym();
440 auto fptr = face_ym.neigh_info.get_read_access(depends_list);
442 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
445 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute ym val (2)", [=](
u64 id_a) {
446 const u32 base_idx = id_a;
447 const u32 block_id = id_a / Block::block_size;
448 const u32 lid = id_a % Block::block_size;
450 std::array<u32, 3> lid_coord = Block::get_coord(lid);
452 if (lid_coord[1] == 0) {
453 auto tmp = cell_max[block_id] - cell_min[block_id];
454 i32 Va = tmp.x() * tmp.y() * tmp.z();
456 static_assert(dim == 3,
"implemented only in dim 3");
457 faces_ym.for_each_object(block_id, [&](
u32 block_id_b) {
458 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
459 i32 nV = tmp.x() * tmp.y() * tmp.z();
462 val_out[base_idx] = src
463 [block_id_b * Block::block_size
464 + Block::get_index({lid_coord[0], Block::Nside - 1, lid_coord[2]})];
478 face_ym.neigh_info.complete_event_state(resulting_events);
481template<
class Tvec,
class Tgr
idVec,
class T>
484 std::array<Tgridscal, dim> offset,
496 using Block =
typename Config::AMRBlock;
499 OrientedNeighFaceList<Tvec> &face_yp = face_lists.yp();
509 auto fptr = face_yp.neigh_info.get_read_access(depends_list);
511 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
514 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute ym val (2)", [=](
u64 id_a) {
515 const u32 base_idx = id_a;
516 const u32 block_id = id_a / Block::block_size;
517 const u32 lid = id_a % Block::block_size;
519 std::array<u32, 3> lid_coord = Block::get_coord(lid);
521 if (lid_coord[1] == Block::Nside - 1) {
522 auto tmp = cell_max[block_id] - cell_min[block_id];
523 i32 Va = tmp.x() * tmp.y() * tmp.z();
525 static_assert(dim == 3,
"implemented only in dim 3");
526 faces_yp.for_each_object(block_id, [&](
u32 block_id_b) {
527 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
528 i32 nV = tmp.x() * tmp.y() * tmp.z();
531 val_out[base_idx] = src
532 [block_id_b * Block::block_size
533 + Block::get_index({lid_coord[0], 0, lid_coord[2]})];
547 face_yp.neigh_info.complete_event_state(resulting_events);
550template<
class Tvec,
class Tgr
idVec,
class T>
553 std::array<Tgridscal, dim> offset,
565 using Block =
typename Config::AMRBlock;
568 OrientedNeighFaceList<Tvec> &face_zm = face_lists.zm();
578 auto fptr = face_zm.neigh_info.get_read_access(depends_list);
580 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
583 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute zm val (2)", [=](
u64 id_a) {
584 const u32 base_idx = id_a;
585 const u32 block_id = id_a / Block::block_size;
586 const u32 lid = id_a % Block::block_size;
588 std::array<u32, 3> lid_coord = Block::get_coord(lid);
590 if (lid_coord[2] == 0) {
591 auto tmp = cell_max[block_id] - cell_min[block_id];
592 i32 Va = tmp.x() * tmp.y() * tmp.z();
594 static_assert(dim == 3,
"implemented only in dim 3");
595 faces_zm.for_each_object(block_id, [&](
u32 block_id_b) {
596 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
597 i32 nV = tmp.x() * tmp.y() * tmp.z();
600 val_out[base_idx] = src
601 [block_id_b * Block::block_size
602 + Block::get_index({lid_coord[0], lid_coord[1], Block::Nside - 1})];
616 face_zm.neigh_info.complete_event_state(resulting_events);
619template<
class Tvec,
class Tgr
idVec,
class T>
622 std::array<Tgridscal, dim> offset,
634 using Block =
typename Config::AMRBlock;
637 OrientedNeighFaceList<Tvec> &face_zp = face_lists.zp();
647 auto fptr = face_zp.neigh_info.get_read_access(depends_list);
649 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
652 shambase::parallel_for(cgh, nobj * Block::block_size,
"compute zm val (2)", [=](
u64 id_a) {
653 const u32 base_idx = id_a;
654 const u32 block_id = id_a / Block::block_size;
655 const u32 lid = id_a % Block::block_size;
657 std::array<u32, 3> lid_coord = Block::get_coord(lid);
659 if (lid_coord[2] == Block::Nside - 1) {
660 auto tmp = cell_max[block_id] - cell_min[block_id];
661 i32 Va = tmp.x() * tmp.y() * tmp.z();
663 static_assert(dim == 3,
"implemented only in dim 3");
664 faces_zp.for_each_object(block_id, [&](
u32 block_id_b) {
665 auto tmp = cell_max[block_id_b] - cell_min[block_id_b];
666 i32 nV = tmp.x() * tmp.y() * tmp.z();
669 val_out[base_idx] = src
670 [block_id_b * Block::block_size
671 + Block::get_index({lid_coord[0], lid_coord[1], 0})];
685 face_zp.neigh_info.complete_event_state(resulting_events);
688template<
class Tvec,
class Tgr
idVec,
class T>
691 std::array<Tgridscal, dim> offset,
702 using Block =
typename Config::AMRBlock;
704 using namespace shamrock::patch;
709 if constexpr (dim == 3) {
710 if (offset[0] == -1 && offset[1] == 0 && offset[2] == 0) {
712 load_patch_neigh_same_level_xm(
713 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
715 }
else if (offset[0] == 0 && offset[1] == -1 && offset[2] == 0) {
717 load_patch_neigh_same_level_ym(
718 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
720 }
else if (offset[0] == 0 && offset[1] == 0 && offset[2] == -1) {
722 load_patch_neigh_same_level_zm(
723 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
725 }
else if (offset[0] == 1 && offset[1] == 0 && offset[2] == 0) {
727 load_patch_neigh_same_level_xp(
728 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
730 }
else if (offset[0] == 0 && offset[1] == 1 && offset[2] == 0) {
732 load_patch_neigh_same_level_yp(
733 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
735 }
else if (offset[0] == 0 && offset[1] == 0 && offset[2] == 1) {
737 load_patch_neigh_same_level_zp(
738 offset, buf_cell_min, buf_cell_max, face_lists, nobj, nvar, buf_src, buf_dest);
742 "offset : ({},{},{}) is invalid", offset[0], offset[1], offset[2]));
753template<
class Tvec,
class Tgr
idVec,
class T>
756 std::array<Tgridscal, dim> offset,
768 using Block =
typename Config::AMRBlock;
770 using namespace shamrock::patch;
775 if constexpr (dim == 3) {
776 if (offset[0] == -1 && offset[1] == 0 && offset[2] == 0) {
778 OrientedNeighFaceList<Tvec> &face_xm = face_lists.xm();
780 }
else if (offset[0] == 0 && offset[1] == -1 && offset[2] == 0) {
782 OrientedNeighFaceList<Tvec> &face_ym = face_lists.ym();
784 }
else if (offset[0] == 0 && offset[1] == 0 && offset[2] == -1) {
786 OrientedNeighFaceList<Tvec> &face_zm = face_lists.zm();
788 }
else if (offset[0] == 1 && offset[1] == 0 && offset[2] == 0) {
790 OrientedNeighFaceList<Tvec> &face_xp = face_lists.xp();
792 }
else if (offset[0] == 0 && offset[1] == 1 && offset[2] == 0) {
794 OrientedNeighFaceList<Tvec> &face_yp = face_lists.yp();
796 }
else if (offset[0] == 0 && offset[1] == 0 && offset[2] == 1) {
798 OrientedNeighFaceList<Tvec> &face_zp = face_lists.zp();
802 "offset : ({},{},{}) is invalid", offset[0], offset[1], offset[2]));
813template<
class Tvec,
class Tgr
idVec,
class T>
816 std::array<Tgridscal, dim> offset,
827 using Block =
typename Config::AMRBlock;
829 using namespace shamrock::patch;
834 if constexpr (dim == 3) {
835 if (offset[0] == -1 && offset[1] == 0 && offset[2] == 0) {
837 OrientedNeighFaceList<Tvec> &face_xm = face_lists.xm();
839 }
else if (offset[0] == 0 && offset[1] == -1 && offset[2] == 0) {
841 OrientedNeighFaceList<Tvec> &face_ym = face_lists.ym();
843 }
else if (offset[0] == 0 && offset[1] == 0 && offset[2] == -1) {
845 OrientedNeighFaceList<Tvec> &face_zm = face_lists.zm();
847 }
else if (offset[0] == 1 && offset[1] == 0 && offset[2] == 0) {
849 OrientedNeighFaceList<Tvec> &face_xp = face_lists.xp();
851 }
else if (offset[0] == 0 && offset[1] == 1 && offset[2] == 0) {
853 OrientedNeighFaceList<Tvec> &face_yp = face_lists.yp();
855 }
else if (offset[0] == 0 && offset[1] == 0 && offset[2] == 1) {
857 OrientedNeighFaceList<Tvec> &face_zp = face_lists.zp();
861 "offset : ({},{},{}) is invalid", offset[0], offset[1], offset[2]));
872template<
class Tvec,
class Tgr
idVec,
class T>
875 std::string field_name, std::array<Tgridscal, dim> offset, std::string result_name) {
879 using namespace shamrock::patch;
889 return storage.merged_patchdata_ghost.get().get(
id).total_elements;
894 u32 ifield = ghost_layout.get_field_idx<T>(field_name);
895 u32 nvar = ghost_layout.get_field<T>(ifield).nvar;
898 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
903 load_patch_internal_block(offset, mpdat.total_elements, nvar, buf_src, buf_dest);
907 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
916 = storage.face_lists.get().get(p.id_patch);
918 load_patch_neigh_same_level(
923 mpdat.total_elements,
930 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
939 = storage.face_lists.get().get(p.id_patch);
941 load_patch_neigh_level_up(
946 mpdat.total_elements,
953 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
962 = storage.face_lists.get().get(p.id_patch);
964 load_patch_neigh_level_down(
969 mpdat.total_elements,
978template<
class Tvec,
class Tgr
idVec,
class T>
982 std::array<Tgridscal, dim> offset,
983 std::string result_name) {
987 using namespace shamrock::patch;
991 using Flagger = FaceFlagger<Tvec, TgridVec>;
992 using Block =
typename Config::AMRBlock;
996 = utility.make_compute_field<T>(result_name, Block::block_size, [&](
u64 id) {
997 return storage.merged_patchdata_ghost.get().get(
id).total_elements;
1001 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
1006 load_patch_internal_block(
1008 mpdat.total_elements,
1009 compute_field.get_field(p.id_patch).get_nvar(),
1015 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
1024 = storage.face_lists.get().get(p.id_patch);
1026 load_patch_neigh_same_level(
1031 mpdat.total_elements,
1032 compute_field.get_field(p.id_patch).get_nvar(),
1038 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
1047 = storage.face_lists.get().get(p.id_patch);
1049 load_patch_neigh_level_up(
1054 mpdat.total_elements,
1055 compute_field.get_field(p.id_patch).get_nvar(),
1061 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
1070 = storage.face_lists.get().get(p.id_patch);
1072 load_patch_neigh_level_down(
1077 mpdat.total_elements,
1078 compute_field.get_field(p.id_patch).get_nvar(),
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.
DeviceQueue & get_queue(u32 id=0)
Get a reference to a DeviceQueue.
Class to manage a list of SYCL events.
void add_event(sycl::event e)
Add an event to the list of events.
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 throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
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...
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
namespace for math utility
namespace for the main framework
utility class to handle AMR blocks
Patch object that contain generic patch information.