Skip to content

Commit

Permalink
support blosc2 compressors
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Sep 12, 2022
1 parent 3f9542e commit 944fb12
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 27 deletions.
8 changes: 7 additions & 1 deletion include/zmatlib.h
Expand Up @@ -63,9 +63,15 @@ extern "C"
* 4: lzma
* 5: lz4
* 6: lz4hc
* 7: blosc2blosclz
* 8: blosc2lz4
* 9: blosc2lz4hc
* 10: blosc2zlib
* 11: blosc2zstd
* -1: unknown
*/

enum TZipMethod {zmZlib, zmGzip, zmBase64, zmLzip, zmLzma, zmLz4, zmLz4hc};
enum TZipMethod {zmZlib, zmGzip, zmBase64, zmLzip, zmLzma, zmLz4, zmLz4hc, zmBlosc2Blosclz, zmBlosc2Lz4, zmBlosc2Lz4hc, zmBlosc2Zlib, zmBlosc2Zstd, zmUnknown=-1};

/**
* @brief Main interface to perform compression/decompression
Expand Down
Binary file removed private/zipmat.mexa64
Binary file not shown.
Binary file removed private/zipmat.mexmaci64
Binary file not shown.
Binary file removed private/zipmat.mexw64
Binary file not shown.
52 changes: 45 additions & 7 deletions src/Makefile
Expand Up @@ -11,6 +11,9 @@ ZMATDIR ?=$(ROOTDIR)
LIBDIR ?=$(ROOTDIR)/lib

MKDIR :=mkdir
HAVE_LZMA ?=yes
HAVE_LZ4 ?=yes
HAVE_BLOSC2?=yes

MEX=mex
AR=$(CC)
Expand All @@ -23,7 +26,7 @@ DOXY := doxygen
DOCDIR := $(ZMATDIR)/doc
DOXYCFG=zmat.cfg

INCLUDEDIRS=-I../include -Ieasylzma -Ieasylzma/pavlov -Ilz4
INCLUDEDIRS=-I../include

CUOMPLINK=

Expand All @@ -39,11 +42,7 @@ OUTPUTFLAG:=-o
OBJSUFFIX=.o
EXESUFFIX=.mex*

FILES=zmatlib lz4/lz4 lz4/lz4hc easylzma/compress easylzma/decompress \
easylzma/lzma_header easylzma/lzip_header easylzma/common_internal \
easylzma/pavlov/LzmaEnc easylzma/pavlov/LzmaDec easylzma/pavlov/LzmaLib \
easylzma/pavlov/LzFind easylzma/pavlov/Bra easylzma/pavlov/BraIA64 \
easylzma/pavlov/Alloc easylzma/pavlov/7zCrc
FILES=zmatlib

ifeq ($(findstring CYGWIN,$(PLATFORM)), CYGWIN)
ifeq ($(findstring x86_64,$(ARCH)), x86_64)
Expand Down Expand Up @@ -76,6 +75,38 @@ else
endif
endif

ifeq ($(HAVE_LZMA),no)
CFLAGS+=-DNO_LZMA
else
INCLUDEDIRS+=-Ieasylzma -Ieasylzma/pavlov
FILES+=easylzma/compress easylzma/decompress \
easylzma/lzma_header easylzma/lzip_header easylzma/common_internal \
easylzma/pavlov/LzmaEnc easylzma/pavlov/LzmaDec easylzma/pavlov/LzmaLib \
easylzma/pavlov/LzFind easylzma/pavlov/Bra easylzma/pavlov/BraIA64 \
easylzma/pavlov/Alloc easylzma/pavlov/7zCrc
endif

ifeq ($(HAVE_BLOSC2),no)
CFLAGS+=-DNO_BLOSC2
else
ifeq ($(HAVE_LZ4),no)
INCLUDEDIRS+=-Ilz4
FILES+= lz4/lz4 lz4/lz4hc
endif
LINKOPT+=-Lblosc2/lib -lblosc2 -Lblosc2/internal-complibs/zstd-1.5.2 -lzstd
INCLUDEDIRS+=-Iblosc2/include
endif

ifeq ($(HAVE_LZ4),no)
CFLAGS+=-DNO_LZ4
else
INCLUDEDIRS+=-Ilz4
FILES+= lz4/lz4 lz4/lz4hc
endif




ifeq ($(MAKECMDGOALS),lib)
AR :=ar
ARFLAGS :=cr
Expand Down Expand Up @@ -135,18 +166,24 @@ OBJS := $(addsuffix $(OBJSUFFIX), $(FILES))

all dll lib mex oct: $(OUTPUT_DIR)/$(BINARY)

blosc:
@if [ $(HAVE_BLOSC2) = "yes" ]; then\
$(MAKE) -C blosc2 all;\
fi

makedirs:
@if test ! -d $(OUTPUT_DIR); then $(MKDIR) $(OUTPUT_DIR); fi

makedocdir:
@if test ! -d $(DOCDIR); then $(MKDIR) $(DOCDIR); fi

$(OUTPUT_DIR)/$(BINARY): makedirs $(OBJS)
$(OUTPUT_DIR)/$(BINARY): makedirs $(OBJS) blosc
$(OUTPUT_DIR)/$(BINARY): $(OBJS)
@$(ECHO) Building $@
$(AR) $(ARFLAGS) $(OUTPUTFLAG) $@ $(OBJS) $(LINKOPT) $(USERLINKOPT)

%$(OBJSUFFIX): %.cpp
@$(ECHO) Building $@
$(CXX) $(INCLUDEDIRS) $(CPPOPT) -c -o $@ $<

%$(OBJSUFFIX): %.c
Expand All @@ -159,6 +196,7 @@ $(OUTPUT_DIR)/$(BINARY): $(OBJS)

clean:
-rm -f $(OBJS) $(OUTPUT_DIR)/$(BINARY)$(EXESUFFIX) zmat$(OBJSUFFIX) $(LIBDIR)/*
-$(MAKE) -C blosc2 clean

pretty:
astyle \
Expand Down
80 changes: 71 additions & 9 deletions src/zmat.cpp
Expand Up @@ -66,15 +66,53 @@ const char* metadata[] = {"type", "size", "byte", "method", "status", "level"};
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
TZipMethod zipid = zmZlib;
int iscompress = 1;
#if defined(NO_LZ4) && defined(NO_LZMA)
const char* zipmethods[] = {"zlib", "gzip", "base64", ""};
#elif !defined(NO_LZMA) && defined(NO_LZ4)
const char* zipmethods[] = {"zlib", "gzip", "base64", "lzip", "lzma", ""};
#elif defined(NO_LZMA) && !defined(NO_LZ4)
const char* zipmethods[] = {"zlib", "gzip", "base64", "lz4", "lz4hc", ""};
#else
const char* zipmethods[] = {"zlib", "gzip", "base64", "lzip", "lzma", "lz4", "lz4hc", ""};
const char* zipmethods[] = {
"zlib",
"gzip",
"base64",
#if !defined(NO_LZMA)
"lzip",
"lzma",
#endif
#if !defined(NO_LZ4)
"lz4",
"lz4hc",
#endif
#if !defined(NO_BLOSC2)
"blosc2blosclz",
"blosc2lz4",
"blosc2lz4hc",
"blosc2zlib",
"blosc2zstd",
#endif
""};

const TZipMethod zipmethodid[] = {
zmZlib,
zmGzip,
zmBase64,
#if !defined(NO_LZMA)
zmLzip,
zmLzma,
#endif
#if !defined(NO_LZ4)
zmLz4,
zmLz4hc,
#endif
#if !defined(NO_BLOSC2)
zmBlosc2Blosclz,
zmBlosc2Lz4,
zmBlosc2Lz4hc,
zmBlosc2Zlib,
zmBlosc2Zstd,
#endif
zmUnknown};

int nthread = 1; /*nthread, shuffle and typesize are only used by blosc2 compressors*/
int shuffle = 1;
int typesize = 4;
char clevel = 1;

