Skip to content

Commit

Permalink
add the functionality of protecting value range (need to change #defi…
Browse files Browse the repository at this point in the history
…ne PROTECT_VALUE_RANGE 0 and recompile)
  • Loading branch information
Sheng Di committed Nov 26, 2019
1 parent 6f99260 commit 19ccec6
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 46 deletions.
6 changes: 5 additions & 1 deletion example/sz.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ void usage()
printf("* operation type:\n");
printf(" -z <compressed file>: the compression operation with an optionally specified output file.\n");
printf(" (the compressed file will be named as <input_file>.sz if not specified)\n");
printf(" -x <decompressed file>: the decompression operation with an optionally specified output file.\n");
printf(" -x <decompressed file>: the decompression operation with an optionally specified output file\n");
printf(" (the decompressed file will be named as <cmpred_file>.out if not specified)\n");
printf(" -p: print meta data (configuration info)\n");
printf(" -h: print the help information\n");
printf(" -v: print the version number\n");
printf("* data type:\n");
printf(" -f: single precision (float type)\n");
printf(" -d: double precision (double type)\n");
Expand Down Expand Up @@ -120,6 +121,9 @@ int main(int argc, char* argv[])
case 'h':
usage();
exit(0);
case 'v':
printf("version: %d.%d.%d\n", SZ_VER_MAJOR, SZ_VER_MINOR, SZ_VER_BUILD);
exit(0);
case 'b':
binaryOutput = 1;
break;
Expand Down
8 changes: 6 additions & 2 deletions sz/include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define SZ_VERNUM 0x0200
#define SZ_VER_MAJOR 2
#define SZ_VER_MINOR 1
#define SZ_VER_BUILD 7
#define SZ_VER_BUILD 8
#define SZ_VER_REVISION 0

#define PASTRI 103
Expand Down Expand Up @@ -93,11 +93,15 @@

#define GROUP_COUNT 16 //2^{16}=65536

#define MetaDataByteLength 20
#define MetaDataByteLength 28
#define MetaDataByteLength_double 36 //meta data length for double type

#define numOfBufferedSteps 1 //the number of time steps in the buffer


#define GZIP_COMPRESSOR 0 //i.e., ZLIB_COMPRSSOR
#define ZSTD_COMPRESSOR 1

#define PROTECT_VALUE_RANGE 0

#endif /* _SZ_DEFINES_H */
6 changes: 5 additions & 1 deletion sz/include/sz.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,18 @@ typedef struct sz_params
int segment_size; //only used for 2D/3D data compression with pw_relBoundRatio (deprecated)
int pwr_type; //only used for 2D/3D data compression with pw_relBoundRatio

float fmin, fmax;
double dmin, dmax;

int snapshotCmprStep; //perform single-snapshot-based compression if time_step == snapshotCmprStep
int predictionMode;

int accelerate_pw_rel_compression;
int plus_bits;

int randomAccess;
int withRegression;
int withRegression;

} sz_params;

typedef struct sz_metadata
Expand Down
24 changes: 24 additions & 0 deletions sz/src/ByteToolkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,18 @@ void convertSZParamsToBytes(sz_params* params, unsigned char* result)
int32ToBytes_bigEndian(&result[16], params->max_quant_intervals);
else
int32ToBytes_bigEndian(&result[16], params->quantization_intervals);

if(params->dataType==SZ_FLOAT)
{
floatToBytes(&result[20], params->fmin);
floatToBytes(&result[24], params->fmax);
}
else
{
doubleToBytes(&result[20], params->dmin);
doubleToBytes(&result[28], params->dmax);
}

}

void convertBytesToSZParams(unsigned char* bytes, sz_params* params)
Expand Down Expand Up @@ -1036,4 +1048,16 @@ void convertBytesToSZParams(unsigned char* bytes, sz_params* params)
params->max_quant_intervals = 0;
params->quantization_intervals = bytesToInt32_bigEndian(&bytes[16]);
}

if(params->dataType==SZ_FLOAT)
{
params->fmin = bytesToFloat(&bytes[20]);
params->fmax = bytesToFloat(&bytes[24]);
}
else if(params->dataType==SZ_DOUBLE)
{
params->dmin = bytesToDouble(&bytes[20]);
params->dmax = bytesToDouble(&bytes[28]);
}

}
26 changes: 13 additions & 13 deletions sz/src/TightDataPointStorageD.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int new_TightDataPointStorageD_fromFlatBytes(TightDataPointStorageD **this, unsi
}
convertBytesToSZParams(&(flatBytes[index]), confparams_dec);

index += MetaDataByteLength;
index += MetaDataByteLength_double;

int isRegression = (sameRByte >> 7) & 0x01;

