Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
DeviceCounter.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
19#include "shambase/integer.hpp"
20#include "shamalgs/memory.hpp"
21#include "shambackends/sycl.hpp"
22
23namespace shamalgs::atomic {
24
30 template<class int_t>
31 class DeviceCounter;
32
33 template<class int_t>
35 public:
36 sycl::accessor<int_t, 1, sycl::access::mode::read_write, sycl::access::target::device>
37 counter;
38
39 inline AccessedDeviceCounter(sycl::handler &cgh, DeviceCounter<int_t> &gen)
40 : counter{gen.counter, cgh, sycl::read_write} {}
41
42 template<sycl::memory_order order>
43 inline sycl::atomic_ref<
44 int_t,
45 order,
46 sycl::memory_scope_device,
47 sycl::access::address_space::global_space>
48 attach_atomic() const {
49 return sycl::atomic_ref<
50 int_t,
51 order,
52 sycl::memory_scope_device,
53 sycl::access::address_space::global_space>(counter[0]);
54 }
55 };
56
57 template<class int_t>
59 public:
60 sycl::buffer<int_t> counter;
61
62 inline explicit DeviceCounter(sycl::queue &q) : counter(1) {
63 memory::buf_fill_discard(q, counter, int_t(0));
64 }
65
66 inline AccessedDeviceCounter<int_t> get_access(sycl::handler &cgh) { return {cgh, *this}; }
67 };
68
69} // namespace shamalgs::atomic
Utility to count group id on device.
void buf_fill_discard(sycl::queue &q, sycl::buffer< T > &buf, T value)
Fill a buffer with a given value (sycl::no_init mode)
Definition memory.hpp:159
main include file for memory algorithms