Skip to content

Commit 4bf1bab

Browse files
committed
Modify to include plugin operators
1 parent 06eafa4 commit 4bf1bab

File tree

5 files changed

+95
-45
lines changed

5 files changed

+95
-45
lines changed

source/adios2/core/VariableBase.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,15 @@ size_t VariableBase::AddOperation(const std::string &type, const Params &paramet
343343
auto op = MakeOperator(type, parameters);
344344
if (op->IsDataTypeValid(m_Type))
345345
{
346-
m_Operations.push_back(op);
346+
if (!m_Operations.empty() && (m_Operations[0]->m_TypeString == "null"))
347+
{
348+
// if there's a dummy operation in place, replace it
349+
m_Operations[0] = op;
350+
}
351+
else
352+
{
353+
m_Operations.push_back(op);
354+
}
347355
}
348356
else
349357
{

source/adios2/operator/plugin/PluginOperator.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ PluginOperator::PluginOperator(const Params &parameters)
6161
}
6262
}
6363

64-
PluginOperator::~PluginOperator() { m_Impl->m_HandleDestroy(m_Impl->m_Plugin); }
64+
PluginOperator::~PluginOperator()
65+
{
66+
if (m_Impl->m_Plugin)
67+
m_Impl->m_HandleDestroy(m_Impl->m_Plugin);
68+
}
6569

