Skip to content

Commit

Permalink
#2281: Remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Sep 16, 2024
1 parent 90c5668 commit 11426c1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 89 deletions.
9 changes: 7 additions & 2 deletions src/vt/collective/reduce/allreduce/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ struct ShouldUseView<Scalar, Kokkos::View<Scalar*, Kokkos::HostSpace>> {
};
#endif // MAGISTRATE_KOKKOS_ENABLED

inline NodeType getActualDest(NodeType vrt_node, uint32_t scatter_mask, NodeType nprocs_rem) {
auto vdest = static_cast<NodeType>(vrt_node ^ scatter_mask);
return (vdest < nprocs_rem) ? vdest * 2 : vdest + nprocs_rem;
}

// Helper alias for cleaner usage
template <typename Scalar, typename DataT>
inline constexpr bool ShouldUseView_v = ShouldUseView<Scalar, DataT>::Value;
Expand All @@ -110,7 +115,7 @@ struct DataHelper {

static auto createMessage(
const std::vector<Scalar>& payload, size_t begin, size_t count, size_t id,
int32_t step = 0) {
uint32_t step = 0) {
return vt::makeMessage<RabenseifnerMsg<Scalar, DataT>>(
payload.data() + begin, count, id, step);
}
Expand Down Expand Up @@ -156,7 +161,7 @@ struct DataHelper<Scalar, Kokkos::View<Scalar*, Kokkos::HostSpace>> {

static auto createMessage(
const DataT& payload, size_t begin, size_t count, size_t id,
int32_t step = 0) {
uint32_t step = 0) {
return vt::makeMessage<RabenseifnerMsg<Scalar, DataT>>(
Kokkos::subview(payload, std::make_pair(begin, begin + count)), id, step
);
Expand Down
7 changes: 4 additions & 3 deletions src/vt/collective/reduce/allreduce/rabenseifner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*/

#include "vt/collective/reduce/allreduce/rabenseifner.h"
#include "vt/group/group_manager.h"
#include "vt/configs/error/config_assert.h"

namespace vt::collective::reduce::allreduce {
Expand All @@ -53,7 +54,7 @@ Rabenseifner::Rabenseifner(
nodes_(theGroup()->GetGroupNodes(group.get())),
num_nodes_(nodes_.size()),
this_node_(theContext()->getNode()),
num_steps_(static_cast<int32_t>(std::log2(num_nodes_))),
num_steps_(static_cast<uint32_t>(std::log2(num_nodes_))),
nprocs_pof2_(1 << num_steps_),
nprocs_rem_(num_nodes_ - nprocs_pof2_) {

Expand Down Expand Up @@ -90,7 +91,7 @@ Rabenseifner::Rabenseifner(
nodes_(theGroup()->GetGroupNodes(group.get())),
num_nodes_(nodes_.size()),
this_node_(theContext()->getNode()),
num_steps_(static_cast<int32_t>(log2(num_nodes_))),
num_steps_(static_cast<uint32_t>(std::log2(num_nodes_))),
nprocs_pof2_(1 << num_steps_),
nprocs_rem_(num_nodes_ - nprocs_pof2_) {
std::string nodes_info;
Expand Down Expand Up @@ -139,7 +140,7 @@ Rabenseifner::Rabenseifner(detail::StrongObjGroup objgroup)
nodes_(theGroup()->GetGroupNodes(default_group)),
num_nodes_(nodes_.size()),
this_node_(theContext()->getNode()),
num_steps_(static_cast<int32_t>(log2(num_nodes_))),
num_steps_(static_cast<uint32_t>(std::log2(num_nodes_))),
nprocs_pof2_(1 << num_steps_),
nprocs_rem_(num_nodes_ - nprocs_pof2_) {
std::string nodes_info;
Expand Down
10 changes: 5 additions & 5 deletions src/vt/collective/reduce/allreduce/rabenseifner.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ struct Rabenseifner {
* \param step The current step in the scatter phase.
*/
template <typename DataT, template <typename Arg> class Op>
void scatterTryReduce(size_t id, int32_t step);
void scatterTryReduce(size_t id, uint32_t step);

/**
* \brief Perform the scatter-reduce iteration.
Expand Down Expand Up @@ -234,7 +234,7 @@ struct Rabenseifner {
* \param step The current step in the gather phase.
*/
template <typename DataT>
void gatherTryReduce(size_t id, int32_t step);
void gatherTryReduce(size_t id, uint32_t step);

/**
* \brief Perform the gather iteration.
Expand Down Expand Up @@ -299,11 +299,11 @@ struct Rabenseifner {
bool is_even_ = false;

/// Num steps for each scatter/gather phase
int32_t num_steps_ = {};
uint32_t num_steps_ = {};

/// 2^num_steps_
int32_t nprocs_pof2_ = {};
int32_t nprocs_rem_ = {};
uint32_t nprocs_pof2_ = {};
NodeType nprocs_rem_ = {};

/// For non-power-of-2 number of nodes this respresents whether current Node
/// is excluded (has value of -1) from computation
Expand Down
23 changes: 7 additions & 16 deletions src/vt/collective/reduce/allreduce/rabenseifner.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
#include "vt/config.h"
#include "vt/context/context.h"
#include "vt/configs/error/config_assert.h"
#include "vt/group/global/group_default.h"
#include "vt/group/group_manager.h"
#include "vt/group/group_info.h"
#include "vt/configs/types/types_sentinels.h"
#include "vt/registry/auto/auto_registry.h"
#include "vt/utils/fntraits/fntraits.h"
#include "vt/configs/debug/debug_print.h"
#include "vt/configs/debug/debug_printconst.h"
#include "vt/collective/reduce/allreduce/type.h"
Expand Down Expand Up @@ -157,12 +151,11 @@ void Rabenseifner::initialize(size_t id, Args&&... data) {
initializeState<DataT>(id);
}

int step = 0;
uint32_t step = 0;
state.size_ = state.val_.size();
auto size = state.size_;
for (int mask = 1; mask < nprocs_pof2_; mask <<= 1) {
auto vdest = vrt_node_ ^ mask;
auto dest = (vdest < nprocs_rem_) ? vdest * 2 : vdest + nprocs_rem_;
for (uint32_t mask = 1; mask < nprocs_pof2_; mask <<= 1) {
auto const dest = getActualDest(vrt_node_, state.scatter_mask_, nprocs_rem_);

if (this_node_ < dest) {
state.r_count_[step] = size / 2;
Expand Down Expand Up @@ -377,7 +370,7 @@ bool Rabenseifner::scatterIsReady(size_t id) {
}

template <typename DataT, template <typename Arg> class Op>
void Rabenseifner::scatterTryReduce(size_t id, int32_t step) {
void Rabenseifner::scatterTryReduce(size_t id, uint32_t step) {
using DataHelperT = DataHelper<typename DataHandler<DataT>::Scalar, DataT>;
auto& state = getState<RabenseifnerT, DataT>(
collection_proxy_, objgroup_proxy_, group_, id);
Expand Down Expand Up @@ -420,8 +413,7 @@ void Rabenseifner::scatterReduceIter(size_t id) {
state.scatter_step_, state.s_index_.size(), state.s_count_.size(), id,
proxy_.getProxy(), print_ptr(&state));

auto vdest = vrt_node_ ^ state.scatter_mask_;
auto dest = (vdest < nprocs_rem_) ? vdest * 2 : vdest + nprocs_rem_;
auto const dest = getActualDest(vrt_node_, state.scatter_mask_, nprocs_rem_);
auto const actual_partner = nodes_[dest];

vt_debug_print(
Expand Down Expand Up @@ -536,7 +528,7 @@ bool Rabenseifner::gatherIsReady(size_t id) {
}

template <typename DataT>
void Rabenseifner::gatherTryReduce(size_t id, int32_t step) {
void Rabenseifner::gatherTryReduce(size_t id, uint32_t step) {
using DataHelperT = DataHelper<typename DataHandler<DataT>::Scalar, DataT>;
auto& state = getState<RabenseifnerT, DataT>(
collection_proxy_, objgroup_proxy_, group_, id);
Expand Down Expand Up @@ -565,8 +557,7 @@ void Rabenseifner::gatherIter(size_t id) {
using DataHelperT = DataHelper<Scalar, DataT>;
auto& state = getState<RabenseifnerT, DataT>(
collection_proxy_, objgroup_proxy_, group_, id);
auto vdest = vrt_node_ ^ state.gather_mask_;
auto dest = (vdest < nprocs_rem_) ? vdest * 2 : vdest + nprocs_rem_;
auto const dest = getActualDest(vrt_node_, state.scatter_mask_, nprocs_rem_);
auto const actual_partner = nodes_[dest];

vt_debug_print(
Expand Down
61 changes: 4 additions & 57 deletions src/vt/collective/reduce/allreduce/rabenseifner_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct RabenseifnerMsg : Message {
}
}

RabenseifnerMsg(const Scalar* in_val, size_t size, size_t id, int step = 0)
RabenseifnerMsg(const Scalar* in_val, size_t size, size_t id, uint32_t step = 0)
: MessageParentType(),
val_(in_val),
size_(size),
Expand All @@ -89,63 +89,10 @@ struct RabenseifnerMsg : Message {
s | step_;
}

struct NoCombine {};

template <typename>
struct IsTuple : std::false_type {};
template <typename... Args>
struct IsTuple<std::tuple<Args...>> : std::true_type {};

template <typename MsgT, typename Op, typename ActOp>
static void combine(MsgT* m1, MsgT* m2) {
Op()(m1->getVal(), m2->getConstVal());
}

template <typename Tuple, typename Op, typename ActOp>
static void FinalHandler(ReduceTMsg<Tuple>* msg) {
// using MsgT = ReduceTMsg<Tuple>;
vt_debug_print(
terse, reduce,
"FinalHandler: reduce root: ptr={}\n", print_ptr(msg)
);
// if (msg->isRoot()) {
// vt_debug_print(
// terse, reduce,
// "FinalHandler::ROOT: reduce root: ptr={}\n", print_ptr(msg)
// );
// if (msg->hasValidCallback()) {
// envelopeUnlockForForwarding(msg->env);
// if (msg->isParamCallback()) {
// if constexpr (IsTuple<typename MsgT::DataT>::value) {
// msg->getParamCallback().sendTuple(std::move(msg->getVal()));
// }
// } else {
// // We need to force the type to the more specific one here
// auto cb = msg->getMsgCallback();
// auto typed_cb = reinterpret_cast<Callback<MsgT>*>(&cb);
// typed_cb->sendMsg(msg);
// }
// } else if (msg->root_handler_ != uninitialized_handler) {
// auto_registry::getAutoHandler(msg->root_handler_)->dispatch(msg, nullptr);
// }
// } else {
// MsgT* fst_msg = msg;
// MsgT* cur_msg = msg->template getNext<MsgT>();
// vt_debug_print(
// terse, reduce,
// "FinalHandler::leaf: fst ptr={}\n", print_ptr(fst_msg)
// );
// while (cur_msg != nullptr) {
// RabenseifnerMsg<Scalar, DataT>::combine<MsgT,Op,ActOp>(fst_msg, cur_msg);
// cur_msg = cur_msg->template getNext<MsgT>();
// }
// }
}

const Scalar* val_ = {};
size_t size_ = {};
size_t id_ = {};
int32_t step_ = {};
uint32_t step_ = {};
bool owning_ = false;
};

Expand All @@ -160,7 +107,7 @@ struct RabenseifnerMsg<Scalar, Kokkos::View<Scalar*, Kokkos::HostSpace>> : Messa
RabenseifnerMsg(RabenseifnerMsg const&) = default;
RabenseifnerMsg(RabenseifnerMsg&&) = default;

RabenseifnerMsg(const ViewT& in_val, size_t id, int step = 0)
RabenseifnerMsg(const ViewT& in_val, size_t id, uint32_t step = 0)
: MessageParentType(),
val_(in_val),
id_(id),
Expand All @@ -177,7 +124,7 @@ struct RabenseifnerMsg<Scalar, Kokkos::View<Scalar*, Kokkos::HostSpace>> : Messa

ViewT val_ = {};
size_t id_ = {};
int32_t step_ = {};
uint32_t step_ = {};
};
#endif // MAGISTRATE_KOKKOS_ENABLED

Expand Down
12 changes: 6 additions & 6 deletions src/vt/collective/reduce/allreduce/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ struct StateBase {

struct RabensiferBase : StateBase {
// Scatter
int32_t scatter_mask_ = 1;
int32_t scatter_step_ = 0;
int32_t scatter_num_recv_ = 0;
uint32_t scatter_mask_ = 1;
uint32_t scatter_step_ = 0;
uint32_t scatter_num_recv_ = 0;
std::vector<bool> scatter_steps_recv_ = {};
std::vector<bool> scatter_steps_reduced_ = {};

bool finished_scatter_part_ = false;

// Gather
int32_t gather_step_ = 0;
int32_t gather_mask_ = 1;
int32_t gather_num_recv_ = 0;
uint32_t gather_step_ = 0;
uint32_t gather_mask_ = 1;
uint32_t gather_num_recv_ = 0;
std::vector<bool> gather_steps_recv_ = {};
std::vector<bool> gather_steps_reduced_ = {};

Expand Down

0 comments on commit 11426c1

Please sign in to comment.