Skip to content

Commit

Permalink
Expose span-based adios2::Engine::Get
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 22, 2021
1 parent e743c03 commit d3e8f15
Show file tree
Hide file tree
Showing 25 changed files with 1,025 additions and 99 deletions.
47 changes: 23 additions & 24 deletions include/openPMD/Datatype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,30 +962,29 @@ auto switchNonVectorType( Datatype dt, Action action, Args &&... args )

#undef OPENPMD_TEMPLATE_OPERATOR

namespace detail {
template<typename T>
struct BasicDatatypeHelper {
Datatype m_dt = determineDatatype<T>();
};

template<typename T>
struct BasicDatatypeHelper<std::vector<T>> {
Datatype m_dt = BasicDatatypeHelper<T>{}.m_dt;
};

template<typename T, long n>
struct BasicDatatypeHelper<std::array<T, n>> {
Datatype m_dt = BasicDatatypeHelper<T>{}.m_dt;
};

struct BasicDatatype {
template <typename T>
Datatype operator()();

template <int n>
Datatype operator()();
};
}
template< typename T >
struct BasicDatatype
{
using type = T;
constexpr static bool isBasicDatatype = true;
Datatype m_dt = determineDatatype< T >();
};

template< typename T >
struct BasicDatatype< std::vector< T > >
{
using type = T;
constexpr static bool isBasicDatatype = false;
Datatype m_dt = BasicDatatype< T >{}.m_dt;
};

template< typename T, long n >
struct BasicDatatype< std::array< T, n > >
{
using type = T;
constexpr static bool isBasicDatatype = false;
Datatype m_dt = BasicDatatype< T >{}.m_dt;
};

/**
* @brief basicDatatype Strip openPMD Datatype of std::vector, std::array et. al.
Expand Down
41 changes: 37 additions & 4 deletions include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ADIOS2IOHandler;
namespace detail
{
template < typename, typename > struct DatasetHelper;
template< typename, typename > struct GetSpanHelper;
struct DatasetReader;
struct AttributeReader;
struct AttributeWriter;
Expand All @@ -83,6 +84,7 @@ class ADIOS2IOHandlerImpl
: public AbstractIOHandlerImplCommon< ADIOS2FilePosition >
{
template < typename, typename > friend struct detail::DatasetHelper;
template < typename, typename > friend struct detail::GetSpanHelper;
friend struct detail::DatasetReader;
friend struct detail::AttributeReader;
friend struct detail::AttributeWriter;
Expand Down Expand Up @@ -171,6 +173,9 @@ class ADIOS2IOHandlerImpl
void readDataset( Writable *,
Parameter< Operation::READ_DATASET > & ) override;

void getBufferView( Writable *,
Parameter< Operation::GET_BUFFER_VIEW > & ) override;

void readAttribute( Writable *,
Parameter< Operation::READ_ATT > & ) override;

Expand Down Expand Up @@ -977,6 +982,8 @@ namespace detail
template < typename... Params > void writeDataset( Params &&... );

template < typename... Params > static void blocksInfo( Params &&... );

template< typename... Params > static void getSpan( Params &&... );
};

// Other datatypes used in the ADIOS2IOHandler implementation
Expand All @@ -989,8 +996,15 @@ namespace detail
*/
struct BufferedAction
{
explicit BufferedAction( ) = default;
virtual ~BufferedAction( ) = default;

BufferedAction( BufferedAction const & other ) = delete;
BufferedAction( BufferedAction && other ) = default;

BufferedAction & operator=( BufferedAction const & other ) = delete;
BufferedAction & operator=( BufferedAction && other ) = default;

virtual void run( BufferedActions & ) = 0;
};

Expand Down Expand Up @@ -1027,15 +1041,30 @@ namespace detail
run( BufferedActions & );
};

struct BufferedAttributeWrite
struct BufferedAttributeWrite : BufferedAction
{
std::string name;
Datatype dtype;
Attribute::resource resource;
std::vector< char > bufferForVecString;

void
run( BufferedActions & );
void run( BufferedActions & ) override;
};

