Skip to content

Commit

Permalink
Optimizing use of certain #includes
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Feb 16, 2024
1 parent e47a884 commit b18fa39
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 123 deletions.
1 change: 1 addition & 0 deletions libs/core/affinity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(affinity_headers
hpx/affinity/affinity_data.hpp hpx/affinity/detail/partlit.hpp
hpx/affinity/detail/parse_mappings.hpp
hpx/affinity/parse_affinity_options.hpp
)

Expand Down
104 changes: 104 additions & 0 deletions libs/core/affinity/include/hpx/affinity/detail/parse_mappings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright (c) 2007-2024 Hartmut Kaiser
// Copyright (c) 2008-2009 Chirag Dekate, Anshul Tandon
// Copyright (c) 2012-2013 Thomas Heller
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <hpx/config.hpp>
#include <hpx/assert.hpp>
#include <hpx/modules/errors.hpp>

#include <boost/variant.hpp>

#include <cstddef>
#include <cstdint>
#include <limits>
#include <string>
#include <utility>
#include <vector>

namespace hpx::threads::detail {

using bounds_type = std::vector<std::int64_t>;

enum class distribution_type : std::int8_t
{
compact = 0x01,
scatter = 0x02,
balanced = 0x04,
numa_balanced = 0x08
};

struct spec_type
{
enum class type : std::int8_t
{
unknown,
thread,
socket,
numanode,
core,
pu
};

HPX_CORE_EXPORT static char const* type_name(type t) noexcept;

static constexpr std::int64_t all_entities() noexcept
{
return (std::numeric_limits<std::int64_t>::min)();
}

spec_type() noexcept
: type_(type::unknown)
{
}

explicit spec_type(type t, std::int64_t min = all_entities(),
std::int64_t max = all_entities())
: type_(t)
{
if (t != type::unknown)
{
if (max == 0 || max == all_entities())
{
// one or all entities
index_bounds_.push_back(min);
}
else if (min != all_entities())
{
// all entities between min and -max, or just min,max
HPX_ASSERT(min >= 0);
index_bounds_.push_back(min);
index_bounds_.push_back(max);
}
}
}

constexpr bool operator==(spec_type const& rhs) const noexcept
{
return type_ == rhs.type_ && index_bounds_ == rhs.index_bounds_;
}
constexpr bool operator!=(spec_type const& rhs) const noexcept
{
return !(*this == rhs);
}

type type_;
bounds_type index_bounds_;
};

using mapping_type = std::vector<spec_type>;
using full_mapping_type = std::pair<spec_type, mapping_type>;
using mappings_spec_type = std::vector<full_mapping_type>;
using mappings_type = boost::variant<distribution_type, mappings_spec_type>;

HPX_CORE_EXPORT bounds_type extract_bounds(
spec_type const& m, std::size_t default_last, error_code& ec);

HPX_CORE_EXPORT void parse_mappings(std::string const& spec,
mappings_type& mappings, error_code& ec = throws);
} // namespace hpx::threads::detail
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
// Copyright (c) 2008-2009 Chirag Dekate, Anshul Tandon
// Copyright (c) 2012-2013 Thomas Heller
//
Expand All @@ -11,104 +11,15 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/assert.hpp>
#include <hpx/modules/errors.hpp>
#include <hpx/topology/cpu_mask.hpp>

#include <boost/variant.hpp>

#include <cstddef>
#include <cstdint>
#include <limits>
#include <string>
#include <utility>
#include <vector>

