Skip to content

Commit

Permalink
Cleanup up and Fixing component creation and deletion
Browse files Browse the repository at this point in the history
This patch contains various fixes related to component registration, creation
and deletion.

The main motivation was to allow direct creation of components without going
through a factory function, disallowing perfect forwarding for local component
creation.

The component registration has been cleaned up, the factory class for creation
and deletion of components has been removed, and the component type registration
has been moved to the component_registry.

The component deletion has been moved out of the runtime_support server, since
no factory is required anymore.

Various other cleanups have been performed leading to an overall reduction in
binary size and removal of various different duplicate code while preserving
existing functionality.

Fixes include:
    - The functionality of component instance counters has been fixed for
      local_new
    - The deletion of components now correctly takes migrated components
      into account
    - The component heap instances are now ensured to live in single module only
      avoiding freeing memory that has been allocated by a different module.
  • Loading branch information
Thomas Heller committed Nov 21, 2017
1 parent b95cf86 commit a7fc77a
Show file tree
Hide file tree
Showing 80 changed files with 876 additions and 2,105 deletions.
4 changes: 2 additions & 2 deletions examples/allgather/ag_client.cpp
Expand Up @@ -24,7 +24,7 @@ void test_allgather(std::size_t np)
{
// Get the component type for our point component.
hpx::components::component_type block_type =
ag::server::allgather::get_component_type();
hpx::components::get_component_type<ag::server::allgather>();

std::vector<hpx::id_type> localities =
hpx::find_all_localities(block_type);
Expand Down Expand Up @@ -74,7 +74,7 @@ void test_allgather_and_gate(std::size_t np)
{
// Get the component type for our point component.
hpx::components::component_type block_type =
ag::server::allgather_and_gate::get_component_type();
hpx::components::get_component_type<ag::server::allgather>();

std::vector<hpx::naming::id_type> localities =
hpx::find_all_localities(block_type);
Expand Down
4 changes: 0 additions & 4 deletions examples/throttle/throttle/server/throttle.hpp
Expand Up @@ -30,10 +30,6 @@ namespace throttle { namespace server
throttle();
~throttle();

// components must contain a typedef for wrapping_type defining the
// component type used to encapsulate instances of this component
typedef throttle wrapping_type;

///////////////////////////////////////////////////////////////////////
// parcel action code: the action to be performed on the destination
// object (the accumulator)
Expand Down
39 changes: 39 additions & 0 deletions hpx/lcos/base_lco_with_value.hpp
@@ -1,4 +1,5 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2012-2017 Thomas Heller
//
// 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)
Expand All @@ -15,6 +16,7 @@
#include <hpx/runtime/components/component_type.hpp>
#include <hpx/runtime/components/server/managed_component_base.hpp>
#include <hpx/runtime/components/server/component_base.hpp>
#include <hpx/runtime/components/server/component_heap.hpp>
#include <hpx/runtime/components_fwd.hpp>
#include <hpx/runtime/naming/id_type.hpp>
#include <hpx/traits/is_component.hpp>
Expand Down Expand Up @@ -237,6 +239,43 @@ namespace hpx { namespace traits
}
};
}}
namespace hpx { namespace components {
namespace detail {
template <typename Result, typename RemoteResult>
struct component_heap_impl<
hpx::components::managed_component<hpx::lcos::base_lco_with_value<
Result, RemoteResult, traits::detail::managed_component_tag>>>
{
typedef void valid;
typedef hpx::components::managed_component<hpx::lcos::base_lco_with_value<
Result, RemoteResult, traits::detail::managed_component_tag>>
component_type;
HPX_ALWAYS_EXPORT static typename component_type::heap_type& call()
{
util::reinitializable_static<typename component_type::heap_type>
heap;
return heap.get();
}
};
template <typename Result, typename RemoteResult>
struct component_heap_impl<
hpx::components::managed_component<hpx::lcos::base_lco_with_value<
Result, RemoteResult, traits::detail::component_tag>>>
{
typedef void valid;
typedef hpx::components::managed_component<hpx::lcos::base_lco_with_value<
Result, RemoteResult, traits::detail::component_tag>>
component_type;
HPX_ALWAYS_EXPORT static
typename component_type::heap_type& call()
{
util::reinitializable_static<typename component_type::heap_type>
heap;
return heap.get();
}
};
}
}}

