Skip to content

Commit b4a8819

Browse files
committed
Do not flush if the backend does not support Span API
1 parent 43005e1 commit b4a8819

3 files changed

Lines changed: 38 additions & 13 deletions

File tree

include/openPMD/IO/IOTask.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ struct OPENPMDAPI_EXPORT
561561
}
562562

563563
// in parameters
564+
bool queryOnly = false; // query if the backend supports this
564565
Offset offset;
565566
Extent extent;
566567
Datatype dtype = Datatype::UNDEFINED;

include/openPMD/RecordComponent.tpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,46 @@ RecordComponent::storeChunk(Offset o, Extent e, F &&createBuffer)
103103
"using storeChunk() (see RecordComponent::resetDataset()).");
104104
}
105105

106-
if (!written())
107-
{
108-
Parameter<Operation::CREATE_DATASET> dCreate(rc.m_dataset.value());
109-
dCreate.name = Attributable::get().m_writable.ownKeyWithinParent;
110-
IOHandler()->enqueue(IOTask(this, dCreate));
111-
112-
setWritten(true, EnqueueAsynchronously::Yes);
113-
}
106+
Parameter<Operation::GET_BUFFER_VIEW> query;
107+
query.queryOnly = true;
108+
IOHandler()->enqueue(IOTask(this, query));
109+
IOHandler()->flush(internal::defaultFlushParams);
114110

115111
Parameter<Operation::GET_BUFFER_VIEW> getBufferView;
116112
getBufferView.offset = o;
117113
getBufferView.extent = e;
118114
getBufferView.dtype = getDatatype();
119-
IOHandler()->enqueue(IOTask(this, getBufferView));
120-
IOHandler()->flush(internal::defaultFlushParams);
121-
auto &out = *getBufferView.out;
122-
if (!out.backendManagedBuffer)
115+
116+
if (query.out->backendManagedBuffer)
117+
{
118+
// Need to initialize the dataset for the Span API
119+
// But this is a non-collective call and initializing the dataset is
120+
// collective in HDF5 So we do this only in backends that actually
121+
// support the Span API (i.e. ADIOS2) which do not share this
122+
// restriction
123+
// TODO: Add some form of collective ::commitDefinitions() call to
124+
// RecordComponents to be called by users before the Span API
125+
if (!written())
126+
{
127+
Parameter<Operation::CREATE_DATASET> dCreate(rc.m_dataset.value());
128+
dCreate.name = Attributable::get().m_writable.ownKeyWithinParent;
129+
IOHandler()->enqueue(IOTask(this, dCreate));
130+
131+
setWritten(true, EnqueueAsynchronously::Yes);
132+
}
133+
134+
IOHandler()->enqueue(IOTask(this, getBufferView));
135+
IOHandler()->flush(internal::defaultFlushParams);
136+
}
137+
138+
// The backend might still refuse the operation even if backend managed
139+
// buffers are generally supported, so check again
140+
if (!getBufferView.out->backendManagedBuffer)
123141
{
124142
// note that data might have either
125143
// type shared_ptr<T> or shared_ptr<T[]>
126144
auto data = std::forward<F>(createBuffer)(size);
127-
out.ptr = static_cast<void *>(data.get());
145+
getBufferView.out->ptr = static_cast<void *>(data.get());
128146
if (size > 0)
129147
{
130148
storeChunk(std::move(data), std::move(o), std::move(e));

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,12 @@ void ADIOS2IOHandlerImpl::getBufferView(
13161316
parameters.out->backendManagedBuffer = false;
13171317
return;
13181318
}
1319+
else if (parameters.queryOnly)
1320+
{
1321+
parameters.out->backendManagedBuffer = true;
1322+
return;
1323+
}
1324+
13191325
setAndGetFilePosition(writable);
13201326
auto file = refreshFileFromParent(writable, /* preferParentFile = */ false);
13211327
detail::ADIOS2File &ba = getFileData(file, IfFileNotOpen::ThrowError);

0 commit comments

Comments
 (0)