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

Issue 510d: add DataspacePool and DataspaceHolder to speed-up h5cpp #515

Merged
merged 12 commits into from
Nov 4, 2021
2 changes: 1 addition & 1 deletion doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ PLANTUML_JAR_PATH =
# Minimum value: 0, maximum value: 10000, default value: 50.
# This tag requires that the tag HAVE_DOT is set to YES.

DOT_GRAPH_MAX_NODES = 50
DOT_GRAPH_MAX_NODES = 100

# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
# generated by dot. A depth value of 3 means that only nodes reachable from the
Expand Down
2 changes: 1 addition & 1 deletion doc/mainpage.dox
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! \mainpage Welcome to the h5++ documentation


\subpage uguide
\subpage uguide "Users Guide"

*/

Expand Down
3 changes: 2 additions & 1 deletion doc/source/advanced/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ of *h5cpp*.
:maxdepth: 1

cpp_datastructures
c_arrays
c_arrays
user_data
4 changes: 2 additions & 2 deletions doc/source/api_reference/namespace_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The :cpp:class:`File` class
Functions
---------

.. doxygenfunction:: hdf5::file::create(const boost::filesystem::path &, AccessFlags, const property::FileCreationList &, const property::FileAccessList &)
.. doxygenfunction:: hdf5::file::create(const fs::path &, AccessFlags, const property::FileCreationList &, const property::FileAccessList &)

.. doxygenfunction:: hdf5::file::open(const boost::filesystem::path &, AccessFlags, const property::FileAccessList &)
.. doxygenfunction:: hdf5::file::open(const fs::path &, AccessFlags, const property::FileAccessList &)

.. doxygenfunction:: hdf5::file::is_hdf5_file

Expand Down
4 changes: 2 additions & 2 deletions doc/source/api_reference/namespace_node.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Enumerations

.. doxygenenum:: hdf5::node::LinkType

.. doxygenenum:: hdf5::node::operator<<(std::ostream &, const LinkType &)
.. doxygenfunction:: hdf5::node::operator<<(std::ostream &, const LinkType &)

Classes
=======
Expand Down Expand Up @@ -170,4 +170,4 @@ Functions





2 changes: 1 addition & 1 deletion doc/source/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,4 @@ texinfo_documents = [
# texinfo_no_detailmenu = False

# workaround fix for qualifiers error
cpp_id_attributes = ["DLL_EXPORT"]
cpp_id_attributes = ["DLL_EXPORT", "friend"]
6 changes: 6 additions & 0 deletions doc/source/users_guide/dataspace_custom_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ a type trait as follows
{
return Simple({3,3});
}

const static DataspaceType & get(const Matrix &)
{
const static DataspaceType & cref_ = Simple({3,3});
return cref_;
}

static void *ptr(Matrix &value)
{
Expand Down
6 changes: 6 additions & 0 deletions examples/image_h5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ class TypeTrait<Image<PixelT>>
hdf5::Dimensions{value.ny(),value.nx()});
}

const static DataspaceType & get(const Image<PixelT> &value)
{
const static DataspaceType & cref_ = Simple(hdf5::Dimensions{value.ny(),value.nx()},
hdf5::Dimensions{value.ny(),value.nx()});
}

