szcompressor / SZ

Error-bounded Lossy Data Compressor (for floating-point/integer datasets)
http://szcompressor.org
Other
151 stars 56 forks source link

Seg fault when calling SZ_Init_Params #22

Closed williamfgc closed 6 years ago

williamfgc commented 6 years ago
    sz_params sz;
    memset(&sz, 0, sizeof(sz_params));
    sz.max_quant_intervals = 65536;
    sz.quantization_intervals = 0;
    // sz.dataEndianType = LITTLE_ENDIAN_DATA;
    //    sz.sysEndianType = LITTLE_ENDIAN_DATA;
    sz.sol_ID = SZ;
    // sz.layers = 1;
    sz.sampleDistance = 100;
    sz.predThreshold = 0.99;
    //    sz.offset = 0;
    sz.szMode = SZ_BEST_COMPRESSION; // SZ_BEST_SPEED; //SZ_BEST_COMPRESSION;
    sz.gzipMode = 1;
    sz.errorBoundMode = ABS;
    sz.absErrBound = 1E-4;
    sz.relBoundRatio = 1E-3;
    sz.psnr = 80.0;
    sz.pw_relBoundRatio = 1E-5;
    sz.segment_size = (int)pow(5, (double)ndims);
    sz.pwr_type = SZ_PWR_MIN_TYPE;

   Params::const_iterator it;
    for (it = parameters.begin(); it != parameters.end(); it++)
    {
        std::cout << it->first << " => " << it->second << '\n';
        if (it->first == "init")
        {
            use_configfile = 1;
            sz_configfile = std::string(it->second);
        }
        else if (it->first == "max_quant_intervals")
        {
            sz.max_quant_intervals = std::stoi(it->second);
        }
        else if (it->first == "quantization_intervals")
        {
            sz.quantization_intervals = std::stoi(it->second);
        }
        else if (it->first == "sol_ID")
        {
            sz.sol_ID = std::stoi(it->second);
        }
        else if (it->first == "sampleDistance")
        {
            sz.sampleDistance = std::stoi(it->second);
        }
        else if (it->first == "predThreshold")
        {
            sz.predThreshold = std::stof(it->second);
        }
        else if (it->first == "szMode")
        {
            int szMode = SZ_BEST_SPEED;
            if (it->second == "SZ_BEST_SPEED")
            {
                szMode = SZ_BEST_SPEED;
            }
            else if (it->second == "SZ_BEST_COMPRESSION")
            {
                szMode = SZ_BEST_COMPRESSION;
            }
            else if (it->second == "SZ_DEFAULT_COMPRESSION")
            {
                szMode = SZ_DEFAULT_COMPRESSION;
            }
            else
            {
                std::cout << "[WARN] An unknown szMode: " << it->second
                          << std::endl;
            }
            sz.szMode = szMode;
        }
        else if (it->first == "gzipMode")
        {
            sz.gzipMode = std::stoi(it->second);
        }
        else if (it->first == "errorBoundMode")
        {
            int errorBoundMode = ABS;
            if (it->second == "ABS")
            {
                errorBoundMode = ABS;
            }
            else if (it->second == "REL")
            {
                errorBoundMode = REL;
            }
            else if (it->second == "ABS_AND_REL")
            {
                errorBoundMode = ABS_AND_REL;
            }
            else if (it->second == "ABS_OR_REL")
            {
                errorBoundMode = ABS_OR_REL;
            }
            else if (it->second == "PW_REL")
            {
                errorBoundMode = PW_REL;
            }
            else
            {
                std::cout << "[WARN] An unknown errorBoundMode: " << it->second
                          << std::endl;
            }
            sz.errorBoundMode = errorBoundMode;
        }
        else if (it->first == "absErrBound")
        {
            sz.absErrBound = std::stof(it->second);
        }
        else if (it->first == "relBoundRatio")
        {
            sz.relBoundRatio = std::stof(it->second);
        }
        else if (it->first == "pw_relBoundRatio")
        {
            sz.pw_relBoundRatio = std::stof(it->second);
        }
        else if (it->first == "segment_size")
        {
            sz.segment_size = std::stoi(it->second);
        }
        else if (it->first == "pwr_type")
        {
            int pwr_type = SZ_PWR_MIN_TYPE;
            if ((it->first == "MIN") || (it->first == "SZ_PWR_MIN_TYPE"))
            {
                pwr_type = SZ_PWR_MIN_TYPE;
            }
            else if ((it->first == "AVG") || (it->first == "SZ_PWR_AVG_TYPE"))
            {
                pwr_type = SZ_PWR_AVG_TYPE;
            }
            else if ((it->first == "MAX") || (it->first == "SZ_PWR_MAX_TYPE"))
            {
                pwr_type = SZ_PWR_MAX_TYPE;
            }
            else
            {
                std::cout << "[WARN] An unknown pwr_type: " << it->second
                          << std::endl;
            }
            sz.pwr_type = pwr_type;
        }
        else if ((it->first == "abs") || (it->first == "absolute") ||
                 (it->first == "accuracy"))
        {
            sz.errorBoundMode = ABS;
            sz.absErrBound = std::stod(it->second);
        }
        else if ((it->first == "rel") || (it->first == "relative"))
        {
            sz.errorBoundMode = REL;
            sz.relBoundRatio = std::stof(it->second);
        }
        else if ((it->first == "pw") || (it->first == "pwr") ||
                 (it->first == "pwrel") || (it->first == "pwrelative"))
        {
            sz.errorBoundMode = PW_REL;
            sz.pw_relBoundRatio = std::stof(it->second);
        }
        else if ((it->first == "zchecker") || (it->first == "zcheck") ||
                 (it->first == "z-checker") || (it->first == "z-check"))
        {
            use_zchecker = (it->second == "") ? 1 : std::stof(it->second);
        }
        else
        {
            std::cout << "[WARN] An unknown SZ parameter: " << it->first
                      << std::endl;
        }
    }
    SZ_Init_Params(&sz); //seg fault happens here

