Skip to content

Commit

Permalink
Allow plugin operators to take advantage of the estimated size API
Browse files Browse the repository at this point in the history
  • Loading branch information
rupertnash committed Feb 26, 2024
1 parent 87fe33e commit 5b0f319
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions source/adios2/operator/plugin/PluginOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ void PluginOperator::PluginInit(const std::string &pluginName, const std::string
m_Impl->m_Plugin = m_Impl->m_HandleCreate(m_Parameters);
}

size_t PluginOperator::GetEstimatedSize(
const size_t ElemCount, const size_t ElemSize,
const size_t ndims, const size_t *dims
) const {
// Need to calculate the size of the header written by Operate and then add our plugin's size.
constexpr size_t commonHeaderSize = sizeof(m_TypeEnum) + sizeof(std::uint8_t) + sizeof(std::uint16_t);

auto& pp = m_Impl->m_PluginParams;
// Want to use std::transform_reduce but C++11
size_t paramsSize = 1; // for the number of parameters
for (auto&&p: pp) {
// Need length and string for key and values.
paramsSize += p.first.size() + p.second.size() + 2;
}

// Plugin's estimate of size so it doesn't need to know about headers.
auto implSize = m_Impl->m_Plugin->GetEstimatedSize(ElemCount, ElemSize, ndims, dims);

return commonHeaderSize + paramsSize + implSize;
}

size_t PluginOperator::Operate(const char *dataIn, const Dims &blockStart, const Dims &blockCount,
const DataType type, char *bufferOut)
{
Expand Down
3 changes: 3 additions & 0 deletions source/adios2/operator/plugin/PluginOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class PluginOperator : public core::Operator
PluginOperator(const Params &parameters);
virtual ~PluginOperator();

size_t GetEstimatedSize(const size_t ElemCount, const size_t ElemSize,
const size_t ndims, const size_t *dims) const override;

size_t Operate(const char *dataIn, const Dims &blockStart, const Dims &blockCount,
const DataType type, char *bufferOut) override;

Expand Down

0 comments on commit 5b0f319

Please sign in to comment.