-
Notifications
You must be signed in to change notification settings - Fork 32
[Patch] migrate SerialPatchTree & PatchtreeField to sham::DeviceBuffer #1798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2fb03d1
8e0470e
f44883e
663d24b
039c48e
8b5fdbe
ff85c06
170dba2
72434c1
f957225
199ce84
f1e29d2
08d1a1b
d051bfd
d2c5cac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,8 +290,7 @@ auto BasicSPHGhostHandler<vec>::find_interfaces( | |
| base_timer.start(); | ||
|
|
||
| if (BCPeriodic *cfg = std::get_if<BCPeriodic>(&ghost_config)) { | ||
| sycl::host_accessor acc_tf{ | ||
| shambase::get_check_ref(int_range_max_tree.internal_buf), sycl::read_only}; | ||
| auto acc_tf = int_range_max_tree.internal_buf->template mirror_to<sham::host>(); | ||
|
|
||
| for (i32 xoff = -repetition_x; xoff <= repetition_x; xoff++) { | ||
| for (i32 yoff = -repetition_y; yoff <= repetition_y; yoff++) { | ||
|
|
@@ -300,10 +299,8 @@ auto BasicSPHGhostHandler<vec>::find_interfaces( | |
| // sender translation | ||
| vec periodic_offset = vec{xoff * bsize.x(), yoff * bsize.y(), zoff * bsize.z()}; | ||
|
|
||
| sycl::host_accessor tree{ | ||
| shambase::get_check_ref(sptree.serial_tree_buf), sycl::read_only}; | ||
| sycl::host_accessor lpid{ | ||
| shambase::get_check_ref(sptree.linked_patch_ids_buf), sycl::read_only}; | ||
| auto tree = sptree.serial_tree_buf->template mirror_to<sham::host>(); | ||
| auto lpid = sptree.linked_patch_ids_buf->template mirror_to<sham::host>(); | ||
|
|
||
| #pragma omp parallel for | ||
| for (u32 i = 0; i < sched.patch_list.local.size(); i++) { | ||
|
|
@@ -359,8 +356,7 @@ auto BasicSPHGhostHandler<vec>::find_interfaces( | |
| } | ||
| } | ||
| } else if (BCShearingPeriodic *cfg = std::get_if<BCShearingPeriodic>(&ghost_config)) { | ||
| sycl::host_accessor acc_tf{ | ||
| shambase::get_check_ref(int_range_max_tree.internal_buf), sycl::read_only}; | ||
| auto acc_tf = int_range_max_tree.internal_buf->template mirror_to<sham::host>(); | ||
|
|
||
| for_each_patch_shift<flt>(*cfg, bsize, [&](i32_3 ioff, ShiftInfo<flt> shift) { | ||
| i32 xoff = ioff.x(); | ||
|
|
@@ -369,10 +365,8 @@ auto BasicSPHGhostHandler<vec>::find_interfaces( | |
|
|
||
| vec offset = shift.shift; | ||
|
|
||
| sycl::host_accessor tree{ | ||
| shambase::get_check_ref(sptree.serial_tree_buf), sycl::read_only}; | ||
| sycl::host_accessor lpid{ | ||
| shambase::get_check_ref(sptree.linked_patch_ids_buf), sycl::read_only}; | ||
| auto tree = sptree.serial_tree_buf->template mirror_to<sham::host>(); | ||
| auto lpid = sptree.linked_patch_ids_buf->template mirror_to<sham::host>(); | ||
|
Comment on lines
+368
to
+369
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| #pragma omp parallel for | ||
| for (u32 i = 0; i < sched.patch_list.local.size(); i++) { | ||
|
|
@@ -429,14 +423,12 @@ auto BasicSPHGhostHandler<vec>::find_interfaces( | |
| }); | ||
|
|
||
| } else { | ||
| sycl::host_accessor acc_tf{ | ||
| shambase::get_check_ref(int_range_max_tree.internal_buf), sycl::read_only}; | ||
| auto acc_tf = int_range_max_tree.internal_buf->template mirror_to<sham::host>(); | ||
| // sender translation | ||
| vec periodic_offset = vec{0, 0, 0}; | ||
|
|
||
| sycl::host_accessor tree{shambase::get_check_ref(sptree.serial_tree_buf), sycl::read_only}; | ||
| sycl::host_accessor lpid{ | ||
| shambase::get_check_ref(sptree.linked_patch_ids_buf), sycl::read_only}; | ||
| auto tree = sptree.serial_tree_buf->template mirror_to<sham::host>(); | ||
| auto lpid = sptree.linked_patch_ids_buf->template mirror_to<sham::host>(); | ||
|
|
||
| #pragma omp parallel for | ||
| for (u32 i = 0; i < sched.patch_list.local.size(); i++) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,12 +59,12 @@ namespace shamrock { | |
| * bound). | ||
| */ | ||
| template<class T> | ||
| shambase::DistributedData<sycl::buffer<u64>> compute_new_pid( | ||
| shambase::DistributedData<sham::DeviceBuffer<u64>> compute_new_pid( | ||
| SerialPatchTree<T> &sptree, u32 ipos) { | ||
|
|
||
| StackEntry stack_loc{}; | ||
|
|
||
| shambase::DistributedData<sycl::buffer<u64>> newid_buf_map; | ||
| shambase::DistributedData<sham::DeviceBuffer<u64>> newid_buf_map; | ||
|
|
||
| sched.patch_data.for_each_patchdata([&](u64 id, shamrock::patch::PatchDataLayer &pdat) { | ||
| if (!pdat.is_empty()) { | ||
|
|
@@ -84,7 +84,7 @@ namespace shamrock { | |
|
|
||
| bool err_id_in_newid = false; | ||
| { | ||
| sycl::host_accessor nid{newid_buf_map.get(id), sycl::read_only}; | ||
| std::vector<u64> nid = newid_buf_map.get(id).copy_to_stdvec(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| for (u32 i = 0; i < pdat.get_obj_cnt(); i++) { | ||
| bool err = nid[i] == u64_max; | ||
| err_id_in_newid = err_id_in_newid || (err); | ||
|
|
@@ -114,7 +114,7 @@ namespace shamrock { | |
| * @return A shared distributed data object containing the extracted patch data. | ||
| */ | ||
| inline shambase::DistributedDataShared<shamrock::patch::PatchDataLayer> extract_elements( | ||
| shambase::DistributedData<sycl::buffer<u64>> new_pid) { | ||
| shambase::DistributedData<sham::DeviceBuffer<u64>> &&new_pid) { | ||
| shambase::DistributedDataShared<patch::PatchDataLayer> part_exchange; | ||
|
|
||
| StackEntry stack_loc{}; | ||
|
|
@@ -128,7 +128,7 @@ namespace shamrock { | |
| histogram_extract[current_pid] = 0; | ||
| if (!pdat.is_empty()) { | ||
|
|
||
| sycl::host_accessor nid{new_pid.get(current_pid), sycl::read_only}; | ||
| std::vector<u64> nid = new_pid.get(current_pid).copy_to_stdvec(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| if (false) { | ||
|
|
||
|
|
@@ -222,9 +222,10 @@ namespace shamrock { | |
|
|
||
| u32 ipos = sched.pdl_old().get_field_idx<T>(position_field); | ||
|
|
||
| DistributedData<sycl::buffer<u64>> new_pid = compute_new_pid(sptree, ipos); | ||
| DistributedData<sham::DeviceBuffer<u64>> new_pid = compute_new_pid(sptree, ipos); | ||
|
|
||
| DistributedDataShared<patch::PatchDataLayer> part_exchange = extract_elements(new_pid); | ||
| DistributedDataShared<patch::PatchDataLayer> part_exchange | ||
| = extract_elements(std::move(new_pid)); | ||
|
|
||
| part_exchange.for_each([](u64 sender, u64 receiver, PatchDataLayer &pdat) { | ||
| shamlog_debug_ln("ReattributeDataUtility", sender, receiver, pdat.get_obj_cnt()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating and destroying
BufferMirrorobjects inside the triple loop over periodic offsets is highly inefficient. Each creation triggers a Device-to-Host copy, and each destruction triggers a Host-to-Device copy (write-back). These mirrors should be moved outside the loops (before line 296) to avoid redundant data transfers.