Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
TreeMortonCodes.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
17
24#include <stdexcept>
25
26namespace shamrock::tree {
27
28 template<class u_morton>
29 class TreeMortonCodes {
30 public:
31 u32 obj_cnt;
32
33 std::unique_ptr<sycl::buffer<u_morton>> buf_morton;
34 std::unique_ptr<sycl::buffer<u32>> buf_particle_index_map;
35
36 template<class T>
37 void build(
38 sycl::queue &queue,
39 shammath::CoordRange<T> coord_range,
40 u32 obj_cnt,
41 sycl::buffer<T> &pos_buf);
42
43 template<class T>
44 void build(
45 sham::DeviceScheduler_ptr dev_sched,
46 shammath::CoordRange<T> coord_range,
47 u32 obj_cnt,
48 sham::DeviceBuffer<T> &pos_buf);
49
50 [[nodiscard]] inline u64 memsize() const {
51 u64 sum = 0;
52
53 auto add_ptr = [&](auto &a) {
54 if (a) {
55 sum += a->byte_size();
56 }
57 };
58
59 sum += sizeof(obj_cnt);
60
61 add_ptr(buf_morton);
62 add_ptr(buf_particle_index_map);
63
64 return sum;
65 }
66
67 inline TreeMortonCodes() = default;
68
69 inline TreeMortonCodes(const TreeMortonCodes &other)
70 : obj_cnt(other.obj_cnt),
71 buf_morton(
72 shamalgs::memory::duplicate(
73 shamsys::instance::get_compute_queue(), other.buf_morton)),
74 buf_particle_index_map(
75 shamalgs::memory::duplicate(
76 shamsys::instance::get_compute_queue(), other.buf_particle_index_map)) {}
77
78 inline TreeMortonCodes &operator=(TreeMortonCodes &&other) noexcept {
79 obj_cnt = std::move(other.obj_cnt);
80 buf_morton = std::move(other.buf_morton);
81 buf_particle_index_map = std::move(other.buf_particle_index_map);
82
83 return *this;
84 } // move assignment
85
86 bool operator==(const TreeMortonCodes &rhs) const;
87
93 inline void serialize(shamalgs::SerializeHelper &serializer) {
94 StackEntry stack_loc{};
95
96 serializer.write(obj_cnt);
97 if (!buf_morton) {
99 }
100 // serializer.write(buf_morton->size());
101 serializer.write_buf(*buf_morton, obj_cnt);
102 if (!buf_particle_index_map) {
104 }
105 serializer.write_buf(*buf_particle_index_map, obj_cnt);
106 }
107
118 inline static TreeMortonCodes deserialize(shamalgs::SerializeHelper &serializer) {
119 StackEntry stack_loc{};
120 TreeMortonCodes ret;
121 serializer.load(ret.obj_cnt);
122
123 // u32 morton_len;
124 // serializer.load(morton_len);
125 ret.buf_morton = std::make_unique<sycl::buffer<u_morton>>(ret.obj_cnt);
126 ret.buf_particle_index_map = std::make_unique<sycl::buffer<u32>>(ret.obj_cnt);
127
128 serializer.load_buf(*ret.buf_morton, ret.obj_cnt);
129 serializer.load_buf(*ret.buf_particle_index_map, ret.obj_cnt);
130
131 return ret;
132 }
133
141 return H::serialize_byte_size<u32>() + H::serialize_byte_size<u32>(obj_cnt)
142 + H::serialize_byte_size<u_morton>(obj_cnt);
143 }
144 };
145
146} // namespace shamrock::tree
Header file describing a Node Instance.
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).
static TreeMortonCodes deserialize(shamalgs::SerializeHelper &serializer)
deserialize a TreeMortonCodes object Note : here since the initial buffer is a pow of 2 with traillin...
shamalgs::SerializeSize serialize_byte_size()
give the size of the serialized object
void serialize(shamalgs::SerializeHelper &serializer)
serialize a TreeMortonCodes object
This header file contains utility functions related to exception handling in the code.
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
This file contains the definition for the stacktrace related functionality.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.