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

Support for HPXCL's opencl::event #2227

Merged
merged 2 commits into from Jun 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion hpx/lcos/detail/future_data.hpp
Expand Up @@ -739,7 +739,7 @@ namespace detail
if (!started_test())
return future_status::deferred; //-V110
return this->future_data<Result>::wait_until(abs_time, ec);
};
}

private:
bool started_test() const
Expand Down
68 changes: 49 additions & 19 deletions hpx/lcos/detail/promise_base.hpp
Expand Up @@ -16,6 +16,7 @@
#include <hpx/runtime/naming/address.hpp>
#include <hpx/runtime/naming/id_type.hpp>
#include <hpx/throw_exception.hpp>
#include <hpx/traits/detail/wrap_int.hpp>
#include <hpx/util/deferred_call.hpp>
#include <hpx/util/unique_function.hpp>

Expand Down Expand Up @@ -56,36 +57,58 @@ namespace lcos {
util::unique_function_nonser<void()> f_;
};

///////////////////////////////////////////////////////////////////////
struct set_id_helper
{
template <typename SharedState>
HPX_FORCEINLINE static void call(hpx::traits::detail::wrap_int,
SharedState const& shared_state, id_type const& id)
{
// by default, do nothing
}

template <typename SharedState>
HPX_FORCEINLINE static auto call(int,
SharedState const& shared_state, id_type const& id)
-> decltype(shared_state->set_id(id))
{
shared_state->set_id(id);
}
};

template <typename SharedState>
HPX_FORCEINLINE
void call_set_id(SharedState const& shared_state, id_type const& id)
{
set_id_helper::call(0, shared_state, id);
}

