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
16
18
19template<class Tvec, class TgridVec>
20void shammodels::zeus::modules::WriteBack<Tvec, TgridVec>::write_back_merged_data() {
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
50 q,
51 sham::MultiRef{rho_merged, eint_merged, vel_merged},
52 sham::MultiRef{rho_dest, eint_dest, vel_dest},
53 mpdat.original_elements * Block::block_size,
54 [](u32 id,
55 const Tscal *__restrict acc_rho_src,
56 const Tscal *__restrict acc_eint_src,
57 const Tvec *__restrict acc_vel_src,
58 Tscal *__restrict acc_rho_dest,
59 Tscal *__restrict acc_eint_dest,
60 Tvec *__restrict acc_vel_dest) {
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 if (mpdat.pdat.has_nan()) {
67 logger::err_ln("[Zeus]", "nan detected in write back");
69 }
70 });
71}
72
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
A SYCL queue associated with a device and a context.
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 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.
namespace for the main framework
Definition __init__.py:1
void err_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:132
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