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

Add MinBlocksInfo to BP5 writer engine #3794

Merged
merged 2 commits into from
Sep 11, 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
50 changes: 50 additions & 0 deletions source/adios2/common/ADIOSTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,54 @@ int TypeElementSize(DataType adiosvartype)
}
}

static void PrintMBI(std::ostream &os, const MinBlockInfo &blk, int Dims)
{
os << "Writer: " << blk.WriterID << ", Blk: " << blk.BlockID << ", Start: {";
if ((Dims == 0) || (blk.Start == NULL))
os << "NULL";
else
{
for (int i = 0; i < Dims; i++)
{
os << blk.Start[i];
if (i < Dims - 1)
os << ", ";
}
}
os << "}, Count: {";

if ((Dims == 0) || (blk.Count == NULL))
os << "NULL";
else
{
for (int i = 0; i < Dims; i++)
{
os << blk.Count[i];
if (i < Dims - 1)
os << ", ";
}
}
os << "}, Data: " << (void *)blk.BufferP << std::endl;
}

void PrintMVI(std::ostream &os, const MinVarInfo &mvi)
{
os << "Step: " << mvi.Step << " Dims: " << mvi.Dims << " Shape: {";
if ((mvi.Dims == 0) || (mvi.Shape == NULL))
os << "NULL";
else
{
for (int i = 0; i < mvi.Dims; i++)
{
os << mvi.Shape[i];
if (i < mvi.Dims - 1)
os << ", ";
}
}
os << "}, BlockCount: " << mvi.BlocksInfo.size() << " ";
for (const auto &blk : mvi.BlocksInfo)
PrintMBI(os, blk, mvi.Dims);
os << std::endl;
}

} // end namespace adios2
3 changes: 3 additions & 0 deletions source/adios2/common/ADIOSTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ struct MinBlockInfo
MinMaxStruct MinMax;
void *BufferP = NULL;
};

struct MinVarInfo
{
size_t Step;
Expand All @@ -229,6 +230,8 @@ struct MinVarInfo
}
};

void PrintMVI(std::ostream &os, const MinVarInfo &mvi);

// adios defaults
#ifdef _WIN32
const std::string DefaultFileLibrary("fstream");
Expand Down
27 changes: 25 additions & 2 deletions source/adios2/engine/bp5/BP5Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,33 @@ void BP5Writer::MarshalAttributes()

void BP5Writer::EndStep()
{
/* Seconds ts = Now() - m_EngineStart;
std::cout << "END STEP starts at: " << ts.count() << std::endl; */
m_BetweenStepPairs = false;
PERFSTUBS_SCOPED_TIMER("BP5Writer::EndStep");
m_Profiler.Start("ES");

m_Profiler.Start("ES_close");
MarshalAttributes();

#ifdef NOT_DEF
anagainaru marked this conversation as resolved.
Show resolved Hide resolved
const auto &vars = m_IO.GetVariables();
for (const auto &varPair : vars)
{
auto baseVar = varPair.second.get();
auto mvi = WriterMinBlocksInfo(*baseVar);
if (mvi)
{
std::cout << "Info for Variable " << varPair.first << std::endl;
PrintMVI(std::cout, *mvi);
if (baseVar->m_Type == DataType::Double)
std::cout << "Double value is " << *((double *)mvi->BlocksInfo[0].BufferP)
<< std::endl;
delete mvi;
}
else
std::cout << "Variable " << varPair.first << " not written on this step" << std::endl;
}
#endif

// true: advances step
auto TSInfo = m_BP5Serializer.CloseTimestep((int)m_WriterStep,
m_Parameters.AsyncWrite || m_Parameters.DirectIO);
Expand Down Expand Up @@ -668,6 +686,11 @@ void BP5Writer::Init()
InitBPBuffer();
}

MinVarInfo *BP5Writer::WriterMinBlocksInfo(const core::VariableBase &Var)
{
return m_BP5Serializer.MinBlocksInfo(Var);
}

