Skip to content

Commit a5e40c0

Browse files
Real-Chen-Happyrobertu94
authored andcommitted
libpressio version 0.59.0
Major Changes + Integrated SZAuto https://github.com/szcompressor/szauto. Thanks to Hengzhi Chen and Kai Zhao for contributing it!
1 parent 936ba74 commit a5e40c0

File tree

5 files changed

+176
-2
lines changed

5 files changed

+176
-2
lines changed

CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
2-
project(libpressio VERSION "0.58.0" LANGUAGES CXX C)
2+
project(libpressio VERSION "0.59.0" LANGUAGES CXX C)
33

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

171+
option(LIBPRESSIO_HAS_SZ_AUTO "build the SZauto plugin" OFF)
172+
if(LIBPRESSIO_HAS_SZ_AUTO)
173+
set(LIBPRESSIO_COMPRESSORS "${LIBPRESSIO_COMPRESSORS} SZauto")
174+
find_package(szauto REQUIRED)
175+
pkg_search_module(ZSTD IMPORTED_TARGET GLOBAL libzstd)
176+
target_sources(libpressio
177+
PRIVATE
178+
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/compressors/sz_auto_plugin.cc
179+
)
180+
target_link_libraries(libpressio PRIVATE szauto::sz_cpp)
181+
endif()
182+
171183
option(LIBPRESSIO_HAS_MGARD "build the MGARD plugin" OFF)
172184
if(LIBPRESSIO_HAS_MGARD)
173185
set(LIBPRESSIO_COMPRESSORS "${LIBPRESSIO_COMPRESSORS} mgard")

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ alphabetical order:
6161
+ Justin Sybrant
6262
+ Franck Cappello
6363
+ Jon C. Calhoun
64+
+ Kai Zhao
6465
+ Sheng Di
6566
+ Peter Lindstrom
6667

COPYRIGHT.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Copyright © 2021 , UChicago Argonne, LLC
22
All Rights Reserved
3-
[libpressio, Version 0.58.0]
3+
[libpressio, Version 0.59.0]
44
Robert Underwood
55
Argonne National Laboratory
66

docs/PressioOptions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ option | type | description
4040
`digit_rounding:prec` | int32 | the prec parameter of digit rounding (a number between 0 and 64)
4141

4242

43+
44+
### sz auto
45+
46+
47+
option | type | description
48+
------------------------|-------------|------------
49+
`sz_auto:error_bounds` | double | the error bounds for the compression
50+
`sz_auto:sample_ratio` | float | the sample ratio for the compression
51+
52+
4353
### fpzip
4454