struct I_UpdateSpan
{
virtual void *update() = 0;
virtual ~I_UpdateSpan() = default;
};

template< typename T >
struct UpdateSpan : I_UpdateSpan
{
adios2::detail::Span< T > span;

UpdateSpan( adios2::detail::Span< T > );

void *update() override;
};

/*
Expand Down Expand Up @@ -1079,7 +1108,9 @@ namespace detail
std::vector< std::unique_ptr< BufferedAction > > m_buffer;
std::map< std::string, BufferedAttributeWrite > m_attributeWrites;
std::vector< BufferedAttributeRead > m_attributeReads;
std::vector< std::unique_ptr< BufferedAction > > m_alreadyEnqueued;
adios2::Mode m_mode;
std::map< unsigned, std::unique_ptr< I_UpdateSpan > > m_updateSpans;
detail::WriteDataset const m_writeDataset;
detail::DatasetReader const m_readDataset;
detail::AttributeReader const m_attributeReader;
Expand Down Expand Up @@ -1129,6 +1160,7 @@ namespace detail
/**
* Flush deferred IO actions.
*
* @param level Flush Level. Only execute performPutsGets if UserFlush.
* @param performPutsGets A functor that takes as parameters (1) *this
* and (2) the ADIOS2 engine.
* Its task is to ensure that ADIOS2 performs Put/Get operations.
Expand All @@ -1144,6 +1176,7 @@ namespace detail
template< typename F >
void
flush(
FlushLevel level,
F && performPutsGets,
bool writeAttributes,
bool flushUnconditionally );
Expand All @@ -1154,7 +1187,7 @@ namespace detail
*
*/
void
flush( bool writeAttributes = false );
flush( FlushLevel, bool writeAttributes = false );

/**
* @brief Begin or end an ADIOS step.
Expand Down
23 changes: 23 additions & 0 deletions include/openPMD/IO/AbstractIOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ class unsupported_data_error : public std::runtime_error
virtual ~unsupported_data_error() { }
};

/**
* @brief Determine what items should be flushed upon Series::flush()
*
*/
enum class FlushLevel : unsigned char
{
UserFlush,
/**
* Default mode, flush everything that can be flushed
* Does not need to uphold user-level guarantees about clearing and filling
* buffers. Spans must not yet be read.
*/
FlushEverything,
/**
* Restricted mode, flush all objects in the openPMD hierarchy to the
* backend, i.e. open paths and create files.
* Do not flush record components / datasets.
* Attributes may or may not be flushed yet.
*/
SkeletonOnly
};


/** Interface for communicating between logical and physically persistent data.
*
Expand Down Expand Up @@ -104,6 +126,7 @@ class AbstractIOHandler
Access const m_backendAccess;
Access const m_frontendAccess;
std::queue< IOTask > m_work;
FlushLevel m_flushLevel = FlushLevel::FlushEverything;
}; // AbstractIOHandler

} // namespace openPMD
29 changes: 27 additions & 2 deletions include/openPMD/IO/AbstractIOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class AbstractIOHandlerImpl
case O::READ_DATASET:
readDataset(i.writable, deref_dynamic_cast< Parameter< O::READ_DATASET > >(i.parameter.get()));
break;
case O::GET_BUFFER_VIEW:
getBufferView(i.writable, deref_dynamic_cast< Parameter< O::GET_BUFFER_VIEW > >(i.parameter.get()));
break;
case O::READ_ATT:
readAttribute(i.writable, deref_dynamic_cast< Parameter< O::READ_ATT > >(i.parameter.get()));
break;
Expand Down Expand Up @@ -136,7 +139,7 @@ class AbstractIOHandlerImpl
*/
virtual void
closeFile( Writable *, Parameter< Operation::CLOSE_FILE > const & ) = 0;

