Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SinkParticlesEvictAccretedParticles.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
23#include <shambackends/sycl.hpp>
24
26
27 template<class Tvec>
29
31
32 auto edges = get_edges();
33
34 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
35 auto &q = shambase::get_check_ref(dev_sched).get_queue();
36
37 sham::DeviceBuffer<u32> keep_flag(0, dev_sched);
38 sham::DeviceBuffer<int> accr_flag(1, dev_sched);
39
40 edges.part_counts.indexes.for_each([&](u64 id_patch, u32 Nobj) {
41 auto &pdat = edges.pdats.get(id_patch);
42 auto &acc_table = edges.sink_accretion_table.get_spans().get(id_patch);
43
44 keep_flag.resize(Nobj);
45 accr_flag.fill(0);
46
48 q,
49 sham::MultiRef{acc_table},
50 sham::MultiRef{keep_flag, accr_flag},
51 Nobj,
52 [](u32 id_a,
53 const u32 *__restrict acc_table,
54 u32 *__restrict keep_flag,
55 int *__restrict accr_flag) {
56 bool keep = acc_table[id_a] == u32_max;
57 keep_flag[id_a] = keep ? 1 : 0;
58
59 sycl::atomic_ref<
60 int,
61 sycl::memory_order_relaxed,
62 sycl::memory_scope_device,
63 sycl::access::address_space::global_space>
64 atomic_accr(accr_flag[0]);
65
66 if (!keep) {
67 atomic_accr.fetch_or(1);
68 }
69 });
70
71 int accr_flag_val = accr_flag.get_val_at_idx(0);
72
73 if (accr_flag_val != 0) {
74
75 sham::DeviceBuffer<u32> id_list_keep
76 = shamalgs::stream_compact(dev_sched, keep_flag, Nobj);
77
78 pdat.keep_ids(
79 id_list_keep, shambase::narrow_or_throw<u32>(id_list_keep.get_size()));
80 }
81 });
82 }
83
84 template<class Tvec>
86 return "TODO";
87 }
88
89} // namespace shammodels::sph::modules
90
Header file describing a Node Instance.
Remove SPH particles flagged for sink accretion from patch data.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
void resize(size_t new_size, bool keep_data=true)
Resizes the buffer to a given size.
void fill(T value, std::array< size_t, 2 > idx_range)
Fill a subpart of the buffer with a given value.
T get_val_at_idx(size_t idx) const
Get the value at a given index in the buffer.
size_t get_size() const
Gets the number of elements in the buffer.
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.
std::tuple< std::optional< sycl::buffer< u32 > >, u32 > stream_compact(sycl::queue &q, sycl::buffer< u32 > &buf_flags, u32 len)
Stream compaction algorithm.
Definition numeric.cpp:84
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
namespace for the sph model modules
Utilities for safe type narrowing conversions.
constexpr u32 u32_max
u32 max value
#define __shamrock_stack_entry()
Macro to create a stack entry.
A class that references multiple buffers or similar objects.
Definition MultiRef.hpp:33