namespace hpx::threads {

namespace detail {

using bounds_type = std::vector<std::int64_t>;

enum class distribution_type : std::int8_t
{
compact = 0x01,
scatter = 0x02,
balanced = 0x04,
numa_balanced = 0x08
};

struct spec_type
{
enum class type : std::int8_t
{
unknown,
thread,
socket,
numanode,
core,
pu
};

HPX_CORE_EXPORT static char const* type_name(type t) noexcept;

static constexpr std::int64_t all_entities() noexcept
{
return (std::numeric_limits<std::int64_t>::min)();
}

spec_type() noexcept
: type_(type::unknown)
{
}

explicit spec_type(type t, std::int64_t min = all_entities(),
std::int64_t max = all_entities())
: type_(t)
{
if (t != type::unknown)
{
if (max == 0 || max == all_entities())
{
// one or all entities
index_bounds_.push_back(min);
}
else if (min != all_entities())
{
// all entities between min and -max, or just min,max
HPX_ASSERT(min >= 0);
index_bounds_.push_back(min);
index_bounds_.push_back(max);
}
}
}

constexpr bool operator==(spec_type const& rhs) const noexcept
{
return type_ == rhs.type_ && index_bounds_ == rhs.index_bounds_;
}
constexpr bool operator!=(spec_type const& rhs) const noexcept
{
return !(*this == rhs);
}

type type_;
bounds_type index_bounds_;
};

using mapping_type = std::vector<spec_type>;
using full_mapping_type = std::pair<spec_type, mapping_type>;
using mappings_spec_type = std::vector<full_mapping_type>;
using mappings_type =
boost::variant<distribution_type, mappings_spec_type>;

HPX_CORE_EXPORT bounds_type extract_bounds(
spec_type const& m, std::size_t default_last, error_code& ec);

HPX_CORE_EXPORT void parse_mappings(std::string const& spec,
mappings_type& mappings, error_code& ec = throws);
} // namespace detail

HPX_CORE_EXPORT void parse_affinity_options(std::string const& spec,
std::vector<mask_type>& affinities, std::size_t used_cores,
std::size_t max_cores, std::size_t num_threads,
Expand Down
3 changes: 2 additions & 1 deletion libs/core/affinity/src/parse_affinity_options.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/affinity/detail/parse_mappings.hpp>
#include <hpx/affinity/detail/partlit.hpp>
#include <hpx/affinity/parse_affinity_options.hpp>
#include <hpx/assert.hpp>
Expand Down
4 changes: 3 additions & 1 deletion libs/core/affinity/tests/unit/parse_affinity_options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -8,6 +8,8 @@
#include <hpx/modules/testing.hpp>
#include <hpx/thread.hpp>

#include <hpx/affinity/detail/parse_mappings.hpp>

#include <algorithm>
#include <cstddef>
#include <cstdint>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 Hartmut Kaiser
// Copyright (c) 2022-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -12,6 +12,7 @@
#include <hpx/errors/try_catch_exception_ptr.hpp>
#include <hpx/execution/queries/get_scheduler.hpp>
#include <hpx/execution/queries/get_stop_token.hpp>
#include <hpx/execution_base/completion_scheduler.hpp>
#include <hpx/execution_base/completion_signatures.hpp>
#include <hpx/execution_base/execution.hpp>
#include <hpx/execution_base/get_env.hpp>
Expand Down
3 changes: 2 additions & 1 deletion libs/core/futures/include/hpx/futures/futures_factory.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -22,6 +22,7 @@
#include <hpx/modules/errors.hpp>
#include <hpx/modules/memory.hpp>
#include <hpx/threading_base/detail/get_default_pool.hpp>
#include <hpx/threading_base/scheduler_base.hpp>
#include <hpx/threading_base/thread_description.hpp>
#include <hpx/threading_base/thread_helpers.hpp>
#include <hpx/threading_base/thread_num_tss.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
// Copyright (c) 2014-2015 Agustin Berge
//
// SPDX-License-Identifier: BSL-1.0
Expand All @@ -21,6 +21,7 @@
#include <hpx/modules/errors.hpp>
#include <hpx/modules/memory.hpp>
#include <hpx/threading_base/annotated_function.hpp>
#include <hpx/threading_base/scoped_annotation.hpp>
#include <hpx/threading_base/thread_description.hpp>

#include <exception>
Expand Down
8 changes: 6 additions & 2 deletions libs/core/serialization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,18 @@ set(serialization_compat_headers
# cmake-format: on

if(HPX_SERIALIZATION_WITH_BOOST_TYPES)
set(serialization_headers
${serialization_headers}
set(boost_serialization_headers
hpx/serialization/boost_array.hpp
hpx/serialization/boost_intrusive_ptr.hpp
hpx/serialization/boost_multi_array.hpp
hpx/serialization/boost_shared_ptr.hpp
hpx/serialization/boost_variant.hpp
)

set(serialization_headers ${serialization_headers}
${boost_serialization_headers}
)

# cmake-format: off
set(serialization_compat_headers ${serialization_compat_headers}
hpx/serialization/multi_array.hpp => hpx/serialization/boost_multi_array.hpp
Expand Down Expand Up @@ -246,5 +249,6 @@ add_hpx_module(
hpx_type_support
DEPENDENCIES ${serialization_optional_dependencies}
ADD_TO_GLOBAL_HEADER hpx/serialization/detail/allow_zero_copy_receive.hpp
EXCLUDE_FROM_GLOBAL_HEADER ${boost_serialization_headers}
CMAKE_SUBDIRS examples tests
)
4 changes: 0 additions & 4 deletions libs/core/serialization/include/hpx/serialization/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#include <hpx/serialization/traits/is_bitwise_serializable.hpp>
#include <hpx/serialization/traits/is_not_bitwise_serializable.hpp>

#if defined(HPX_SERIALIZATION_HAVE_BOOST_TYPES)
#include <hpx/serialization/boost_array.hpp> // for backwards compatibility
#endif

#include <array>
#include <cstddef>
#include <type_traits>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <hpx/serialization/serialization_fwd.hpp>
#include <hpx/serialization/traits/polymorphic_traits.hpp>
#include <hpx/type_support/static.hpp>
#include <hpx/type_support/unused.hpp>

#include <cstddef>
#include <cstdint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/modules/debugging.hpp>
#include <hpx/debugging/demangle_helper.hpp>
#include <hpx/preprocessor/cat.hpp>
#include <hpx/preprocessor/expand.hpp>
#include <hpx/preprocessor/nargs.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2014 Thomas Heller
// Copyright (c) 2015 Anton Bikineev
// Copyright (c) 2015 Andreas Schaefer
// Copyright (c) 2022-2023 Hartmut Kaiser
// Copyright (c) 2022-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0.
Expand All @@ -12,7 +12,7 @@

#include <hpx/config.hpp>
#include <hpx/assert.hpp>
#include <hpx/modules/debugging.hpp>
#include <hpx/debugging/demangle_helper.hpp>
#include <hpx/modules/errors.hpp>
#include <hpx/preprocessor/stringize.hpp>
#include <hpx/preprocessor/strip_parens.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
#include <hpx/serialization/serialization_fwd.hpp>
#include <hpx/serialization/serialize.hpp>

#if defined(HPX_SERIALIZATION_HAVE_BOOST_TYPES)
#include <hpx/serialization/boost_shared_ptr.hpp> // for backwards compatibility
#endif

#include <memory>

namespace hpx::serialization {
Expand Down
4 changes: 0 additions & 4 deletions libs/core/serialization/include/hpx/serialization/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
#include <hpx/modules/errors.hpp>
#include <hpx/serialization/serialization_fwd.hpp>

#if defined(HPX_SERIALIZATION_HAVE_BOOST_TYPES)
#include <hpx/serialization/boost_variant.hpp> // for backwards compatibility
#endif

#include <cstddef>
#include <cstdint>
#include <utility>
Expand Down
Loading

0 comments on commit b18fa39

Please sign in to comment.