Skip to content

Commit

Permalink
Initial untested attempt at supporting unsupported engines
Browse files Browse the repository at this point in the history
heh
  • Loading branch information
franzpoeschel committed Jul 19, 2024
1 parent 7efa3b7 commit 3f82b1c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
2 changes: 2 additions & 0 deletions include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ namespace adios_defaults
using const_str = char const *const;
constexpr const_str str_engine = "engine";
constexpr const_str str_type = "type";
constexpr const_str str_treat_unsupported_engine_like =
"treat_unsupported_engine_like";
constexpr const_str str_params = "parameters";
constexpr const_str str_usesteps = "usesteps";
constexpr const_str str_flushtarget = "preferred_flush_target";
Expand Down
4 changes: 0 additions & 4 deletions include/openPMD/IO/ADIOS/ADIOS2File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,6 @@ class ADIOS2File
private:
ADIOS2IOHandlerImpl *m_impl;
std::optional<adios2::Engine> m_engine; //! ADIOS engine
/**
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
*/
std::string m_engineType;

/*
* Not all engines support the CurrentStep() call, so we have to
Expand Down
13 changes: 13 additions & 0 deletions include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ class ADIOS2IOHandlerImpl
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
*/
std::string m_engineType;
std::optional<std::string> m_realEngineType;

