-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1004 from williamfgc/mgard
MGARD initial integration
- Loading branch information
Showing
37 changed files
with
1,541 additions
and
4,118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ¶meters, 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 ¶meters) 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 |
Oops, something went wrong.