Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option for using blosc filter #980

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LauZanMo
Copy link

See #978

This PR adds a custom blosc filter and has been tested in create_dataset_double.cpp in examples folder.

Comment on lines +105 to +108
# I install hdf5-blosc to the default path
set(blosc_filter_DIR /usr/local/lib/)
target_link_libraries(HighFive INTERFACE blosc_filter)
target_link_directories(HighFive INTERFACE /usr/local/include/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have to fix that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since blosc is an extra plugin of hdf5, it is necessary to compile and link this external libraries. hdf5-blosc can not be found using find_package macro since it is packaged too simple here. I haven't figured out an elegant way to link this library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that hard coded path to your system is not the valid way to give access to blosc.

Comment on lines +244 to +255
inline herr_t h5p_set_blosc(hid_t plist_id, const unsigned int *cd_values) {
char *version, *date;
if (register_blosc(&version, &date) < 0) {
HDF5ErrMapper::ToException<PropertyException>("Blosc filter unavailable.");
}

herr_t err = H5Pset_filter(plist_id, FILTER_BLOSC, H5Z_FLAG_OPTIONAL, 7, cd_values);
if (err < 0) {
HDF5ErrMapper::ToException<PropertyException>("Error setting blosc property");
}
return err;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1uc I don't think this is how you think how your wrapper, right?
We will need to put this helper in an other place?

Copy link
Author

@LauZanMo LauZanMo Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike szip, a built-in filter in hdf5, blosc filter must be registered before use. Perhaps a register wrapper should be added here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'd prefer splitting it differently:

inline herr_t h5p_set_filter(....) {
    herr_t err = H5Pset_filter(...);
    if (err < 0) {
        HDF5ErrMapper::ToException<PropertyException>("Error setting setting filter.");
    }
    return err;
}

Then in Blosc we do the other half:

inline void Blosc::apply(const hid_t hid) const {
    char *version, *date;
    if (register_blosc(&version, &date) < 0) {
        HDF5ErrMapper::ToException<PropertyException>("Blosc filter unavailable.");
    }
    detail::h5p_set_filter(plist_id, FILTER_BLOSC, H5Z_FLAG_OPTIONAL, 7, cd_values);
}

If you want the error message to contain the word "blosc" when set_filter fail, one would need to catch and rethrow with a different error message.

@1uc
Copy link
Collaborator

1uc commented Apr 16, 2024

To avoid the issue with forcing an optional dependency (blosc) on all users, we'll need to rework the PR. I think we can safely move all blocs related code to highfive/blosc.hpp. Ensure we include the header for blosc. The wrapper for H5Pset_filter stays in h5p_wrapper.hpp.

To fix the build-system maybe the following works:

  1. Temporarily remove all CMake code.
  2. For testing only add it back similar to how boost and Eigen are handled.
  3. Setup CI that installs blosc and runs the tests.

This has the advantage (for us) that we don't specify how to find/link to blosc, it's left up to the user. This is different everywhere and we're likely to get it wrong if blosc doesn't have *-config.cmake files. The solution @LauZanMo shows presumably works very well for their usecase, but unfortunately for a library that's not suitable. We can always add a target highfive::blosc if needed, but we can't take it away.

#include "blosc_filter.h"

inline herr_t h5p_set_blosc(hid_t plist_id, const unsigned int *cd_values) {
char *version, *date;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are both leaked, because register_blosc uses strdup which requires us to call free.

}

inline void Blosc::apply(const hid_t hid) const {
detail::h5p_set_blosc(hid, _cd_values);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function likely can't be called twice. Therefore, if two property lists with Blosc are created I suspect a misleading error message will be printed. It's unclear if it'll work, because register_blosc seems to unconditionally return 1; (despite defining and setting a retval).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants