Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
NeighGraph.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 "shambase/memory.hpp"
25#include "shambackends/sycl.hpp"
27
29
30 struct NeighGraphLinkiterator;
31
32 struct NeighGraph {
33 sham::DeviceBuffer<u32> node_link_offset;
34 sham::DeviceBuffer<u32> node_links;
35 u32 link_count;
36 u32 obj_cnt;
37
38 std::optional<sham::DeviceBuffer<u32>> antecedent = std::nullopt;
39
40 void compute_antecedent(sham::DeviceScheduler_ptr &dev_sched) {
41 sham::DeviceBuffer<u32> ret(link_count, dev_sched);
42
43 auto &q = dev_sched->get_queue(0);
44 sham::EventList deps;
45
47 q,
48 sham::MultiRef{node_link_offset},
49 sham::MultiRef{ret},
50 obj_cnt,
51 [](u32 gid, const u32 *__restrict offset, u32 *__restrict ante) {
52 u32 min_ids = offset[gid];
53 u32 max_ids = offset[gid + 1];
54 for (u32 id_s = min_ids; id_s < max_ids; id_s++) {
55 ante[id_s] = gid;
56 }
57 });
58
59 antecedent = std::move(ret);
60 }
61
62 struct ro_access {
63
64 const u32 *node_link_offset;
65 const u32 *node_links;
66
67 template<class Functor_iter>
68 inline void for_each_object_link(const u32 &cell_id, Functor_iter &&func_it) const {
69 u32 min_ids = node_link_offset[cell_id];
70 u32 max_ids = node_link_offset[cell_id + 1];
71 for (u32 id_s = min_ids; id_s < max_ids; id_s++) {
72 func_it(node_links[id_s]);
73 }
74 }
75
76 template<class Functor_iter>
77 inline void for_each_object_link_id(const u32 &cell_id, Functor_iter &&func_it) const {
78 u32 min_ids = node_link_offset[cell_id];
79 u32 max_ids = node_link_offset[cell_id + 1];
80 for (u32 id_s = min_ids; id_s < max_ids; id_s++) {
81 func_it(node_links[id_s], id_s);
82 }
83 }
84
85 template<class Functor_iter>
86 inline u32 for_each_object_link_cnt(const u32 &cell_id, Functor_iter &&func_it) const {
87 u32 min_ids = node_link_offset[cell_id];
88 u32 max_ids = node_link_offset[cell_id + 1];
89 for (u32 id_s = min_ids; id_s < max_ids; id_s++) {
90 func_it(node_links[id_s]);
91 }
92 return max_ids - min_ids;
93 }
94 };
95
96 ro_access get_read_access(sham::EventList &e) const {
97 return ro_access{node_link_offset.get_read_access(e), node_links.get_read_access(e)};
98 }
99
100 void complete_event_state(sycl::event &e) const {
101 node_link_offset.complete_event_state(e);
102 node_links.complete_event_state(e);
103 }
104
109 node_link_offset.complete_event_state(e);
110 node_links.complete_event_state(e);
111 }
112 };
113
114 using AMRGraph = NeighGraph;
115
116 enum Direction {
117 xp = 0,
118 xm = 1,
119 yp = 2,
120 ym = 3,
121 zp = 4,
122 zm = 5,
123 };
124
125 template<class Tvec, class TgridVec>
127
128 const std::array<TgridVec, 6> offset_check{
129 TgridVec{1, 0, 0},
130 TgridVec{-1, 0, 0},
131 TgridVec{0, 1, 0},
132 TgridVec{0, -1, 0},
133 TgridVec{0, 0, 1},
134 TgridVec{0, 0, -1},
135 };
136
137 std::array<std::unique_ptr<AMRGraph>, 6> graph_links;
138 };
139} // namespace shammodels::basegodunov::modules
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.
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
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.
namespace for the basegodunov model modules
A class that references multiple buffers or similar objects.
void complete_event_state(sham::EventList &e) const
Complete event state based on sham::EventList.