///////////////////////////////////////////////////////////////////////////////
#define HPX_REGISTER_BASE_LCO_WITH_VALUE_DECLARATION(...) \
Expand Down
7 changes: 4 additions & 3 deletions hpx/lcos/detail/promise_base.hpp
@@ -1,5 +1,5 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2016 Thomas Heller
// Copyright (c) 2016-2017 Thomas Heller
// Copyright (c) 2011 Bryce Adelstein-Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -12,6 +12,7 @@
#include <hpx/lcos/detail/future_data.hpp>
#include <hpx/lcos/detail/promise_lco.hpp>
#include <hpx/lcos/local/promise.hpp>
#include <hpx/runtime/components/server/component_heap.hpp>
#include <hpx/runtime/components/server/managed_component_base.hpp>
#include <hpx/runtime/naming/address.hpp>
#include <hpx/runtime/naming/id_type.hpp>
Expand Down Expand Up @@ -293,7 +294,7 @@ namespace lcos {
static void wrapping_deleter(wrapping_type *ptr)
{
ptr->~wrapping_type();
wrapping_type::heap_type::free(ptr);
hpx::components::component_heap<wrapping_type>().free(ptr);
}

protected:
Expand All @@ -305,7 +306,7 @@ namespace lcos {
// shared state.
typedef std::unique_ptr<wrapping_type, void(*)(wrapping_type*)>
wrapping_ptr;
auto ptr = wrapping_type::heap_type::alloc();
auto ptr = hpx::components::component_heap<wrapping_type>().alloc();
wrapping_ptr lco_ptr(new (ptr) wrapping_type(
new wrapped_type(this->shared_state_)), &wrapping_deleter);

Expand Down
25 changes: 25 additions & 0 deletions hpx/lcos/detail/promise_lco.hpp
Expand Up @@ -13,6 +13,7 @@
#include <hpx/lcos/detail/future_data.hpp>
#include <hpx/runtime/components/component_type.hpp>
#include <hpx/runtime/components/server/managed_component_base.hpp>
#include <hpx/runtime/components/server/component_heap.hpp>
#include <hpx/runtime/naming/id_type.hpp>
#include <hpx/traits/component_type_database.hpp>
#include <hpx/util/assert.hpp>
Expand Down Expand Up @@ -219,6 +220,30 @@ namespace traits {
lcos::detail::promise_lco<Result, RemoteResult>>::value =
components::component_invalid;
}
namespace components { namespace detail {
// Forward declare promise_lco<void> to avoid duplicate instantiations
template <> HPX_ALWAYS_EXPORT
hpx::components::managed_component<
lcos::detail::promise_lco<void, hpx::util::unused_type>>::heap_type&
component_heap_helper<hpx::components::managed_component<
lcos::detail::promise_lco<void, hpx::util::unused_type>>>(...);

template <typename Result, typename RemoteResult>
struct component_heap_impl<hpx::components::managed_component<
lcos::detail::promise_lco<Result, RemoteResult>>>
{
typedef void valid;

HPX_ALWAYS_EXPORT static
typename hpx::components::managed_component<
lcos::detail::promise_lco<Result, RemoteResult>>::heap_type& call()
{
util::reinitializable_static<typename hpx::components::managed_component<
lcos::detail::promise_lco<Result, RemoteResult>>::heap_type> heap;
return heap.get();
}
};
}}
}

#endif
3 changes: 0 additions & 3 deletions hpx/performance_counters/base_performance_counter.hpp
Expand Up @@ -51,9 +51,6 @@ namespace hpx { namespace performance_counters
base_type_holder::finalize();
base_type::finalize();
}

using base_type::get_component_type;
using base_type::set_component_type;
};
}}

