Skip to content

Commit b6d64d6

Browse files
committed
Implement memory selection in ADIOS2
1 parent 51748b9 commit b6d64d6

8 files changed

Lines changed: 40 additions & 11 deletions

File tree

include/openPMD/Dataset.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ namespace openPMD
3434
using Extent = std::vector<std::uint64_t>;
3535
using Offset = std::vector<std::uint64_t>;
3636

37+
struct MemorySelection
38+
{
39+
Offset offset;
40+
Extent extent;
41+
};
42+
3743
class Dataset
3844
{
3945
friend class RecordComponent;

include/openPMD/IO/ADIOS/ADIOS2File.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
*/
2121
#pragma once
2222

23+
#include "openPMD/Dataset.hpp"
2324
#include "openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp"
2425
#include "openPMD/IO/AbstractIOHandler.hpp"
2526
#include "openPMD/IO/IOTask.hpp"
2627
#include "openPMD/IO/InvalidatableFile.hpp"
2728
#include "openPMD/config.hpp"
29+
#include <optional>
2830

2931
#if openPMD_HAVE_ADIOS2
3032
#include <adios2.h>
@@ -106,6 +108,7 @@ struct BufferedUniquePtrPut
106108
std::string name;
107109
Offset offset;
108110
Extent extent;
111+
std::optional<MemorySelection> memorySelection;
109112
UniquePtrWithLambda<void> data;
110113
Datatype dtype = Datatype::UNDEFINED;
111114

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
#pragma once
2222

23+
#include "openPMD/Dataset.hpp"
2324
#include "openPMD/Error.hpp"
2425
#include "openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp"
2526
#include "openPMD/IO/ADIOS/ADIOS2FilePosition.hpp"
@@ -398,6 +399,7 @@ class ADIOS2IOHandlerImpl
398399
adios2::Variable<T> verifyDataset(
399400
Offset const &offset,
400401
Extent const &extent,
402+
std::optional<MemorySelection> const &memorySelection,
401403
adios2::IO &IO,
402404
std::string const &varName)
403405
{
@@ -479,6 +481,16 @@ class ADIOS2IOHandlerImpl
479481
var.SetSelection(
480482
{adios2::Dims(offset.begin(), offset.end()),
481483
adios2::Dims(extent.begin(), extent.end())});
484+
if (memorySelection.has_value())
485+
{
486+
var.SetMemorySelection(
487+
{adios2::Dims(
488+
memorySelection->offset.begin(),
489+
memorySelection->offset.end()),
490+
adios2::Dims(
491+
memorySelection->extent.begin(),
492+
memorySelection->extent.end())});
493+
}
482494
return var;
483495
}
484496

include/openPMD/IO/IOTask.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <cstddef>
3434
#include <map>
3535
#include <memory>
36+
#include <optional>
3637
#include <string>
3738
#include <utility>
3839
#include <variant>
@@ -419,6 +420,7 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::WRITE_DATASET>
419420

420421
Extent extent = {};
421422
Offset offset = {};
423+
std::optional<MemorySelection> memorySelection = std::nullopt;
422424
Datatype dtype = Datatype::UNDEFINED;
423425
auxiliary::WriteBuffer data;
424426
};

include/openPMD/LoadStoreChunk.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ class ConfigureStoreChunkFromBuffer;
1616
template <typename T>
1717
class DynamicMemoryView;
1818

19-
struct MemorySelection
20-
{
21-
Offset offset;
22-
Extent extent;
23-
};
24-
2519
namespace internal
2620
{
2721
struct StoreChunkConfig

src/IO/ADIOS/ADIOS2File.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "openPMD/Error.hpp"
2424
#include "openPMD/IO/ADIOS/ADIOS2IOHandler.hpp"
2525
#include "openPMD/auxiliary/Environment.hpp"
26+
#include <optional>
2627

2728
#if openPMD_USE_VERIFY
2829
#define VERIFY(CONDITION, TEXT) \
@@ -55,8 +56,8 @@ void DatasetReader::call(
5556
adios2::Engine &engine,
5657
std::string const &fileName)
5758
{
58-
adios2::Variable<T> var =
59-
impl->verifyDataset<T>(bp.param.offset, bp.param.extent, IO, bp.name);
59+
adios2::Variable<T> var = impl->verifyDataset<T>(
60+
bp.param.offset, bp.param.extent, std::nullopt, IO, bp.name);
6061
if (!var)
6162
{
6263
throw std::runtime_error(
@@ -85,7 +86,11 @@ void WriteDataset::call(ADIOS2File &ba, detail::BufferedPut &bp)
8586
auto ptr = static_cast<T const *>(arg.get());
8687

8788
adios2::Variable<T> var = ba.m_impl->verifyDataset<T>(
88-
bp.param.offset, bp.param.extent, ba.m_IO, bp.name);
89+
bp.param.offset,
90+
bp.param.extent,
91+
bp.param.memorySelection,
92+
ba.m_IO,
93+
bp.name);
8994

9095
ba.getEngine().Put(var, ptr);
9196
}
@@ -97,6 +102,7 @@ void WriteDataset::call(ADIOS2File &ba, detail::BufferedPut &bp)
97102
bput.name = std::move(bp.name);
98103
bput.offset = std::move(bp.param.offset);
99104
bput.extent = std::move(bp.param.extent);
105+
bput.memorySelection = std::move(bp.param.memorySelection);
100106
/*
101107
* Note: Moving is required here since it's a unique_ptr.
102108
* std::forward<>() would theoretically work, but it
@@ -143,7 +149,11 @@ struct RunUniquePtrPut
143149
{
144150
auto ptr = static_cast<T const *>(bufferedPut.data.get());
145151
adios2::Variable<T> var = ba.m_impl->verifyDataset<T>(
146-
bufferedPut.offset, bufferedPut.extent, ba.m_IO, bufferedPut.name);
152+
bufferedPut.offset,
153+
bufferedPut.extent,
154+
bufferedPut.memorySelection,
155+
ba.m_IO,
156+
bufferedPut.name);
147157
ba.getEngine().Put(var, ptr);
148158
}
149159

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <iostream>
4040
#include <iterator>
4141
#include <memory>
42+
#include <optional>
4243
#include <set>
4344
#include <stdexcept>
4445
#include <string>
@@ -1076,7 +1077,7 @@ namespace detail
10761077
auto &IO = ba.m_IO;
10771078
auto &engine = ba.getEngine();
10781079
adios2::Variable<T> variable = impl->verifyDataset<T>(
1079-
params.offset, params.extent, IO, varName);
1080+
params.offset, params.extent, std::nullopt, IO, varName);
10801081
adios2::Dims offset(params.offset.begin(), params.offset.end());
10811082
adios2::Dims extent(params.extent.begin(), params.extent.end());
10821083
variable.SetSelection({std::move(offset), std::move(extent)});

src/RecordComponent.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ void RecordComponent::storeChunk_impl(
510510
Parameter<Operation::WRITE_DATASET> dWrite;
511511
dWrite.offset = std::move(o);
512512
dWrite.extent = std::move(e);
513+
dWrite.memorySelection = memorySelection;
513514
dWrite.dtype = dtype;
514515
/* std::static_pointer_cast correctly reference-counts the pointer */
515516
dWrite.data = std::move(buffer);

0 commit comments

Comments
 (0)