static void *ptr(Image<PixelT> &value)
{
return reinterpret_cast<void*>(value.data());
Expand Down
1 change: 1 addition & 0 deletions src/h5cpp/attribute/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DLL_EXPORT Attribute
//! \brief constructor
//!
//! \param handle rvalue reference to the attributes handle
//! \param parent_link like to the parent object
//!
Attribute(ObjectHandle &&handle,const node::Link &parent_link);

Expand Down
2 changes: 2 additions & 0 deletions src/h5cpp/attribute/attribute_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class DLL_EXPORT AttributeManager
//! \throws std::runtime_error in case of an error
//! \tparam T element data type of the attribute
//! \param name the name of the attribute
//! \param acpl attribute creation property list
//! \return instance of the newly created attribute
//!
template<typename T>
Expand All @@ -166,6 +167,7 @@ class DLL_EXPORT AttributeManager
//! \tparam T element data type
//! \param name the name for the attribute
//! \param shape the number of elements along each dimension
//! \param acpl attribute creation property list
//! \return instance of the newly created attribute
//!
template<typename T>
Expand Down
2 changes: 1 addition & 1 deletion src/h5cpp/core/iterator_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
namespace hdf5 {

//!
//! @brief iteration order
//! \enum IterationOrder iteration order
//!
//! This enumeration is used to control how an iterator traverses an iterable
//! with a particular index.
Expand Down
2 changes: 2 additions & 0 deletions src/h5cpp/core/object_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class DLL_EXPORT ObjectHandle
//! \throws std::runtime_error if the passed id is invalid (<0)
//!
//! \param id HDF5 object ID.
//! \param policy with or w/o ward policy.
//!
explicit ObjectHandle(hid_t id, Policy policy=Policy::WITH_WARD);

//-----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/h5cpp/dataspace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(HEADERS
${dir}/type_trait.hpp
${dir}/view.hpp
${dir}/points.hpp
${dir}/pool.hpp
)

install(FILES ${HEADERS}
Expand Down
35 changes: 21 additions & 14 deletions src/h5cpp/dataspace/dataspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,26 @@ Dataspace::Dataspace(ObjectHandle &&handle)

Dataspace::Dataspace(const Dataspace &space)
: selection(*this) {
hid_t ret = H5Scopy(static_cast<hid_t>(space.handle_));
if (0 > ret) {
error::Singleton::instance().throw_with_stack("could not copy-construct Dataspace");
}
handle_ = ObjectHandle(ret);
swap(space);
}

Dataspace &Dataspace::operator=(const Dataspace &space) {
hid_t ret = H5Scopy(static_cast<hid_t>(space.handle_));
if (0 > ret) {
error::Singleton::instance().throw_with_stack("could not copy Dataspace");
}
handle_ = ObjectHandle(ret);
swap(space);
return *this;
}

void Dataspace::swap(const Dataspace &space) {
if(static_cast<hid_t>(space.handle_)) {
hid_t ret = H5Scopy(static_cast<hid_t>(space.handle_));
if (0 > ret) {
error::Singleton::instance().throw_with_stack("could not copy Dataspace");
}
handle_ = ObjectHandle(ret);
}
else
handle_ = ObjectHandle();
}

Dataspace::Dataspace(Type type)
: selection(*this), handle_(ObjectHandle(H5Screate(static_cast<H5S_class_t>(type)))) {}

Expand All @@ -79,12 +83,15 @@ hssize_t Dataspace::size() const {
}

Type Dataspace::type() const {
H5S_class_t ret = H5Sget_simple_extent_type(static_cast<hid_t>(*this));
if (ret == H5S_NO_CLASS) {
error::Singleton::instance().throw_with_stack("Failure to retrieve the dataspace type!");
if(static_cast<hid_t>(handle_)) {
H5S_class_t ret = H5Sget_simple_extent_type(static_cast<hid_t>(*this));
if (ret == H5S_NO_CLASS) {
error::Singleton::instance().throw_with_stack("Failure to retrieve the dataspace type!");
}
return static_cast<Type>(ret);
}
return Type::NODATA;

return static_cast<Type>(ret);
}

hdf5::Dimensions Dataspace::current_dimensions() const
Expand Down
5 changes: 5 additions & 0 deletions src/h5cpp/dataspace/dataspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ class DLL_EXPORT Dataspace {
private:
ObjectHandle handle_;

//!
//! @brief helper for copy assignment and copy constructor
//!
void swap(const Dataspace &space);

};

} // namespace dataspace
Expand Down
2 changes: 1 addition & 1 deletion src/h5cpp/dataspace/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sources+=files('hyperslab.cpp','dataspace.cpp', 'scalar.cpp',

local_headers=files('hyperslab.hpp', 'dataspace.hpp', 'scalar.hpp',
'selection_manager.hpp', 'selection.hpp', 'simple.hpp',
'type.hpp', 'type_trait.hpp', 'view.hpp', 'points.hpp')
'type.hpp', 'type_trait.hpp', 'view.hpp', 'points.hpp', 'pool.hpp')
headers+=local_headers

install_headers(headers, subdir:join_paths('h5cpp', 'dataspace'))
73 changes: 73 additions & 0 deletions src/h5cpp/dataspace/pool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// (c) Copyright 2017 DESY,ESS
//
// This file is part of h5cpp.
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
// Boston, MA 02110-1301 USA
// ===========================================================================
//
// Authors:
// Jan Kotanski <[email protected]>
// Created on: Nov 1, 2021
//
#pragma once

#include <map>

#include <h5cpp/dataspace/dataspace.hpp>
#include <h5cpp/dataspace/simple.hpp>
#include <h5cpp/core/types.hpp>

namespace hdf5 {
namespace dataspace {

//!
//! @brief data space object pool
//!
class DLL_EXPORT DataspacePool
{
public:

//!
//! \brief pool of reference of Simple data spaces
//!
//! Returns data space reference for static data space object
//!
//! @param size dimension of 1D Simple Dataspace to get or create
//! @return data space reference for data space object
//!
const Dataspace & getSimple(size_t size);

private:
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::map<size_t, Dataspace> pool_map;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
};

inline const Dataspace & DataspacePool::getSimple(size_t size)
{
if(pool_map.count(size) < 1)
pool_map[size] = Simple(hdf5::Dimensions{size}, hdf5::Dimensions{size});
return pool_map[size];
}

} // namespace dataspace
} // namespace hdf5
2 changes: 1 addition & 1 deletion src/h5cpp/dataspace/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace hdf5 {
namespace dataspace {

//!
//! \brief determine the datatype instance
//! \enum Type determine the datatype instance
//!
//! This enumeration type is primarily used to identify the particular type
//! of dataspace when given only a reference to dataspace::Dataspace.
Expand Down
Loading