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

Added naive engine mode for SSC #3109

Merged
merged 7 commits into from
Mar 16, 2022
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
2 changes: 2 additions & 0 deletions source/adios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ if(ADIOS2_HAVE_MPI)
engine/ssc/SscWriter.cpp
engine/ssc/SscWriterBase.cpp
engine/ssc/SscWriterGeneric.cpp
engine/ssc/SscWriterNaive.cpp
engine/ssc/SscReader.cpp
engine/ssc/SscReaderBase.cpp
engine/ssc/SscReaderGeneric.cpp
engine/ssc/SscReaderNaive.cpp
)
set_property(TARGET adios2_core_mpi PROPERTY EXPORT_NAME core_mpi)
set_property(TARGET adios2_core_mpi PROPERTY OUTPUT_NAME adios2${ADIOS2_LIBRARY_SUFFIX}_core_mpi)
Expand Down
220 changes: 117 additions & 103 deletions source/adios2/engine/ssc/SscHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,55 +243,36 @@ void SerializeAttributes(IO &input, Buffer &output)
}
}

void Deserialize(const Buffer &input, BlockVecVec &output, IO &io,
const bool regVars, const bool regAttrs)
void DeserializeAttribute(const Buffer &input, uint64_t &pos, IO &io,
const bool regIO)
{
for (auto &i : output)
{
i.clear();
}
const DataType type = static_cast<DataType>(input[pos]);
++pos;

uint64_t pos = 2;
uint8_t nameSize = input[pos];
++pos;

uint64_t blockSize = input.value<uint64_t>(pos);
std::vector<char> namev(nameSize);
std::memcpy(namev.data(), input.data(pos), nameSize);
std::string name = std::string(namev.begin(), namev.end());
pos += nameSize;

uint64_t size = input.value<uint64_t>(pos);
pos += 8;

while (pos < blockSize)
if (regIO)
{

uint8_t shapeId = input[pos];
++pos;

if (shapeId == 66)
const auto &attributes = io.GetAttributes();
auto it = attributes.find(name);
if (it == attributes.end())
{
const DataType type = static_cast<DataType>(input[pos]);
++pos;

uint8_t nameSize = input[pos];
++pos;

std::vector<char> namev(nameSize);
std::memcpy(namev.data(), input.data(pos), nameSize);
std::string name = std::string(namev.begin(), namev.end());
pos += nameSize;

uint64_t size = input.value<uint64_t>(pos);
pos += 8;

if (regAttrs)
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (type == DataType::String)
{
const auto &attributes = io.GetAttributes();
auto it = attributes.find(name);
if (it == attributes.end())
{
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (type == DataType::String)
{
io.DefineAttribute<std::string>(
name, std::string(input.data<char>(pos), size));
}
io.DefineAttribute<std::string>(
name, std::string(input.data<char>(pos), size));
}
#define declare_type(T) \
else if (type == helper::GetDataType<T>()) \
{ \
Expand All @@ -304,75 +285,73 @@ void Deserialize(const Buffer &input, BlockVecVec &output, IO &io,
io.DefineAttribute<T>(name, input.data<T>(pos), size / sizeof(T)); \
} \
}
ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(declare_type)
ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(declare_type)
#undef declare_type
else
{
helper::Throw<std::runtime_error>(
"Engine", "SscHelper", "Deserialize",
"unknown attribute data type");
}
}
else
{
helper::Throw<std::runtime_error>(
"Engine", "SscHelper", "Deserialize",
"unknown attribute data type");
}
pos += size;
}
else
{
int rank = input.value<int>(pos);
pos += 4;
output[rank].emplace_back();
auto &b = output[rank].back();
b.shapeId = static_cast<ShapeID>(shapeId);
}
pos += size;
}

uint8_t nameSize = input[pos];
++pos;
void DeserializeVariable(const Buffer &input, const ShapeID shapeId,
uint64_t &pos, BlockInfo &b, IO &io, const bool regIO)
{
b.shapeId = static_cast<ShapeID>(shapeId);

std::vector<char> name(nameSize);
std::memcpy(name.data(), input.data(pos), nameSize);
b.name = std::string(name.begin(), name.end());
pos += nameSize;
uint8_t nameSize = input[pos];
++pos;

b.type = static_cast<DataType>(input[pos]);
++pos;
std::vector<char> name(nameSize);
std::memcpy(name.data(), input.data(pos), nameSize);
b.name = std::string(name.begin(), name.end());
pos += nameSize;

uint8_t shapeSize = input[pos];
++pos;
b.shape.resize(shapeSize);
b.start.resize(shapeSize);
b.count.resize(shapeSize);
b.type = static_cast<DataType>(input[pos]);
++pos;

std::memcpy(b.shape.data(), input.data(pos), 8 * shapeSize);
pos += 8 * shapeSize;
uint8_t shapeSize = input[pos];
++pos;
b.shape.resize(shapeSize);
b.start.resize(shapeSize);
b.count.resize(shapeSize);

std::memcpy(b.start.data(), input.data(pos), 8 * shapeSize);
pos += 8 * shapeSize;
std::memcpy(b.shape.data(), input.data(pos), 8 * shapeSize);
pos += 8 * shapeSize;

std::memcpy(b.count.data(), input.data(pos), 8 * shapeSize);
pos += 8 * shapeSize;
std::memcpy(b.start.data(), input.data(pos), 8 * shapeSize);
pos += 8 * shapeSize;

b.bufferStart = input.value<uint64_t>(pos);
pos += 8;
std::memcpy(b.count.data(), input.data(pos), 8 * shapeSize);
pos += 8 * shapeSize;

b.bufferCount = input.value<uint64_t>(pos);
pos += 8;
b.bufferStart = input.value<uint64_t>(pos);
pos += 8;

uint8_t valueSize = input[pos];
pos++;
b.value.resize(valueSize);
if (valueSize > 0)
{
std::memcpy(b.value.data(), input.data() + pos, valueSize);
pos += valueSize;
}
b.bufferCount = input.value<uint64_t>(pos);
pos += 8;

if (regVars)
{
if (b.type == DataType::None)
{
helper::Throw<std::runtime_error>(
"Engine", "SscHelper", "Deserialize",
"unknown variable data type");
}
uint8_t valueSize = input[pos];
pos++;
b.value.resize(valueSize);
if (valueSize > 0)
{
std::memcpy(b.value.data(), input.data() + pos, valueSize);
pos += valueSize;
}

if (regIO)
{
if (b.type == DataType::None)
{
helper::Throw<std::runtime_error>("Engine", "SscHelper",
"Deserialize",
"unknown variable data type");
}
#define declare_type(T) \
else if (b.type == helper::GetDataType<T>()) \
{ \
Expand Down Expand Up @@ -404,15 +383,50 @@ void Deserialize(const Buffer &input, BlockVecVec &output, IO &io,
} \
} \
}
ADIOS2_FOREACH_STDTYPE_1ARG(declare_type)
ADIOS2_FOREACH_STDTYPE_1ARG(declare_type)
#undef declare_type
else
{
helper::Throw<std::runtime_error>(
"Engine", "SscHelper", "Deserialize",
"unknown variable data type");
}
}
else
{
helper::Throw<std::runtime_error>("Engine", "SscHelper",
"Deserialize",
"unknown variable data type");
}
}
}