int use4bytedim = 0;

/**
Expand Down Expand Up @@ -103,7 +141,7 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {

if (nrhs >= 2) {
double* val = mxGetPr(prhs[1]);
iscompress = val[0];
clevel = val[0];
}

if (nrhs >= 3) {
Expand All @@ -116,7 +154,31 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
if ((zipid = (TZipMethod)zmat_keylookup((char*)mxArrayToString(prhs[2]), zipmethods)) < 0) {
mexErrMsgTxt("the specified compression method is not supported");
}

zipid = zipmethodid[(int)zipid];
}

if (nrhs >= 4) {
double* val = mxGetPr(prhs[3]);
nthread = val[0];
}

if (nrhs >= 5) {
double* val = mxGetPr(prhs[4]);
shuffle = val[0];
}

if (nrhs >= 6) {
double* val = mxGetPr(prhs[5]);
typesize = val[0];
}
printf("iscompress=%X %d %d %d %X\n", clevel, nthread, shuffle, typesize, ((nthread & 0xFF) << 8));
if(clevel) {
iscompress = (clevel | ((nthread & 0xFF) << 8) | ((shuffle & 0xFF) << 16) | ((typesize & 0xFF) << 24));
} else {
iscompress = (clevel | ((nthread & 0xFF) << 8));
}
printf("iscompress=%X\n", iscompress);

try {
if (mxIsChar(prhs[0]) || (mxIsNumeric(prhs[0]) && !mxIsComplex(prhs[0])) || mxIsLogical(prhs[0])) {
Expand Down

0 comments on commit 944fb12

Please sign in to comment.