Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ if(ZSTD_FOUND)
target_link_libraries(mgard PRIVATE ZSTD::ZSTD ${CMAKE_DL_LIBS})
endif()

option(DEFINE_MGARD_TIMING "Enable/disable MGARD timing" OFF)
if(DEFINE_MGARD_TIMING)
add_definitions(-DMGARD_TIMING)
endif()

# Make sure we require C++11. Use meta-compile features if available,
# otherwise use specific language features
Expand Down
22 changes: 20 additions & 2 deletions src/mgard.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <numeric>
#include <stdexcept>

#ifdef MGARD_TIMING
#include <chrono>
#endif

#include "mgard_compress.hpp"
#include "mgard_mesh.hpp"
#include "mgard_nuni.h"
Expand Down Expand Up @@ -342,7 +346,9 @@ unsigned char *refactor_qz_1D(int ncol, const Real *u, int &outsize, Real tol) {

if (dims.is_2kplus1()) {
// to be clean up.

#ifdef MGARD_TIMING
auto start = std::chrono::high_resolution_clock::now();
#endif
tol /= dims.nlevel + 1;

const int l_target = dims.nlevel - 1;
Expand All @@ -354,6 +360,11 @@ unsigned char *refactor_qz_1D(int ncol, const Real *u, int &outsize, Real tol) {
int size_ratio = sizeof(Real) / sizeof(int);
std::vector<int> qv(ncol + size_ratio);

#ifdef MGARD_TIMING
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << "Refactor Time = " << (double)duration.count()/1000000 << "\n";
#endif
quantize_interleave(hierarchy, v.data(), qv.data(), norm, tol);

std::vector<unsigned char> out_data;
Expand All @@ -367,7 +378,9 @@ unsigned char *refactor_qz_1D(int ncol, const Real *u, int &outsize, Real tol) {
tol /= dims.nlevel + 1;

const int l_target = dims.nlevel - 1;

#ifdef MGARD_TIMING
auto start = std::chrono::high_resolution_clock::now();
#endif
mgard_2d::mgard_gen::prep_1D(dims.rnded[0], dims.input[0], l_target,
v.data(), work, coords_x, row_vec);

Expand All @@ -380,6 +393,11 @@ unsigned char *refactor_qz_1D(int ncol, const Real *u, int &outsize, Real tol) {
const int size_ratio = sizeof(Real) / sizeof(int);
std::vector<int> qv(ncol + size_ratio);

#ifdef MGARD_TIMING
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::seconds>(stop - start);
std::cout << "Refactor Time = " << duration.count() << "\n";
#endif
quantize_interleave(hierarchy, v.data(), qv.data(), norm, tol);

std::vector<unsigned char> out_data;
Expand Down
29 changes: 28 additions & 1 deletion src/mgard_compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <queue>
#include <vector>

#ifdef MGARD_TIMING
#include <chrono>
#endif

#include <zlib.h>

#ifdef MGARD_ZSTD
Expand Down Expand Up @@ -280,10 +284,17 @@ unsigned char *compress_memory_huffman(std::vector<int> &qv,
size_t out_data_miss_size;
unsigned char *out_tree = 0;
size_t out_tree_size;
#ifdef MGARD_TIMING
auto huff_time1 = std::chrono::high_resolution_clock::now();
#endif
mgard::huffman_encoding(qv.data(), qv.size(), &out_data_hit,
&out_data_hit_size, &out_data_miss,
&out_data_miss_size, &out_tree, &out_tree_size);

#ifdef MGARD_TIMING
auto huff_time2 = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(huff_time2 - huff_time1);
std::cout << "Huffman tree time = " << (double)duration.count()/1000000 << "\n";
#endif
size_t total_size =
out_data_hit_size / 8 + 4 + out_data_miss_size + out_tree_size;
unsigned char *payload = (unsigned char *)malloc(total_size);
Expand All @@ -302,9 +313,25 @@ unsigned char *compress_memory_huffman(std::vector<int> &qv,
free(out_data_hit);
free(out_data_miss);
#ifndef MGARD_ZSTD
#ifdef MGARD_TIMING
auto z_time1 = std::chrono::high_resolution_clock::now();
#endif
mgard::compress_memory_z(payload, total_size, out_data);
#ifdef MGARD_TIMING
auto z_time2 = std::chrono::high_resolution_clock::now();
auto z_duration = std::chrono::duration_cast<std::chrono::microseconds>(z_time2 - z_time1);
std::cout << "ZLIB compression time = " << (double)z_duration.count()/1000000 << "\n";
#endif
#else
#ifdef MGARD_TIMING
auto zstd_time1 = std::chrono::high_resolution_clock::now();
#endif
mgard::compress_memory_zstd(payload, total_size, out_data);
#ifdef MGARD_TIMING
auto zstd_time2 = std::chrono::high_resolution_clock::now();
auto zstd_duration = std::chrono::duration_cast<std::chrono::microseconds>(zstd_time2 - zstd_time1);
std::cout << "ZSTD compression time = " << (double)zstd_duration.count()/1000000 << "\n";
#endif
#endif
outsize = out_data.size() + 3 * sizeof(size_t);
unsigned char *buffer = (unsigned char *)malloc(outsize);
Expand Down
1 change: 1 addition & 0 deletions src/mgard_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int get_lindex(const int n, const int no, const int i) {
: no - 1);
}


std::size_t stride_from_index_difference(const std::size_t index_difference) {
return 1 << index_difference;
}
Expand Down
22 changes: 16 additions & 6 deletions tests/test_1d/test_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <fstream>
#include <iostream>
#include <vector>
#ifdef MGARD_TIMING
#include <chrono>
#endif

using namespace std;

Expand All @@ -29,14 +32,21 @@ int main(int argc, char **argv) {
std::vector<double> data(num_elements);
datafile.read(reinterpret_cast<char *>(&data[0]),
num_elements * sizeof(double));

#ifdef MGARD_TIMING
auto start = chrono::high_resolution_clock::now();
#endif
compressed_data =
mgard_compress(data.data(), out_size, 1, num_elements, 1, tol);
mgard_compress(0, data.data(), out_size, 1, num_elements, 1, tol);
#ifdef MGARD_TIMING
auto stop = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
cout << "Original size = " << num_elements * 8 << " out_size = " << out_size
<< " CR = " << num_elements * 8.0 / out_size << endl;

double *decompressed_data =
mgard_decompress<double>(compressed_data, out_size, 1, num_elements, 1);
<< " CR = " << num_elements * 8.0 / out_size
<< " Time = " << (double) duration.count() / 1000000<< endl;
#endif
double quantizer;
double *decompressed_data = mgard_decompress(0, quantizer, compressed_data,
out_size, 1, num_elements, 1);

double abserr = 0.0;
double max_abserr = 0.0;
Expand Down