Skip to content

Commit 90c89b7

Browse files
Real-Chen-Happyrobertu94
authored andcommitted
libpressio version 0.49.0
Major Changes + Added BitGrooming and DigitRounding compressor plugins. Thanks to Hengzhi Chen for contributing them!
1 parent 59d09bf commit 90c89b7

File tree

5 files changed

+359
-1
lines changed

5 files changed

+359
-1
lines changed

CMakeLists.txt

Lines changed: 25 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.48.0" LANGUAGES CXX C)
2+
project(libpressio VERSION "0.49.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/
@@ -170,6 +170,30 @@ if(LIBPRESSIO_HAS_OPENMP)
170170
)
171171
endif()
172172

173+
option(LIBPRESSIO_HAS_DIGIT_ROUNDING "build the DIGIT ROUNDING plugin" OFF)
174+
if(LIBPRESSIO_HAS_DIGIT_ROUNDING)
175+
set(LIBPRESSIO_COMPRESSORS "${LIBPRESSIO_COMPRESSORS} DR")
176+
find_package(dround REQUIRED)
177+
find_package(ZLIB REQUIRED)
178+
target_sources(libpressio
179+
PRIVATE
180+
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/compressors/digit_rounding_plugin.cc
181+
)
182+
target_link_libraries(libpressio PRIVATE dround ZLIB::ZLIB)
183+
endif()
184+
185+
option(LIBPRESSIO_HAS_BIT_GROOMING "build the BIT GROOMING plugin" OFF)
186+
if(LIBPRESSIO_HAS_BIT_GROOMING)
187+
set(LIBPRESSIO_COMPRESSORS "${LIBPRESSIO_COMPRESSORS} BG")
188+
find_package(bg REQUIRED)
189+
find_package(ZLIB REQUIRED)
190+
target_sources(libpressio
191+
PRIVATE
192+
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/compressors/bit_groooming_plugin.cc
193+
)
194+
target_link_libraries(libpressio PRIVATE bg ZLIB::ZLIB)
195+
endif()
196+
173197
option(LIBPRESSIO_HAS_MGARD "build the MGARD plugin" OFF)
174198
if(LIBPRESSIO_HAS_MGARD)
175199
set(LIBPRESSIO_COMPRESSORS "${LIBPRESSIO_COMPRESSORS} mgard")

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Thanks for you interest in LibPressio! Here are a few things you can do to spee
4343
The following people have contributed code to LibPressio in alphabetical order:
4444

4545
+ Robert Underwood
46+
+ Hengzhi Chen
4647

4748
# Acknowledgments
4849

docs/PressioOptions.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
## Compressors
44

5+
### bit grooming
6+
7+
8+
9+
option | type | description
10+
------------------------|-------------|------------
11+
`bit_grooming:mode` | int32 | the mode parameter of bit grooming: BITGROOM, BITSHAVE and BITSET.
12+
`bit_grooming:mode_str` | char* | name of the mode to use. One of : BITGROOM, BITSHAVE and BITSET.
13+
`bit_grooming:error_control_mode` | int32 | the error control mode of bit grooming: BG_NSD or BG_DSD. BG_NSD stands for number of significant number. BG_DSD stands for number of significant decimal number.
14+
`bit_grooming:error_control_mode_str` | char* | the error control mode of bit grooming: either NSD or DSD. NSD stands for number of significant number. DSD stands for number of significant decimal number.
15+
`bit_grooming:n_sig_digits` | int32 | If you set BG_NSD in the error control mode, please set this parameter.
16+
`bit_grooming:n_sig_decimals` | int32 | If you set BG_DSD in the error control mode, please set this parameter.
17+
18+
19+
20+
521
### BLOSC
622

