Skip to content

Commit

Permalink
libpressio version 0.9.0
Browse files Browse the repository at this point in the history
Major Features

- New MGARD compressor plugin
- Provided the ability to disable compressor plugins at compile time.
- Breaking Change: the compressor_compress and compressor_decompress and
  implementing functions now accept the input as const instead of
  mutable. This was done to reduce user surprise

Bug Fixes:

- Removed invalid uses of constexpr
- Added Header include guards that were missing
- Corrected naming inconsistency between pressio_data_num_dimensions and
  pressio_data::num_dimensions.  New pressio_data::dimentions function
  returns a copy of the vector of the sizes.
  • Loading branch information
robertu94 committed Aug 22, 2019
1 parent a26cf5d commit 11238eb
Show file tree
Hide file tree
Showing 20 changed files with 372 additions and 73 deletions.
74 changes: 51 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(libpressio VERSION "0.8.0" LANGUAGES CXX C)
project(libpressio VERSION "0.9.0" LANGUAGES CXX C)

enable_testing()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(BUILD_SHARED_LIBS "build libpressio as a shared library" ON)

include(GNUInstallDirs)
find_package(ZFP REQUIRED)
find_package(SZ REQUIRED)
find_package(ZLIB REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(Python COMPONENTS Interpreter Development NumPy)
pkg_search_module(ZSTD IMPORTED_TARGET GLOBAL libzstd)


set(LIBPRESSIO_FEATURES "sz zfp")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/pressio_version.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/pressio_version.h
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/libpressio.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libpressio.pc
@ONLY
)
set(LIBPRESSIO_FEATURES "")

