Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ErrorChecker.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
20#include "shambackends/sycl.hpp"
21
22namespace shamalgs::atomic {
23
67
70
72 ErrorCheckerFlags(sham::DeviceScheduler_ptr sched) : buf_err(1, sched) { buf_err.fill(0); }
73
75 struct accessed {
77
79 void set_flag_on(u32 flag_val) const {
80 sycl::atomic_ref<
81 u32,
82 sycl::memory_order_relaxed,
83 sycl::memory_scope_device,
84 sycl::access::address_space::global_space>
85 atom(*ptr);
86 atom |= flag_val;
87 }
88 };
89
92 return accessed{buf_err.get_write_access(depends_list)};
93 }
94
97
99 u32 get_output() { return buf_err.copy_to_stdvec().at(0); }
100 };
101
136
139
141 ErrorCheckCounter(sham::DeviceScheduler_ptr sched, u32 error_counter)
142 : buf_err(error_counter, sched) {
143 buf_err.fill(0_u32);
144 }
145
147 struct accessed {
149
151 void set_error(u32 id) const {
152 sycl::atomic_ref<
153 u32,
154 sycl::memory_order_relaxed,
155 sycl::memory_scope_device,
156 sycl::access::address_space::global_space>
157 atom(ptr[id]);
158 atom.fetch_add(1_u32);
159 }
160 };
161
164 return accessed{buf_err.get_write_access(depends_list)};
165 }
166
169
171 std::vector<u32> get_outputs() { return buf_err.copy_to_stdvec(); }
172 };
173
174} // namespace shamalgs::atomic
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.
void fill(T value, std::array< size_t, 2 > idx_range)
Fill a subpart of the buffer with a given value.
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
A struct to access the pointer associated to the buffer.
void set_error(u32 id) const
Increments the error count associated to the given id in the buffer.
This class is used to check for errors in kernels. It is composed of a buffer of u32 that is used to ...
accessed get_write_access(sham::EventList &depends_list)
Get a write access to the buffer.
ErrorCheckCounter(sham::DeviceScheduler_ptr sched, u32 error_counter)
Constructor.
std::vector< u32 > get_outputs()
Get the resulting error counts.
void complete_event_state(sycl::event e)
Complete the event state.
sham::DeviceBuffer< u32 > buf_err
The buffer used to store the error counts.
A struct to access the pointer associated to the buffer.
u32 * ptr
The pointer to the buffer.
void set_flag_on(u32 flag_val) const
Set a flag on the error flags buffer atomically.
A utility class to check for errors on device, using a single uint to store all the error flags.
u32 get_output()
Get the resulting error flag.
sham::DeviceBuffer< u32 > buf_err
The buffer used to store the error flag.
ErrorCheckerFlags(sham::DeviceScheduler_ptr sched)
Constructor.
accessed get_write_access(sham::EventList &depends_list)
Get a write access to the buffer.
void complete_event_state(sycl::event e)
Complete the event state.