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
24#include <stdexcept>
25
26namespace shamrock::tree {
27
28 template<class u_morton>
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 template<class T>
51 static std::unique_ptr<sycl::buffer<u_morton>> build_raw(
52 sycl::queue &queue,
53 shammath::CoordRange<T> coord_range,
54 u32 obj_cnt,
55 sycl::buffer<T> &pos_buf);
56
57 [[nodiscard]] inline u64 memsize() const {
58 u64 sum = 0;
59
60 auto add_ptr = [&](auto &a) {
61 if (a) {
62 sum += a->byte_size();
63 }
64 };
65
66 sum += sizeof(obj_cnt);
67
68 add_ptr(buf_morton);
69 add_ptr(buf_particle_index_map);
70
71 return sum;
72 }
73
74 inline TreeMortonCodes() = default;
75
76 inline TreeMortonCodes(const TreeMortonCodes &other)
77 : obj_cnt(other.obj_cnt),
78 buf_morton(
79 shamalgs::memory::duplicate(
80 shamsys::instance::get_compute_queue(), other.buf_morton)),
81 buf_particle_index_map(
82 shamalgs::memory::duplicate(
83 shamsys::instance::get_compute_queue(), other.buf_particle_index_map)) {}
84
85 inline TreeMortonCodes &operator=(TreeMortonCodes &&other) noexcept {
86 obj_cnt = std::move(other.obj_cnt);
87 buf_morton = std::move(other.buf_morton);
88 buf_particle_index_map = std::move(other.buf_particle_index_map);
89
90 return *this;
91 } // move assignment
92
93 bool operator==(const TreeMortonCodes &rhs) const;
94
100 inline void serialize(shamalgs::SerializeHelper &serializer) {
101 StackEntry stack_loc{};
102
103 serializer.write(obj_cnt);
104 if (!buf_morton) {
106 }
107 // serializer.write(buf_morton->size());
108 serializer.write_buf(*buf_morton, obj_cnt);
109 if (!buf_particle_index_map) {
111 }
112 serializer.write_buf(*buf_particle_index_map, obj_cnt);
113 }
114
126 StackEntry stack_loc{};
127 TreeMortonCodes ret;
128 serializer.load(ret.obj_cnt);
129
130 // u32 morton_len;
131 // serializer.load(morton_len);
132 ret.buf_morton = std::make_unique<sycl::buffer<u_morton>>(ret.obj_cnt);
133 ret.buf_particle_index_map = std::make_unique<sycl::buffer<u32>>(ret.obj_cnt);
134
135 serializer.load_buf(*ret.buf_morton, ret.obj_cnt);
136 serializer.load_buf(*ret.buf_particle_index_map, ret.obj_cnt);
137
138 return ret;
139 }
140
148 return H::serialize_byte_size<u32>() + H::serialize_byte_size<u32>(obj_cnt)
149 + H::serialize_byte_size<u_morton>(obj_cnt);
150 }
151 };
152
153} // namespace shamrock::tree
Header file describing a Node Instance.
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.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
This file contains the definition for the stacktrace related functionality.