Skip to content

Commit

Permalink
Merge pull request #1004 from williamfgc/mgard
Browse files Browse the repository at this point in the history
MGARD initial integration
  • Loading branch information
williamfgc committed Nov 16, 2018
2 parents 48e7e4e + 1525aee commit dd1fe0a
Show file tree
Hide file tree
Showing 37 changed files with 1,541 additions and 4,118 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ mark_as_advanced(CMAKE_POSITION_INDEPENDENT_CODE)
adios_option(BZip2 "Enable support for BZip2 transforms" AUTO)
adios_option(ZFP "Enable support for ZFP transforms" AUTO)
adios_option(SZ "Enable support for SZ transforms" AUTO)
adios_option(MGARD "Enable support for MGARD transforms" AUTO)
adios_option(MPI "Enable support for MPI" AUTO)
adios_option(DataMan "Enable support for DataMan" AUTO)
adios_option(SST "Enable support for SST" AUTO)
Expand All @@ -142,7 +143,7 @@ if(ADIOS2_HAVE_MPI)
endif()

set(ADIOS2_CONFIG_OPTS
BZip2 ZFP SZ MPI DataMan SST ZeroMQ HDF5 Python Fortran SysVShMem
BZip2 ZFP SZ MGARD MPI DataMan SST ZeroMQ HDF5 Python Fortran SysVShMem
)
GenerateADIOSHeaderConfig(${ADIOS2_CONFIG_OPTS})
configure_file(
Expand Down
5 changes: 5 additions & 0 deletions cmake/ADIOS2ConfigCommon.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ if(NOT @BUILD_SHARED_LIBS@)
if(ADIOS2_HAVE_ZFP)
find_dependency(ZFP)
endif()

set(ADIOS2_HAVE_MGARD @ADIOS2_HAVE_MGARD@)
if(ADIOS2_HAVE_MGARD)
find_dependency(MGARD)
endif()

set(ADIOS2_HAVE_ZeroMQ @ADIOS2_HAVE_ZeroMQ@)
if(ADIOS2_HAVE_ZeroMQ)
Expand Down
7 changes: 7 additions & 0 deletions cmake/ADIOSFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ function(GenerateADIOSPackageConfig)
list(APPEND ADIOS2_CXX_LIBS ${ZFP_LIBRARIES})
list(APPEND ADIOS2_CXX_INCS ${ZFP_INCLUDE_DIRS})
endif()
if(ADIOS2_HAVE_MGARD)
install(FILES cmake/FindMGARD.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/Modules
)
list(APPEND ADIOS2_CXX_LIBS ${MGARD_LIBRARIES})
list(APPEND ADIOS2_CXX_INCS ${MGARD_INCLUDE_DIRS})
endif()
if(ADIOS2_HAVE_ZeroMQ)
install(FILES cmake/FindZeroMQ.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/Modules
Expand Down
10 changes: 10 additions & 0 deletions cmake/DetectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ if(SZ_FOUND)
set(ADIOS2_HAVE_SZ TRUE)
endif()

# MGARD
if(ADIOS2_USE_MGARD STREQUAL AUTO)
find_package(MGARD)
elseif(ADIOS2_USE_MGARD)
find_package(MGARD REQUIRED)
endif()
if(MGARD_FOUND)
set(ADIOS2_HAVE_MGARD TRUE)
endif()

set(mpi_find_components C)

# Fortran
Expand Down
61 changes: 61 additions & 0 deletions cmake/FindMGARD.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#------------------------------------------------------------------------------#
# Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details.
#------------------------------------------------------------------------------#
#
# FindMGARD
# -----------
#
# Try to find the MGARD library
#
# This module defines the following variables:
#
# MGARD_FOUND - System has MGARD
# MGARD_INCLUDE_DIRS - The MGARD include directory
# MGARD_LIBRARIES - Link these to use MGARD
#
# and the following imported targets:
# MGARD::MGARD - The MGARD compression library target
#
# You can also set the following variable to help guide the search:
# MGARD_ROOT - The install prefix for MGARD containing the
# include and lib folders
# Note: this can be set as a CMake variable or an
# environment variable. If specified as a CMake
# variable, it will override any setting specified
# as an environment variable.

if(NOT MGARD_FOUND)
if((NOT MGARD_ROOT) AND (NOT (ENV{MGARD_ROOT} STREQUAL "")))
set(MGARD_ROOT "$ENV{MGARD_ROOT}")
endif()
if(MGARD_ROOT)
set(MGARD_INCLUDE_OPTS HINTS ${MGARD_ROOT}/include NO_DEFAULT_PATHS)
set(MGARD_LIBRARY_OPTS
HINTS ${MGARD_ROOT}/lib ${MGARD_ROOT}/lib64
NO_DEFAULT_PATHS
)
endif()

find_path(MGARD_INCLUDE_DIR mgard.h ${MGARD_INCLUDE_OPTS})
find_library(MGARD_LIBRARY NAMES mgard ${MGARD_LIBRARY_OPTS})
find_library(ZLIB_LIBRARY NAMES zlib ${SZ_LIBRARY_OPTS})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MGARD
FOUND_VAR MGARD_FOUND
REQUIRED_VARS MGARD_LIBRARY ZLIB_LIBRARY MGARD_INCLUDE_DIR
)
if(MGARD_FOUND)
set(MGARD_INCLUDE_DIRS ${MGARD_INCLUDE_DIR})
set(MGARD_LIBRARIES ${MGARD_LIBRARY} ${ZLIB_LIBRARY})
if(MGARD_FOUND AND NOT TARGET MGARD::MGARD)
add_library(MGARD::MGARD UNKNOWN IMPORTED)
set_target_properties(MGARD::MGARD PROPERTIES
IMPORTED_LOCATION "${MGARD_LIBRARY}"
INTERFACE_LINK_LIBRARIES "${MGARD_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${MGARD_INCLUDE_DIR}"
)
endif()
endif()
endif()
2 changes: 2 additions & 0 deletions source/adios2/ADIOSMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
MACRO(float) \
MACRO(double)

#define ADIOS2_FOREACH_MGARD_TYPE_1ARG(MACRO) MACRO(double)

#define ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(MACRO) \
MACRO(std::string) \
MACRO(char) \
Expand Down
7 changes: 7 additions & 0 deletions source/adios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ add_library(adios2
toolkit/format/bp3/operation/BP3Zfp.tcc
toolkit/format/bp3/operation/BP3SZ.cpp
toolkit/format/bp3/operation/BP3SZ.tcc
toolkit/format/bp3/operation/BP3MGARD.cpp
toolkit/format/bp3/operation/BP3MGARD.tcc

toolkit/profiling/iochrono/Timer.cpp

Expand Down Expand Up @@ -136,6 +138,11 @@ if(ADIOS2_HAVE_SZ)
target_link_libraries(adios2 PRIVATE SZ::SZ)
endif()

if(ADIOS2_HAVE_MGARD)
target_sources(adios2 PRIVATE operator/compress/CompressMGARD.cpp)
target_link_libraries(adios2 PRIVATE MGARD::MGARD)
endif()

if(ADIOS2_HAVE_MPI)
target_sources(adios2 PRIVATE
engine/insitumpi/InSituMPIWriter.cpp engine/insitumpi/InSituMPIWriter.tcc
Expand Down
17 changes: 17 additions & 0 deletions source/adios2/core/ADIOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "adios2/operator/compress/CompressSZ.h"
#endif

#ifdef ADIOS2_HAVE_MGARD
#include "adios2/operator/compress/CompressMGARD.h"
#endif

// callbacks
#include "adios2/operator/callback/Signature1.h"
#include "adios2/operator/callback/Signature2.h"
Expand Down Expand Up @@ -187,6 +191,19 @@ Operator &ADIOS::DefineOperator(const std::string name, const std::string type,
throw std::invalid_argument(
"ERROR: this version of ADIOS2 didn't compile with the "
"SZ library (minimum v2.0.2.0), in call to DefineOperator\n");
#endif
}
else if (typeLowerCase == "mgard")
{
#ifdef ADIOS2_HAVE_MGARD
auto itPair = m_Operators.emplace(
name,
std::make_shared<compress::CompressMGARD>(parameters, m_DebugMode));
operatorPtr = itPair.first->second;
#else
throw std::invalid_argument(
"ERROR: this version of ADIOS2 didn't compile with the "
"MGARD library (minimum v0.0.0.1), in call to DefineOperator\n");
#endif
}
else
Expand Down
149 changes: 149 additions & 0 deletions source/adios2/operator/compress/CompressMGARD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* CompressMGARD.cpp :
*
* Created on: Aug 3, 2018
* Author: William F Godoy godoywf@ornl.gov
*/

#include "CompressMGARD.h"

#include <cstring> //std::memcpy

extern "C" {
#include <mgard_capi.h>
}

#include "adios2/helper/adiosFunctions.h"

namespace adios2
{
namespace core
{
namespace compress
{

CompressMGARD::CompressMGARD(const Params &parameters, const bool debugMode)
: Operator("mgard", parameters, debugMode)
{
}

size_t CompressMGARD::Compress(const void *dataIn, const Dims &dimensions,
const size_t elementSize, const std::string type,
void *bufferOut, const Params &parameters) const
{
const size_t ndims = dimensions.size();
if (m_DebugMode)
{
if (ndims != 2)
{
throw std::invalid_argument(
"ERROR: ADIOS2 MGARD compression: no more "
"than 2-dimensions is supported.\n");
}
}

// set type
int mgardType = -1;
if (type == "float")
{
if (m_DebugMode)
{
throw std::invalid_argument(
"ERROR: ADIOS2 operator "
"MGARD only supports double precision, in call to Put\n");
}
}
else if (type == "double")
{
mgardType = 1;
}

int r[ndims];

for (auto i = 0; i < ndims; i++)
{
r[ndims - i - 1] = static_cast<int>(dimensions[i]);
}

// Parameters
auto itTolerance = parameters.find("tolerance");
if (m_DebugMode)
{
if (itTolerance == parameters.end())
{
throw std::invalid_argument("ERROR: missing mandatory parameter "
"tolerance for MGARD compression "
"operator, in call to Put\n");
}
}

double tolerance = std::stod(itTolerance->second);

int sizeOut = 0;
unsigned char *dataOutPtr =
mgard_compress(mgardType, const_cast<void *>(dataIn), &sizeOut, r[0],
r[1], &tolerance);

const size_t sizeOutT = static_cast<size_t>(sizeOut);
std::memcpy(bufferOut, dataOutPtr, sizeOutT);

return sizeOutT;
}

size_t CompressMGARD::Decompress(const void *bufferIn, const size_t sizeIn,
void *dataOut, const Dims &dimensions,
const std::string type,
const Params & /*parameters*/) const
{
int mgardType = -1;
size_t elementSize = 0;

if (type == "float")
{
if (m_DebugMode)
{
throw std::invalid_argument(
"ERROR: ADIOS2 operator "
"MGARD only supports double precision, in call to Get\n");
}
}
else if (type == "double")
{
mgardType = 1;
elementSize = 8;
}
else
{
if (m_DebugMode)
{
throw std::invalid_argument(
"ERROR: ADIOS2 operator "
"MGARD only supports double precision, in call to Get\n");
}
}

const size_t ndims = dimensions.size();
int r[ndims];

for (auto i = 0; i < ndims; i++)
{
r[ndims - i - 1] = static_cast<int>(dimensions[i]);
}

void *dataPtr = mgard_decompress(
mgardType,
reinterpret_cast<unsigned char *>(const_cast<void *>(bufferIn)),
static_cast<int>(sizeIn), r[0], r[1]);

const size_t dataSizeBytes = helper::GetTotalSize(dimensions) * elementSize;
std::memcpy(dataOut, dataPtr, dataSizeBytes);

return static_cast<size_t>(dataSizeBytes);
}

} // end namespace compress
} // end namespace core
} // end namespace adios2

0 comments on commit dd1fe0a

Please sign in to comment.