Skip to content

Commit

Permalink
#2281: Update license and add reduce_op.h file for Kokkos reduce oper…
Browse files Browse the repository at this point in the history
…ators
  • Loading branch information
JacobDomagala committed Sep 26, 2024
1 parent 664cd07 commit 5523e17
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/allreduce_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// allreduce_holder.cc
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/allreduce_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// allreduce_holder.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/data_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// data_handler.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
15 changes: 8 additions & 7 deletions src/vt/collective/reduce/allreduce/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// helpers.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down Expand Up @@ -48,6 +48,7 @@
#include "rabenseifner_msg.h"
#include "vt/messaging/message/shared_message.h"
#include "vt/utils/kokkos/exec_space.h"
#include "vt/utils/kokkos/reduce_op.h"

#include <vector>

Expand Down Expand Up @@ -119,10 +120,10 @@ struct DataHelper {

#if MAGISTRATE_KOKKOS_ENABLED

template <typename Scalar, typename MemorySpace>
struct DataHelper<Scalar, Kokkos::View<Scalar*, MemorySpace>> {
using DataT = Kokkos::View<Scalar*, MemorySpace>;
using ExecSpace = typename utils::kokkos::AssociatedExecSpace<MemorySpace>::type;
template <typename Scalar, typename... Properties>
struct DataHelper<Scalar, Kokkos::View<Scalar*, Properties...>> {
using DataT = Kokkos::View<Scalar*, Properties...>;
using ExecSpace = typename utils::kokkos::AssociatedExecSpace<Properties...>::type;
using DataType = DataHandler<DataT>;

template <typename... Args>
Expand Down Expand Up @@ -155,7 +156,7 @@ struct DataHelper<Scalar, Kokkos::View<Scalar*, MemorySpace>> {
Kokkos::RangePolicy<ExecSpace> policy(0, msg->val_.extent(0));
Kokkos::parallel_for(
"Rabenseifner::reduce", policy, KOKKOS_LAMBDA(const int i) {
Op<Scalar>()(dest(start_idx + i), msg->val_(i));
utils::kokkos::KokkosOp<Op<Scalar>>()(dest(start_idx + i), msg->val_(i));
}
);
}
Expand All @@ -168,7 +169,7 @@ struct DataHelper<Scalar, Kokkos::View<Scalar*, MemorySpace>> {
Kokkos::RangePolicy<ExecSpace> policy(0, view_val.extent(0));
Kokkos::parallel_for(
"Rabenseifner::reduce", policy, KOKKOS_LAMBDA(const int i) {
Op<Scalar>()(dest(i), view_val(i));
utils::kokkos::KokkosOp<Op<Scalar>>()(dest(i), view_val(i));
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/rabenseifner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// rabenseifner.cc
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/rabenseifner.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// rabenseifner.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/rabenseifner.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// rabenseifner.impl.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
8 changes: 4 additions & 4 deletions src/vt/collective/reduce/allreduce/rabenseifner_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// rabenseifner_msg.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down Expand Up @@ -97,9 +97,9 @@ struct RabenseifnerMsg : Message {
};

#if MAGISTRATE_KOKKOS_ENABLED
template <typename Scalar>
struct RabenseifnerMsg<Scalar, Kokkos::View<Scalar*, Kokkos::HostSpace>> : Message {
using ViewT = Kokkos::View<Scalar*, Kokkos::HostSpace>;
template <typename Scalar, typename... Properties>
struct RabenseifnerMsg<Scalar, Kokkos::View<Scalar*, Properties...>> : Message {
using ViewT = Kokkos::View<Scalar*, Properties...>;
using MessageParentType = vt::Message;
vt_msg_serialize_required();

Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/recursive_doubling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// recursive_doubling.cc
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/recursive_doubling.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// recursive_doubling.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// recursive_doubling.impl.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// recursive_doubling_msg.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// state.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/state_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// state_holder.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
2 changes: 1 addition & 1 deletion src/vt/collective/reduce/allreduce/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// type.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
14 changes: 9 additions & 5 deletions src/vt/collective/reduce/operators/functors/plus_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,27 @@ struct PlusOp<std::tuple<Params...>> {

#if MAGISTRATE_KOKKOS_ENABLED

template <typename T, typename MemorySpace>
struct PlusOp<Kokkos::View<T*, MemorySpace>> {
template <typename T, typename... Properties>
struct PlusOp<Kokkos::View<T*, Properties...>> {
void operator()(
Kokkos::View<T*, MemorySpace>& v1,
Kokkos::View<T*, MemorySpace> const& v2) const {
Kokkos::View<T*, Properties...>& v1,
const Kokkos::View<T*, Properties...>& v2) const {

// Determine the associated execution space based on the memory space
using MemorySpace = typename Kokkos::View<T*, Properties...>::memory_space;
using ExecSpace = typename utils::kokkos::AssociatedExecSpace<MemorySpace>::type;

Kokkos::RangePolicy<ExecSpace> policy(0, v1.extent(0));

Kokkos::parallel_for(
"PlusOp_Host",
"Kokkos_PlusOp",
policy,
KOKKOS_LAMBDA(const int i) {
v1(i) += v2(i);
}
);

Kokkos::fence();
}
};
#endif // MAGISTRATE_KOKKOS_ENABLED
Expand Down
1 change: 0 additions & 1 deletion src/vt/objgroup/manager.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
//@HEADER
*/

#include "vt/collective/reduce/allreduce/allreduce_holder.h"
#if !defined INCLUDED_VT_OBJGROUP_MANAGER_IMPL_H
#define INCLUDED_VT_OBJGROUP_MANAGER_IMPL_H

Expand Down
2 changes: 1 addition & 1 deletion src/vt/utils/kokkos/exec_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// exec_space.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2021 National Technology & Engineering Solutions of Sandia, LLC
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
Expand Down
93 changes: 93 additions & 0 deletions src/vt/utils/kokkos/reduce_op.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
//@HEADER
// *****************************************************************************
//
// reduce_op.h
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact [email protected]
//
// *****************************************************************************
//@HEADER
*/

#if !defined INCLUDED_VT_UTILS_KOKKOS_REDUCE_OP_H
#define INCLUDED_VT_UTILS_KOKKOS_REDUCE_OP_H

#include "vt/config.h"

#if MAGISTRATE_KOKKOS_ENABLED

#include "vt/collective/reduce/operators/default_op.h"

namespace vt::utils::kokkos {

template <typename Op>
struct KokkosOp {
template <typename T>
KOKKOS_INLINE_FUNCTION
void operator()(T& v1, T const& v2) {
if constexpr (std::is_same_v<
Op, vt::collective::reduce::operators::AndOp<T>>) {
v1 = v1 && v2;
} else if constexpr (std::is_same_v<
Op,
vt::collective::reduce::operators::BitAndOp<T>>) {
v1 = v1 & v2;
} else if constexpr (std::is_same_v<
Op, vt::collective::reduce::operators::BitOrOp<T>>) {
v1 = v1 | v2;
} else if constexpr (std::is_same_v<
Op,
vt::collective::reduce::operators::BitXorOp<T>>) {
v1 = v1 ^ v2;
} else if constexpr (std::is_same_v<
Op, vt::collective::reduce::operators::MaxOp<T>>) {
v1 = std::max(v1, v2);
} else if constexpr (std::is_same_v<
Op, vt::collective::reduce::operators::MinOp<T>>) {
v1 = std::min(v1, v2);
} else if constexpr (std::is_same_v<
Op, vt::collective::reduce::operators::OrOp<T>>) {
v1 = v1 || v2;
} else if constexpr (std::is_same_v<
Op, vt::collective::reduce::operators::PlusOp<T>>) {
v1 = v1 + v2;
}
}
};

} // namespace vt::utils::kokkos

#endif // MAGISTRATE_KOKKOS_ENABLED
#endif /*INCLUDED_VT_UTILS_KOKKOS_REDUCE_OP_H*/
2 changes: 0 additions & 2 deletions tests/perf/allreduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ VT_PERF_TEST(MyTest, test_allreduce_collection_rabenseifner) {
.wait();

auto const thisNode = vt::theContext()->getNode();
auto const nextNode = (thisNode + 1) % num_nodes_;

theCollective()->barrier();

Expand Down Expand Up @@ -382,7 +381,6 @@ VT_PERF_TEST(MyTest, test_allreduce_collection_racursive_doubling) {
.wait();

auto const thisNode = vt::theContext()->getNode();
auto const nextNode = (thisNode + 1) % num_nodes_;

theCollective()->barrier();

Expand Down
2 changes: 0 additions & 2 deletions tests/perf/send_cost.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ VT_PERF_TEST(SendTest, test_objgroup_send) {

auto const thisNode = vt::theContext()->getNode();
auto const lastNode = theContext()->getNumNodes() - 1;

auto const prevNode = (thisNode - 1 + num_nodes_) % num_nodes_;
auto const nextNode = (thisNode + 1) % num_nodes_;

for (auto size : payloadSizes) {
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/objgroup/test_objgroup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,15 @@ struct MyObjA {

auto n = vt::theContext()->getNumNodes();
auto const total_sum = n * (n - 1) / 2;
using ExecSpace = typename utils::kokkos::AssociatedExecSpace<MemorySpace>::type;

Kokkos::RangePolicy<ExecSpace> policy(0, view.extent(0));
Kokkos::parallel_for("InitView", policy, KOKKOS_LAMBDA(const int i) {
EXPECT_EQ(view(i), total_sum);
});
// Just in case it's not Host space
auto view_host = Kokkos::create_mirror_view(view);
Kokkos::deep_copy(view_host, view);

vtAssert(view_host.extent(0) == 256, "View size is not right");
for(uint32_t i = 0; i < view_host.extent(0); ++i){
EXPECT_EQ(view_host(i), total_sum);
}

total_verify_expected_++;
}
Expand Down

0 comments on commit 5523e17

Please sign in to comment.