inline std::string const &realEngineType() const
{
if (m_realEngineType.has_value())
{
return *m_realEngineType;
}
else
{
return m_engineType;
}
}
/*
* The filename extension specified by the user.
*/
Expand Down
26 changes: 13 additions & 13 deletions src/IO/ADIOS/ADIOS2File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ ADIOS2File::ADIOS2File(ADIOS2IOHandlerImpl &impl, InvalidatableFile file)
: m_file(impl.fullPath(std::move(file)))
, m_ADIOS(impl.m_ADIOS)
, m_impl(&impl)
, m_engineType(impl.m_engineType)
{
// Declaring these members in the constructor body to avoid
// initialization order hazards. Need the IO_ prefix since in some
Expand Down Expand Up @@ -324,7 +323,7 @@ namespace

size_t ADIOS2File::currentStep()
{
if (nonpersistentEngine(m_engineType))
if (nonpersistentEngine(m_impl->m_engineType))
{
return m_currentStep;
}
Expand All @@ -337,9 +336,9 @@ size_t ADIOS2File::currentStep()
void ADIOS2File::configure_IO_Read()
{
bool upfrontParsing = supportsUpfrontParsing(
m_impl->m_handler->m_backendAccess, m_engineType);
m_impl->m_handler->m_backendAccess, m_impl->m_engineType);
PerstepParsing perstepParsing = supportsPerstepParsing(
m_impl->m_handler->m_backendAccess, m_engineType);
m_impl->m_handler->m_backendAccess, m_impl->m_engineType);

switch (m_impl->m_handler->m_backendAccess)
{
Expand All @@ -355,7 +354,7 @@ void ADIOS2File::configure_IO_Read()
* In non-persistent (streaming) engines, per-step parsing is
* always fine and always required.
*/
streamStatus = nonpersistentEngine(m_engineType)
streamStatus = nonpersistentEngine(m_impl->m_engineType)
? StreamStatus::OutsideOfStep
: StreamStatus::Undecided;
parsePreference = ParsePreference::PerStep;
Expand All @@ -374,7 +373,7 @@ void ADIOS2File::configure_IO_Read()
* Prefer up-front parsing, but try to fallback to per-step parsing
* if possible.
*/
if (upfrontParsing == nonpersistentEngine(m_engineType))
if (upfrontParsing == nonpersistentEngine(m_impl->m_engineType))
{
throw error::Internal(
"Internal control flow error: With access types "
Expand Down Expand Up @@ -412,7 +411,7 @@ void ADIOS2File::configure_IO_Write()
// Also, it should only be done when truly streaming, not
// when using a disk-based engine that behaves like a
// streaming engine (otherwise attributes might vanish)
nonpersistentEngine(m_engineType);
nonpersistentEngine(m_impl->m_engineType);

streamStatus = StreamStatus::OutsideOfStep;
}
Expand Down Expand Up @@ -466,13 +465,13 @@ void ADIOS2File::configure_IO()

// set engine type
{
m_IO.SetEngine(m_engineType);
m_IO.SetEngine(m_impl->realEngineType());
}

if (!supportedEngine(m_engineType))
if (!supportedEngine(m_impl->m_engineType))
{
std::stringstream sstream;
sstream << "User-selected ADIOS2 engine '" << m_engineType
sstream << "User-selected ADIOS2 engine '" << m_impl->m_engineType
<< "' is not recognized by the openPMD-api. Select one of: '";
bool first_entry = true;
auto add_entries = [&first_entry, &sstream](auto &list) {
Expand Down Expand Up @@ -687,7 +686,7 @@ void ADIOS2File::configure_IO()
auxiliary::getEnvNum("OPENPMD_ADIOS2_STATS_LEVEL", 0);
m_IO.SetParameter("StatsLevel", std::to_string(stats_level));
}
if (m_engineType == "sst" && notYetConfigured("QueueLimit"))
if (m_impl->realEngineType() == "sst" && notYetConfigured("QueueLimit"))
{
/*
* By default, the SST engine of ADIOS2 does not set a limit on its
Expand Down Expand Up @@ -773,7 +772,8 @@ adios2::Engine &ADIOS2File::getEngine()
bool openedANewStep = false;
{
if (!supportsUpfrontParsing(
m_impl->m_handler->m_backendAccess, m_engineType))
m_impl->m_handler->m_backendAccess,
m_impl->m_engineType))
{
/*
* In BP5 with Linear read mode, we now need to
Expand Down Expand Up @@ -1048,7 +1048,7 @@ void ADIOS2File::flush_impl(ADIOS2FlushParams flushParams, bool writeLatePuts)
{
case FlushTarget::Disk:
case FlushTarget::Disk_Override:
if (m_engineType == "bp5" ||
if (m_impl->realEngineType() == "bp5" ||
/* this second check should be sufficient, but we leave the
first check in as a safeguard against renamings in
ADIOS2. Also do a lowerCase transform since the docstring
Expand Down
32 changes: 29 additions & 3 deletions src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "openPMD/IterationEncoding.hpp"
#include "openPMD/auxiliary/Environment.hpp"
#include "openPMD/auxiliary/Filesystem.hpp"
#include "openPMD/auxiliary/JSON_internal.hpp"
#include "openPMD/auxiliary/Mpi.hpp"
#include "openPMD/auxiliary/StringManip.hpp"
#include "openPMD/auxiliary/TypeTraits.hpp"
Expand Down Expand Up @@ -262,6 +263,25 @@ void ADIOS2IOHandlerImpl::init(
"Must be convertible to string type.");
}
}

if (engineConfig.json().contains(
adios_defaults::str_treat_unsupported_engine_like))
{
auto maybeEngine = json::asLowerCaseStringDynamic(
engineConfig
[adios_defaults::str_treat_unsupported_engine_like]
.json());
if (!maybeEngine.has_value())
{
throw error::BackendConfigSchema(
{"adios2",
adios_defaults::str_engine,
adios_defaults::str_treat_unsupported_engine_like},
"Must be convertible to string type.");
}
m_realEngineType = std::move(m_engineType);
m_engineType = std::move(*maybeEngine);
}
}
auto operators = getOperators();
if (operators)
Expand Down Expand Up @@ -360,6 +380,12 @@ std::string ADIOS2IOHandlerImpl::fileSuffix(bool verbose) const
constexpr char const *const default_file_ending = ".bp4";
#endif

if (m_realEngineType.has_value())
{
// unknown engine type, use whatever ending the user specified
return m_userSpecifiedExtension;
}

static std::map<std::string, AcceptedEndingsForEngine> const endings{
{"sst", {{"", ""}, {".sst", ""}, {".%E", ""}}},
{"staging", {{"", ""}, {".sst", ""}, {".%E", ""}}},
Expand Down Expand Up @@ -654,7 +680,7 @@ void ADIOS2IOHandlerImpl::checkFile(

bool ADIOS2IOHandlerImpl::checkFile(std::string fullFilePath) const
{
if (m_engineType == "bp3")
if (realEngineType() == "bp3")
{
if (!auxiliary::ends_with(fullFilePath, ".bp"))
{
Expand All @@ -664,7 +690,7 @@ bool ADIOS2IOHandlerImpl::checkFile(std::string fullFilePath) const
fullFilePath += ".bp";
}
}
else if (m_engineType == "sst")
else if (realEngineType() == "sst")
{
/*
* SST will add this ending indiscriminately
Expand Down Expand Up @@ -1142,7 +1168,7 @@ void ADIOS2IOHandlerImpl::getBufferView(
begin(optInEngines),
end(optInEngines),
[this](std::string const &engine) {
return engine == this->m_engineType;
return engine == this->realEngineType();
}))
{
parameters.out->backendManagedBuffer = false;
Expand Down

0 comments on commit 3f82b1c

Please sign in to comment.