Skip to content

Commit 274105f

Browse files
authored
Merge pull request silx-kit#342 from t20100/hdf5-blosc2
self-merging, review still welcomed
2 parents 10c74d0 + f19b76a commit 274105f

26 files changed

+1233
-2
lines changed

doc/information.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ HDF5 compression filters and compression libraries sources were obtained from:
6969
using `BZip2 <https://sourceware.org/git/bzip2.git>`_ (v1.0.8).
7070
* `hdf5-blosc plugin <https://github.com/Blosc/hdf5-blosc>`_ (v1.0.1)
7171
using `c-blosc <https://github.com/Blosc/c-blosc>`_ (v1.21.6), LZ4, Snappy, ZLib and ZStd.
72-
* hdf5-blosc2 plugin (from `PyTables <https://github.com/PyTables/PyTables/>`_ v3.10.2)
72+
* `hdf5-blosc2 plugin <https://github.com/Blosc/HDF5-Blosc2>`_ (v2.0.0)
7373
using `c-blosc2 <https://github.com/Blosc/c-blosc2>`_ (v2.17.1), LZ4, ZLib and ZStd.
7474
* `FCIDECOMP plugin <https://gitlab.eumetsat.int/open-source/data-tailor-plugins/fcidecomp>`_
7575
(`v2.1.1 <https://gitlab.eumetsat.int/open-source/data-tailor-plugins/fcidecomp/-/tree/2.1.1>`_)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ def _get_blosc2_plugin():
10821082
10831083
Source from PyTables and c-blosc2
10841084
"""
1085-
hdf5_blosc2_dir = 'src/PyTables/hdf5-blosc2/src'
1085+
hdf5_blosc2_dir = 'src/HDF5-Blosc2/src'
10861086
hdf5_blosc2_sources = prefix(hdf5_blosc2_dir, ['blosc2_filter.c', 'blosc2_plugin.c'])
10871087

10881088
extra_compile_args = ['-O3', '-std=gnu99']

src/HDF5-Blosc2/.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Object files
2+
*.o
3+
*.ko
4+
*.obj
5+
*.elf
6+
7+
# Precompiled Headers
8+
*.gch
9+
*.pch
10+
11+
# Libraries
12+
*.lib
13+
*.a
14+
*.la
15+
*.lo
16+
17+
# Shared objects (inc. Windows DLLs)
18+
*.dll
19+
*.so
20+
*.so.*
21+
*.dylib
22+
23+
# Executables
24+
*.exe
25+
*.out
26+
*.app
27+
*.i*86
28+
*.x86_64
29+
*.hex
30+
31+
# Debug files
32+
*.dSYM/
33+
34+
# Anything in the 'build' folder.
35+
build/
36+

src/HDF5-Blosc2/.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: c
2+
3+
os:
4+
- linux
5+
- osx
6+
7+
compiler:
8+
- gcc
9+
- clang
10+
11+
before_install: ./travis-before-install.sh
12+
13+
install: sudo apt-get install libhdf5-serial-dev
14+
15+
before_script:
16+
- mkdir build
17+
- cd build
18+
- cmake ..
19+
20+
script:
21+
- cmake --build . --config Release
22+
- ctest

src/HDF5-Blosc2/CMakeLists.txt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
cmake_minimum_required(VERSION 2.8.10)
2+
cmake_policy(SET CMP0074 NEW)
3+
project(blosc2_hdf5)
4+
include(ExternalProject)
5+
6+
# options
7+
option(BUILD_TESTS
8+
"Build test programs form the blosc2 filter" ON)
9+
10+
option(BUILD_PLUGIN
11+
"Build dynamically loadable plugin for HDF5 version > 1.8.11" ON)
12+
if(BUILD_PLUGIN)
13+
set(PLUGIN_INSTALL_PATH "/usr/local/hdf5/lib/plugin" CACHE PATH
14+
"Where to install the dynamic HDF5-plugin")
15+
endif(BUILD_PLUGIN)
16+
17+
set(BLOSC2_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/blosc2")
18+
set(BLOSC2_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/blosc2")
19+
set(BLOSC2_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${BLOSC2_INSTALL_DIR})
20+
21+
message("BLOSC2_PREFIX='${BLOSC2_PREFIX}'")
22+
message("BLOSC2_INSTALL_DIR='${BLOSC2_INSTALL_DIR}'")
23+
message("BLOSC2_CMAKE_ARGS='${BLOSC2_CMAKE_ARGS}'")
24+
message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
25+
26+
ExternalProject_Add(project_blosc2
27+
PREFIX ${BLOSC2_PREFIX}
28+
GIT_REPOSITORY https://github.com/Blosc/c-blosc2.git
29+
GIT_TAG main
30+
INSTALL_DIR ${BLOSC2_INSTALL_DIR}
31+
CMAKE_ARGS ${BLOSC2_CMAKE_ARGS}
32+
)
33+
34+
35+
# sources
36+
set(SOURCES src/blosc2_filter.c)
37+
set(PLUGIN_SOURCES src/blosc2_filter.c src/blosc2_plugin.c)
38+
39+
# dependencies
40+
if(MSVC)
41+
# FindHDF5.cmake does not find Windows installations. Try to
42+
# use an environment variable instead until the official "find"
43+
# file can be updated for Windows.
44+
#
45+
# Note that you have to set this environment variable by hand.
46+
file(TO_CMAKE_PATH "$ENV{HDF5_DIR}" HDF5_HINT)
47+
set(HDF5_DIR ${HDF5_HINT} CACHE STRING "Path to HDF5 CMake config directory.")
48+
find_package(HDF5 REQUIRED HINTS ${HDF5_DIR})
49+
else(MSVC)
50+
find_package(HDF5 REQUIRED)
51+
endif(MSVC)
52+
include_directories(${HDF5_INCLUDE_DIRS})
53+
include_directories("/mnt/c/Users/sosca/CLionProjects/build/include")
54+
55+
56+
# add blosc2 libraries
57+
add_library(blosc2_shared SHARED IMPORTED)
58+
set_property(TARGET blosc2_shared PROPERTY IMPORTED_LOCATION ${BLOSC2_INSTALL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}blosc2${CMAKE_SHARED_LIBRARY_SUFFIX})
59+
add_dependencies(blosc2_shared project_blosc2)
60+
include_directories(${BLOSC2_INSTALL_DIR}/include)
61+
62+
add_library(blosc2_filter_shared SHARED ${SOURCES})
63+
set_target_properties(
64+
blosc2_filter_shared PROPERTIES OUTPUT_NAME blosc2_filter)
65+
target_link_libraries(blosc2_filter_shared blosc2_shared ${HDF5_LIBRARIES})
66+
67+
if(BUILD_PLUGIN)
68+
add_library(blosc2_plugin_shared SHARED ${PLUGIN_SOURCES})
69+
set_target_properties(
70+
blosc2_plugin_shared PROPERTIES OUTPUT_NAME H5Zblosc2)
71+
target_link_libraries(blosc2_plugin_shared blosc2_shared ${HDF5_LIBRARIES})
72+
73+
install(TARGETS blosc2_plugin_shared DESTINATION ${PLUGIN_INSTALL_PATH} COMPONENT HDF5_FILTER_DEV)
74+
endif(BUILD_PLUGIN)
75+
76+
# install
77+
install(FILES src/blosc2_filter.h DESTINATION include COMPONENT HDF5_FILTER_DEV)
78+
install(TARGETS blosc2_filter_shared DESTINATION lib COMPONENT HDF5_FILTER_DEV)
79+
80+
81+
# add caterva library
82+
add_library(CAT_LIBRARY SHARED IMPORTED)
83+
set_target_properties(CAT_LIBRARY PROPERTIES IMPORTED_LOCATION "/mnt/c/Users/sosca/CLionProjects/build/libs/release/libcaterva.so")
84+
85+
86+
# test
87+
message("LINK LIBRARIES='blosc2_filter_shared ${HDF5_LIBRARIES}'")
88+
if(BUILD_TESTS)
89+
enable_testing()
90+
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
91+
find_package(Threads REQUIRED)
92+
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
93+
add_executable(example executables/example.c)
94+
target_link_libraries(example blosc2_filter_shared ${HDF5_LIBRARIES} ${LIBS})
95+
add_test(test_hdf5_filter example)
96+
add_executable(test_blosc2_filter_read executables/test_blosc2_filter_read.c)
97+
target_link_libraries(test_blosc2_filter_read blosc2_filter_shared ${HDF5_LIBRARIES} ${LIBS} CAT_LIBRARY)
98+
add_test(test_hdf5_filter test_blosc2_filter_read)
99+
endif(BUILD_TESTS)

src/HDF5-Blosc2/LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Blosc2 for HDF5 - An HDF5 filter that uses the Blosc2 compressor.
2+
3+
Copyright (c) 2009-2018 Francesc Alted <[email protected]>
4+
Copyright (c) 2019-present Blosc Development Team <[email protected]>
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

src/HDF5-Blosc2/LICENSES/BLOSC.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
BSD License
2+
3+
For Blosc - A blocking, shuffling and lossless compression library
4+
5+
Copyright (c) 2009-2018 Francesc Alted <[email protected]>
6+
Copyright (c) 2019-present Blosc Development Team <[email protected]>
7+
8+
Redistribution and use in source and binary forms, with or without modification,
9+
are permitted provided that the following conditions are met:
10+
11+
* Redistributions of source code must retain the above copyright notice, this
12+
list of conditions and the following disclaimer.
13+
14+
* Redistributions in binary form must reproduce the above copyright notice,
15+
this list of conditions and the following disclaimer in the documentation
16+
and/or other materials provided with the distribution.
17+
18+
* Neither the name Francesc Alted nor the names of its contributors may be used
19+
to endorse or promote products derived from this software without specific
20+
prior written permission.
21+
22+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

src/HDF5-Blosc2/LICENSES/H5PY.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Copyright Notice and Statement for the h5py Project
2+
3+
Copyright (c) 2008 Andrew Collette
4+
http://h5py.alfven.org
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are
9+
met:
10+
11+
a. Redistributions of source code must retain the above copyright
12+
notice, this list of conditions and the following disclaimer.
13+
14+
b. Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the
17+
distribution.
18+
19+
c. Neither the name of the author nor the names of contributors may
20+
be used to endorse or promote products derived from this software
21+
without specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+

src/HDF5-Blosc2/README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Blosc2 filter for HDF5
2+
3+
This is a filter for HDF5 that uses the Blosc2 compressor; by installing this
4+
filter, you can read and write HDF5 files with Blosc2-compressed datasets.
5+
6+
You need to be a bit careful before using this filter because you
7+
should not activate the shuffle right in HDF5, but rather from Blosc2
8+
itself. This is because Blosc2 uses an internal SIMD shuffle, which
9+
is much faster.
10+
11+
## Installing the Blosc2 filter plugin
12+
13+
Instead of just linking this Blosc2 filter into your HDF5 application, it is possible to install
14+
it as a system-wide HDF5 plugin (with HDF5 1.8.11 or later). This is useful because it allows
15+
*every* HDF5-using program on your system to transparently read Blosc2-compressed HDF5 files.
16+
17+
As described in the `HDF5 plugin documentation <https://portal.hdfgroup.org/display/HDF5/HDF5+Dynamically+Loaded+Filters>`_, you just need to compile the Blosc2 plugin into a shared library and
18+
copy it to the plugin directory (which defaults to ``/usr/local/hdf5/lib/plugin`` on non-Windows systems).
19+
20+
Following the ``cmake`` instructions below produces a ``libH5Zblosc2.so`` shared library
21+
file (or ``.dylib``/``.dll`` on Mac/Windows), that you can copy to the HDF5 plugin directory.
22+
23+
To *write* Blosc2-compressed HDF5 files, on the other hand, an HDF5 using program must be
24+
specially modified to enable the Blosc2 filter when writing HDF5 datasets, as described below.
25+
26+
27+
## Linking the Blosc2 filter directly into your program
28+
29+
Instead of (or in addition to) installing the Blosc2 plugin system-wide as
30+
described above, you can also link the Blosc2 filter directly into your
31+
application. Although this only makes the Blosc2 filter available in
32+
your application (as opposed to other HDF5-using applications), it
33+
is useful in cases where installing the plugin is inconvenient. Compile
34+
the Blosc2 filter as described above, but link ``libblosc2_filter.a``
35+
(generated by ``make``) directly into your program.
36+
37+
To register Blosc2 in your HDF5 application, you then need to call
38+
a function in blosc2_filter.h, with the following signature:
39+
40+
```C
41+
int register_blosc2(char **version, char **date)
42+
```
43+
44+
Calling this will register the filter with the HDF5 library and will
45+
return info about the Blosc2 release in `**version` and `**date`
46+
char pointers.
47+
48+
A non-negative return value indicates success. If the registration
49+
fails, an error is pushed onto the current error stack and a negative
50+
value is returned.
51+
52+
An example C program ('src/example.c') is included which demonstrates
53+
the proper use of the filter.
54+
55+
This filter has been tested against HDF5 versions 1.6.5 through
56+
1.8.10. It is released under the MIT license (see LICENSE.txt for
57+
details).
58+
59+
## Using the Blosc2 filter in your application
60+
61+
Assuming the filter is installed (either by a system-wide plugin or registered
62+
directly in your program as described above), your application can transparently
63+
*read* HDF5 files with Blosc2-compressed datasets. (The HDF5 library will detect
64+
that the dataset is Blosc2-compressed and invoke the filter automatically).
65+
66+
To *write* an HDF5 file with a Blosc2-compressed dataset, you call the
67+
`H5Pset_filter <https://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetFilter>`_ function
68+
on the property list of the dataset you are creating, and pass ``FILTER_BLOSC2``
69+
(defined in ``blosc2_filter.h``) for the ``filter_id`` parameter. In addition, HDF5
70+
only supports compression for "chunked" datasets; this just means that you need to
71+
call `H5Pset_chunk <https://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetChunk>`_ to
72+
specify a chunk size (e.g. 1MB chunks), and the subsequent chunking of the dataset I/O
73+
is performed transparently by HDF5.
74+
75+
## Compiling
76+
77+
The filter consists of a single 'src/blosc2_filter.c' source file and
78+
'src/blosc2_filter.h' header, which will need the Blosc2 library
79+
installed to work. It is simplest to just use the provided ``cmake``
80+
build scripts, which compile and both the filter and the Blosc2 library
81+
into a library for you
82+
83+
Assuming you have `cmake <http://www.cmake.org/>`_ and other standard
84+
Unix build tools installed, do::
85+
86+
mkdir build
87+
cd build
88+
cmake ..
89+
make
90+
91+
This generates the library/plugin files required above in the ``build``
92+
directory.
93+
94+
## Acknowledgments
95+
96+
This filter was initially written by Francesc Alted, based on the
97+
previous Blosc filter for HDF5. Ivan Vilata i Balaguer contributed
98+
the support for Blosc2 NDim format.
99+
100+
Oscar Guiñón and Tom Birch helped in testing, debugging and fixing
101+
the filter. Thomas Vincent contributed with the integration of this
102+
work into the [hdf5plugin](https://hdf5plugin.readthedocs.io) project.
103+
104+
## License
105+
106+
This software is released under the MIT license. See LICENSE.txt for
107+
details.
108+
109+
**Enjoy data!**

0 commit comments

Comments
 (0)