Expand All @@ -112,7 +112,7 @@ int new_TightDataPointStorageD_fromFlatBytes(TightDataPointStorageD **this, unsi
else if(same==1)
{
(*this)->allSameData = 1;
//size_t exactMidBytesLength = sizeof(double);//flatBytesLength - 3 - 1 - MetaDataByteLength -exe_params->SZ_SIZE_TYPE;
//size_t exactMidBytesLength = sizeof(double);//flatBytesLength - 3 - 1 - MetaDataByteLength_double -exe_params->SZ_SIZE_TYPE;
(*this)->exactMidBytes = &(flatBytes[index]);
return errorBoundMode;
}
Expand All @@ -121,7 +121,7 @@ int new_TightDataPointStorageD_fromFlatBytes(TightDataPointStorageD **this, unsi

if(isRegression == 1)
{
(*this)->raBytes_size = flatBytesLength - 3 - 1 - MetaDataByteLength - exe_params->SZ_SIZE_TYPE;
(*this)->raBytes_size = flatBytesLength - 3 - 1 - MetaDataByteLength_double - exe_params->SZ_SIZE_TYPE;
(*this)->raBytes = &(flatBytes[index]);
return errorBoundMode;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ int new_TightDataPointStorageD_fromFlatBytes(TightDataPointStorageD **this, unsi

if ((*this)->rtypeArray != NULL)
{
(*this)->residualMidBits_size = flatBytesLength - 3 - 1 - MetaDataByteLength - exe_params->SZ_SIZE_TYPE - 4 - radExpoL - segmentL - pwrErrBoundBytesL - 4 - 8 - 1 - 8
(*this)->residualMidBits_size = flatBytesLength - 3 - 1 - MetaDataByteLength_double - exe_params->SZ_SIZE_TYPE - 4 - radExpoL - segmentL - pwrErrBoundBytesL - 4 - 8 - 1 - 8
- exe_params->SZ_SIZE_TYPE - exe_params->SZ_SIZE_TYPE - exe_params->SZ_SIZE_TYPE - minLogValueSize - exe_params->SZ_SIZE_TYPE - 8 - (*this)->rtypeArray_size
- minLogValueSize - (*this)->typeArray_size - (*this)->leadNumArray_size
- (*this)->exactMidBytes_size - pwrErrBoundBytes_size - 1 - 1;
Expand All @@ -231,7 +231,7 @@ int new_TightDataPointStorageD_fromFlatBytes(TightDataPointStorageD **this, unsi
}
else
{
(*this)->residualMidBits_size = flatBytesLength - 3 - 1 - MetaDataByteLength - exe_params->SZ_SIZE_TYPE - 4 - radExpoL - segmentL - pwrErrBoundBytesL - 4 - 8 - 1 - 8
(*this)->residualMidBits_size = flatBytesLength - 3 - 1 - MetaDataByteLength_double - exe_params->SZ_SIZE_TYPE - 4 - radExpoL - segmentL - pwrErrBoundBytesL - 4 - 8 - 1 - 8
- exe_params->SZ_SIZE_TYPE - exe_params->SZ_SIZE_TYPE - exe_params->SZ_SIZE_TYPE - minLogValueSize - (*this)->typeArray_size
- (*this)->leadNumArray_size - (*this)->exactMidBytes_size - pwrErrBoundBytes_size - 1 - 1;
}
Expand Down Expand Up @@ -395,7 +395,7 @@ void convertTDPStoBytes_double(TightDataPointStorageD* tdps, unsigned char* byte
bytes[k++] = sameByte; //1 byte

convertSZParamsToBytes(confparams_cpr, &(bytes[k]));
k = k + MetaDataByteLength;
k = k + MetaDataByteLength_double;

for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST: 4 or 8 bytes
bytes[k++] = dsLengthBytes[i];
Expand Down Expand Up @@ -497,7 +497,7 @@ void convertTDPStoBytes_double_reserve(TightDataPointStorageD* tdps, unsigned ch
bytes[k++] = sameByte; //1

convertSZParamsToBytes(confparams_cpr, &(bytes[k]));
k = k + MetaDataByteLength;
k = k + MetaDataByteLength_double;

for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
bytes[k++] = dsLengthBytes[i];
Expand Down Expand Up @@ -604,15 +604,15 @@ void convertTDPStoFlatBytes_double(TightDataPointStorageD *tdps, unsigned char**

if(tdps->allSameData==1)
{
size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + tdps->exactMidBytes_size;
size_t totalByteLength = 3 + 1 + MetaDataByteLength_double + exe_params->SZ_SIZE_TYPE + tdps->exactMidBytes_size;
*bytes = (unsigned char *)malloc(sizeof(unsigned char)*totalByteLength);

for (i = 0; i < 3; i++)//3
(*bytes)[k++] = versionNumber[i];
(*bytes)[k++] = sameByte;

convertSZParamsToBytes(confparams_cpr, &((*bytes)[k]));
k = k + MetaDataByteLength;
k = k + MetaDataByteLength_double;

for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
(*bytes)[k++] = dsLengthBytes[i];
Expand All @@ -636,7 +636,7 @@ void convertTDPStoFlatBytes_double(TightDataPointStorageD *tdps, unsigned char**
minLogValueSize = 8;
}

size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrBoundArrayL + 4 + 8 + 1 + 8
size_t totalByteLength = 3 + 1 + MetaDataByteLength_double + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrBoundArrayL + 4 + 8 + 1 + 8
+ exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE
+ minLogValueSize /*max absolute log value*/
+ tdps->typeArray_size + tdps->leadNumArray_size
Expand Down Expand Up @@ -678,14 +678,14 @@ void convertTDPStoFlatBytes_double_args(TightDataPointStorageD *tdps, unsigned c
sameByte = (unsigned char) (sameByte | 0x08); //0000,1000, the 7th bit
if(tdps->allSameData==1)
{
size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + tdps->exactMidBytes_size;
size_t totalByteLength = 3 + 1 + MetaDataByteLength_double + exe_params->SZ_SIZE_TYPE + tdps->exactMidBytes_size;

for (i = 0; i < 3; i++)//3
bytes[k++] = versionNumber[i];
bytes[k++] = sameByte;

convertSZParamsToBytes(confparams_cpr, &(bytes[k]));
k = k + MetaDataByteLength;
k = k + MetaDataByteLength_double;

for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
bytes[k++] = dsLengthBytes[i];
Expand All @@ -705,7 +705,7 @@ void convertTDPStoFlatBytes_double_args(TightDataPointStorageD *tdps, unsigned c
pwrBoundArrayL = 4;
}

size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE+ 4 + radExpoL + segmentL + pwrBoundArrayL + 4 + 8 + 1 + 8
size_t totalByteLength = 3 + 1 + MetaDataByteLength_double + exe_params->SZ_SIZE_TYPE+ 4 + radExpoL + segmentL + pwrBoundArrayL + 4 + 8 + 1 + 8
+ exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE
+ tdps->typeArray_size + tdps->leadNumArray_size
+ tdps->exactMidBytes_size + residualMidBitsLength + tdps->pwrErrBoundBytes_size;
Expand Down
2 changes: 1 addition & 1 deletion sz/src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int SZ_ReadConf(const char* sz_cfgFile) {
else if(strcmp(sol_name, "SZ_Transpose")==0)
confparams_cpr->sol_ID = SZ_Transpose;
else{
printf("[SZ] Error: wrong solution name (please check sz.config file)\n");
printf("[SZ] Error: wrong solution name (please check sz.config file), sol=%s\n", sol_name);
iniparser_freedict(ini);
return SZ_NSCS;
}
Expand Down
5 changes: 4 additions & 1 deletion sz/src/dataCompression.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,10 @@ int initRandomAccessBytes(unsigned char* raBytes)
raBytes[k++] = sameByte;

convertSZParamsToBytes(confparams_cpr, &(raBytes[k]));
k = k + MetaDataByteLength;
if(confparams_cpr->dataType==SZ_FLOAT)
k = k + MetaDataByteLength;
else if(confparams_cpr->dataType==SZ_DOUBLE)
k = k + MetaDataByteLength_double;

return k;
}
Expand Down
12 changes: 10 additions & 2 deletions sz/src/sz.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,10 @@ sz_metadata* SZ_getMetadata(unsigned char* bytes)
if(confparams_dec!=NULL)
free(confparams_dec);
confparams_dec = params;*/
index += MetaDataByteLength;
if(confparams_dec->dataType==SZ_FLOAT)
index += MetaDataByteLength;
else if(confparams_dec->dataType==SZ_DOUBLE)
index += MetaDataByteLength_double;

if(confparams_dec->dataType!=SZ_FLOAT && confparams_dec->dataType!= SZ_DOUBLE) //if this type is an Int type
index++; //jump to the dataLength info byte address
Expand Down Expand Up @@ -591,7 +594,8 @@ sz_metadata* SZ_getMetadata(unsigned char* bytes)
pwrErrBoundBytesL = 4;
}

int offset_typearray = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrErrBoundBytesL + 4 + (4 + confparams_dec->dataType*4) + 1 + 8
int mdbl = confparams_dec->dataType==SZ_FLOAT?MetaDataByteLength:MetaDataByteLength_double;
int offset_typearray = 3 + 1 + mdbl + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrErrBoundBytesL + 4 + (4 + confparams_dec->dataType*4) + 1 + 8
+ exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + 4;
defactoNBBins = bytesToInt_bigEndian(bytes+offset_typearray);
}
Expand Down Expand Up @@ -623,9 +627,13 @@ void SZ_printMetadata(sz_metadata* metadata)
{
case SZ_FLOAT:
printf("Data type: \t FLOAT\n");
printf("min value of raw data: \t %f\n", params->fmin);
printf("max value of raw data: \t %f\n", params->fmax);
break;
case SZ_DOUBLE:
printf("Data type: \t DOUBLE\n");
printf("min value of raw data: \t %f\n", params->dmin);
printf("max value of raw data: \t %f\n", params->dmax);
break;
case SZ_INT8:
printf("Data type: \t INT8\n");
Expand Down
Loading

0 comments on commit 19ccec6

Please sign in to comment.