Skip to content

Commit

Permalink
libpressio version 0.59.0
Browse files Browse the repository at this point in the history
Major Changes

+ Integrated SZAuto https://github.com/szcompressor/szauto.  Thanks to
  Hengzhi Chen and Kai Zhao for contributing it!
  • Loading branch information
Real-Chen-Happy authored and robertu94 committed Mar 4, 2021
1 parent 936ba74 commit a5e40c0
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 2 deletions.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(libpressio VERSION "0.58.0" LANGUAGES CXX C)
project(libpressio VERSION "0.59.0" LANGUAGES CXX C)

#correct was to set a default build type
# https://blog.kitware.com/cmake-and-the-default-build-type/
Expand Down Expand Up @@ -168,6 +168,18 @@ if(LIBPRESSIO_HAS_BIT_GROOMING)
target_link_libraries(libpressio PRIVATE bg ZLIB::ZLIB)
endif()

option(LIBPRESSIO_HAS_SZ_AUTO "build the SZauto plugin" OFF)
if(LIBPRESSIO_HAS_SZ_AUTO)
set(LIBPRESSIO_COMPRESSORS "${LIBPRESSIO_COMPRESSORS} SZauto")
find_package(szauto REQUIRED)
pkg_search_module(ZSTD IMPORTED_TARGET GLOBAL libzstd)
target_sources(libpressio
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/compressors/sz_auto_plugin.cc
)
target_link_libraries(libpressio PRIVATE szauto::sz_cpp)
endif()

option(LIBPRESSIO_HAS_MGARD "build the MGARD plugin" OFF)
if(LIBPRESSIO_HAS_MGARD)
set(LIBPRESSIO_COMPRESSORS "${LIBPRESSIO_COMPRESSORS} mgard")
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ alphabetical order:
+ Justin Sybrant
+ Franck Cappello
+ Jon C. Calhoun
+ Kai Zhao
+ Sheng Di
+ Peter Lindstrom

Expand Down
2 changes: 1 addition & 1 deletion COPYRIGHT.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Copyright © 2021 , UChicago Argonne, LLC
All Rights Reserved
[libpressio, Version 0.58.0]
[libpressio, Version 0.59.0]
Robert Underwood
Argonne National Laboratory

Expand Down
10 changes: 10 additions & 0 deletions docs/PressioOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ option | type | description
`digit_rounding:prec` | int32 | the prec parameter of digit rounding (a number between 0 and 64)



### sz auto


option | type | description
------------------------|-------------|------------
`sz_auto:error_bounds` | double | the error bounds for the compression
`sz_auto:sample_ratio` | float | the sample ratio for the compression


### fpzip


Expand Down
151 changes: 151 additions & 0 deletions src/plugins/compressors/sz_auto_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#include <sstream>
#include "sz_autotuning_3d.hpp"
#include "sz_def.hpp"
#include "sz_utils.hpp"
#include "libpressio_ext/cpp/data.h" //for access to pressio_data structures
#include "libpressio_ext/cpp/compressor.h" //for the libpressio_compressor_plugin class
#include "libpressio_ext/cpp/options.h" // for access to pressio_options
#include "libpressio_ext/cpp/pressio.h" //for the plugin registries
#include "pressio_options.h"
#include "pressio_data.h"
#include "pressio_compressor.h"
#include "std_compat/memory.h"

class sz_auto_plugin: public libpressio_compressor_plugin {
public:
sz_auto_plugin() {
std::stringstream ss;
ss << sz_auto_plugin::major_version() << "." << sz_auto_plugin::minor_version() << "." << sz_auto_plugin::patch_version() << "." << sz_auto_plugin::revision_version();
sz_auto_version = ss.str();
};
struct pressio_options get_options_impl() const override {
struct pressio_options options;
set(options, "SZauto:error_bounds", error_bounds);
set(options, "SZauto:sample_ratio", sample_ratio);
return options;
}

struct pressio_options get_configuration_impl() const override {
struct pressio_options options;
options.set("pressio:thread_safe", static_cast<int>(pressio_thread_safety_multiple));
return options;
}

int set_options_impl(struct pressio_options const& options) override {
get(options, "SZauto:error_bounds", &error_bounds);
get(options, "SZauto:sample_ratio", &sample_ratio);
return 0;
}

int compress_impl(const pressio_data *input, struct pressio_data* output) override {
enum pressio_dtype type = pressio_data_dtype(input);
unsigned long outSize;
void* data = pressio_data_ptr(input, nullptr);
unsigned char* compressed_data;

size_t ndims = pressio_data_num_dimensions(input);
size_t r1 = pressio_data_get_dimension(input, 0);
size_t r2 = pressio_data_get_dimension(input, 1);
size_t r3 = pressio_data_get_dimension(input, 2);

if(ndims != 3)
{
return set_error(2, "Error: SZauto only supports 3d compression");
}

if(type == pressio_float_dtype)
{
compressed_data = sz_compress_autotuning_3d<float>((float*)data, r1, r2, r3, error_bounds, outSize, false, false, false, sample_ratio);
}
else if(type == pressio_double_dtype)
{
compressed_data = sz_compress_autotuning_3d<double>((double*)data, r1, r2, r3, error_bounds, outSize, false, false, false, sample_ratio);
}
else
{
return set_error(2, "Error: SZauto only supports float or double");
}

//that means the compressor is complaining about the parameter
if(compressed_data == NULL)
{
return set_error(2, "Error when SZauto is compressing the data");
}

*output = pressio_data::move(pressio_byte_dtype, compressed_data, 1, &outSize, pressio_data_libc_free_fn, nullptr);
return 0;
}

int decompress_impl(const pressio_data *input, struct pressio_data* output) override {
enum pressio_dtype dtype = pressio_data_dtype(output);

size_t r[] = {
pressio_data_get_dimension(output, 0),
pressio_data_get_dimension(output, 1),
pressio_data_get_dimension(output, 2),
};
size_t ndims = pressio_data_num_dimensions(output);
if(ndims != 3)
{
return set_error(2, "Error: SZauto only supports 3d decompression");
}


size_t compressed_size;
void* compressedBytes = pressio_data_ptr(input, &compressed_size);

void* decompressed_data;
if(dtype == pressio_float_dtype)
{
decompressed_data = sz_decompress_autotuning_3d<float>((unsigned char*)compressedBytes, compressed_size, r[0], r[1], r[2]);
}
else if(dtype == pressio_double_dtype)
{
decompressed_data = sz_decompress_autotuning_3d<double>((unsigned char*)compressedBytes, compressed_size, r[0], r[1], r[2]);
}
else
{
return set_error(2, "Error: SZauto only supports float or double");
}


*output = pressio_data::move(dtype, decompressed_data, ndims, r, pressio_data_libc_free_fn, nullptr);
return 0;
}


//the author of SZauto does not release their version info.
int major_version() const override {
return SZAUTO_MAJOR_VERSION;
}
int minor_version() const override {
return SZAUTO_MINOR_VERSION;
}
int patch_version() const override {
return SZAUTO_PATCH_VERSION;
}
int revision_version () const {
return SZAUTO_REVISION_VERSION;
}

const char* version() const override {
return sz_auto_version.c_str();
}


const char* prefix() const override {
return "SZauto";
}

std::shared_ptr<libpressio_compressor_plugin> clone() override {
return compat::make_unique<sz_auto_plugin>(*this);
}
private:

std::string sz_auto_version;
double error_bounds = 0.1; //params for compressing the sz-auto
float sample_ratio = 0.05;
};

static pressio_register compressor_sz_auto_plugin(compressor_plugins(), "SZauto", [](){return compat::make_unique<sz_auto_plugin>(); });

0 comments on commit a5e40c0

Please sign in to comment.