35 class PatchDataLayer {
41 std::vector<var_t> fields;
42 std::shared_ptr<PatchDataLayerLayout> pdl_ptr;
44 inline var_t &get_field_variant(
u32 idx) {
45 if (idx >= fields.size()) {
47 "the requested field index is out of bounds\n"
48 " current map is : \n"
49 + pdl().get_description_str()
52 + std::to_string(idx));
57 inline const var_t &get_field_variant(
u32 idx)
const {
58 if (idx >= fields.size()) {
60 "the requested field index is out of bounds\n"
61 " current map is : \n"
62 + pdl().get_description_str()
65 + std::to_string(idx));
71 using field_variant_t = var_t;
76 inline std::shared_ptr<PatchDataLayerLayout> get_layout_ptr()
const {
return pdl_ptr; }
78 inline PatchDataLayer(
const std::shared_ptr<PatchDataLayerLayout> &pdl) : pdl_ptr(pdl) {
90 PatchDataLayer(
const PatchDataLayer &other);
98 : fields(std::move(other.fields)), pdl_ptr(std::move(other.pdl_ptr)) {}
105 inline PatchDataLayer &
operator=(PatchDataLayer &&other)
noexcept {
106 fields = std::move(other.fields);
107 pdl_ptr = std::move(other.pdl_ptr);
114 u64 seed,
u32 obj_cnt,
const std::shared_ptr<PatchDataLayerLayout> &pdl);
116 template<
class Functor>
117 inline void for_each_field_any(Functor &&func) {
118 for (
auto &f : fields) {
119 f.visit([&](
auto &arg) {
125 template<
class Functor>
126 inline void for_each_field_any(Functor &&func)
const {
127 for (
auto &f : fields) {
128 f.visit([&](
const auto &arg) {
135 inline PatchDataLayer(
const std::shared_ptr<PatchDataLayerLayout> &pdl, Func &&fct_init)
143 inline PatchDataLayer duplicate() {
144 const PatchDataLayer ¤t = *
this;
145 return PatchDataLayer(current);
148 inline std::unique_ptr<PatchDataLayer> duplicate_to_ptr() {
149 const PatchDataLayer ¤t = *
this;
150 return std::make_unique<PatchDataLayer>(current);
161 void extract_elements(
const sham::DeviceBuffer<u32> &idxs, PatchDataLayer &out_pdat);
163 void keep_ids(sycl::buffer<u32> &index_map,
u32 len);
165 void insert_elements(
const PatchDataLayer &pdat);
178 void resize(
u32 new_obj_cnt);
180 void reserve(
u32 new_obj_cnt);
182 void expand(
u32 obj_cnt);
208 void keep_ids(sham::DeviceBuffer<u32> &index_map,
u32 len);
211 void remove_ids(
const sham::DeviceBuffer<u32> &indexes,
u32 len);
222 template<
class Tvecbox>
223 void split_patchdata(
224 std::array<std::reference_wrapper<PatchDataLayer>, 8> pdats,
225 std::array<Tvecbox, 8> min_box,
226 std::array<Tvecbox, 8> max_box);
228 void append_subset_to(
const std::vector<u32> &idxs, PatchDataLayer &pdat);
229 void append_subset_to(sycl::buffer<u32> &idxs_buf,
u32 sz, PatchDataLayer &pdat);
230 void append_subset_to(
231 const sham::DeviceBuffer<u32> &idxs_buf,
u32 sz, PatchDataLayer &pdat)
const;
247 inline bool is_empty() {
return get_obj_cnt() == 0; }
252 void overwrite(PatchDataLayer &pdat,
u32 obj_cnt);
255 bool check_field_type(
u32 idx) {
256 var_t &tmp = get_field_variant(idx);
258 PatchDataField<T> *pval = std::get_if<PatchDataField<T>>(&tmp.value);
268 PatchDataField<T> &get_field(
u32 idx) {
270 var_t &tmp = get_field_variant(idx);
272 PatchDataField<T> *pval = std::get_if<PatchDataField<T>>(&tmp.value);
279 "the request id is not of correct type\n"
280 " current map is : \n"
281 + pdl().get_description_str()
284 + std::to_string(idx));
288 const PatchDataField<T> &get_field(
u32 idx)
const {
290 const var_t &tmp = get_field_variant(idx);
292 const PatchDataField<T> *pval = std::get_if<PatchDataField<T>>(&tmp.value);
299 "the request id is not of correct type\n"
300 " current map is : \n"
301 + pdl().get_description_str()
304 + std::to_string(idx));
308 PatchDataField<T> &get_field(
const std::string &field_name) {
309 return get_field<T>(pdl().get_field_idx<T>(field_name));
313 const PatchDataField<T> &get_field(
const std::string &field_name)
const {
314 return get_field<T>(pdl().get_field_idx<T>(field_name));
318 sham::DeviceBuffer<T> &get_field_buf_ref(
u32 idx) {
320 var_t &tmp = get_field_variant(idx);
322 PatchDataField<T> *pval = std::get_if<PatchDataField<T>>(&tmp.value);
325 return pval->get_buf();
329 "the request id is not of correct type\n"
330 " current map is : \n"
331 + pdl().get_description_str()
334 + std::to_string(idx));
343 template<
class T, u32 nvar>
345 return get_field<T>(idx).template get_span<nvar>();
357 return get_field<T>(idx).get_span_nvar_dynamic();
362 get_field_pointer_span(
u32 idx) {
363 return get_field<T>(idx).get_pointer_span();
378 template<
class T,
class Functor>
379 inline void for_each_field(Functor &&func) {
380 for (
auto &f : fields) {
390 friend bool operator==(PatchDataLayer &p1, PatchDataLayer &p2);
392 void serialize_buf(shamalgs::SerializeHelper &serializer);
394 shamalgs::SerializeSize serialize_buf_byte_size();
396 static PatchDataLayer deserialize_buf(
397 shamalgs::SerializeHelper &serializer,
398 const std::shared_ptr<PatchDataLayerLayout> &pdl);
433 u32 len = vec.size();
435 sycl::buffer<T> buf(vec.data(), len);
436 f.override(buf, len);
454 auto appender = [&](
auto &field) {
455 if (field.get_name() == key) {
457 shamlog_debug_ln(
"PyShamrockCTX",
"appending field", key);
459 if (!field.is_empty()) {
460 auto acc = field.get_buf().copy_to_stdvec();
461 u32 len = field.get_val_cnt();
463 for (
u32 i = 0; i < len; i++) {
464 vec.push_back(acc[i]);
470 for_each_field<T>([&](
auto &field) {