add_library(libpressio
#core implementation
Expand All @@ -38,8 +23,6 @@ add_library(libpressio

#plugins
./src/plugins/compressors/compressor_base.cc
./src/plugins/compressors/sz_plugin.cc
./src/plugins/compressors/zfp_plugin.cc
./src/plugins/metrics/composite.cc
./src/plugins/metrics/metrics_base.cc
./src/plugins/metrics/size.cc
Expand All @@ -48,8 +31,6 @@ add_library(libpressio

#public headers
include/libpressio.h
include/libpressio_ext/compressors/sz.h
include/libpressio_ext/compressors/zfp.h
include/libpressio_ext/cpp/compressor.h
include/libpressio_ext/cpp/metrics.h
include/libpressio_ext/cpp/plugins.h
Expand All @@ -74,9 +55,57 @@ target_include_directories(libpressio
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
)
target_compile_options(libpressio PRIVATE $<$<CONFIG:Debug>: -Wall -Werror -Wextra -Wpedantic>)
target_link_libraries(libpressio PUBLIC zfp::zfp SZ)
target_compile_features(libpressio PUBLIC cxx_std_17)

option(LIBPRESSIO_HAS_MGARD "build the MGARD plugin" OFF)
if(LIBPRESSIO_HAS_MGARD)
set(LIBPRESSIO_FEATURES "${LIBPRESSIO_FEATURES} mgard")
find_package(mgard REQUIRED)
target_sources(libpressio
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/compressors/mgard_plugin.cc
${CMAKE_CURRENT_SOURCE_DIR}/include/libpressio_ext/compressors/mgard.h
)
target_link_libraries(libpressio PUBLIC mgard::mgard)
endif()

option(LIBPRESSIO_HAS_ZFP "build the ZFP plugin" ON)
if(LIBPRESSIO_HAS_ZFP)
set(LIBPRESSIO_FEATURES "${LIBPRESSIO_FEATURES} zfp")
find_package(ZFP REQUIRED)
target_sources(libpressio
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/compressors/zfp_plugin.cc
${CMAKE_CURRENT_SOURCE_DIR}/include/libpressio_ext/compressors/zfp.h
)
target_link_libraries(libpressio PUBLIC zfp::zfp)
endif()

option(LIBPRESSIO_HAS_SZ "build the SZ plugin" ON)
if(LIBPRESSIO_HAS_SZ)
set(LIBPRESSIO_FEATURES "${LIBPRESSIO_FEATURES} sz")
find_package(SZ REQUIRED)
find_package(ZLIB REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_search_module(ZSTD IMPORTED_TARGET GLOBAL libzstd)
target_sources(libpressio
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/compressors/sz_plugin.cc
${CMAKE_CURRENT_SOURCE_DIR}/include/libpressio_ext/compressors/sz.h
)
target_link_libraries(libpressio PUBLIC SZ)
endif()

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/pressio_version.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/pressio_version.h
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/libpressio.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libpressio.pc
@ONLY
)

export(TARGETS libpressio NAMESPACE LibPressio:: FILE LibPressio.cmake)
install(TARGETS libpressio EXPORT LibPressioConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand All @@ -89,7 +118,6 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/pressio_version.h DESTINATION
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpressio.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pkgconfig)

option(BUILD_TESTS "build the test cases and examples" OFF)

if(BUILD_TESTS)
add_subdirectory(test)
endif()
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.8.0]
[libpressio, Version 0.9.0]
Robert Underwood
Argonne National Laboratory

Expand Down
5 changes: 5 additions & 0 deletions include/libpressio_ext/compressors/mgard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* \file
* \brief Includes definitions needed to use the MGRAD pressio compressor
* */
#include <mgard_capi.h>
8 changes: 4 additions & 4 deletions include/libpressio_ext/cpp/compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class libpressio_compressor_plugin {
/** compresses a pressio_data buffer
* \see pressio_compressor_compress for the semantics this function should obey
*/
int compress(struct pressio_data* input, struct pressio_data* output);
int compress(const pressio_data *input, struct pressio_data* output);
/** decompress a pressio_data buffer
* \see pressio_compressor_decompress for the semantics this function should obey
*/
int decompress(struct pressio_data* input, struct pressio_data* output);
int decompress(const pressio_data *input, struct pressio_data* output);
/** get a version string for the compressor
* \see pressio_compressor_version for the semantics this function should obey
*/
Expand Down Expand Up @@ -123,11 +123,11 @@ class libpressio_compressor_plugin {
/** compresses a pressio_data buffer
* \see pressio_compressor_compress for the semantics this function should obey
*/
virtual int compress_impl(struct pressio_data* input, struct pressio_data* output)=0;
virtual int compress_impl(const pressio_data *input, struct pressio_data* output)=0;
/** decompress a pressio_data buffer
* \see pressio_compressor_decompress for the semantics this function should obey
*/
virtual int decompress_impl(struct pressio_data* input, struct pressio_data* output)=0;
virtual int decompress_impl(const pressio_data *input, struct pressio_data* output)=0;

/** checks for extra arguments set for the compressor.
* Unlike other functions, this option is NOT required
Expand Down
15 changes: 11 additions & 4 deletions include/libpressio_ext/cpp/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,31 +233,38 @@ struct pressio_data {
/**
* \returns the number of dimensions
*/
size_t dimensions() const {
size_t num_dimensions() const {
return dims.size();
}

/**
* \returns a copy of the vector of dimensions
*/
std::vector<size_t> dimensions() const {
return dims;
}

/**
* \param idx the specific index to query
* \returns a specific dimension of the buffer of zero if the index exceeds dimensions()
*/
size_t get_dimension(size_t idx) const {
if(idx >= dimensions()) return 0;
if(idx >= num_dimensions()) return 0;
else return dims[idx];
}

/**
* \returns the size of the buffer in bytes
*/
size_t size_in_bytes() const {
return data_size_in_bytes(data_dtype, dimensions(), dims.data());
return data_size_in_bytes(data_dtype, num_dimensions(), dims.data());
}

/**
* \returns the size of the buffer in elements
*/
size_t num_elements() const {
return data_size_in_elements(dimensions(), dims.data());
return data_size_in_elements(num_dimensions(), dims.data());
}

private:
Expand Down
29 changes: 16 additions & 13 deletions include/libpressio_ext/cpp/options.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef PRESSIO_OPTIONS_CPP
#define PRESSIO_OPTIONS_CPP

#include <optional>
#include <variant>
#include <string>
Expand Down Expand Up @@ -53,11 +56,6 @@ struct pressio_option final {
template<class T>
pressio_option(T value): option(std::optional<T>(value)) {}

/** specialization for option to reset the type to hold no type or value
* \param[in] value the monostate singleton
* */
template<>
pressio_option(std::monostate value): option(value) {}

/** returns a pressio option that has the appropriate type if the conversion is allowed for the specified safety
* \param[in] type the type to convert to
Expand All @@ -75,21 +73,21 @@ struct pressio_option final {
* \returns returns true if the option holds the current type
*/
template <class T>
constexpr bool holds_alternative() const {
bool holds_alternative() const {
return std::holds_alternative<std::optional<T>>(option);
}

/** Specialization for the std::monostate singleton
* \returns true if the option has no specified type or value
*/
template <>
constexpr bool holds_alternative<std::monostate>() const;
bool holds_alternative<std::monostate>() const;

/**
* \returns a std::optional which holds a value if the option has one or an empty optional otherwise
*/
template <class T>
constexpr std::optional<T> const& get() const{
std::optional<T> const& get() const{
return std::get<std::optional<T>>(option);
}

Expand All @@ -98,7 +96,7 @@ struct pressio_option final {
* \returns the value contained by the option
*/
template <class T>
constexpr T const& get_value() const{
T const& get_value() const{
return get<T>().value();
}

Expand Down Expand Up @@ -187,14 +185,17 @@ struct pressio_option final {
option_type option;
};

/** specialization for option to reset the type to hold no type or value
* \param[in] value the monostate singleton
* */
template<>
pressio_option::pressio_option(std::monostate value);

/** Specialization for the std::monostate singleton
* \returns true if the option has no specified type or value
*/
template <>
constexpr bool pressio_option::holds_alternative<std::monostate>() const {
return std::holds_alternative<std::monostate>(option);
}

bool pressio_option::holds_alternative<std::monostate>() const;
/**
* represents a map of dynamically typed objects
*/
Expand Down Expand Up @@ -381,3 +382,5 @@ enum pressio_options_key_status pressio_options::get(std::string const& key, con
*/
template <>
enum pressio_options_key_status pressio_options::cast(std::string const& key, char** value, enum pressio_conversion_safety safety) const;

#endif
12 changes: 12 additions & 0 deletions include/libpressio_ext/cpp/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
#define LIBPRESSIO_PLUGINS_PUBLIC
#include <memory>
#include <vector>
#include "pressio_version.h"
#include "libpressio_ext/cpp/compressor.h"
#include "libpressio_ext/cpp/metrics.h"

#if LIBPRESSIO_HAS_SZ
/** construct the sz plugin */
std::unique_ptr<libpressio_compressor_plugin> make_c_sz();
#endif

#if LIBPRESSIO_HAS_ZFP
/** construct the zfp plugin */
std::unique_ptr<libpressio_compressor_plugin> make_c_zfp();
#endif

#if LIBPRESSIO_HAS_MGARD
std::unique_ptr<libpressio_compressor_plugin> make_c_mgard();
#endif

/** construct the time metrics plugin */
std::unique_ptr<libpressio_metrics_plugin> make_m_time();
/** construct the size metrics plugin */
Expand Down
35 changes: 35 additions & 0 deletions include/libpressio_ext/cpp/printers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <string>
#include <ostream>
#include "options.h"
#include "pressio_dtype.h"

/** \file
* \brief C++ stream compatible IO functions
Expand Down Expand Up @@ -82,3 +83,37 @@ operator<<(std::basic_ostream<CharT, Traits>& out, pressio_options const& option
return out;
}

/**
* human readable debugging IO function for pressio_dtype, the format is unspecified
* \param[in] out the stream to write to
* \param[in] type the type to print
*/
template <class CharT = char, class Traits = std::char_traits<CharT>>
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& out, enum pressio_dtype type)
{
switch (type) {
case pressio_double_dtype:
return out << "double";
case pressio_float_dtype:
return out << "float";
case pressio_uint8_dtype:
return out << "uint8_t";
case pressio_uint16_dtype:
return out << "uint16_t";
case pressio_uint32_dtype:
return out << "uint32_t";
case pressio_uint64_dtype:
return out << "uint64_t";
case pressio_int8_dtype:
return out << "int8_t";
case pressio_int16_dtype:
return out << "int16_t";
case pressio_int32_dtype:
return out << "int32_t";
case pressio_int64_dtype:
return out << "int64_t";
case pressio_byte_dtype:
return out << "byte";
}
}
4 changes: 2 additions & 2 deletions include/pressio_compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int pressio_compressor_check_options(struct pressio_compressor* compressor, stru
* 2. A new owning pressio_data structure with the results of the compression
* \returns 0 if successful, positive values on errors, negative values on warnings
*/
int pressio_compressor_compress(struct pressio_compressor* compressor, struct pressio_data * input, struct pressio_data* output);
int pressio_compressor_compress(struct pressio_compressor* compressor, const struct pressio_data *input, struct pressio_data* output);
/*!
* decompresses the compressed data using the specified compressor
* calling this without calling libpressio_compressor_set_options() has undefined behavior
Expand All @@ -80,7 +80,7 @@ int pressio_compressor_compress(struct pressio_compressor* compressor, struct pr
* \see pressio_data_new_empty often used as the pointer passed into \c output
* \see pressio_data_new_move often used as the pointer passed out of \c output
*/
int pressio_compressor_decompress(struct pressio_compressor* compressor, struct pressio_data * input, struct pressio_data* output);
int pressio_compressor_decompress(struct pressio_compressor* compressor, const struct pressio_data *input, struct pressio_data* output);

/**
* \param[in] compressor the compressor to get results from
Expand Down
2 changes: 2 additions & 0 deletions include/pressio_version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
#define LIBPRESSIO_MAJOR_VERSION @PROJECT_VERSION_MAJOR@
#define LIBPRESSIO_MINOR_VERSION @PROJECT_VERSION_MINOR@
#define LIBPRESSIO_PATCH_VERSION @PROJECT_VERSION_PATCH@
#cmakedefine01 LIBPRESSIO_HAS_SZ
#cmakedefine01 LIBPRESSIO_HAS_ZFP
4 changes: 2 additions & 2 deletions src/plugins/compressors/compressor_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ int libpressio_compressor_plugin::set_options(struct pressio_options const* opti
return ret;
}

int libpressio_compressor_plugin::compress(struct pressio_data* input, struct pressio_data* output) {
int libpressio_compressor_plugin::compress(const pressio_data *input, struct pressio_data* output) {
if(metrics_plugin) (*metrics_plugin)->begin_compress(input, output);
auto ret = compress_impl(input, output);
if(metrics_plugin) (*metrics_plugin)->end_compress(input, output, ret);
return ret;
}

int libpressio_compressor_plugin::decompress(struct pressio_data* input, struct pressio_data* output) {
int libpressio_compressor_plugin::decompress(const pressio_data *input, struct pressio_data* output) {
if(metrics_plugin) (*metrics_plugin)->begin_decompress(input, output);
auto ret = decompress_impl(input, output);
if(metrics_plugin) (*metrics_plugin)->end_decompress(input, output, ret);
Expand Down
Loading

0 comments on commit 11238eb

Please sign in to comment.