void Deserialize(const Buffer &input, BlockVecVec &output, IO &io,
const bool regVars, const bool regAttrs)
{
for (auto &i : output)
{
i.clear();
}

uint64_t pos = 2;

uint64_t blockSize = input.value<uint64_t>(pos);

pos += 8;

while (pos < blockSize)
{

uint8_t shapeId = input[pos];
++pos;

if (shapeId == 66)
{
DeserializeAttribute(input, pos, io, regAttrs);
}
else
{
int rank = input.value<int>(pos);
pos += 4;
output[rank].emplace_back();
auto &b = output[rank].back();

DeserializeVariable(input, static_cast<ShapeID>(shapeId), pos, b,
io, regVars);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions source/adios2/engine/ssc/SscHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ RankPosMap CalculateOverlap(BlockVecVec &globalPattern,

void SerializeVariables(const BlockVec &input, Buffer &output, const int rank);
void SerializeAttributes(IO &input, Buffer &output);
void DeserializeVariable(const Buffer &input, const ShapeID shapeId,
uint64_t &pos, BlockInfo &b, IO &io, const bool regIO);
void DeserializeAttribute(const Buffer &input, uint64_t &pos, IO &io,
const bool regIO);
void Deserialize(const Buffer &input, BlockVecVec &output, IO &io,
const bool regVars, const bool regAttrs);
void AggregateMetadata(const Buffer &localBuffer, Buffer &globalBuffer,
Expand Down
11 changes: 8 additions & 3 deletions source/adios2/engine/ssc/SscReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "SscReader.h"
#include "SscReaderGeneric.h"
#include "SscReaderNaive.h"
#include "adios2/helper/adiosCommMPI.h"
#include "adios2/helper/adiosString.h"
#include <adios2-perfstubs-interface.h>
Expand Down Expand Up @@ -37,19 +38,23 @@ SscReader::SscReader(IO &io, const std::string &name, const Mode mode,
}
else if (m_EngineMode == "naive")
{
m_EngineInstance = std::make_shared<ssc::SscReaderNaive>(
io, name, mode, CommAsMPI(m_Comm));
}
}

StepStatus SscReader::BeginStep(StepMode stepMode, const float timeoutSeconds)
{
PERFSTUBS_SCOPED_TIMER_FUNC();

helper::Log("Engine", "SSCReader", "BeginStep",
auto ret = m_EngineInstance->BeginStep(stepMode, timeoutSeconds,
m_ReaderSelectionsLocked);

helper::Log("Engine", "SscReader", "BeginStep",
std::to_string(CurrentStep()), 0, m_Comm.Rank(), 5, m_Verbosity,
helper::LogMode::INFO);

return m_EngineInstance->BeginStep(stepMode, timeoutSeconds,
m_ReaderSelectionsLocked);
return ret;
}

size_t SscReader::CurrentStep() const
Expand Down
1 change: 0 additions & 1 deletion source/adios2/engine/ssc/SscReaderGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

#include "SscReaderGeneric.tcc"
#include "adios2/helper/adiosMemory.h"

namespace adios2
{
Expand Down
5 changes: 5 additions & 0 deletions source/adios2/engine/ssc/SscReaderGeneric.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Author: Jason Wang
*/

#ifndef ADIOS2_ENGINE_SSCREADERGENERIC_TCC_
#define ADIOS2_ENGINE_SSCREADERGENERIC_TCC_

#include "SscReaderGeneric.h"
#include "adios2/helper/adiosMemory.h"

Expand Down Expand Up @@ -212,3 +215,5 @@ SscReaderGeneric::BlocksInfoCommon(const Variable<T> &variable,
}
}
}

#endif // ADIOS2_ENGINE_SSCREADERGENERIC_TCC_
Loading