723
BLOSC is a collection of lossless compressors optimized to transfer data more quickly than a direct memory fetch can preform. More information on BLOSC can be found on its [project homepage](https://blosc.org/pages/blosc-in-depth/)
@@ -14,6 +30,16 @@ option | type | description
1430
`blosc:doshuffle` | int32 | what if any kind of pre-bit shuffling to preform
1531
`blosc:numinternalthreads` | int32 | number of threads used internally by the library
1632

33+
34+
### digit rounding
35+
36+
37+
38+
option | type | description
39+
------------------------|-------------|------------
40+
`digit_rounding:prec` | int32 | the prec parameter of digit rounding (a number between 0 and 64)
41+
42+
1743
### fpzip
1844

1945

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#include <cmath> //for exp and log
2+
#include <iterator>
3+
#include <map>
4+
#include <sstream>
5+
#include <bg/bg.h>
6+
#include "libpressio_ext/cpp/data.h" //for access to pressio_data structures
7+
#include "libpressio_ext/cpp/compressor.h" //for the libpressio_compressor_plugin class
8+
#include "libpressio_ext/cpp/options.h" // for access to pressio_options
9+
#include "libpressio_ext/cpp/pressio.h" //for the plugin registries
10+
#include "pressio_options.h"
11+
#include "pressio_data.h"
12+
#include "pressio_compressor.h"
13+
#include "libpressio_ext/compat/memory.h"
14+
15+
#define INVALID_TYPE -1
16+
17+
namespace {
18+
struct bg_iless {
19+
bool operator()(std::string lhs, std::string rhs) const {
20+
std::transform(std::begin(lhs), std::end(lhs), std::begin(lhs), [](unsigned char c){return std::tolower(c);});
21+
std::transform(std::begin(rhs), std::end(rhs), std::begin(rhs), [](unsigned char c){return std::tolower(c);});
22+
return lhs < rhs;
23+
}
24+
};
25+
static std::map<std::string, int, bg_iless> const bitgroom_mode_str_to_code {
26+
{"bitgroom", BITGROOM},
27+
{"bitshave", BITSHAVE},
28+
{"bitset", BITSET},
29+
};
30+
static std::map<std::string, int, bg_iless> const bitgroom_ec_mode_str_to_code {
31+
{"nsd", BG_NSD},
32+
{"dsd", BG_DSD},
33+
};
34+
35+
template <class Map>
36+
std::vector<std::string> bg_keys(Map const& map) {
37+
std::vector<std::string> keys;
38+
keys.reserve(map.size());
39+
std::transform(
40+
std::begin(map), std::end(map), std::back_inserter(keys),
41+
[](typename Map::const_reference it) { return it.first; });
42+
return keys;
43+
}
44+
}
45+
46+
47+
class bit_grooming_plugin: public libpressio_compressor_plugin {
48+
public:
49+
bit_grooming_plugin() {
50+
std::stringstream ss;
51+
ss << bit_grooming_plugin::major_version() << "." << bit_grooming_plugin::minor_version() << "." << bit_grooming_plugin::patch_version() << "." << bit_grooming_plugin::revision_version();
52+
bg_version = ss.str();
53+
};
54+
struct pressio_options get_options_impl() const override {
55+
struct pressio_options options;
56+
57+
set(options, "bit_grooming:mode", bgMode);
58+
set_type(options, "bit_grooming:mode_str", pressio_option_charptr_type);
59+
60+
set(options, "bit_grooming:error_control_mode", errorControlMode);
61+
set_type(options, "bit_grooming:error_control_mode_str", pressio_option_charptr_type);
62+
63+
set(options, "bit_grooming:n_sig_digits", nun_sig_digits); // number of significant digits
64+
set(options, "bit_grooming:n_sig_decimals", num_sig_decimals); // number of significant decimal digits
65+
return options;
66+
}
67+
68+
struct pressio_options get_configuration_impl() const override {
69+
struct pressio_options options;
70+
set(options, "pressio:thread_safe", static_cast<int>(pressio_thread_safety_multiple));
71+
set(options, "bit_grooming:mode", bg_keys(bitgroom_mode_str_to_code));
72+
set(options, "bit_grooming:error_control_mode_mode", bg_keys(bitgroom_ec_mode_str_to_code));
73+
return options;
74+
}
75+
76+
int set_options_impl(struct pressio_options const& options) override {
77+
get(options, "bit_grooming:mode", &bgMode);
78+
79+
std::string tmp_mode;
80+
if(get(options, "bit_grooming:mode_str", &tmp_mode) == pressio_options_key_set) {
81+
auto const& it = bitgroom_mode_str_to_code.find(tmp_mode);
82+
if(it != bitgroom_mode_str_to_code.end()) {
83+
bgMode = it->second;
84+
}
85+
}
86+
if(get(options, "bit_grooming:error_control_mode_str", &tmp_mode) == pressio_options_key_set) {
87+
auto const& it = bitgroom_ec_mode_str_to_code.find(tmp_mode);
88+
if(it != bitgroom_ec_mode_str_to_code.end()) {
89+
errorControlMode = it->second;
90+
}
91+
}
92+
get(options, "bit_grooming:error_control_mode", &errorControlMode);
93+
get(options, "bit_grooming:n_sig_digits", &nun_sig_digits); // number of significant digits
94+
get(options, "bit_grooming:n_sig_decimals",
95+
&num_sig_decimals); // number of significant decimal digits
96+
return 0;
97+
}
98+
99+
int compress_impl(const pressio_data *input, struct pressio_data* output) override {
100+
int type = libpressio_type_to_bg_type(pressio_data_dtype(input));
101+
if(type == INVALID_TYPE) {
102+
return INVALID_TYPE;
103+
}
104+
105+
size_t nbEle = pressio_data_num_elements(input);
106+
unsigned long outSize;
107+
void* data = pressio_data_ptr(input, nullptr);
108+
unsigned char* compressed_data;
109+
110+
compressed_data = BG_compress_args(type, data, &outSize, bgMode, errorControlMode,
111+
nun_sig_digits, num_sig_decimals, nbEle);
112+
113+
if(compressed_data == NULL)
114+
{
115+
return set_error(2, "Error when bit grooming is compressing the data");
116+
}
117+
118+
*output = pressio_data::move(pressio_byte_dtype, compressed_data, 1, &outSize, pressio_data_libc_free_fn, nullptr);
119+
return 0;
120+
}
121+
122+
int decompress_impl(const pressio_data *input, struct pressio_data* output) override {
123+
int type = libpressio_type_to_bg_type(pressio_data_dtype(output));
124+
if(type == INVALID_TYPE) {
125+
return INVALID_TYPE;
126+
}
127+
unsigned char* bytes = (unsigned char*)pressio_data_ptr(input, nullptr);
128+
size_t nbEle = pressio_data_num_elements(output);
129+
size_t byteLength = pressio_data_get_bytes(input);
130+
131+
void* decompressed_data = BG_decompress(type, bytes, byteLength, nbEle);
132+
*output = pressio_data::move(pressio_data_dtype(output), decompressed_data, 1, &nbEle, pressio_data_libc_free_fn, nullptr);
133+
return 0;
134+
}
135+
136+
137+
138+
int major_version() const override {
139+
return BG_VER_MAJOR;
140+
}
141+
int minor_version() const override {
142+
return BG_VER_MINOR;
143+
}
144+
int patch_version() const override {
145+
return BG_VER_BUILD;
146+
}
147+
int revision_version () const {
148+
return BG_VER_REVISION;
149+
}
150+
151+
const char* version() const override {
152+
return bg_version.c_str();
153+
}
154+
155+
156+
const char* prefix() const override {
157+
return "bit_grooming";
158+
}
159+
160+
std::shared_ptr<libpressio_compressor_plugin> clone() override {
161+
return compat::make_unique<bit_grooming_plugin>(*this);
162+
}
163+
private:
164+
std::string bg_version;
165+
int libpressio_type_to_bg_type(pressio_dtype type)
166+
{
167+
if(type == pressio_float_dtype)
168+
{
169+
return BG_FLOAT;
170+
}
171+
else if(type == pressio_double_dtype)
172+
{
173+
return BG_FLOAT;
174+
}
175+
else
176+
{
177+
set_error(2, "Invalid data type");
178+
return INVALID_TYPE;
179+
}
180+
}
181+
182+
int bgMode = BITGROOM;
183+
int errorControlMode = BG_NSD;
184+
int nun_sig_digits = 5;
185+
int num_sig_decimals = 5;
186+
};
187+
188+
static pressio_register compressor_bit_grooming_plugin(compressor_plugins(), "bit_grooming", [](){return compat::make_unique<bit_grooming_plugin>(); });
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#include <cmath> //for exp and log
2+
#include <sstream>
3+
#include <dr/libdround.h>
4+
#include "libpressio_ext/cpp/data.h" //for access to pressio_data structures
5+
#include "libpressio_ext/cpp/compressor.h" //for the libpressio_compressor_plugin class
6+
#include "libpressio_ext/cpp/options.h" // for access to pressio_options
7+
#include "libpressio_ext/cpp/pressio.h" //for the plugin registries
8+
#include "pressio_options.h"
9+
#include "pressio_data.h"
10+
#include "pressio_compressor.h"
11+
#include "libpressio_ext/compat/memory.h"
12+
13+
#define INVALID_TYPE -1
14+
15+
class digit_rounding_plugin: public libpressio_compressor_plugin {
16+
public:
17+
digit_rounding_plugin() {
18+
std::stringstream ss;
19+
ss << digit_rounding_plugin::major_version() << "." << digit_rounding_plugin::minor_version() << "." << digit_rounding_plugin::patch_version() << "." << digit_rounding_plugin::revision_version();
20+
dround_version = ss.str();
21+
};
22+
struct pressio_options get_options_impl() const override {
23+
struct pressio_options options;
24+
set(options, "digit_rounding:prec", prec);
25+
return options;
26+
}
27+
28+
struct pressio_options get_configuration_impl() const override {
29+
struct pressio_options options;
30+
set(options, "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, "digit_rounding:prec", &prec);
36+
37+
return 0;
38+
}
39+
40+
int compress_impl(const pressio_data *input, struct pressio_data* output) override {
41+
int type = libpressio_type_to_dr_type(pressio_data_dtype(input));
42+
if(type == INVALID_TYPE) {
43+
return INVALID_TYPE;
44+
}
45+
46+
size_t nbEle = pressio_data_num_elements(input);
47+
unsigned long outSize;
48+
void* data = pressio_data_ptr(input, nullptr);
49+
unsigned char* compressed_data = dround_compress(type, data, nbEle, prec, &outSize);
50+
51+
*output = pressio_data::move(pressio_byte_dtype, compressed_data, 1, &outSize, pressio_data_libc_free_fn, nullptr);
52+
return 0;
53+
}
54+
55+
int decompress_impl(const pressio_data *input, struct pressio_data* output) override {
56+
int type = libpressio_type_to_dr_type(pressio_data_dtype(output));
57+
if(type == INVALID_TYPE) {
58+
return INVALID_TYPE;
59+
}
60+
void* bytes = pressio_data_ptr(input, nullptr);
61+
size_t nbEle = pressio_data_num_elements(output);
62+
size_t outSize = input -> size_in_bytes();
63+
void* decompressed_data = dround_decompress(type, (unsigned char*)bytes, nbEle, static_cast<unsigned long>(outSize));
64+
*output = pressio_data::move(pressio_data_dtype(output), decompressed_data, 1, &nbEle, pressio_data_libc_free_fn, nullptr);
65+
return 0;
66+
}
67+
68+
69+
70+
int major_version() const override {
71+
return DROUND_VER_MAJOR;
72+
}
73+
int minor_version() const override {
74+
return DROUND_VER_MINOR;
75+
}
76+
int patch_version() const override {
77+
return DROUND_VER_BUILD;
78+
}
79+
int revision_version () const {
80+
return DROUND_VER_REVISION;
81+
}
82+
83+
const char* version() const override {
84+
return dround_version.c_str();
85+
}
86+
87+
88+
const char* prefix() const override {
89+
return "digit_rounding";
90+
}
91+
92+
std::shared_ptr<libpressio_compressor_plugin> clone() override {
93+
return compat::make_unique<digit_rounding_plugin>(*this);
94+
}
95+
private:
96+
int prec;
97+
std::string dround_version;
98+
int libpressio_type_to_dr_type(pressio_dtype type)
99+
{
100+
if(type == pressio_float_dtype)
101+
{
102+
return DIGIT_FLOAT;
103+
}
104+
else if(type == pressio_double_dtype)
105+
{
106+
return DIGIT_DOUBLE;
107+
}
108+
else
109+
{
110+
set_error(2, "Invalid data type");
111+
return INVALID_TYPE;
112+
}
113+
}
114+
115+
116+
117+
};
118+
119+
static pressio_register compressor_digit_rounding_plugin(compressor_plugins(), "digit_rounding", [](){return compat::make_unique<digit_rounding_plugin>(); });

0 commit comments

Comments
 (0)