Skip to content

Commit

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

- Breaking Change: pressio_options_get_string now returns new memory to
  fix a bug where a dangling pointer is returned from
  pressio_options::get.
- SZ now supports new SZ_{,de}compress_customize interface as main
  entrypoint into SZ
- Compatible with new SZ packaging requirements (now requires FFTW3)
  • Loading branch information
robertu94 committed Aug 27, 2019
1 parent e92b562 commit f281e31
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(libpressio VERSION "0.9.1" LANGUAGES CXX C)
project(libpressio VERSION "0.10.0" LANGUAGES CXX C)

enable_testing()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down Expand Up @@ -88,6 +88,7 @@ if(LIBPRESSIO_HAS_SZ)
find_package(ZLIB REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_search_module(ZSTD IMPORTED_TARGET GLOBAL libzstd)
pkg_search_module(FFTW3 IMPORTED_TARGET GLOBAL fftw3)
target_sources(libpressio
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/compressors/sz_plugin.cc
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 © 2019 , UChicago Argonne, LLC
All Rights Reserved
[libpressio, Version 0.9.1]
[libpressio, Version 0.10.0]
Robert Underwood
Argonne National Laboratory

Expand Down
3 changes: 3 additions & 0 deletions include/libpressio_ext/cpp/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ struct pressio_options final {
//special case for strings
/**
* special case for strings for memory management reasons \see pressio_options::get
*
* \param[in] key the option to access
* \param[out] value a newly allocated c-string, the pointer returned must be passed to free()
*/
template <>
enum pressio_options_key_status pressio_options::get(std::string const& key, const char** value) const;
Expand Down
2 changes: 2 additions & 0 deletions include/pressio_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ void pressio_options_clear(struct pressio_options* options, const char* key);
/** internal macro used to define getter functions */
#define pressio_options_define_type_get(name, type) \
/** Gets a particular value in a map if it exists
*
* pressio_options_get_string returns a newly allocated copy of the string
\param[in] options the options structure to modify
\param[in] key the key to change
\param[out] value the value retrieved
Expand Down
29 changes: 24 additions & 5 deletions src/plugins/compressors/sz_plugin.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <memory>
#include <sstream>
#include <cstdlib>

#include <sz/sz.h>

Expand Down Expand Up @@ -48,6 +49,8 @@ class sz_plugin: public libpressio_compressor_plugin {
pressio_options_set_type(options, "sz:plus_bits", pressio_option_int32_type);
pressio_options_set_type(options, "sz:random_access", pressio_option_int32_type);
pressio_options_set_type(options, "sz:data_type", pressio_option_double_type);
pressio_options_set_string(options, "sz:app", app.c_str());
pressio_options_set_userptr(options, "sz:user_params", user_params);
return options;
}

Expand Down Expand Up @@ -85,6 +88,13 @@ class sz_plugin: public libpressio_compressor_plugin {
pressio_options_get_integer(options, "sz:plus_bits", &confparams_cpr->plus_bits);
pressio_options_get_integer(options, "sz:random_access", &confparams_cpr->randomAccess);
pressio_options_get_integer(options, "sz:data_type", &confparams_cpr->dataType);
const char* tmp_app;
if(pressio_options_get_string(options, "sz:app", &tmp_app) == pressio_options_key_set)
{
app = tmp_app;
free((void*)tmp_app);
}
pressio_options_get_userptr(options, "sz:user_params", &user_params);

return 0;
}
Expand All @@ -95,16 +105,19 @@ class sz_plugin: public libpressio_compressor_plugin {
size_t r3 = pressio_data_get_dimension(input, 2);
size_t r4 = pressio_data_get_dimension(input, 3);
size_t r5 = pressio_data_get_dimension(input, 4);
int status = SZ_NSCS;
size_t outsize = 0;
unsigned char* compressed_data = SZ_compress(
unsigned char* compressed_data = SZ_compress_customize(app.c_str(), user_params,
libpressio_type_to_sz_type(pressio_data_dtype(input)),
pressio_data_ptr(input, nullptr),
&outsize,
r5,
r4,
r3,
r2,
r1);
r1,
&outsize,
&status
);
*output = pressio_data::move(pressio_byte_dtype, compressed_data, 1, &outsize, pressio_data_libc_free_fn, nullptr);
return 0;
}
Expand All @@ -119,16 +132,20 @@ class sz_plugin: public libpressio_compressor_plugin {
};
size_t ndims = pressio_data_num_dimensions(output);

int status = SZ_NSCS;
pressio_dtype type = pressio_data_dtype(output);
void* decompressed_data = SZ_decompress(
void* decompressed_data = SZ_decompress_customize(
app.c_str(),
user_params,
libpressio_type_to_sz_type(type),
(unsigned char*)pressio_data_ptr(input, nullptr),
pressio_data_get_dimension(input, 0),
r[4],
r[3],
r[2],
r[1],
r[0]
r[0],
&status
);
*output = pressio_data::move(type, decompressed_data, ndims, r, pressio_data_libc_free_fn, nullptr);
return 0;
Expand Down Expand Up @@ -170,6 +187,8 @@ class sz_plugin: public libpressio_compressor_plugin {
return -1;
}
std::string sz_version;
std::string app = "SZ";
void* user_params = nullptr;
};

std::unique_ptr<libpressio_compressor_plugin> make_c_sz() {
Expand Down
2 changes: 1 addition & 1 deletion src/pressio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace {
std::pair(std::string("mgard"), std::function(make_c_mgard)),
#endif
};
std::map metrics_constructor{
std::map<std::string, std::function<std::unique_ptr<libpressio_metrics_plugin>()>> metrics_constructor{
std::pair(std::string("time"), std::function(make_m_time)),
std::pair(std::string("size"), std::function(make_m_size)),
};
Expand Down
2 changes: 1 addition & 1 deletion src/pressio_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ enum pressio_options_key_status pressio_options::get(std::string const& key, con
{
auto opt = get(key);
if(opt.holds_alternative<std::string>()) {
*value = opt.get_value<std::string>().c_str();
*value = strdup(opt.get_value<std::string>().c_str());
return pressio_options_key_set;
} else {
return pressio_options_key_exists;
Expand Down

0 comments on commit f281e31

Please sign in to comment.