Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak min blocks interface to avoid leak in Shape() #3458

Merged
merged 3 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/adios2/core/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,10 @@ class Engine
}

// in this call, Step is RELATIVE, not absolute
virtual Dims *VarShape(const VariableBase &, const size_t Step) const
virtual bool VarShape(const VariableBase &, const size_t Step,
Dims &Shape) const
{
return nullptr;
return false;
}

virtual bool VariableMinMax(const VariableBase &, const size_t Step,
Expand Down
8 changes: 3 additions & 5 deletions source/adios2/core/VariableBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,10 @@ Dims VariableBase::Shape(const size_t step) const

if (m_Engine)
{
Dims tmp;
// see if the engine implements Variable Shape inquiry
auto ShapePtr = m_Engine->VarShape(*this, step);
if (ShapePtr)
{
return *ShapePtr;
}
if (m_Engine->VarShape(*this, step, tmp))
return tmp;
}
if (m_FirstStreamingStep && step == adios2::EngineCurrentStep)
{
Expand Down
5 changes: 3 additions & 2 deletions source/adios2/engine/bp5/BP5Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,10 @@ MinVarInfo *BP5Reader::MinBlocksInfo(const VariableBase &Var,
return m_BP5Deserializer->MinBlocksInfo(Var, Step);
}

Dims *BP5Reader::VarShape(const VariableBase &Var, const size_t Step) const
bool BP5Reader::VarShape(const VariableBase &Var, const size_t Step,
Dims &Shape) const
{
return m_BP5Deserializer->VarShape(Var, Step);
return m_BP5Deserializer->VarShape(Var, Step, Shape);
}

bool BP5Reader::VariableMinMax(const VariableBase &Var, const size_t Step,
Expand Down
3 changes: 2 additions & 1 deletion source/adios2/engine/bp5/BP5Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class BP5Reader : public BP5Engine, public Engine
void PerformGets() final;

MinVarInfo *MinBlocksInfo(const VariableBase &, const size_t Step) const;
Dims *VarShape(const VariableBase &, const size_t Step) const;
bool VarShape(const VariableBase &Var, const size_t Step,
Dims &Shape) const;
bool VariableMinMax(const VariableBase &, const size_t Step,
MinMaxStruct &MinMax);

Expand Down
7 changes: 4 additions & 3 deletions source/adios2/engine/sst/SstReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,13 @@ void SstReader::DoGetStructDeferred(VariableStruct &variable, void *data)
m_BP5Deserializer->QueueGet(variable, data);
}

Dims *SstReader::VarShape(const VariableBase &Var, const size_t Step) const
bool SstReader::VarShape(const VariableBase &Var, const size_t Step,
Dims &Shape) const
{
if (m_WriterMarshalMethod != SstMarshalBP5)
return nullptr;
return false;

return m_BP5Deserializer->VarShape(Var, Step);
return m_BP5Deserializer->VarShape(Var, Step, Shape);
}

bool SstReader::VariableMinMax(const VariableBase &Var, const size_t Step,
Expand Down
3 changes: 2 additions & 1 deletion source/adios2/engine/sst/SstReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class SstReader : public Engine
void PerformGets();
void Flush(const int transportIndex = -1) final;
MinVarInfo *MinBlocksInfo(const VariableBase &, const size_t Step) const;
Dims *VarShape(const VariableBase &, const size_t Step) const;
bool VarShape(const VariableBase &Var, const size_t Step,
Dims &Shape) const;
bool VariableMinMax(const VariableBase &, const size_t Step,
MinMaxStruct &MinMax);

Expand Down
18 changes: 10 additions & 8 deletions source/adios2/toolkit/format/bp5/BP5Deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ void *BP5Deserializer::VarSetup(core::Engine *engine, const char *variableName,
{ \
core::Variable<T> *variable = \
&(engine->m_IO.DefineVariable<T>(variableName)); \
engine->RegisterCreatedVariable(variable); \
variable->SetData((T *)data); \
variable->m_AvailableStepsCount = 1; \
return (void *)variable; \
Expand Down Expand Up @@ -547,6 +548,7 @@ void *BP5Deserializer::ArrayVarSetup(core::Engine *engine,
{
core::VariableStruct *variable = &(engine->m_IO.DefineStructVariable(
variableName, *Def, VecShape, VecStart, VecCount));
engine->RegisterCreatedVariable(variable);
variable->m_ReadStructDefinition = ReaderDef;
return (void *)variable;
}
Expand All @@ -555,6 +557,7 @@ void *BP5Deserializer::ArrayVarSetup(core::Engine *engine,
{ \
core::Variable<T> *variable = \
&(engine->m_IO.DefineVariable<T>(variableName)); \
engine->RegisterCreatedVariable(variable); \
variable->m_Shape = VecShape; \
variable->m_Start = VecStart; \
variable->m_Count = VecCount; \
Expand Down Expand Up @@ -2100,13 +2103,13 @@ void BP5Deserializer::GetAbsoluteSteps(const VariableBase &Var,
}
}

Dims *BP5Deserializer::VarShape(const VariableBase &Var,
const size_t RelStep) const
bool BP5Deserializer::VarShape(const VariableBase &Var, const size_t RelStep,
Dims &Shape) const
{
BP5VarRec *VarRec = LookupVarByKey((void *)&Var);
if (VarRec->OrigShapeID != ShapeID::GlobalArray)
{
return nullptr;
return false;
}
size_t AbsStep = RelStep;
if (m_RandomAccessMode)
Expand All @@ -2127,16 +2130,15 @@ Dims *BP5Deserializer::VarShape(const VariableBase &Var,
(MetaArrayRec *)GetMetadataBase(VarRec, AbsStep, WriterRank);
if (writer_meta_base && writer_meta_base->Shape)
{
Dims *Shape = new Dims();
Shape->reserve(writer_meta_base->Dims);
Shape.resize(writer_meta_base->Dims);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Shape has a bigger size than the writer_meta_base, resize will remove the values but not update the size. Would this be a problem? This is not the case in any of the test so I assume no, but just want to point this out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't think it would be a problem. In all the current uses, Shape passed in by reference is an fresh Dims value with default size 0. So, I think no worries...

for (size_t i = 0; i < writer_meta_base->Dims; i++)
{
Shape->push_back(writer_meta_base->Shape[i]);
Shape[i] = writer_meta_base->Shape[i];
}
return Shape;
return true;
}
}
return nullptr;
return false;
}

bool BP5Deserializer::VariableMinMax(const VariableBase &Var, const size_t Step,
Expand Down
2 changes: 1 addition & 1 deletion source/adios2/toolkit/format/bp5/BP5Deserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class BP5Deserializer : virtual public BP5Base
MinVarInfo *AllRelativeStepsMinBlocksInfo(const VariableBase &var);
MinVarInfo *AllStepsMinBlocksInfo(const VariableBase &var);
MinVarInfo *MinBlocksInfo(const VariableBase &Var, const size_t Step);
Dims *VarShape(const VariableBase &, const size_t Step) const;
bool VarShape(const VariableBase &, const size_t Step, Dims &Shape) const;
bool VariableMinMax(const VariableBase &var, const size_t Step,
MinMaxStruct &MinMax);
void GetAbsoluteSteps(const VariableBase &variable,
Expand Down
2 changes: 2 additions & 0 deletions testing/adios2/engine/staging-common/TestCommonRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ TEST_F(CommonReadTest, ADIOS2CommonRead1D8)
}
ts = std::chrono::steady_clock::now();
adios2::StepStatus status = engine.BeginStep();
auto av = io.AvailableVariables();

Seconds timeBeginStep = std::chrono::steady_clock::now() - ts;
begin_statuses.push_back(status);
begin_times.push_back(timeBeginStep);
Expand Down