Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
BufferMirror.hpp
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
10#pragma once
11
22#include "shamcomm/logs.hpp"
23
24namespace sham {
25
50 template<class T, USMKindTarget target, USMKindTarget orgin_target>
52
53 DeviceBuffer<T, orgin_target> &mirrored_buffer;
54
56 T *ptr_mirror;
57
58 public:
68 : mirrored_buffer(mirrored_buffer), mirror(mirrored_buffer.template copy_to<target>()) {
69 sham::EventList depends_list;
70 ptr_mirror = mirror.get_write_access(depends_list);
71 depends_list.wait();
72 mirror.complete_event_state(sycl::event{});
73 }
74
75 BufferMirror(const BufferMirror &) = delete; //< Please don't
76 BufferMirror(BufferMirror &&) = delete; //< Please don't
77 BufferMirror &operator=(const BufferMirror &) = delete; //< Please don't
78 BufferMirror &operator=(BufferMirror &&) = delete; //< Please don't
79
85 T *data() const { return ptr_mirror; }
86
92 u32 size() const { return mirrored_buffer.size(); }
93
100 T &operator[](u32 i) const { return ptr_mirror[i]; }
101
107 ~BufferMirror() { mirrored_buffer.copy_from(mirror); }
108 };
109
110} // namespace sham
Source location utility.
std::uint32_t u32
32 bit unsigned integer
A class template for creating a mirrored buffer.
BufferMirror(DeviceBuffer< T, orgin_target > &mirrored_buffer)
Constructs a BufferMirror.
T * data() const
Provides access to the mirrored data.
T & operator[](u32 i) const
Accesses the mirrored data at a given index.
~BufferMirror()
Destructor.
u32 size() const
Returns the size of the mirrored buffer.
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.
void copy_from(const DeviceBuffer< T, new_target > &other, size_t copy_size)
Copies the content of another buffer to this one.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
void wait()
Wait for all events in the list to be finished.
Definition EventList.hpp:57
namespace for backends this one is named only sham since shambackends is too long to write