Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
WriteBack.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
18
19template<class Tvec, class TgridVec>
21
22 StackEntry stack_loc{};
23
24 using namespace shamrock::patch;
25 using namespace shamrock;
26
27 using Block = typename Config::AMRBlock;
28
29 PatchDataLayerLayout &ghost_layout = shambase::get_check_ref(storage.ghost_layout.get());
30 u32 irho_interf = ghost_layout.get_field_idx<Tscal>("rho");
31 u32 ieint_interf = ghost_layout.get_field_idx<Tscal>("eint");
32 u32 ivel_interf = ghost_layout.get_field_idx<Tvec>("vel");
33
34 scheduler().for_each_patchdata_nonempty([&](Patch p, PatchDataLayer &pdat) {
35 using MergedPDat = shamrock::MergedPatchData;
36 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
37
38 sham::DeviceBuffer<Tscal> &rho_merged = mpdat.pdat.get_field_buf_ref<Tscal>(irho_interf);
39 sham::DeviceBuffer<Tscal> &eint_merged = mpdat.pdat.get_field_buf_ref<Tscal>(ieint_interf);
40 sham::DeviceBuffer<Tvec> &vel_merged = mpdat.pdat.get_field_buf_ref<Tvec>(ivel_interf);
41
42 PatchDataLayer &patch_dest = scheduler().patch_data.get_pdat(p.id_patch);
43 sham::DeviceBuffer<Tscal> &rho_dest = patch_dest.get_field_buf_ref<Tscal>(irho_interf);
44 sham::DeviceBuffer<Tscal> &eint_dest = patch_dest.get_field_buf_ref<Tscal>(ieint_interf);
45 sham::DeviceBuffer<Tvec> &vel_dest = patch_dest.get_field_buf_ref<Tvec>(ivel_interf);
46
47 sham::DeviceQueue &q = shamsys::instance::get_compute_scheduler().get_queue();
48
49 sham::EventList depends_list;
50 auto acc_rho_src = rho_merged.get_read_access(depends_list);
51 auto acc_eint_src = eint_merged.get_read_access(depends_list);
52 auto acc_vel_src = vel_merged.get_read_access(depends_list);
53
54 auto acc_rho_dest = rho_dest.get_write_access(depends_list);
55 auto acc_eint_dest = eint_dest.get_write_access(depends_list);
56 auto acc_vel_dest = vel_dest.get_write_access(depends_list);
57
58 auto e = q.submit(depends_list, [&](sycl::handler &cgh) {
59 shambase::parallel_for(
60 cgh, mpdat.original_elements * Block::block_size, "copy_back", [=](u32 id) {
61 acc_rho_dest[id] = acc_rho_src[id];
62 acc_eint_dest[id] = acc_eint_src[id];
63 acc_vel_dest[id] = acc_vel_src[id];
64 });
65 });
66
67 rho_merged.complete_event_state(e);
68 eint_merged.complete_event_state(e);
69 vel_merged.complete_event_state(e);
70
71 rho_dest.complete_event_state(e);
72 eint_dest.complete_event_state(e);
73 vel_dest.complete_event_state(e);
74
75 if (mpdat.pdat.has_nan()) {
76 logger::err_ln("[Zeus]", "nan detected in write back");
78 }
79 });
80}
81
std::uint32_t u32
32 bit unsigned 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.
DeviceQueue & get_queue(u32 id=0)
Get a reference to a DeviceQueue.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
u32 get_field_idx(const std::string &field_name) const
Get the field id if matching name & type.
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...
Definition memory.hpp:110
namespace for the main framework
Definition __init__.py:1
Patch object that contain generic patch information.
Definition Patch.hpp:33