/** Advance the file/stream that this writable belongs to.
*
* If the backend is based around usage of IO steps (especially streaming
Expand All @@ -157,7 +160,7 @@ class AbstractIOHandlerImpl
{}

/** Close an openPMD group.
*
*
* This is an optimization-enabling task and may be ignored by backends.
* Indicates that the group will not be accessed any further.
* Especially in step-based IO mode (e.g. streaming):
Expand Down Expand Up @@ -303,6 +306,28 @@ class AbstractIOHandlerImpl
* The region of the chunk should be written to physical storage after the operation completes successfully.
*/
virtual void writeDataset(Writable*, Parameter< Operation::WRITE_DATASET > const&) = 0;

/** Get a view into a dataset buffer that can be filled by a user.
*
* The operation should fail if m_handler->m_frontendAccess is Access::READ_ONLY.
* The dataset should be associated with the Writable.
* The operation should fail if the dataset does not exist.
* The operation should fail if the chunk extent parameters.extent is not smaller or equals in every dimension.
* The operation should fail if chunk positions parameters.offset+parameters.extent do not reside inside the dataset.
* The dataset should match the dataype parameters.dtype.
* The buffer should be stored as a cast-to-char pointer to a flattened version of the backend buffer in parameters.out->ptr. The chunk is stored row-major.
* The buffer's content should be written to storage not before the next call to AbstractIOHandler::flush where AbstractIOHandler::m_flushLevel == FlushLevel::FlushEverything.
* The precise time of data consumption is defined by the backend:
* * Data written to the returned buffer should be consumed not earlier than the next call to AbstractIOHandler::flush where AbstractIOHandler::m_flushLevel == FlushLevel::FlushEverything.
* * Data should be consumed not later than the next Operation::ADVANCE task where parameter.mode == AdvanceMode::ENDSTEP.
*
* This task is optional and should either (1) not be implemented by a backend at all or (2) be implemented as indicated above and set parameters.out->taskSupportedByBackend = true.
*/
virtual void getBufferView(Writable*, Parameter< Operation::GET_BUFFER_VIEW >& parameters)
{
// default implementation: operation unsupported by backend
parameters.out->taskSupportedByBackend = false;
}
/** Create a single attribute and fill the value, possibly overwriting an existing attribute.
*
* The operation should fail if m_handler->m_frontendAccess is Access::READ_ONLY.
Expand Down
32 changes: 32 additions & 0 deletions include/openPMD/IO/IOTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ OPENPMDAPI_EXPORT_ENUM_CLASS(Operation)
WRITE_DATASET,
READ_DATASET,
LIST_DATASETS,
GET_BUFFER_VIEW,

DELETE_ATT,
WRITE_ATT,
Expand Down Expand Up @@ -408,6 +409,37 @@ struct OPENPMDAPI_EXPORT Parameter< Operation::LIST_DATASETS > : public Abstract
= std::make_shared< std::vector< std::string > >();
};

template<>
struct OPENPMDAPI_EXPORT Parameter< Operation::GET_BUFFER_VIEW > : public AbstractParameter
{
Parameter() = default;
Parameter(Parameter const & p) : AbstractParameter(),
offset(p.offset), extent(p.extent), dtype(p.dtype), update(p.update),
out(p.out)
{}

std::unique_ptr< AbstractParameter >
clone() const override
{
return std::unique_ptr< AbstractParameter >(
new Parameter< Operation::GET_BUFFER_VIEW >(*this));
}

// in parameters
Offset offset;
Extent extent;
Datatype dtype = Datatype::UNDEFINED;
bool update = false;
// out parameters
struct OutParameters
{
bool taskSupportedByBackend = false;
unsigned viewIndex = 0;
void *ptr = nullptr;
};
std::shared_ptr< OutParameters > out = std::make_shared< OutParameters >();
};

template<>
struct OPENPMDAPI_EXPORT Parameter< Operation::DELETE_ATT > : public AbstractParameter
{
Expand Down
Loading

0 comments on commit d3e8f15

Please sign in to comment.