// Promise base contains the actual implementation for the remotely
// settable
// promise. It consists of two parts:
// 1) The shared state, which is used to signal the future
// 2) The LCO, which is used to set the promise remotely
//
// The LCO is a component, which lifetime is completely controlled by
// the
// shared state. That is, in the GID that we send along as the
// continuation
// can be unmanaged, AGAS doesn't participate in the promise lifetime
// management. The LCO is being reset once the shared state either
// contains
// a value or the data, which is set through the LCO interface, which
// can go
// out of scope safely when the shared state is set.
template <typename Result, typename RemoteResult>
// the shared state. That is, in the GID that we send along as the
// continuation can be unmanaged, AGAS doesn't participate in the
// promise lifetime management. The LCO is being reset once the shared
// state either contains a value or the data, which is set through the
// LCO interface, which can go out of scope safely when the shared
// state is set.
template <typename Result, typename RemoteResult, typename SharedState>
class promise_base
: public hpx::lcos::local::detail::promise_base<Result,
promise_data<Result>>
: public hpx::lcos::local::detail::promise_base<Result, SharedState>
{
HPX_MOVABLE_ONLY(promise_base);

typedef hpx::lcos::local::detail::promise_base<Result,
promise_data<Result>>
base_type;
typedef hpx::lcos::local::detail::promise_base<
Result, SharedState
> base_type;

protected:
typedef Result result_type;
typedef lcos::detail::future_data<Result> shared_state_type;
typedef SharedState shared_state_type;
typedef boost::intrusive_ptr<shared_state_type> shared_state_ptr;

typedef promise_lco<Result, RemoteResult> wrapped_type;
Expand All @@ -99,8 +122,7 @@ namespace lcos {
// The lifetime of the LCO (component) part is completely
// handled by the shared state, we create the object to get our
// gid and then attach it to the completion handler of the
// shared
// state.
// shared state.
typedef std::unique_ptr<wrapping_type> wrapping_ptr;
wrapping_ptr lco_ptr(
new wrapping_type(new wrapped_type(this->shared_state_)));
Expand All @@ -110,12 +132,18 @@ namespace lcos {
lco_ptr->get_component_type(),
lco_ptr.get());

// Pass id to shared state if it exposes the set_id() function
detail::call_set_id(this->shared_state_, id_);

// This helper is used to keep the component alive until the
// completion handler has been called. We need to manually free
// the component here, since we don't rely on reference counting
// anymore
auto keep_alive = hpx::util::deferred_call(
[](wrapping_ptr ptr) { delete ptr->get(); },
[](wrapping_ptr ptr)
{
delete ptr->get(); // delete wrapped_type
},
std::move(lco_ptr));
this->shared_state_->set_on_completed(std::move(keep_alive));
}
Expand All @@ -126,6 +154,7 @@ namespace lcos {
id_(std::move(other.id_)),
addr_(std::move(other.addr_))
{
other.id_retrieved_ = false;
other.id_ = naming::invalid_id;
other.addr_ = naming::address();
}
Expand All @@ -144,6 +173,7 @@ namespace lcos {
id_ = std::move(other.id_);
addr_ = std::move(other.addr_);

other.id_retrieved_ = false;
other.id_ = naming::invalid_id;
other.addr_ = naming::address();
return *this;
Expand Down
6 changes: 2 additions & 4 deletions hpx/lcos/detail/promise_lco.hpp
Expand Up @@ -80,10 +80,8 @@ namespace lcos {
}

// This is the component id. Every component needs to have an
// embedded
// enumerator 'value' which is used by the generic action
// implementation
// to associate this component with a given action.
// embedded enumerator 'value' which is used by the generic action
// implementation to associate this component with a given action.
enum
{
value = components::component_promise
Expand Down
53 changes: 18 additions & 35 deletions hpx/lcos/promise.hpp
Expand Up @@ -55,11 +55,15 @@ namespace lcos {
/// template parameter \a RemoteResult
///////////////////////////////////////////////////////////////////////////
template <typename Result, typename RemoteResult>
class promise : public detail::promise_base<Result, RemoteResult>
class promise
: public detail::promise_base<
Result, RemoteResult, detail::promise_data<Result> >
{
HPX_MOVABLE_ONLY(promise);

typedef detail::promise_base<Result, RemoteResult> base_type;
typedef detail::promise_base<
Result, RemoteResult, detail::promise_data<Result>
> base_type;

public:
// Effects: constructs a promise object and a shared state.
Expand Down Expand Up @@ -98,10 +102,7 @@ namespace lcos {
}

// Returns: true only if *this refers to a shared state.
bool valid() const HPX_NOEXCEPT
{
return base_type::valid();
}
using base_type::valid;

// Returns: A future<Result> object with the same shared state as *this.
// Throws: future_error if *this has no shared state or if get_future
Expand All @@ -111,10 +112,7 @@ namespace lcos {
// - future_already_retrieved if get_future has already been called
// on a promise with the same shared state as *this.
// - no_state if *this has no shared state.
future<Result> get_future(error_code& ec = throws)
{
return base_type::get_future(ec);
}
using base_type::get_future;

// Effects: atomically stores the value r in the shared state and makes
// that state ready (30.6.4).
Expand All @@ -125,11 +123,7 @@ namespace lcos {
// - promise_already_satisfied if its shared state already has a
// stored value or exception.
// - no_state if *this has no shared state.
template <typename T>
void set_value(T&& t, error_code& ec = throws)
{
base_type::set_value(std::forward<T>(t), ec);
}
using base_type::set_value;

// Effects: atomically stores the exception pointer p in the shared
// state and makes that state ready (30.6.4).
Expand All @@ -139,20 +133,19 @@ namespace lcos {
// - promise_already_satisfied if its shared state already has a
// stored value or exception.
// - no_state if *this has no shared state.
void set_exception(
boost::exception_ptr const& e, error_code& ec = throws)
{
base_type::set_exception(e, ec);
}
using base_type::set_exception;
Copy link
Member

Choose a reason for hiding this comment

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

How does this look like for generated doxygen?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we generate docs using doxygen for this? I didn't think so.

Copy link
Member

Choose a reason for hiding this comment

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

On Donnerstag, 23. Juni 2016 13:30:15 CEST Hartmut Kaiser wrote:

@@ -139,20 +133,19 @@ namespace lcos {

     //   - promise_already_satisfied if its shared state already has
     a
     //     stored value or exception.
     //   - no_state if *this has no shared state.
  •    void set_exception(
    
  •        boost::exception_ptr const& e, error_code& ec = throws)
    
  •    {
    
  •        base_type::set_exception(e, ec);
    
  •    }
    
  •    using base_type::set_exception;
    

Do we generate docs using doxygen for this? I didn't think so.

Just checked, we don't, but we probably should, and those are already almost
doxygen comments.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/STEllAR-GROUP/hpx/pull/2227/files/64f79a91506d10b1b247f82
a5a9305bb72113870#r68308989

Copy link
Member Author

Choose a reason for hiding this comment

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

I should probably revert those changes. We have not done it this way (using base_type::...) in other places either.

Also, if we decided to stick with it, we could easily use doxygens \copydoc directive to pull in the docs from the base class, if needed.

};

template <>
class promise<void, hpx::util::unused_type>
: public detail::promise_base<void, hpx::util::unused_type>
: public detail::promise_base<
void, hpx::util::unused_type, detail::promise_data<void> >
{
HPX_MOVABLE_ONLY(promise);

typedef detail::promise_base<void, hpx::util::unused_type> base_type;
typedef detail::promise_base<
void, hpx::util::unused_type, detail::promise_data<void>
> base_type;

public:
// Effects: constructs a promise object and a shared state.
Expand Down Expand Up @@ -190,10 +183,7 @@ namespace lcos {
}

// Returns: true only if *this refers to a shared state.
bool valid() const HPX_NOEXCEPT
{
return base_type::valid();
}
using base_type::valid;

// Returns: A future<Result> object with the same shared state as *this.
// Throws: future_error if *this has no shared state or if get_future
Expand All @@ -203,10 +193,7 @@ namespace lcos {
// - future_already_retrieved if get_future has already been called
// on a promise with the same shared state as *this.
// - no_state if *this has no shared state.
future<void> get_future(error_code& ec = throws)
{
return base_type::get_future(ec);
}
using base_type::get_future;

// Effects: atomically stores the value r in the shared state and makes
// that state ready (30.6.4).
Expand All @@ -232,11 +219,7 @@ namespace lcos {
// - promise_already_satisfied if its shared state already has a
// stored value or exception.
// - no_state if *this has no shared state.
void set_exception(
boost::exception_ptr const& e, error_code& ec = throws)
{
base_type::set_exception(e, ec);
}
using base_type::set_exception;
};

template <typename Result, typename RemoteResult>
Expand Down