void BP5Writer::InitParameters()
{
ParseParams(m_IO, m_Parameters);
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/engine/bp5/BP5Writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class BP5Writer : public BP5Engine, public core::Engine
*/
void NotifyEngineAttribute(std::string name, AttributeBase *Attr, void *data) noexcept;

MinVarInfo *WriterMinBlocksInfo(const VariableBase &);

void EnterComputationBlock() noexcept;
/** Inform about computation block through User->ADIOS->IO */
void ExitComputationBlock() noexcept;
Expand Down
69 changes: 68 additions & 1 deletion source/adios2/toolkit/format/bp5/BP5Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void BP5Serializer::Init()
((BP5MetadataInfoStruct *)MetadataBuf)->BitField = (std::size_t *)malloc(sizeof(size_t));
((BP5MetadataInfoStruct *)MetadataBuf)->DataBlockSize = 0;
}
BP5Serializer::BP5WriterRec BP5Serializer::LookupWriterRec(void *Key)
BP5Serializer::BP5WriterRec BP5Serializer::LookupWriterRec(void *Key) const
{
for (int i = 0; i < Info.RecCount; i++)
{
Expand Down Expand Up @@ -858,6 +858,73 @@ void BP5Serializer::Marshal(void *Variable, const char *Name, const DataType Typ
}
}

MinVarInfo *BP5Serializer::MinBlocksInfo(const core::VariableBase &Var)
{
BP5WriterRec VarRec = LookupWriterRec((void *)&Var);

if (!VarRec)
return NULL;

MinVarInfo *MV = new MinVarInfo((int)VarRec->DimCount, (size_t *)Var.m_Shape.data());

BP5MetadataInfoStruct *MBase = (struct BP5MetadataInfoStruct *)MetadataBuf;

int AlreadyWritten = BP5BitfieldTest(MBase, VarRec->FieldID);

if (!AlreadyWritten)
return MV;

if (Var.m_SingleValue)
{
// single value case
MinBlockInfo Blk;
Blk.MinMax.Init(Var.m_Type);
Blk.WriterID = (int)-1;
Blk.BlockID = 0;
Blk.Start = NULL;
Blk.Count = NULL;
if (Var.m_Type != DataType::String)
{
Blk.BufferP = (char *)(MetadataBuf) + VarRec->MetaOffset;
}
else
{
char **StrPtr = (char **)((char *)(MetadataBuf) + VarRec->MetaOffset);
Blk.BufferP = *StrPtr;
}
MV->BlocksInfo.push_back(Blk);
}
else
{
// everything else
MetaArrayRec *MetaEntry = (MetaArrayRec *)((char *)(MetadataBuf) + VarRec->MetaOffset);
for (size_t b = 0; b < MetaEntry->BlockCount; b++)
{
MinBlockInfo Blk;
Blk.MinMax.Init(Var.m_Type);
Blk.WriterID = (int)-1;
Blk.BlockID = 0;
Blk.Start = NULL;
if (MetaEntry->Offsets)
{
Blk.Start = &(MetaEntry->Offsets[b * MetaEntry->Dims]);
}
Blk.Count = &(MetaEntry->Count[b * MetaEntry->Dims]);
if (MetaEntry->DataBlockLocation[b] < m_PriorDataBufferSizeTotal)
{
Blk.BufferP = (void *)(intptr_t)(-1); // data is out of memory
}
else
{
Blk.BufferP = CurDataBuffer->GetPtr(MetaEntry->DataBlockLocation[b] -
m_PriorDataBufferSizeTotal);
}
MV->BlocksInfo.push_back(Blk);
}
}
return MV;
}

void BP5Serializer::MarshalAttribute(const char *Name, const DataType Type, size_t ElemSize,
size_t ElemCount, const void *Data)
{
Expand Down
4 changes: 3 additions & 1 deletion source/adios2/toolkit/format/bp5/BP5Serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class BP5Serializer : virtual public BP5Base

size_t DebugGetDataBufferSize() const;

MinVarInfo *MinBlocksInfo(const core::VariableBase &Var);

int m_StatsLevel = 1;

/* Variables to help appending to existing file */
Expand Down Expand Up @@ -204,7 +206,7 @@ class BP5Serializer : virtual public BP5Base

size_t m_PriorDataBufferSizeTotal = 0;

BP5WriterRec LookupWriterRec(void *Key);
BP5WriterRec LookupWriterRec(void *Key) const;
BP5WriterRec CreateWriterRec(void *Variable, const char *Name, DataType Type, size_t ElemSize,
size_t DimCount);
void ValidateWriterRec(BP5WriterRec Rec, void *Variable);
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/toolkit/format/buffer/BufferV.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class BufferV

virtual void *GetPtr(int bufferIdx, size_t posInBuffer) = 0;

virtual void *GetPtr(size_t overallPosInVector) = 0;

protected:
std::vector<char> zero;
const bool m_AlwaysCopy = false;
Expand Down
24 changes: 24 additions & 0 deletions source/adios2/toolkit/format/buffer/chunk/ChunkV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,30 @@ void *ChunkV::GetPtr(int bufferIdx, size_t posInBuffer)
}
}

void *ChunkV::GetPtr(size_t OverallPosInBuffer)
{
int bufferIdx = 0;
if (DataV.size() == 0)
return nullptr;
while (DataV[bufferIdx].Size <= OverallPosInBuffer)
{
OverallPosInBuffer -= DataV[bufferIdx].Size;
bufferIdx++;
if (static_cast<size_t>(bufferIdx) > DataV.size())
{
helper::Throw<std::invalid_argument>(
"Toolkit", "format::ChunkV", "GetPtr",
"ChunkV::GetPtr(" + std::to_string(OverallPosInBuffer) +
") refers to a non-existing or deferred memory chunk.");
return nullptr;
}
}
if (DataV[bufferIdx].External)
return ((char *)DataV[bufferIdx].External) + OverallPosInBuffer;

return (void *)((char *)DataV[bufferIdx].Base + OverallPosInBuffer);
}

std::vector<core::iovec> ChunkV::DataVec() noexcept
{
std::vector<core::iovec> iov(DataV.size());
Expand Down
1 change: 1 addition & 0 deletions source/adios2/toolkit/format/buffer/chunk/ChunkV.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ChunkV : public BufferV
virtual void DownsizeLastAlloc(const size_t oldSize, const size_t newSize);

virtual void *GetPtr(int bufferIdx, size_t posInBuffer);
virtual void *GetPtr(size_t OverallPosInBuffer);

void CopyDataToBuffer(const size_t size, const void *buf, size_t pos, MemorySpace MemSpace);

Expand Down
2 changes: 2 additions & 0 deletions source/adios2/toolkit/format/buffer/malloc/MallocV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ void *MallocV::GetPtr(int bufferIdx, size_t posInBuffer)
}
}

void *MallocV::GetPtr(size_t posInBuffer) { return m_InternalBlock + posInBuffer; }

std::vector<core::iovec> MallocV::DataVec() noexcept
{
std::vector<core::iovec> iov(DataV.size());
Expand Down
1 change: 1 addition & 0 deletions source/adios2/toolkit/format/buffer/malloc/MallocV.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MallocV : public BufferV
void DownsizeLastAlloc(const size_t oldSize, const size_t newSize);

virtual void *GetPtr(int bufferIdx, size_t posInBuffer);
virtual void *GetPtr(size_t posInBuffer);

private:
char *m_InternalBlock = NULL;
Expand Down
Loading