Skip to content

Commit

Permalink
libpressio version 0.34.4
Browse files Browse the repository at this point in the history
Bug Fixes:

- previously, pressio_data objects would incorrectly report that an
  empty buffer had data_size == 1, which caused a host of issues with
  these objects.  All of them have been fixed.
- the ZFP-plugin previously would cause a double-free if copied.  This
  has been resolved, by following the rule of 5
- the ZFP-plugin would read uninitialized memory if it wasn't configured
  prior to calling set_options with some options information.  It is now
  initalized to a default state.
- the ZFP plugin would previously fail to decompress if using the OpenMP
  mode requiring a reconfiguration between compression and decompression.
  Since this isn't expected, we save the mode, use serial mode, then
  restore to the previous mode.
- the SZ plugin used enable_shared_from_this in an undefined way.  Now
  the code relies upon the default plugin mechanics in libpressio to get
  another handle to the same shared object.
  • Loading branch information
robertu94 committed Feb 28, 2020
1 parent d5ccdfd commit 86e9778
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 14 deletions.
2 changes: 1 addition & 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.34.3" LANGUAGES CXX C)
project(libpressio VERSION "0.34.4" LANGUAGES CXX C)

#correct was to set a default build type
# https://blog.kitware.com/cmake-and-the-default-build-type/
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 © 2020 , UChicago Argonne, LLC
All Rights Reserved
[libpressio, Version 0.34.3]
[libpressio, Version 0.34.4]
Robert Underwood
Argonne National Laboratory

