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

Make HDF5.jl compatible with profilers that use LD_PRELOAD #791

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ else
if libhdf5_size != filesize(Libdl.dlpath(libhdf5))
error("HDF5 library has changed, re-run Pkg.build(\\\"HDF5\\\")")
end
if libversion < v"1.10.4"
if libversion[] < v"1.10.4"
Copy link
Author

Choose a reason for hiding this comment

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

libversion is now set in HDF5.__init__ so it needs to be a Ref.

error("HDF5.jl requires ≥ v1.10.4 of the HDF5 library.")
end
end
Expand Down
2 changes: 1 addition & 1 deletion gen/bind_generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function _bind(__module__, __source__, sig::Expr, err::Union{String,Expr,Nothing
statsym = Symbol("#status#") # not using gensym() to have stable naming

# The ccall(...) itself
cfunclib = Expr(:tuple, quot(cfuncname), lib)
cfunclib = Expr(:quote, cfuncname)
ccallexpr = :(ccall($cfunclib, $rettype, ($(argt...),), $(args...)))

# The error condition expression
Expand Down
11 changes: 10 additions & 1 deletion src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ dataspace, datatype
# H5DataStore, Attribute, File, Group, Dataset, Datatype, Opaque,
# Dataspace, Object, Properties, VLen, ChunkStorage, Reference

# Define the handles to the shared objects (these will be set in __init__)
const dlhdf5 = Ref{Ptr{Nothing}}(0)
const dlhdf5_hl = Ref{Ptr{Nothing}}(0)

const depsfile = joinpath(dirname(@__DIR__), "deps", "deps.jl")
if isfile(depsfile)
Expand Down Expand Up @@ -1899,7 +1902,7 @@ h5t_get_native_type(type_id) = h5t_get_native_type(type_id, H5T_DIR_ASCEND)

# Functions that require special handling

const libversion = h5_get_libversion()
const libversion = Ref{VersionNumber}(v"0.0.0")

vlen_get_buf_size(dset::Dataset, dtype::Datatype, dspace::Dataspace) = h5d_vlen_get_buf_size(dset, dtype, dspace)

Expand Down Expand Up @@ -1990,8 +1993,14 @@ For the second condition to be true, MPI.jl must be imported before HDF5.jl.
has_parallel() = HAS_PARALLEL[]

function __init__()
# Load the shared objects (dlhdf5 Ref declared way above)
dlhdf5[] = Libdl.dlopen(libhdf5, Libdl.RTLD_GLOBAL | Libdl.RTLD_LAZY)
dlhdf5_hl[] = Libdl.dlopen(libhdf5_hl, Libdl.RTLD_GLOBAL | Libdl.RTLD_LAZY)

libversion[] = h5_get_libversion()
check_deps()


# disable file locking as that can cause problems with mmap'ing
if !haskey(ENV, "HDF5_USE_FILE_LOCKING")
ENV["HDF5_USE_FILE_LOCKING"] = "FALSE"
Expand Down
396 changes: 198 additions & 198 deletions src/api.jl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/api_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ end
See `libhdf5` documentation for [`H5Oopen`](https://portal.hdfgroup.org/display/HDF5/H5P_GET_CLASS_NAME).
"""
function h5p_get_class_name(pcid)
pc = ccall((:H5Pget_class_name, libhdf5), Ptr{UInt8}, (hid_t,), pcid)
pc = ccall(:H5Pget_class_name, Ptr{UInt8}, (hid_t,), pcid)
if pc == C_NULL
error("Error getting class name")
end
Expand Down Expand Up @@ -310,7 +310,7 @@ end
See `libhdf5` documentation for [`H5Oopen`](https://portal.hdfgroup.org/display/HDF5/H5T_GET_MEMBER_NAME).
"""
function h5t_get_member_name(type_id, index)
pn = ccall((:H5Tget_member_name, libhdf5), Ptr{UInt8}, (hid_t, Cuint), type_id, index)
pn = ccall(:H5Tget_member_name, Ptr{UInt8}, (hid_t, Cuint), type_id, index)
if pn == C_NULL
error("Error getting name of compound datatype member #", index)
end
Expand All @@ -325,7 +325,7 @@ end
See `libhdf5` documentation for [`H5Oopen`](https://portal.hdfgroup.org/display/HDF5/H5T_GET_TAG).
"""
function h5t_get_tag(type_id)
pc = ccall((:H5Tget_tag, libhdf5), Ptr{UInt8}, (hid_t,), type_id)
pc = ccall(:H5Tget_tag, Ptr{UInt8}, (hid_t,), type_id)
if pc == C_NULL
error("Error getting opaque tag")
end
Expand Down
5 changes: 2 additions & 3 deletions src/mpio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ using .MPI
import Libdl

# Check whether the HDF5 libraries were compiled with parallel support.
HAS_PARALLEL[] = Libdl.dlopen(libhdf5) do lib
Libdl.dlsym(lib, :H5Pget_fapl_mpio, throw_error=false) !== nothing
end
HAS_PARALLEL[] = Libdl.dlsym(dlhdf5[], :H5Pget_fapl_mpio, throw_error=false) !== nothing


# Low-level MPI handles.
const MPIHandle = Union{MPI.MPI_Comm, MPI.MPI_Info}
Expand Down
2 changes: 1 addition & 1 deletion test/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ dspace_scal = HDF5.Dataspace(HDF5.h5s_create(HDF5.H5S_SCALAR))
dspace_norm = dataspace((100, 4))
dspace_maxd = dataspace((100, 4), max_dims = (256, 4))
dspace_slab = HDF5.hyperslab(dataspace((100, 4)), 1:20:100, 1:4)
if HDF5.libversion ≥ v"1.10.7"
if HDF5.h5_get_libversion() ≥ v"1.10.7"
Copy link
Author

Choose a reason for hiding this comment

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

Call the function instead of using the const global (to do the latter, it would need to be HDF5.libversion[] since it's a Ref).

dspace_irrg = HDF5.Dataspace(HDF5.h5s_combine_select(
HDF5.h5s_copy(dspace_slab), HDF5.H5S_SELECT_OR,
HDF5.hyperslab(dataspace((100, 4)), 2, 2)))
Expand Down