Expand Down
9 changes: 0 additions & 9 deletions hpx/performance_counters/server/arithmetics_counter.hpp
Expand Up @@ -52,15 +52,6 @@ namespace hpx { namespace performance_counters { namespace server
base_type::finalize();
}

static components::component_type get_component_type()
{
return base_type::get_component_type();
}
static void set_component_type(components::component_type t)
{
base_type::set_component_type(t);
}

private:
// base counters to be queried
performance_counter_set counters_;
Expand Down
Expand Up @@ -54,15 +54,6 @@ namespace hpx { namespace performance_counters { namespace server
base_type::finalize();
}

static components::component_type get_component_type()
{
return base_type::get_component_type();
}
static void set_component_type(components::component_type t)
{
base_type::set_component_type(t);
}

private:
// base counters to be queried
performance_counter_set counters_;
Expand Down
9 changes: 0 additions & 9 deletions hpx/performance_counters/server/elapsed_time_counter.hpp
Expand Up @@ -40,15 +40,6 @@ namespace hpx { namespace performance_counters { namespace server
base_performance_counter::finalize();
base_type::finalize();
}

static components::component_type get_component_type()
{
return base_type::get_component_type();
}
static void set_component_type(components::component_type t)
{
base_type::set_component_type(t);
}
};
}}}