Expand Down
28 changes: 19 additions & 9 deletions include/libpressio_ext/cpp/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace {
template <class T>
size_t data_size_in_elements(size_t dimensions, T const dims[]) {
if(dimensions == 0) return 0;
size_t totalsize = 1;
for (size_t i = 0; i < dimensions; ++i) {
totalsize *= dims[i];
Expand Down Expand Up @@ -136,8 +137,11 @@ struct pressio_data {
* */
static pressio_data copy(const enum pressio_dtype dtype, const void* src, size_t const num_dimensions, size_t const dimensions[]) {
size_t bytes = data_size_in_bytes(dtype, num_dimensions, dimensions);
void* data = malloc(bytes);
memcpy(data, src, bytes);
void* data = nullptr;
if(bytes != 0) {
data = malloc(bytes);
memcpy(data, src, bytes);
}
return pressio_data(dtype, data, nullptr, pressio_data_libc_free_fn, num_dimensions, dimensions);
}

Expand All @@ -151,7 +155,9 @@ struct pressio_data {
* \see pressio_data_new_owning
* */
static pressio_data owning(const pressio_dtype dtype, size_t const num_dimensions, size_t const dimensions[]) {
void* data = malloc(data_size_in_bytes(dtype, num_dimensions, dimensions));
size_t bytes = data_size_in_bytes(dtype, num_dimensions, dimensions);
void* data = nullptr;
if(bytes != 0) data = malloc(bytes);
return pressio_data(dtype, data, nullptr, pressio_data_libc_free_fn, num_dimensions, dimensions);
}

Expand Down Expand Up @@ -187,8 +193,12 @@ struct pressio_data {
*
*/
static pressio_data clone(pressio_data const& src){
auto data = static_cast<unsigned char*>(malloc(src.size_in_bytes()));
memcpy(data, src.data(), src.size_in_bytes());
size_t bytes = src.size_in_bytes();
unsigned char* data = nullptr;
if(bytes != 0) {
data = static_cast<unsigned char*>(malloc(bytes));
memcpy(data, src.data(), src.size_in_bytes());
}
return pressio_data(src.dtype(),
data,
nullptr,
Expand Down Expand Up @@ -217,7 +227,7 @@ struct pressio_data {
pressio_data& operator=(pressio_data const& rhs) {
if(this == &rhs) return *this;
data_dtype = rhs.data_dtype;
if(rhs.has_data()) {
if(rhs.has_data() && rhs.size_in_bytes() > 0) {
data_ptr = malloc(rhs.size_in_bytes());
memcpy(data_ptr, rhs.data_ptr, rhs.size_in_bytes());
} else {
Expand All @@ -234,12 +244,12 @@ struct pressio_data {
* */
pressio_data(pressio_data const& rhs):
data_dtype(rhs.data_dtype),
data_ptr(rhs.has_data()? malloc(rhs.size_in_bytes()) : nullptr),
data_ptr((rhs.has_data())? malloc(rhs.size_in_bytes()) : nullptr),
metadata_ptr(nullptr),
deleter(pressio_data_libc_free_fn),
dims(rhs.dims)
{
if(rhs.has_data()) {
if(rhs.has_data() && rhs.size_in_bytes() > 0) {
memcpy(data_ptr, rhs.data_ptr, rhs.size_in_bytes());
}
}
Expand Down Expand Up @@ -281,7 +291,7 @@ struct pressio_data {
template <class T>
pressio_data(std::initializer_list<T> il):
data_dtype(pressio_dtype_from_type<T>()),
data_ptr(malloc(il.size() * sizeof(T))),
data_ptr((il.size() == 0)? nullptr:malloc(il.size() * sizeof(T))),
metadata_ptr(nullptr),
deleter(pressio_data_libc_free_fn),
dims({il.size()})
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/compressors/sz_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "pressio_option.h"


class sz_plugin: public libpressio_compressor_plugin, std::enable_shared_from_this<sz_plugin> {
class sz_plugin: public libpressio_compressor_plugin {
public:
sz_plugin() {
std::stringstream ss;
Expand Down Expand Up @@ -179,7 +179,7 @@ class sz_plugin: public libpressio_compressor_plugin, std::enable_shared_from_th
}

std::shared_ptr<libpressio_compressor_plugin> clone() override {
return this->shared_from_this();
return compressor_plugins().build("sz");
}


Expand Down
38 changes: 37 additions & 1 deletion src/plugins/compressors/zfp_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,35 @@ class zfp_plugin: public libpressio_compressor_plugin {
//to be serial by default, we need to set it last. However, we also want the
//threads and chunck sizes to be set rather than undefined in the default case so
//we must set them too
zfp_stream_set_accuracy(zfp, 1e-3);
zfp_stream_set_omp_threads(zfp, 0);
zfp_stream_set_omp_chunk_size(zfp, 0);
zfp_stream_set_execution(zfp, zfp_exec_serial);
}
~zfp_plugin() {
zfp_stream_close(zfp);
}
zfp_plugin(zfp_plugin const& rhs): libpressio_compressor_plugin(rhs), zfp(zfp_stream_open(NULL)) {
zfp_stream_set_params(zfp, rhs.zfp->minbits, rhs.zfp->maxbits, rhs.zfp->maxprec, rhs.zfp->minexp);
zfp_stream_set_omp_threads(zfp, zfp_stream_omp_threads(rhs.zfp));
zfp_stream_set_omp_chunk_size(zfp, zfp_stream_omp_chunk_size(rhs.zfp));
zfp_stream_set_execution(zfp, zfp_stream_execution(rhs.zfp));
}
zfp_plugin(zfp_plugin && rhs) noexcept: zfp(std::exchange(rhs.zfp, zfp_stream_open(NULL))) {}
zfp_plugin& operator=(zfp_plugin && rhs) noexcept {
if(this != &rhs) return *this;
zfp = std::exchange(rhs.zfp, zfp_stream_open(NULL));
return *this;
}

zfp_plugin& operator=(zfp_plugin const& rhs) {
if(this == &rhs) return *this;
zfp_stream_set_params(zfp, rhs.zfp->minbits, rhs.zfp->maxbits, rhs.zfp->maxprec, rhs.zfp->minexp);
zfp_stream_set_omp_threads(zfp, zfp_stream_omp_threads(rhs.zfp));
zfp_stream_set_omp_chunk_size(zfp, zfp_stream_omp_chunk_size(rhs.zfp));
zfp_stream_set_execution(zfp, zfp_stream_execution(rhs.zfp));
return *this;
}

struct pressio_options get_options_impl() const override {
struct pressio_options options;
Expand Down Expand Up @@ -80,7 +102,7 @@ class zfp_plugin: public libpressio_compressor_plugin {
options.get("zfp:minexp", &zfp->minexp);
}

unsigned int execution;
int execution;
if(options.get("zfp:execution", &execution) == pressio_options_key_set) {
zfp_stream_set_execution(zfp, (zfp_exec_policy)execution);
}
Expand Down Expand Up @@ -128,6 +150,17 @@ class zfp_plugin: public libpressio_compressor_plugin {
}

int decompress_impl(const pressio_data *input, struct pressio_data* output) override {
//save the exec mode, set it to serial, and reset it at the end of the decompression
//if parallel decompression is requested and not supported
//
//currently only serial supports all modes, and cuda supports fixed rate decompression
zfp_exec_policy policy = zfp_stream_execution(zfp);
zfp_mode zfp_zmode = zfp_stream_compression_mode(zfp);
if(! (policy == zfp_exec_serial || (zfp_zmode == zfp_mode_fixed_rate && policy == zfp_exec_cuda))) {
zfp_stream_set_execution(zfp, zfp_exec_serial);
}


size_t size;
void* ptr = pressio_data_ptr(input, &size);
bitstream* stream = stream_open(ptr, size);
Expand All @@ -152,6 +185,9 @@ class zfp_plugin: public libpressio_compressor_plugin {
zfp_field_free(out_field);
stream_close(stream);

//reset the execution policy
zfp_stream_set_execution(zfp, policy);

if(num_bytes == 0) {
return decompression_failed();
} else {
Expand Down

0 comments on commit 86e9778

Please sign in to comment.