Skip to content

Commit

Permalink
adding hpx support to master branch of pnnl
Browse files Browse the repository at this point in the history
  • Loading branch information
NanmiaoWu committed Apr 4, 2022
1 parent 25fee7b commit 12b08ec
Show file tree
Hide file tree
Showing 22 changed files with 1,786 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ option(SHAD_ENABLE_PERFORMANCE_TEST "Enable the compilation of the Performance T

set(
SHAD_RUNTIME_SYSTEM "CPP_SIMPLE" CACHE STRING
"(Default) Runtime system to be used as backend of the Abstract Runtime API (Default=CPP_SIMPLE, Supported=CPP_SIMPLE | TBB | GMT)")
"(Default) Runtime system to be used as backend of the Abstract Runtime API (Default=CPP_SIMPLE, Supported=CPP_SIMPLE | TBB | GMT | HPX)")


include(config)
Expand Down
6 changes: 6 additions & 0 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ elseif (SHAD_RUNTIME_SYSTEM STREQUAL "GMT")
include_directories(${GMT_INCLUDE_DIR})
set(HAVE_GMT 1)
set(SHAD_RUNTIME_LIB ${GMT_LIBRARIES})
elseif (SHAD_RUNTIME_SYSTEM STREQUAL "HPX")
message(STATUS "Using HPX as backend of the Abstract Runtime API.")
find_package(HPX REQUIRED)
include_directories(${HPX_INCLUDE_DIR})
set(HAVE_HPX 1)
set(SHAD_RUNTIME_LIB HPX::hpx)
else()
message(FATAL_ERROR "${SHAD_RUNTIME_SYSTEM} is not a supported runtime system.")
endif()
Expand Down
39 changes: 22 additions & 17 deletions examples/pi/pi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,30 @@ int main(int argc, char *argv[]) {
const size_t numberOfPoints = 1e10;
const size_t numberOfPointsPerSim = numberOfPoints / counters.size();

shad::generate(
shad::distributed_parallel_tag{},
counters.begin(), counters.end(),
[=]() -> uint64_t {
size_t counter = 0;
auto generator = [=]() -> uint64_t {
size_t counter = 0;

std::random_device rd;
std::default_random_engine G(rd());
std::uniform_real_distribution<double> dist(0.0, 1.0);
std::random_device rd;
std::default_random_engine G(rd());
std::uniform_real_distribution<double> dist(0.0, 1.0);

for (size_t i = 0; i < numberOfPointsPerSim; ++i) {
double x = dist(G);
double y = dist(G);
if ((x * x + y * y) < 1) {
++counter;
}
}
return counter;
});
for (size_t i = 0; i < numberOfPointsPerSim; ++i) {
double x = dist(G);
double y = dist(G);
if ((x * x + y * y) < 1) {
++counter;
}
}
return counter;
};

#ifdef HAVE_HPX
shad::generate(shad::distributed_parallel_tag{}, counters.begin(),
counters.end(), shad::rt::lambda_wrapper(generator));
#else
shad::generate(shad::distributed_parallel_tag{}, counters.begin(),
counters.end(), generator);
#endif

uint64_t count = shad::reduce(
shad::distributed_parallel_tag{}, counters.begin(), counters.end());
Expand Down
84 changes: 84 additions & 0 deletions include/shad/core/impl/impl_patterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ S distributed_folding_map(ForwardIt first, ForwardIt last, MapF&& map_kernel,
using itr_traits = distributed_iterator_traits<ForwardIt>;
auto localities = itr_traits::localities(first, last);
auto res = init_sol;
#ifdef HAVE_HPX
for (auto locality = localities.begin(), end = localities.end();
locality != end; ++locality) {
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
std::forward<MapF>(map_kernel)),
first, last, res, args...);
rt::executeAtWithRet(
locality,
[](const typeof(d_args)& d_args, S* result) {
*result = apply_from<1>(::std::get<0>(d_args),
::std::forward<typeof(d_args)>(d_args));
},
d_args, &res);
}
#else
for (auto locality = localities.begin(), end = localities.end();
locality != end; ++locality) {
auto d_args = std::make_tuple(map_kernel, first, last, res, args...);
Expand All @@ -103,6 +118,7 @@ S distributed_folding_map(ForwardIt first, ForwardIt last, MapF&& map_kernel,
},
d_args, &res);
}
#endif
return res;
}

Expand All @@ -112,6 +128,21 @@ void distributed_folding_map_void(ForwardIt first, ForwardIt last,
MapF&& map_kernel, Args&&... args) {
using itr_traits = distributed_iterator_traits<ForwardIt>;
auto localities = itr_traits::localities(first, last);
#ifdef HAVE_HPX
for (auto locality = localities.begin(), end = localities.end();
locality != end; ++locality) {
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
std::forward<MapF>(map_kernel)),
first, last, args...);
rt::executeAt(
locality,
[](const typeof(d_args)& d_args) {
apply_from<1>(::std::get<0>(d_args),
::std::forward<typeof(d_args)>(d_args));
},
d_args);
}
#else
for (auto locality = localities.begin(), end = localities.end();
locality != end; ++locality) {
auto d_args = std::make_tuple(map_kernel, first, last, args...);
Expand All @@ -123,6 +154,7 @@ void distributed_folding_map_void(ForwardIt first, ForwardIt last,
},
d_args);
}
#endif
}

