Skip to content

[WIP] Introducing execution- and launch policies #300

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

Open
wants to merge 6 commits into
base: development
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
1 change: 1 addition & 0 deletions dash/examples/ex.06.pattern-visualizer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <dash/tools/PatternVisualizer.h>


using std::cout;
using std::cerr;
using std::endl;
Expand Down
69 changes: 69 additions & 0 deletions dash/include/dash/Execution.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef DASH__EXECUTION_H__INCLUDED
#define DASH__EXECUTION_H__INCLUDED

#include <type_traits>


namespace dash {

/**
* Execution policy type trait.
*/
template<class T>
struct is_execution_policy
: public std::integral_constant<bool, false>
{ };

namespace execution {

/**
* Sequential execution policy.
*/
class sequenced_policy { };

/**
* Parallel execution policy.
*/
class parallel_policy { };

/**
* Parallel non-sequential execution policy.
*/
class parallel_unsequenced_policy { };
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference in semantics between parallel_policy and parallel_unsequenced_policy?

Choose a reason for hiding this comment

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

This is well described on cppreference.


constexpr sequenced_policy seq;
constexpr parallel_policy par;
constexpr parallel_unsequenced_policy par_unseq;

} // namespace execution

/**
* Specialization of execution policy type trait for sequential execution
* policy.
*/
template<>
struct is_execution_policy<dash::execution::sequenced_policy>
: public std::integral_constant<bool, true>
{ };

/**
* Specialization of execution policy type trait for parallel execution
* policy.
*/
template<>
struct is_execution_policy<dash::execution::parallel_policy>
: public std::integral_constant<bool, true>
{ };

/**
* Specialization of execution policy type trait for parallel non-sequential
* execution policy.
*/
template<>
struct is_execution_policy<dash::execution::parallel_unsequenced_policy>
: public std::integral_constant<bool, true>
{ };

} // namespace dash

#endif // DASH__EXECUTION_H__INCLUDED
8 changes: 5 additions & 3 deletions dash/include/dash/Future.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#ifndef DASH__FUTURE_H__INCLUDED
#define DASH__FUTURE_H__INCLUDED

#include <dash/Exception.h>
#include <dash/LaunchPolicy.h>

#include <dash/internal/Logging.h>

#include <cstddef>
#include <functional>
#include <sstream>
#include <iostream>

#include <dash/Exception.h>
#include <dash/internal/Logging.h>


namespace dash {

Expand Down
18 changes: 11 additions & 7 deletions dash/include/dash/LaunchPolicy.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#ifndef DASH__LAUNCH__H__INCLUDED
#define DASH__LAUNCH__H__INCLUDED
#ifndef DASH__LAUNCH_POLICY_H__INCLUDED
#define DASH__LAUNCH_POLICY_H__INCLUDED

#include <cstdint>

namespace dash {

enum class launch : uint16_t {
/// synchronous launch policy
sync = 0x1,
/// async launch policy
async = 0x2
/// synchronous launch policy
sync = 0x1,
/// async launch policy
async = 0x2,
/// deferred launch policy
deferred = 0x4,
/// unspecified launch policy
any = sync | async | deferred
};

}


#endif // DASH__LAUNCH__H__INCLUDED
#endif // DASH__LAUNCH_POLICY_H__INCLUDED
40 changes: 23 additions & 17 deletions dash/include/dash/algorithm/Copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace dash {
* \ingroup DashAlgorithms
*/
template <
typename ValueType,
class ValueType,
class InputIt,
class OutputIt >
OutputIt copy(
Expand All @@ -58,23 +58,28 @@ OutputIt copy(
OutputIt out_first);

/**
* Asynchronous variant of \c dash::copy.
* Asynchronous or deferred execution of \c dash::copy.
* Copies the elements in the range, defined by \c [in_first, in_last), to
* another range beginning at \c out_first.
*
* In terms of data distribution, source and destination ranges passed to
* \c dash::copy can be local (\c *ValueType) or global (\c GlobIter<ValueType>).
* \c dash::copy can be
*
* - local (\c *ValueType)
* - or global (\c GlobIter<ValueType>)
*
* For a blocking variant of \c dash::copy_async, see \c dash::copy.
* For a blocking variant, see \c dash::copy without launch policy parameter.
*
* Example:
*
* \code
* // Start asynchronous copying
* dash::Future<T*> fut_dest_end =
* dash::copy_async(array_a.block(0).begin(),
* array_a.block(0).end(),
* local_array);
* dash::copy(
* dash::launch::async,
* array_a.block(0).begin(),
* array_a.block(0).end(),
* local_array);
* // Overlapping computation here
* // ...
* // Wait for completion of asynchronous copying:
Expand All @@ -88,12 +93,14 @@ OutputIt copy(
* \ingroup DashAlgorithms
*/
template <
typename ValueType,
class ExecutionPolicy,
class ValueType,
class GlobInputIt >
dash::Future<ValueType *> copy_async(
InputIt in_first,
InputIt in_last,
OutputIt out_first);
dash::Future<ValueType *> copy(
ExecutionPolicy && policy,
Copy link
Member

Choose a reason for hiding this comment

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

The execution policy is ignored atm, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I just pinned the branch as PR to simplify discussion. It's work in progress (= [WIP] in title).

InputIt in_first,
InputIt in_last,
OutputIt out_first);

#else // DOXYGEN

Expand Down Expand Up @@ -1028,15 +1035,14 @@ ValueType * copy(
template <
typename ValueType,
class GlobOutputIt >
dash::Future<GlobOutputIt> copy_async(
constexpr dash::Future<GlobOutputIt> copy_async(
ValueType * in_first,
ValueType * in_last,
GlobOutputIt out_first)
{
auto fut = dash::internal::copy_async_impl(in_first,
in_last,
out_first);
return fut;
return dash::internal::copy_async_impl(in_first,
in_last,
out_first);
}

/**
Expand Down
19 changes: 14 additions & 5 deletions dash/include/libdash.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,28 @@ namespace dash {

#include <dash/Onesided.h>

#include <dash/Future.h>
#include <dash/Execution.h>
#include <dash/LaunchPolicy.h>

#include <dash/Atomic.h>
#include <dash/Mutex.h>

#include <dash/Container.h>
#include <dash/Array.h>
#include <dash/Matrix.h>
#include <dash/List.h>
#include <dash/UnorderedMap.h>

#include <dash/Pattern.h>

#include <dash/Shared.h>
#include <dash/SharedCounter.h>

#include <dash/Exception.h>
#include <dash/Algorithm.h>
#include <dash/Atomic.h>
#include <dash/Mutex.h>

#include <dash/Pattern.h>
#include <dash/Allocator.h>

#include <dash/util/BenchmarkParams.h>
#include <dash/util/Config.h>
Expand All @@ -66,6 +77,4 @@ namespace dash {
#include <dash/internal/Math.h>
#include <dash/internal/Logging.h>

#include <dash/tools/PatternVisualizer.h>

#endif // DASH__LIBDASH_H_