6670
void PluginOperator::PluginInit(const std::string &pluginName, const std::string &pluginLibrary)
6771
{
@@ -72,11 +76,22 @@ void PluginOperator::PluginInit(const std::string &pluginName, const std::string
7276

7377
auto &pluginManager = PluginManager::GetInstance();
7478
pluginManager.SetParameters(m_Parameters);
75-
pluginManager.LoadPlugin(pluginName, pluginLibrary);
76-
79+
try
80+
{
81+
pluginManager.LoadPlugin(pluginName, pluginLibrary);
82+
}
83+
catch (...)
84+
{
85+
helper::Throw<std::runtime_error>("Plugins", "PluginOperator", "PluginInit",
86+
"Failed to load library \"" + pluginLibrary +
87+
"\" looking for plugin \"" + pluginName + "\"");
88+
}
7789
m_Impl->m_HandleCreate = pluginManager.GetOperatorCreateFun(pluginName);
7890
m_Impl->m_HandleDestroy = pluginManager.GetOperatorDestroyFun(pluginName);
7991
m_Impl->m_Plugin = m_Impl->m_HandleCreate(m_Parameters);
92+
// add for external visibility
93+
m_PluginName = pluginName;
94+
m_PluginLibrary = pluginLibrary;
8095
}
8196

8297
size_t PluginOperator::GetEstimatedSize(const size_t ElemCount, const size_t ElemSize,

source/adios2/operator/plugin/PluginOperator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class PluginOperator : public core::Operator
4848

4949
bool IsDataTypeValid(const DataType type) const override;
5050

51+
std::string m_PluginLibrary;
52+
std::string m_PluginName;
53+
5154
protected:
5255
void PluginInit(const std::string &pluginName, const std::string &pluginLibrary);
5356

source/adios2/toolkit/format/bp5/BP5Deserializer.cpp

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,56 +1980,57 @@ void BP5Deserializer::FinalizeGet(const ReadRequest &Read, const bool freeAddr)
19801980
std::vector<char> decompressBuffer;
19811981
if (((struct BP5VarRec *)Req.VarRec)->Operator != NULL)
19821982
{
1983-
size_t DestSize = ((struct BP5VarRec *)Req.VarRec)->ElementSize;
1984-
for (size_t dim = 0; dim < ((struct BP5VarRec *)Req.VarRec)->DimCount; dim++)
1983+
try
19851984
{
1986-
DestSize *= writer_meta_base->Count[dim + Read.BlockID * writer_meta_base->Dims];
1987-
}
1988-
decompressBuffer.resize(DestSize);
1985+
size_t DestSize = ((struct BP5VarRec *)Req.VarRec)->ElementSize;
1986+
for (size_t dim = 0; dim < ((struct BP5VarRec *)Req.VarRec)->DimCount; dim++)
1987+
{
1988+
DestSize *= writer_meta_base->Count[dim + Read.BlockID * writer_meta_base->Dims];
1989+
}
1990+
decompressBuffer.resize(DestSize);
19891991

1990-
// Get the operator of the variable if exists or create one
1991-
std::shared_ptr<Operator> op = nullptr;
1992-
VariableBase *VB = static_cast<VariableBase *>(((struct BP5VarRec *)Req.VarRec)->Variable);
1993-
if (!VB->m_Operations.empty() && (VB->m_Operations[0]->m_TypeString != "null"))
1994-
{
1995-
op = VB->m_Operations[0];
1996-
}
1997-
else
1998-
{
1999-
Operator::OperatorType compressorType =
2000-
static_cast<Operator::OperatorType>(IncomingData[0]);
2001-
try
1992+
// Get the operator of the variable if exists or create one
1993+
std::shared_ptr<Operator> op = nullptr;
1994+
VariableBase *VB =
1995+
static_cast<VariableBase *>(((struct BP5VarRec *)Req.VarRec)->Variable);
1996+
if (!VB->m_Operations.empty() && (VB->m_Operations[0]->m_TypeString != "null"))
20021997
{
1998+
op = VB->m_Operations[0];
1999+
}
2000+
else
2001+
{
2002+
Operator::OperatorType compressorType =
2003+
static_cast<Operator::OperatorType>(IncomingData[0]);
20032004
op = MakeOperator(OperatorTypeToString(compressorType), {});
2005+
VB->m_Operations.resize(1);
2006+
VB->m_Operations[0] = op;
20042007
}
2005-
catch (...)
2008+
op->SetAccuracy(VB->GetAccuracyRequested());
2009+
20062010
{
2007-
std::exception_ptr ex = std::current_exception();
2008-
// if MakeOperator throws an exception, we can't complete this request. To make it
2009-
// isn't tried again, we have to clear PendingGetRequests. Also cleanup
2010-
// Read.DestinationAddr.
2011-
PendingGetRequests.clear();
2012-
if (freeAddr)
2013-
{
2014-
free((char *)Read.DestinationAddr);
2015-
}
2016-
std::rethrow_exception(ex);
2011+
std::lock_guard<std::mutex> lockGuard(mutexDecompress);
2012+
core::Decompress(
2013+
IncomingData,
2014+
((MetaArrayRecOperator *)writer_meta_base)->DataBlockSize[Read.BlockID],
2015+
decompressBuffer.data(), Req.MemSpace, op, m_Engine, VB);
2016+
VB->m_AccuracyProvided = op->GetAccuracy();
20172017
}
2018-
VB->m_Operations.resize(1);
2019-
VB->m_Operations[0] = op;
2018+
IncomingData = decompressBuffer.data();
2019+
VirtualIncomingData = IncomingData;
20202020
}
2021-
op->SetAccuracy(VB->GetAccuracyRequested());
2022-
2021+
catch (...)
20232022
{
2024-
std::lock_guard<std::mutex> lockGuard(mutexDecompress);
2025-
core::Decompress(
2026-
IncomingData,
2027-
((MetaArrayRecOperator *)writer_meta_base)->DataBlockSize[Read.BlockID],
2028-
decompressBuffer.data(), Req.MemSpace, op, m_Engine, VB);
2029-
VB->m_AccuracyProvided = op->GetAccuracy();
2023+
std::exception_ptr ex = std::current_exception();
2024+
// if MakeOperator or Decompress throws an exception, we can't complete this request. To
2025+
// make it isn't tried again, we have to clear PendingGetRequests. Also cleanup
2026+
// Read.DestinationAddr.
2027+
PendingGetRequests.clear();
2028+
if (freeAddr)
2029+
{
2030+
free((char *)Read.DestinationAddr);
2031+
}
2032+
std::rethrow_exception(ex);
20302033
}
2031-
IncomingData = decompressBuffer.data();
2032-
VirtualIncomingData = IncomingData;
20332034
}
20342035
if (Req.Start.size())
20352036
{

source/utils/bpls/bpls.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <errno.h>
3333

3434
#include "adios2/helper/adiosLog.h"
35+
#include "adios2/operator/plugin/PluginOperator.h"
3536

3637
#if defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
3738
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900
@@ -1014,7 +1015,16 @@ int doList_operators(core::Engine *fp, core::IO *io)
10141015
ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation)
10151016
#undef declare_template_instantiation
10161017
op = e.var->m_Operations[0];
1017-
OpStrings.insert(op->m_TypeString);
1018+
auto plugin = dynamic_cast<plugin::PluginOperator *>(op.get());
1019+
if (plugin)
1020+
{
1021+
OpStrings.insert(plugin->m_PluginLibrary + "(" + plugin->m_PluginName +
1022+
")");
1023+
}
1024+
else
1025+
{
1026+
OpStrings.insert(op->m_TypeString);
1027+
}
10181028
}
10191029
catch (std::invalid_argument const &ex)
10201030
{
@@ -1025,6 +1035,19 @@ int doList_operators(core::Engine *fp, core::IO *io)
10251035
std::string op = text.substr(start, end);
10261036
OpStrings.insert(op);
10271037
}
1038+
catch (std::runtime_error const &ex)
1039+
{
1040+
// plugin operator we didn't find Parse the text
1041+
std::string text = ex.what();
1042+
size_t libstart = text.find("library \"") + 9;
1043+
size_t libend = text.substr(libstart).find('"');
1044+
std::string lib = text.substr(libstart, libend);
1045+
std::string rem = text.substr(libstart + libend + 1);
1046+
size_t opstart = rem.find('"') + 1;
1047+
size_t opend = rem.substr(opstart).find('"');
1048+
std::string op = rem.substr(opstart, opend);
1049+
OpStrings.insert(lib + "(" + op + ")");
1050+
}
10281051
}
10291052
}
10301053
}

0 commit comments

Comments
 (0)