valgrind output signal an invalid write of size 4:

BPWriteReadSZ.ADIOS2BPWriteRead1D
debugMode:1
accuracy => 0.001
sz.max_quant_intervals: 65536
sz.quantization_intervals: 0
sz.sol_ID: 101
sz.sampleDistance: 100
sz.predThreshold: 0.99
sz.szMode: 1
sz.gzipMode: 1
sz.errorBoundMode: 0
sz.absErrBound: 0.001
sz.relBoundRatio: 0.001
sz.psnr: 80
sz.pw_relBoundRatio: 1e-05
sz.segment_size: 5
sz.pwr_type: 0
==22812== Invalid write of size 4
==22812==    at 0x72AB4F6: SZ_Init_Params (in /opt/sz/2.0.2.0/lib/libSZ.so.1.0.4)
==22812==    by 0x5812752: adios2::core::compress::CompressSZ::Compress(void const*, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&) const (CompressSZ.cpp:264)
==22812==    by 0x578C645: void adios2::format::BP3SZ::SetDataCommon<float>(adios2::core::Variable<float> const&, adios2::core::Variable<float>::Info const&, adios2::core::Variable<float>::Operation const&, adios2::BufferSTL&) const (BP3SZ.tcc:35)
jychoi-hpc commented 6 years ago

Just a quick information, my initial SZ implementation in Adios2 was based on 1.4.12.x version. To use the most recent SZ, we need to change a few things in Adios2. I will start looking at.

williamfgc commented 6 years ago

Thanks @jychoi-hpc . Yes, I removed a few things (see the // above) from sz parameters to make ADIOS2 compile with the latest SZ master. Still, shouldn't crash if defaults are passed.

disheng222 commented 6 years ago

I fixed the issue. Thanks for the feedback. In testdouble_decompress.c, there is an example to show how to call SZ_Init_Params() to do the initialization without reading the configuration file sz.config. Specifically, you can change the following code

status = SZ_Init(cfgFile);

/*sz_params sz;
memset(&sz, 0, sizeof(sz_params));
sz.sol_ID = SZ;
sz.sampleDistance = 100;
sz.quantization_intervals = 0;
sz.max_quant_intervals = 65536;
sz.predThreshold = 0.98;
sz.szMode = SZ_BEST_COMPRESSION;
sz.losslessCompressor = ZSTD_COMPRESSOR;
sz.gzipMode = 1;
sz.errorBoundMode = REL;
sz.absErrBound = 1E-6;
sz.relBoundRatio = 1E-5;

SZ_Init_Params(&sz);*/

to be

//status = SZ_Init(cfgFile);

sz_params sz;
memset(&sz, 0, sizeof(sz_params));
sz.sol_ID = SZ;
sz.sampleDistance = 100;
sz.quantization_intervals = 0;
sz.max_quant_intervals = 65536;
sz.predThreshold = 0.98;
sz.szMode = SZ_BEST_COMPRESSION;
sz.losslessCompressor = ZSTD_COMPRESSOR;
sz.gzipMode = 1;
sz.errorBoundMode = REL;
sz.absErrBound = 1E-6;
sz.relBoundRatio = 1E-5;

SZ_Init_Params(&sz);

Then, execute "make" in the example/ directory. Then, you can test the compression as follows: ./testdouble_compress sz.config testdata/x86/testdouble_8_8_128.dat 8 8 128

Please let me know if you encounter any more questions/problems.

Please also note that the parameters are different between sz 1.4 and sz 2.0, because of some parameters become deprecated in sz 2.0. For instance, the following parameters are removed in SZ 2.0: layers offset segment_size pwr_type

Moreover, the default setting of sz.szMode is SZ_BEST_COMPRESSION now.

In SZ 2.0, we added a parameter called losslessCompressor, which is either GZIP_COMPRESSOR or ZSTD_COMPRSSOR. The latter is the recommended setting. If not set for this parameter, ZSTD_COMPRSSOR will be set by default.