Introduce more flexible storeChunk() syntax, use to add ADIOS2 memory selection#1620
Open
franzpoeschel wants to merge 47 commits intoopenPMD:devfrom
Open
Introduce more flexible storeChunk() syntax, use to add ADIOS2 memory selection#1620franzpoeschel wants to merge 47 commits intoopenPMD:devfrom
franzpoeschel wants to merge 47 commits intoopenPMD:devfrom
Conversation
727cbbc to
ddcdfc9
Compare
c05d535 to
ba7c582
Compare
ba7c582 to
d7eb891
Compare
332932f to
efb0876
Compare
efb0876 to
39e3d71
Compare
47d497b to
b2bc355
Compare
b699520 to
3430b6d
Compare
9b5acff to
bd7b378
Compare
208c381 to
e51e635
Compare
c8be94b to
8e455b4
Compare
8e455b4 to
430fe3b
Compare
430fe3b to
e98c840
Compare
190674f to
e04f76d
Compare
b99bb95 to
d05e029
Compare
bit of code duplication, but better than CRT complexity
for more information, see https://pre-commit.ci
for when no computation is needed
for more information, see https://pre-commit.ci
7182268 to
3ba15d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We currently don't support memory selections yet, e.g. when you have a 2D memory buffer but want to write only an arbitrary block from it. That block is then non-contiguous, but ADIOS2 has so-called memory selections to support this.
We currently don't have an API that would be able to expose this (except in Python where the native Python buffer protocol is powerful enough to express this; we currently throw an error when detecting this
strides in selection are inefficient, not implemented!). Since theloadChunk()/storeChunk()API is somewhat convoluted by now anyway, I didn't want to add even further overloads.New API Design
The new API is centered around
RecordComponent::prepareLoadStore(), which returns a configuration object that can be chained with various methods before executing the actual load/store operation.Methods return an
auxiliary::DeferredComputation<T>object that encapsulates the operation without immediately executing it. The computation is only performed whenget()(oroperator()()) is called on the returned object:Configuration Methods
The configuration chain supports:
offset(Offset)- Set the offset within the dataset (optional)extent(Extent)- Set the extent within the dataset (optional)memorySelection(MemorySelection)- Set memory selection for non-contiguous buffers (only available afterwithSharedPtr(),withRawPtr(), orwithContiguousContainer())unsafeNoAutomaticFlush(): The returnedDeferredComputationobject will be a no-op object. Buffers will still be returned, but they might not yet be written/read until manually flushing.Buffer Specification Methods
If not specifying a buffer, the following allocating load/store operations are available:
storeSpan<T>()- ReturnsDynamicMemoryView<T>(a span-like view)load<T>()- ReturnsDeferredComputation<std::shared_ptr<T>>loadVariant()- ReturnsDeferredComputation<variant>for type-erased loadingload<T>(policy)- Returnsstd::shared_ptr<T>>Alternatively, you may specify a buffer using one of:
withSharedPtr(std::shared_ptr<T>)- For shared pointer managed bufferswithUniquePtr(UniquePtrWithLambda<T>)- For unique pointer with custom deleterwithRawPtr(T*)- For raw pointer bufferswithContiguousContainer(Container&)- For contiguous containers (automatically deduces size if extent is not set)The following operations are only available after specifying a buffer. Template parameters are no longer needed as the type is given through the buffer type:
store()/load()- ReturnsDeferredComputation<void>(Load operations are only available after specifying a writable buffer, i.e. raw/shared pointer or contiguous container of non-const type)
ADIOS2 Memory Selection Support
This PR adds support for ADIOS2 memory selections, allowing writing from non-contiguous memory blocks:
Note: Memory selection support depends on ADIOS2 version. For ADIOS2 versions that cannot reset memory selections (PR ornladios/ADIOS2#4169), a warning is displayed. The API gracefully handles both cases.
Migration from Old API
The old
loadChunk()andstoreChunk()methods are now fully implemented using the new API internally, providing full backward compatibility while benefiting from the new implementation. Existing code continues to work without changes.Examples of Old to New Migration
Old:
New:
Old:
New:
E_y.prepareLoadStore() .offset({0, 5}) .extent({1, 5}) .withContiguousContainer(data) .store();Design Considerations & Open Questions
Memory Selection Limitations
prepareLoadStore())Files Changed
include/openPMD/LoadStoreChunk.hpp- New header with the main APIinclude/openPMD/LoadStoreChunk.tpp- Template implementationsinclude/openPMD/auxiliary/Future.hpp- NewDeferredComputationwrapperinclude/openPMD/Dataset.hpp- AddedMemorySelectionstructinclude/openPMD/RecordComponent.hpp- Integration of new APIsrc/LoadStoreChunk.cpp- Non-template implementationssrc/auxiliary/Future.cpp- DeferredComputation implementationTODO
.noop_future()option to disable future return types for cases where you don't need to track completionRelated
TODO: