diff --git a/CMakeLists.txt b/CMakeLists.txt index a6c94f3e..bf60ddd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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/ @@ -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") diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 80410dd8..d186bae3 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -61,6 +61,7 @@ alphabetical order: + Justin Sybrant + Franck Cappello + Jon C. Calhoun ++ Kai Zhao + Sheng Di + Peter Lindstrom diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index 40a30eee..0bdc75f5 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -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 diff --git a/docs/PressioOptions.md b/docs/PressioOptions.md index 9e6f65be..b43c65c7 100644 --- a/docs/PressioOptions.md +++ b/docs/PressioOptions.md @@ -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 diff --git a/src/plugins/compressors/sz_auto_plugin.cc b/src/plugins/compressors/sz_auto_plugin.cc new file mode 100644 index 00000000..5e59b179 --- /dev/null +++ b/src/plugins/compressors/sz_auto_plugin.cc @@ -0,0 +1,151 @@ +#include +#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(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*)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*)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((unsigned char*)compressedBytes, compressed_size, r[0], r[1], r[2]); + } + else if(dtype == pressio_double_dtype) + { + decompressed_data = sz_decompress_autotuning_3d((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 clone() override { + return compat::make_unique(*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(); }); +