|
12 | 12 | // comment to keep clang-format from reordering |
13 | 13 | #include "openPMD/DatatypeMacros.hpp" |
14 | 14 |
|
| 15 | +#include <future> |
15 | 16 | #include <memory> |
16 | 17 | #include <optional> |
17 | 18 | #include <stdexcept> |
@@ -147,32 +148,65 @@ auto ConfigureLoadStore<ChildClass>::enqueueStore() -> DynamicMemoryView<T> |
147 | 148 |
|
148 | 149 | template <typename ChildClass> |
149 | 150 | template <typename T> |
150 | | -auto ConfigureLoadStore<ChildClass>::enqueueLoad() -> std::shared_ptr<T> |
| 151 | +auto ConfigureLoadStore<ChildClass>::enqueueLoad() |
| 152 | + -> std::future<std::shared_ptr<T>> |
151 | 153 | { |
152 | | - return m_rc.loadChunkAllocate_impl<T>(storeChunkConfig()); |
| 154 | + auto res = m_rc.loadChunkAllocate_impl<T>(storeChunkConfig()); |
| 155 | + return std::async( |
| 156 | + std::launch::deferred, |
| 157 | + [res_lambda = std::move(res), rc = m_rc]() mutable { |
| 158 | + rc.seriesFlush(); |
| 159 | + return res_lambda; |
| 160 | + }); |
153 | 161 | } |
154 | 162 |
|
155 | | -namespace |
| 163 | +template <typename ChildClass> |
| 164 | +template <typename T> |
| 165 | +auto ConfigureLoadStore<ChildClass>::load(EnqueuePolicy ep) |
| 166 | + -> std::shared_ptr<T> |
156 | 167 | { |
157 | | - template <typename ConfigureLoadStore_t> |
158 | | - struct VisitorEnqueueLoadVariant |
| 168 | + auto res = m_rc.loadChunkAllocate_impl<T>(storeChunkConfig()); |
| 169 | + switch (ep) |
159 | 170 | { |
160 | | - template <typename T> |
161 | | - static auto call(RecordComponent const &, ConfigureLoadStore_t &cfg) -> |
162 | | - typename ConfigureLoadStore_t::shared_ptr_dataset_types |
163 | | - { |
164 | | - return cfg.template enqueueLoad<T>(); |
165 | | - } |
166 | | - }; |
167 | | -} // namespace |
| 171 | + case EnqueuePolicy::Defer: |
| 172 | + break; |
| 173 | + case EnqueuePolicy::Immediate: |
| 174 | + m_rc.seriesFlush(); |
| 175 | + break; |
| 176 | + } |
| 177 | + return res; |
| 178 | +} |
| 179 | + |
| 180 | +struct VisitorEnqueueLoadVariant |
| 181 | +{ |
| 182 | + template <typename T> |
| 183 | + static auto call(RecordComponent &rc, internal::LoadStoreConfig cfg) |
| 184 | + -> std::future<auxiliary::detail::future_to_shared_ptr_dataset_types> |
| 185 | + { |
| 186 | + auto res = rc.loadChunkAllocate_impl<T>(std::move(cfg)); |
| 187 | + return std::async( |
| 188 | + std::launch::deferred, |
| 189 | + [res_lambda = std::move(res), rc_lambda = rc]() mutable |
| 190 | + -> auxiliary::detail::future_to_shared_ptr_dataset_types { |
| 191 | + rc_lambda.seriesFlush(); |
| 192 | + return res_lambda; |
| 193 | + }); |
| 194 | + } |
| 195 | + |
| 196 | + static auto non_templated_implementation( |
| 197 | + RecordComponent &rc, internal::LoadStoreConfig cfg) |
| 198 | + -> std::future<auxiliary::detail::future_to_shared_ptr_dataset_types> |
| 199 | + { |
| 200 | + return rc.visit<VisitorEnqueueLoadVariant>(std::move(cfg)); |
| 201 | + } |
| 202 | +}; |
168 | 203 |
|
169 | 204 | template <typename ChildClass> |
170 | 205 | auto ConfigureLoadStore<ChildClass>::enqueueLoadVariant() |
171 | | - -> shared_ptr_dataset_types |
| 206 | + -> std::future<auxiliary::detail::future_to_shared_ptr_dataset_types> |
172 | 207 | { |
173 | | - return m_rc |
174 | | - .visit<VisitorEnqueueLoadVariant<ConfigureLoadStore<ChildClass>>>( |
175 | | - *this); |
| 208 | + return VisitorEnqueueLoadVariant::non_templated_implementation( |
| 209 | + m_rc, this->storeChunkConfig()); |
176 | 210 | } |
177 | 211 |
|
178 | 212 | template <typename Ptr_Type, typename ChildClass> |
@@ -245,9 +279,31 @@ auto ConfigureLoadStoreFromBuffer<Ptr_Type>::enqueueLoad() -> void |
245 | 279 | std::move(this->m_buffer), this->storeChunkConfig()); |
246 | 280 | } |
247 | 281 |
|
| 282 | +template <typename Ptr_Type> |
| 283 | +auto ConfigureLoadStoreFromBuffer<Ptr_Type>::load(EnqueuePolicy ep) -> void |
| 284 | +{ |
| 285 | + this->m_rc.loadChunk_impl( |
| 286 | + std::move(this->m_buffer), this->storeChunkConfig()); |
| 287 | + switch (ep) |
| 288 | + { |
| 289 | + |
| 290 | + case EnqueuePolicy::Defer: |
| 291 | + break; |
| 292 | + case EnqueuePolicy::Immediate: |
| 293 | + this->m_rc.seriesFlush(); |
| 294 | + break; |
| 295 | + } |
| 296 | +} |
| 297 | + |
| 298 | +/* clang-format would destroy the NOLINT comments */ |
| 299 | +// clang-format off |
248 | 300 | #define INSTANTIATE_METHOD_TEMPLATES(base_class, dtype) \ |
249 | | - template auto base_class::enqueueStore() -> DynamicMemoryView<dtype>; \ |
250 | | - template auto base_class::enqueueLoad() -> std::shared_ptr<dtype>; |
| 301 | + template auto base_class::enqueueStore()->DynamicMemoryView<dtype>; \ |
| 302 | + template auto base_class::enqueueLoad() \ |
| 303 | + /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ |
| 304 | + ->std::future<std::shared_ptr<dtype>>; \ |
| 305 | + template auto base_class::load(EnqueuePolicy)->std::shared_ptr<dtype>; |
| 306 | +// clang-format on |
251 | 307 |
|
252 | 308 | #define INSTANTIATE_METHOD_TEMPLATES_FOR_BASE(dtype) \ |
253 | 309 | INSTANTIATE_METHOD_TEMPLATES(ConfigureLoadStore<void>, dtype) |
|
0 commit comments