Expand Down
9 changes: 0 additions & 9 deletions hpx/performance_counters/server/raw_counter.hpp
Expand Up @@ -45,15 +45,6 @@ namespace hpx { namespace performance_counters { namespace server
base_type::finalize();
}

static components::component_type get_component_type()
{
return base_type::get_component_type();
}
static void set_component_type(components::component_type t)
{
base_type::set_component_type(t);
}

private:
hpx::util::function_nonser<std::int64_t(bool)> f_;
bool reset_;
Expand Down
9 changes: 0 additions & 9 deletions hpx/performance_counters/server/raw_values_counter.hpp
Expand Up @@ -46,15 +46,6 @@ namespace hpx { namespace performance_counters { namespace server
base_type::finalize();
}

static components::component_type get_component_type()
{
return base_type::get_component_type();
}
static void set_component_type(components::component_type t)
{
base_type::set_component_type(t);
}

private:
hpx::util::function_nonser<std::vector<std::int64_t>(bool)> f_;
bool reset_;
Expand Down
9 changes: 0 additions & 9 deletions hpx/performance_counters/server/statistics_counter.hpp
Expand Up @@ -82,15 +82,6 @@ namespace hpx { namespace performance_counters { namespace server
base_type::finalize();
}

static components::component_type get_component_type()
{
return base_type::get_component_type();
}
static void set_component_type(components::component_type t)
{
base_type::set_component_type(t);
}

protected:
bool evaluate_base_counter(counter_value& value);
bool evaluate();
Expand Down
13 changes: 0 additions & 13 deletions hpx/runtime.hpp
Expand Up @@ -218,12 +218,6 @@ namespace hpx

virtual void add_shutdown_function(shutdown_function_type f) = 0;

/// Keep the factory object alive which is responsible for the given
/// component type. This a purely internal function allowing to work
/// around certain library specific problems related to dynamic
/// loading of external libraries.
virtual bool keep_factory_alive(components::component_type type) = 0;

/// Access one of the internal thread pools (io_service instances)
/// HPX is using to perform specific tasks. The three possible values
/// for the argument \p name are "main_pool", "io_pool", "parcel_pool",
Expand Down Expand Up @@ -344,13 +338,6 @@ namespace hpx
boost::scoped_ptr<components::server::memory> memory_;
boost::scoped_ptr<components::server::runtime_support> runtime_support_;
};

///////////////////////////////////////////////////////////////////////////
/// Keep the factory object alive which is responsible for the given
/// component type. This a purely internal function allowing to work
/// around certain library specific problems related to dynamic
/// loading of external libraries.
HPX_EXPORT bool keep_factory_alive(components::component_type type);
} // namespace hpx

#include <hpx/config/warnings_suffix.hpp>
Expand Down
2 changes: 0 additions & 2 deletions hpx/runtime/actions/basic_action.hpp
Expand Up @@ -604,7 +604,6 @@ namespace hpx { namespace actions
broadcast_call_shutdown_functions_action_id,
broadcast_call_startup_functions_action_id,
broadcast_symbol_namespace_on_event_action_id,
bulk_create_components_action_id,
call_shutdown_functions_action_id,
call_startup_functions_action_id,
component_namespace_bind_prefix_action_id,
Expand All @@ -624,7 +623,6 @@ namespace hpx { namespace actions
free_component_action_id,
garbage_collect_action_id,
get_config_action_id,
get_instance_count_action_id,
hpx_get_locality_name_action_id,
hpx_lcos_server_barrier_create_component_action_id,
hpx_lcos_server_latch_create_component_action_id,
Expand Down
1 change: 0 additions & 1 deletion hpx/runtime/actions/plain_action.hpp
Expand Up @@ -12,7 +12,6 @@
#include <hpx/config.hpp>
#include <hpx/runtime/actions/basic_action.hpp>
#include <hpx/runtime/actions/continuation.hpp>
#include <hpx/runtime/components/console_error_sink.hpp>
#include <hpx/runtime/naming/address.hpp>
#include <hpx/traits/component_type_database.hpp>
#include <hpx/util/assert.hpp>
Expand Down
7 changes: 6 additions & 1 deletion hpx/runtime/agas_fwd.hpp
Expand Up @@ -8,11 +8,16 @@
#define HPX_RUNTIME_AGAS_FWD_HPP

#include <hpx/config.hpp>
#include <hpx/runtime/components/component_type.hpp>
#include <hpx/util/function.hpp>

#include <cstdint>
#include <string>

namespace hpx { namespace components
{
typedef std::int32_t component_type;
}}

namespace hpx { namespace agas
{
typedef hpx::util::function<
Expand Down
16 changes: 5 additions & 11 deletions hpx/runtime/components/binpacking_distribution_policy.hpp
Expand Up @@ -12,8 +12,8 @@
#include <hpx/dataflow.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/performance_counters/performance_counter.hpp>
#include <hpx/runtime/components/component_type.hpp>
#include <hpx/runtime/components/stubs/stub_base.hpp>
#include <hpx/runtime/components/unique_component_name.hpp>
#include <hpx/runtime/naming/id_type.hpp>
#include <hpx/runtime/naming/name.hpp>
#include <hpx/runtime/serialization/serialization_fwd.hpp>
Expand Down Expand Up @@ -242,11 +242,8 @@ namespace hpx { namespace components
// schedule creation of all objects across given localities
hpx::future<std::vector<std::uint64_t> > values =
detail::get_counter_values(
hpx::components::unique_component_name<
hpx::components::component_factory<
typename Component::wrapping_type
>
>::call(), counter_name_, localities_);
get_component_name<Component>(),
counter_name_, localities_);

using hpx::util::placeholders::_1;
return values.then(hpx::util::bind(
Expand Down Expand Up @@ -280,11 +277,8 @@ namespace hpx { namespace components
// schedule creation of all objects across given localities
hpx::future<std::vector<std::uint64_t> > values =
detail::get_counter_values(
hpx::components::unique_component_name<
hpx::components::component_factory<
typename Component::wrapping_type
>
>::call(), counter_name_, localities_);
get_component_name<Component>(),
counter_name_, localities_);

using hpx::util::placeholders::_1;
return values.then(
Expand Down

0 comments on commit a7fc77a

Please sign in to comment.