24 template<
class Umorton,
class Tgr
idVec>
25 void __internal_correct_tree_bb(
30 u32 leaf_count = tree.tree_reduced_morton_codes.tree_leaf_count;
31 u32 internal_cell_count = tree.tree_struct.internal_cell_count;
32 u32 tot_count = leaf_count + internal_cell_count;
34 sycl::buffer<TgridVec> tmp_min_cell(tot_count);
35 sycl::buffer<TgridVec> tmp_max_cell(tot_count);
46 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
49 u32 leaf_offset = tree.tree_struct.internal_cell_count;
51 sycl::accessor comp_min{tmp_min_cell, cgh, sycl::write_only, sycl::no_init};
52 sycl::accessor comp_max{tmp_max_cell, cgh, sycl::write_only, sycl::no_init};
54 TgridVec imin = shambase::VectorProperties<TgridVec>::get_max();
55 TgridVec imax = shambase::VectorProperties<TgridVec>::get_min();
57 shambase::parallel_for(cgh, leaf_count,
"compute leaf boxes", [=](
u64 leaf_id) {
61 cell_looper.iter_object_in_cell(leaf_id + leaf_offset, [&](
u32 block_id) {
62 TgridVec bmin = acc_bmin[block_id];
63 TgridVec bmax = acc_bmax[block_id];
65 min = sham::min(min, bmin);
66 max = sham::max(max, bmax);
69 comp_min[leaf_offset + leaf_id] = min;
70 comp_max[leaf_offset + leaf_id] = max;
77 auto ker_reduc_hmax = [&](sycl::handler &cgh) {
78 u32 offset_leaf = internal_cell_count;
80 sycl::accessor comp_min{tmp_min_cell, cgh, sycl::read_write};
81 sycl::accessor comp_max{tmp_max_cell, cgh, sycl::read_write};
83 sycl::accessor rchild_id{
85 sycl::accessor lchild_id{
87 sycl::accessor rchild_flag{
89 sycl::accessor lchild_flag{
92 shambase::parallel_for(cgh, internal_cell_count,
"propagate up", [=](
u64 gid) {
93 u32 lid = lchild_id[gid] + offset_leaf * lchild_flag[gid];
94 u32 rid = rchild_id[gid] + offset_leaf * rchild_flag[gid];
96 TgridVec bminl = comp_min[lid];
97 TgridVec bminr = comp_min[rid];
98 TgridVec bmaxl = comp_max[lid];
99 TgridVec bmaxr = comp_max[rid];
101 TgridVec bmin = sham::min(bminl, bminr);
102 TgridVec bmax = sham::max(bmaxl, bmaxr);
104 comp_min[gid] = bmin;
105 comp_max[gid] = bmax;
109 for (
u32 i = 0; i < tree.tree_depth; i++) {
113 sycl::buffer<TgridVec> &tree_bmin
115 sycl::buffer<TgridVec> &tree_bmax
121 u32 leaf_offset = tree.tree_struct.internal_cell_count;
123 sycl::accessor comp_bmin{tmp_min_cell, cgh, sycl::read_only};
124 sycl::accessor comp_bmax{tmp_max_cell, cgh, sycl::read_only};
126 sycl::accessor tree_buf_min{tree_bmin, cgh, sycl::read_write};
127 sycl::accessor tree_buf_max{tree_bmax, cgh, sycl::read_write};
129 shambase::parallel_for(cgh, tot_count,
"write in tree range", [=](
u64 nid) {
130 TgridVec load_min = comp_bmin[nid];
131 TgridVec load_max = comp_bmax[nid];
150 tree_buf_min[nid] = load_min;
151 tree_buf_max[nid] = load_max;
159 template<
class Umorton,
class Tgr
idVec>
161 auto edges = get_edges();
163 auto &block_min = edges.block_min;
164 auto &block_max = edges.block_max;
172 bounds = indexes_dd.template map<shammath::AABB<TgridVec>>([&](
u64 id,
auto &merged) {
173 TgridVec min_bound = block_min.get_field(
id).compute_min();
174 TgridVec max_bound = block_max.get_field(
id).compute_max();
182 = indexes_dd.template map<RTree>([&](
u64 id,
auto &merged) {
183 shamlog_debug_ln(
"AMR",
"compute tree for merged patch",
id);
185 auto aabb = bounds.
get(
id);
187 TgridVec bmin = aabb.lower;
188 TgridVec bmax = aabb.upper;
190 TgridVec diff = bmax - bmin;
196 auto &field_pos = block_min.get_field(
id);
199 shamsys::instance::get_compute_scheduler_ptr(),
202 field_pos.get_obj_cnt(),
212 trees.for_each([](
u64 id, RTree &tree) {
216 trees.for_each([&](
u64 id, RTree &tree) {
217 __internal_correct_tree_bb(
218 tree, block_min.get_field(
id).get_buf(), block_max.get_field(
id).get_buf());
221 edges.trees.trees = std::move(trees);
224 template<
class Umorton,
class Tgr
idVec>
232 std::string tex = R
"tex(
236 {trees}_{\rm patch} &= RadixTree(\{{block_min}_{\rm patch}\}_{\Omega_i}, \{{block_max}_{\rm patch}\}_{\Omega_i}) \\
237 {\Omega_i} &= [0, {sizes}_{\rm patch} )
sycl::queue & get_compute_queue(u32 id=0)
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 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.
A SYCL queue associated with a device and a context.
sycl::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
Class to manage a list of SYCL events.
Represents a collection of objects distributed across patches identified by a u64 id.
void for_each(std::function< void(u64, T &)> &&f)
Applies a function to each object in the collection.
T & get(u64 id)
Returns a reference to an object in the collection.
virtual std::string _impl_get_tex() const
get the tex of the node
void _impl_evaluate_internal()
evaluate the node
IEdge & get_rw_edge_base(int slot)
Get a reference to a read write edge and cast it to the type IEdge.
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
constexpr T roundup_pow2(T v) noexcept
round up to the next power of two Source : https://graphics.stanford.edu/~seander/bithacks....
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...
namespace for the basegodunov model modules
Axis-Aligned bounding box.