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 a no-parameter constructor for operator class #2936

Closed
wants to merge 6 commits into from
Closed
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/core/Operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Operator::Operator(const std::string type, const Params &parameters)
{
}

Operator::Operator(const std::string type) : m_Type(type) {}

void Operator::SetParameter(const std::string key,
const std::string value) noexcept
{
Expand Down
6 changes: 2 additions & 4 deletions source/adios2/core/Operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ class Operator
/** From derived class */
const std::string m_Type;

/**
* Base class constructor
* @param type from derived class object: e.g. bzip2, zfp, callback
*/
Operator(const std::string type, const Params &parameters);

Operator(const std::string type);

virtual ~Operator() = default;

void SetParameter(const std::string key, const std::string value) noexcept;
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/operator/compress/CompressBZIP2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ CompressBZIP2::CompressBZIP2(const Params &parameters)
{
}

CompressBZIP2::CompressBZIP2() : Operator("bzip2") {}

size_t CompressBZIP2::Operate(const char *dataIn, const Dims &blockStart,
const Dims &blockCount, DataType type,
char *bufferOut, const Params &parameters)
Expand Down
5 changes: 2 additions & 3 deletions source/adios2/operator/compress/CompressBZIP2.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ class CompressBZIP2 : public Operator
{

public:
/**
* Unique constructor
*/
CompressBZIP2(const Params &parameters);

CompressBZIP2();

~CompressBZIP2() = default;

/**
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/operator/compress/CompressBlosc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ CompressBlosc::CompressBlosc(const Params &parameters)
{
}

CompressBlosc::CompressBlosc() : Operator("blosc") {}

size_t CompressBlosc::Operate(const char *dataIn, const Dims &blockStart,
const Dims &blockCount, const DataType type,
char *bufferOut, const Params &parameters)
Expand Down
5 changes: 2 additions & 3 deletions source/adios2/operator/compress/CompressBlosc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ class CompressBlosc : public Operator
{

public:
/**
* Unique constructor
*/
CompressBlosc(const Params &parameters);

CompressBlosc();

~CompressBlosc() = default;

/**
Expand Down
210 changes: 106 additions & 104 deletions source/adios2/operator/compress/CompressLibPressio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,111 +27,12 @@ namespace core
namespace compress
{

size_t CompressLibPressio::Operate(const char *dataIn, const Dims &blockStart,
const Dims &blockCount, const DataType type,
char *bufferOut, const Params &parameters)
{
const uint8_t bufferVersion = 1;
size_t bufferOutOffset = 0;

// Universal operator metadata
PutParameter(bufferOut, bufferOutOffset, OperatorType::LIBPRESSIO);
PutParameter(bufferOut, bufferOutOffset, bufferVersion);
PutParameter(bufferOut, bufferOutOffset, static_cast<uint16_t>(0));
// Universal operator metadata end

const size_t ndims = blockCount.size();

// zfp V1 metadata
PutParameter(bufferOut, bufferOutOffset, ndims);
for (const auto &d : blockCount)
{
PutParameter(bufferOut, bufferOutOffset, d);
}
PutParameter(bufferOut, bufferOutOffset, type);
PutParameter(bufferOut, bufferOutOffset,
static_cast<uint8_t>(pressio_major_version()));
PutParameter(bufferOut, bufferOutOffset,
static_cast<uint8_t>(pressio_minor_version()));
PutParameter(bufferOut, bufferOutOffset,
static_cast<uint8_t>(pressio_patch_version()));
PutParameters(bufferOut, bufferOutOffset, parameters);
// zfp V1 metadata end

auto inputs_dims = adios_to_libpressio_dims(blockCount);
pressio_data *input_buf = pressio_data_new_nonowning(
adios_to_libpressio_dtype(type), const_cast<char *>(dataIn),
inputs_dims.size(), inputs_dims.data());
pressio_data *output_buf =
pressio_data_new_empty(pressio_byte_dtype, 0, nullptr);
pressio_compressor *compressor = nullptr;
try
{
compressor = adios_to_libpressio_compressor(parameters);
}
catch (std::exception &e)
{
pressio_data_free(input_buf);
pressio_data_free(output_buf);
throw;
}

if (pressio_compressor_compress(compressor, input_buf, output_buf) != 0)
{
pressio_data_free(input_buf);
pressio_data_free(output_buf);
throw std::runtime_error(std::string("pressio_compressor_compress: ") +
pressio_compressor_error_msg(compressor));
}

size_t size_in_bytes = 0;
void *bytes = pressio_data_ptr(output_buf, &size_in_bytes);
memcpy(bufferOut + bufferOutOffset, bytes, size_in_bytes);
bufferOutOffset += size_in_bytes;

pressio_data_free(input_buf);
pressio_data_free(output_buf);

return bufferOutOffset;
}

size_t CompressLibPressio::InverseOperate(const char *bufferIn,
const size_t sizeIn, char *dataOut)
CompressLibPressio::CompressLibPressio(const Params &parameters)
: Operator("libpressio", parameters)
{
size_t bufferInOffset = 1; // skip operator type
const uint8_t bufferVersion =
GetParameter<uint8_t>(bufferIn, bufferInOffset);
bufferInOffset += 2; // skip two reserved bytes

if (bufferVersion == 1)
{
return DecompressV1(bufferIn + bufferInOffset, sizeIn - bufferInOffset,
dataOut);
}
else if (bufferVersion == 2)
{
// TODO: if a Version 2 LibPressio buffer is being implemented, put it
// here and keep the DecompressV1 routine for backward compatibility
}
else
{
throw("unknown LibPressio buffer version");
}

return 0;
}

bool CompressLibPressio::IsDataTypeValid(const DataType type) const
{
#define declare_type(T) \
if (helper::GetDataType<T>() == type) \
{ \
return true; \
}
ADIOS2_FOREACH_LIBPRESSIO_TYPE_1ARG(declare_type)
#undef declare_type
return false;
}
CompressLibPressio::CompressLibPressio() : Operator("libpressio") {}

static pressio_dtype adios_to_libpressio_dtype(DataType var_type)
{
Expand Down Expand Up @@ -386,9 +287,110 @@ static pressio_compressor *adios_to_libpressio_compressor(Params const &params)
throw std::runtime_error("missing required \"compressor_id\" setting");
}

CompressLibPressio::CompressLibPressio(const Params &parameters)
: Operator("libpressio", parameters)
size_t CompressLibPressio::Operate(const char *dataIn, const Dims &blockStart,
const Dims &blockCount, const DataType type,
char *bufferOut, const Params &parameters)
{
const uint8_t bufferVersion = 1;
size_t bufferOutOffset = 0;

// Universal operator metadata
PutParameter(bufferOut, bufferOutOffset, OperatorType::LIBPRESSIO);
PutParameter(bufferOut, bufferOutOffset, bufferVersion);
PutParameter(bufferOut, bufferOutOffset, static_cast<uint16_t>(0));
// Universal operator metadata end

const size_t ndims = blockCount.size();

// zfp V1 metadata
PutParameter(bufferOut, bufferOutOffset, ndims);
for (const auto &d : blockCount)
{
PutParameter(bufferOut, bufferOutOffset, d);
}
PutParameter(bufferOut, bufferOutOffset, type);
PutParameter(bufferOut, bufferOutOffset,
static_cast<uint8_t>(pressio_major_version()));
PutParameter(bufferOut, bufferOutOffset,
static_cast<uint8_t>(pressio_minor_version()));
PutParameter(bufferOut, bufferOutOffset,
static_cast<uint8_t>(pressio_patch_version()));
PutParameters(bufferOut, bufferOutOffset, parameters);
// zfp V1 metadata end

auto inputs_dims = adios_to_libpressio_dims(blockCount);
pressio_data *input_buf = pressio_data_new_nonowning(
adios_to_libpressio_dtype(type), const_cast<char *>(dataIn),
inputs_dims.size(), inputs_dims.data());
pressio_data *output_buf =
pressio_data_new_empty(pressio_byte_dtype, 0, nullptr);
pressio_compressor *compressor = nullptr;
try
{
compressor = adios_to_libpressio_compressor(parameters);
}
catch (std::exception &e)
{
pressio_data_free(input_buf);
pressio_data_free(output_buf);
throw;
}

if (pressio_compressor_compress(compressor, input_buf, output_buf) != 0)
{
pressio_data_free(input_buf);
pressio_data_free(output_buf);
throw std::runtime_error(std::string("pressio_compressor_compress: ") +
pressio_compressor_error_msg(compressor));
}

size_t size_in_bytes = 0;
void *bytes = pressio_data_ptr(output_buf, &size_in_bytes);
memcpy(bufferOut + bufferOutOffset, bytes, size_in_bytes);
bufferOutOffset += size_in_bytes;

pressio_data_free(input_buf);
pressio_data_free(output_buf);

return bufferOutOffset;
}

size_t CompressLibPressio::InverseOperate(const char *bufferIn,
const size_t sizeIn, char *dataOut)
{
size_t bufferInOffset = 1; // skip operator type
const uint8_t bufferVersion =
GetParameter<uint8_t>(bufferIn, bufferInOffset);
bufferInOffset += 2; // skip two reserved bytes

if (bufferVersion == 1)
{
return DecompressV1(bufferIn + bufferInOffset, sizeIn - bufferInOffset,
dataOut);
}
else if (bufferVersion == 2)
{
// TODO: if a Version 2 LibPressio buffer is being implemented, put it
// here and keep the DecompressV1 routine for backward compatibility
}
else
{
throw("unknown LibPressio buffer version");
}

return 0;
}

bool CompressLibPressio::IsDataTypeValid(const DataType type) const
{
#define declare_type(T) \
if (helper::GetDataType<T>() == type) \
{ \
return true; \
}
ADIOS2_FOREACH_LIBPRESSIO_TYPE_1ARG(declare_type)
#undef declare_type
return false;
}

size_t CompressLibPressio::DecompressV1(const char *bufferIn,
Expand Down
5 changes: 2 additions & 3 deletions source/adios2/operator/compress/CompressLibPressio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ class CompressLibPressio : public Operator
{

public:
/**
* Unique constructor
*/
CompressLibPressio(const Params &parameters);

CompressLibPressio();

~CompressLibPressio() = default;

/**
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/operator/compress/CompressMGARD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ CompressMGARD::CompressMGARD(const Params &parameters)
{
}

CompressMGARD::CompressMGARD() : Operator("mgard") {}

size_t CompressMGARD::Operate(const char *dataIn, const Dims &blockStart,
const Dims &blockCount, const DataType type,
char *bufferOut, const Params &parameters)
Expand Down
5 changes: 2 additions & 3 deletions source/adios2/operator/compress/CompressMGARD.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ class CompressMGARD : public Operator
{

public:
/**
* Unique constructor
*/
CompressMGARD(const Params &parameters);

CompressMGARD();

~CompressMGARD() = default;

/**
Expand Down
3 changes: 3 additions & 0 deletions source/adios2/operator/compress/CompressPNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ const std::map<std::string, std::set<uint32_t>> CompressPNG::m_BitDepths = {
{"PNG_COLOR_TYPE_GA", {8, 16}}};

// PUBLIC

CompressPNG::CompressPNG(const Params &parameters) : Operator("png", parameters)
{
}

CompressPNG::CompressPNG() : Operator("png") {}

size_t CompressPNG::Operate(const char *dataIn, const Dims &blockStart,
const Dims &blockCount, const DataType type,
char *bufferOut, const Params &parameters)
Expand Down
5 changes: 2 additions & 3 deletions source/adios2/operator/compress/CompressPNG.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ class CompressPNG : public Operator
{

public:
/**
* Unique constructor
*/
CompressPNG(const Params &parameters);

CompressPNG();

~CompressPNG() = default;

/**
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/operator/compress/CompressSZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace compress

CompressSZ::CompressSZ(const Params &parameters) : Operator("sz", parameters) {}

CompressSZ::CompressSZ() : Operator("sz") {}

size_t CompressSZ::Operate(const char *dataIn, const Dims &blockStart,
const Dims &blockCount, const DataType varType,
char *bufferOut, const Params &parameters)
Expand Down
5 changes: 2 additions & 3 deletions source/adios2/operator/compress/CompressSZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ class CompressSZ : public Operator
{

public:
/**
* Unique constructor
*/
CompressSZ(const Params &parameters);

CompressSZ();

~CompressSZ() = default;

/**
Expand Down
7 changes: 7 additions & 0 deletions source/adios2/operator/compress/CompressSirius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ CompressSirius::CompressSirius(const Params &parameters)
m_TierBuffers.resize(m_Tiers);
}

CompressSirius::CompressSirius() : Operator("sirius")
{
m_Tiers = 4;
m_TierBuffersMap.resize(m_Tiers);
m_TierBuffers.resize(m_Tiers);
}

size_t CompressSirius::Operate(const char *dataIn, const Dims &blockStart,
const Dims &blockCount, const DataType varType,
char *bufferOut, const Params &params)
Expand Down
Loading