4555

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#include <sstream>
2+
#include "sz_autotuning_3d.hpp"
3+
#include "sz_def.hpp"
4+
#include "sz_utils.hpp"
5+
#include "libpressio_ext/cpp/data.h" //for access to pressio_data structures
6+
#include "libpressio_ext/cpp/compressor.h" //for the libpressio_compressor_plugin class
7+
#include "libpressio_ext/cpp/options.h" // for access to pressio_options
8+
#include "libpressio_ext/cpp/pressio.h" //for the plugin registries
9+
#include "pressio_options.h"
10+
#include "pressio_data.h"
11+
#include "pressio_compressor.h"
12+
#include "std_compat/memory.h"
13+
14+
class sz_auto_plugin: public libpressio_compressor_plugin {
15+
public:
16+
sz_auto_plugin() {
17+
std::stringstream ss;
18+
ss << sz_auto_plugin::major_version() << "." << sz_auto_plugin::minor_version() << "." << sz_auto_plugin::patch_version() << "." << sz_auto_plugin::revision_version();
19+
sz_auto_version = ss.str();
20+
};
21+
struct pressio_options get_options_impl() const override {
22+
struct pressio_options options;
23+
set(options, "SZauto:error_bounds", error_bounds);
24+
set(options, "SZauto:sample_ratio", sample_ratio);
25+
return options;
26+
}
27+
28+
struct pressio_options get_configuration_impl() const override {
29+
struct pressio_options options;
30+
options.set("pressio:thread_safe", static_cast<int>(pressio_thread_safety_multiple));
31+
return options;
32+
}
33+
34+
int set_options_impl(struct pressio_options const& options) override {
35+
get(options, "SZauto:error_bounds", &error_bounds);
36+
get(options, "SZauto:sample_ratio", &sample_ratio);
37+
return 0;
38+
}
39+
40+
int compress_impl(const pressio_data *input, struct pressio_data* output) override {
41+
enum pressio_dtype type = pressio_data_dtype(input);
42+
unsigned long outSize;
43+
void* data = pressio_data_ptr(input, nullptr);
44+
unsigned char* compressed_data;
45+
46+
size_t ndims = pressio_data_num_dimensions(input);
47+
size_t r1 = pressio_data_get_dimension(input, 0);
48+
size_t r2 = pressio_data_get_dimension(input, 1);
49+
size_t r3 = pressio_data_get_dimension(input, 2);
50+
51+
if(ndims != 3)
52+
{
53+
return set_error(2, "Error: SZauto only supports 3d compression");
54+
}
55+
56+
if(type == pressio_float_dtype)
57+
{
58+
compressed_data = sz_compress_autotuning_3d<float>((float*)data, r1, r2, r3, error_bounds, outSize, false, false, false, sample_ratio);
59+
}
60+
else if(type == pressio_double_dtype)
61+
{
62+
compressed_data = sz_compress_autotuning_3d<double>((double*)data, r1, r2, r3, error_bounds, outSize, false, false, false, sample_ratio);
63+
}
64+
else
65+
{
66+
return set_error(2, "Error: SZauto only supports float or double");
67+
}
68+
69+
//that means the compressor is complaining about the parameter
70+
if(compressed_data == NULL)
71+
{
72+
return set_error(2, "Error when SZauto is compressing the data");
73+
}
74+
75+
*output = pressio_data::move(pressio_byte_dtype, compressed_data, 1, &outSize, pressio_data_libc_free_fn, nullptr);
76+
return 0;
77+
}
78+
79+
int decompress_impl(const pressio_data *input, struct pressio_data* output) override {
80+
enum pressio_dtype dtype = pressio_data_dtype(output);
81+
82+
size_t r[] = {
83+
pressio_data_get_dimension(output, 0),
84+
pressio_data_get_dimension(output, 1),
85+
pressio_data_get_dimension(output, 2),
86+
};
87+
size_t ndims = pressio_data_num_dimensions(output);
88+
if(ndims != 3)
89+
{
90+
return set_error(2, "Error: SZauto only supports 3d decompression");
91+
}
92+
93+
94+
size_t compressed_size;
95+
void* compressedBytes = pressio_data_ptr(input, &compressed_size);
96+
97+
void* decompressed_data;
98+
if(dtype == pressio_float_dtype)
99+
{
100+
decompressed_data = sz_decompress_autotuning_3d<float>((unsigned char*)compressedBytes, compressed_size, r[0], r[1], r[2]);
101+
}
102+
else if(dtype == pressio_double_dtype)
103+
{
104+
decompressed_data = sz_decompress_autotuning_3d<double>((unsigned char*)compressedBytes, compressed_size, r[0], r[1], r[2]);
105+
}
106+
else
107+
{
108+
return set_error(2, "Error: SZauto only supports float or double");
109+
}
110+
111+
112+
*output = pressio_data::move(dtype, decompressed_data, ndims, r, pressio_data_libc_free_fn, nullptr);
113+
return 0;
114+
}
115+
116+
117+
//the author of SZauto does not release their version info.
118+
int major_version() const override {
119+
return SZAUTO_MAJOR_VERSION;
120+
}
121+
int minor_version() const override {
122+
return SZAUTO_MINOR_VERSION;
123+
}
124+
int patch_version() const override {
125+
return SZAUTO_PATCH_VERSION;
126+
}
127+
int revision_version () const {
128+
return SZAUTO_REVISION_VERSION;
129+
}
130+
131+
const char* version() const override {
132+
return sz_auto_version.c_str();
133+
}
134+
135+
136+
const char* prefix() const override {
137+
return "SZauto";
138+
}
139+
140+
std::shared_ptr<libpressio_compressor_plugin> clone() override {
141+
return compat::make_unique<sz_auto_plugin>(*this);
142+
}
143+
private:
144+
145+
std::string sz_auto_version;
146+
double error_bounds = 0.1; //params for compressing the sz-auto
147+
float sample_ratio = 0.05;
148+
};
149+
150+
static pressio_register compressor_sz_auto_plugin(compressor_plugins(), "SZauto", [](){return compat::make_unique<sz_auto_plugin>(); });
151+

0 commit comments

Comments
 (0)