// distributed_folding_map variant testing for early termination
Expand All @@ -134,6 +166,22 @@ S distributed_folding_map_early_termination(ForwardIt first, ForwardIt last,
using itr_traits = distributed_iterator_traits<ForwardIt>;
auto localities = itr_traits::localities(first, last);
auto res = init_sol;
#ifdef HAVE_HPX
for (auto locality = localities.begin(), end = localities.end();
locality != end; ++locality) {
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
std::forward<MapF>(map_kernel)),
first, last, res, args...);
rt::executeAtWithRet(
locality,
[](const typeof(d_args)& d_args, S* result) {
*result = apply_from<1>(::std::get<0>(d_args),
::std::forward<typeof(d_args)>(d_args));
},
d_args, &res);
if (halt(res)) return res;
}
#else
for (auto locality = localities.begin(), end = localities.end();
locality != end; ++locality) {
auto d_args = std::make_tuple(map_kernel, first, last, res, args...);
Expand All @@ -146,6 +194,8 @@ S distributed_folding_map_early_termination(ForwardIt first, ForwardIt last,
d_args, &res);
if (halt(res)) return res;
}
#endif

return res;
}

Expand Down Expand Up @@ -205,7 +255,13 @@ distributed_map_init(
auto localities = itr_traits::localities(first, last);
size_t i = 0;
rt::Handle h;
#ifdef HAVE_HPX
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
std::forward<MapF>(map_kernel)),
first, last, args...);
#else
auto d_args = std::make_tuple(map_kernel, first, last, args...);
#endif
optional_vector<mapped_t> opt_res(localities.size(), init);
for (auto locality = localities.begin(), end = localities.end();
locality != end; ++locality, ++i) {
Expand Down Expand Up @@ -255,7 +311,13 @@ void distributed_map_void(ForwardIt first, ForwardIt last, MapF&& map_kernel,
auto localities = itr_traits::localities(first, last);
size_t i = 0;
rt::Handle h;
#ifdef HAVE_HPX
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
std::forward<MapF>(map_kernel)),
first, last, args...);
#else
auto d_args = std::make_tuple(map_kernel, first, last, args...);
#endif
for (auto locality = localities.begin(), end = localities.end();
locality != end; ++locality, ++i) {
rt::asyncExecuteAt(
Expand Down Expand Up @@ -301,7 +363,15 @@ local_map_init(
std::vector<mapped_t> map_res(parts.size(), init);

if (parts.size()) {
#ifdef HAVE_HPX
auto map_args =
std::make_tuple(parts.data(),
shad::rt::lambda_wrapper<std::decay_t<MapF>>(
std::forward<MapF>(map_kernel)),
map_res.data());
#else
auto map_args = std::make_tuple(parts.data(), map_kernel, map_res.data());
#endif
shad::rt::forEachAt(
rt::thisLocality(),
[](const typeof(map_args)& map_args, size_t iter) {
Expand Down Expand Up @@ -339,7 +409,13 @@ void local_map_void(ForwardIt first, ForwardIt last, MapF&& map_kernel) {
first, last, rt::impl::getConcurrency());

if (parts.size()) {
#ifdef HAVE_HPX
auto map_args = std::make_tuple(
parts.data(), shad::rt::lambda_wrapper<std::decay_t<MapF>>(
std::forward<MapF>(map_kernel)));
#else
auto map_args = std::make_tuple(parts.data(), map_kernel);
#endif
shad::rt::forEachAt(
rt::thisLocality(),
[](const typeof(map_args)& map_args, size_t iter) {
Expand All @@ -361,7 +437,15 @@ void local_map_void_offset(ForwardIt first, ForwardIt last, MapF&& map_kernel) {
first, last, rt::impl::getConcurrency());

if (parts.size()) {
#ifdef HAVE_HPX
auto map_args =
std::make_tuple(parts.data(),
shad::rt::lambda_wrapper<std::decay_t<MapF>>(
std::forward<MapF>(map_kernel)),
first);
#else
auto map_args = std::make_tuple(parts.data(), map_kernel, first);
#endif
shad::rt::forEachAt(
rt::thisLocality(),
[](const typeof(map_args)& map_args, size_t iter) {
Expand Down
21 changes: 21 additions & 0 deletions include/shad/core/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <memory>

#include "shad/runtime/runtime.h"
#ifdef HAVE_HPX
#include "hpx/serialization.hpp"
#endif

namespace shad {

Expand Down Expand Up @@ -59,6 +62,9 @@ class insert_iterator
insert_iterator(Container& container, Iterator iterator)
: global_id_(container.global_id()), iterator_(iterator) {}

#ifdef HAVE_HPX
insert_iterator() = default;
#endif
/// @brief The assignment operator.
///
/// The assignment operator inserts a value (through buffering) and advance
Expand Down Expand Up @@ -114,6 +120,10 @@ class buffered_insert_iterator : public insert_iterator<Container> {
buffered_insert_iterator(Container& container, Iterator iterator)
: base_t(container, iterator) {}

#ifdef HAVE_HPX
buffered_insert_iterator() = default;
#endif

/// @brief The assignment operator.
///
/// The assignment operator inserts a value (through buffering) and advance
Expand Down Expand Up @@ -152,6 +162,17 @@ class buffered_insert_iterator : public insert_iterator<Container> {
buffered_insert_iterator& operator++() { return *this; }
buffered_insert_iterator& operator++(int) { return *this; }

#ifdef HAVE_HPX
private:
friend class hpx::serialization::access;

template <typename Archive>
void serialize(Archive& ar, unsigned)
{
ar & handle_;
}
#endif

private:
rt::Handle handle_;
};
Expand Down
4 changes: 4 additions & 0 deletions include/shad/data_structures/object_identifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ class ObjectIdentifier {
static constexpr uint8_t kIdentifierBitsize = 48u;

/// @brief Constructor.
#ifdef HAVE_HPX
explicit constexpr ObjectIdentifier(uint64_t id = 0) : id_(id) {}
#else
explicit constexpr ObjectIdentifier(uint64_t id) : id_(id) {}
#endif

/// @brief Constructor.
/// @param[in] locality The locality identifier part.
Expand Down
3 changes: 3 additions & 0 deletions include/shad/extensions/graph_library/edge_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ class EdgeIndex

using LocalEdgeListChunk = typename StorageT::LocalEdgeListChunk;
struct EdgeListChunk {
#ifdef HAVE_HPX
EdgeListChunk() = default;
#endif
EdgeListChunk(ObjectID &_oid, SrcT _src, LocalEdgeListChunk &_chunk)
: oid(_oid), src(_src), chunk(_chunk) {}
typename EdgeIndex<SrcT, DestT, StorageT>::ObjectID oid;
Expand Down
6 changes: 6 additions & 0 deletions include/shad/extensions/graph_library/local_edge_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class DefaultEdgeIndexStorage {
public:
struct EmptyAttr {};
using SrcAttributesT = EmptyAttr;
#ifdef HAVE_HPX
DefaultEdgeIndexStorage() = default;
#endif
explicit DefaultEdgeIndexStorage(const size_t numVertices)
: edgeList_(std::max(numVertices / constants::kDefaultNumEntriesPerBucket,
1lu)) {}
Expand All @@ -59,6 +62,9 @@ class DefaultEdgeIndexStorage {
1lu)) {}
static constexpr size_t kEdgeListChunkSize_ = 3072 / sizeof(DestT);
struct LocalEdgeListChunk {
#ifdef HAVE_HPX
LocalEdgeListChunk() = default;
#endif
LocalEdgeListChunk(size_t _numDest, bool _ow, DestT* _dest)
: numDest(_numDest), overwrite(_ow) {
memcpy(destinations.data(), _dest,
Expand Down
17 changes: 17 additions & 0 deletions include/shad/runtime/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "shad/runtime/mapping_traits.h"
#include "shad/runtime/mappings/available_traits_mappings.h"


namespace shad {

namespace rt {
Expand Down Expand Up @@ -87,8 +88,24 @@ class Handle {
/// @brief Null Test.
/// @return true if the Handle is null, false otherwise.
bool IsNull() const {
#ifdef HAVE_HPX
return impl::HandleTrait<TargetSystemTag>::Equal(
id_, impl::HandleTrait<TargetSystemTag>::NullValue());
#else
return id_ == impl::HandleTrait<TargetSystemTag>::NullValue();
#endif
}

#ifdef HAVE_HPX
private:
friend class hpx::serialization::access;

template <typename Archive>
void serialize(Archive& ar, unsigned)
{
ar & id_;
}
#endif

private:
friend void waitForCompletion(Handle &handle);
Expand Down
3 changes: 3 additions & 0 deletions include/shad/runtime/mappings/available_mappings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#elif defined HAVE_GMT
#include "shad/runtime/mappings/gmt/gmt_asynchronous_interface.h"
#include "shad/runtime/mappings/gmt/gmt_synchronous_interface.h"
#elif defined HAVE_HPX
#include "shad/runtime/mappings/hpx/hpx_asynchronous_interface.h"
#include "shad/runtime/mappings/hpx/hpx_synchronous_interface.h"
#else
#error Unsupported Runtime System
#endif
Expand Down
3 changes: 3 additions & 0 deletions include/shad/runtime/mappings/available_traits_mappings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "shad/runtime/mappings/tbb/tbb_traits_mapping.h"
#elif defined HAVE_GMT
#include "shad/runtime/mappings/gmt/gmt_traits_mapping.h"
#elif defined HAVE_HPX
#include "shad/runtime/mappings/hpx/hpx_traits_mapping.h"
#include "hpx/serialization.hpp"
#endif

#endif // INCLUDE_SHAD_RUNTIME_MAPPINGS_AVAILABLE_TRAITS_MAPPINGS_H_

0 comments on commit 12b08ec

Please sign in to comment.