From eafa36496d99e366ef2e8830e85eb06f80fe64d7 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Wed, 17 Jul 2024 23:37:57 +0200 Subject: [PATCH] #2240: Add helpers and use Kokkos::View for internals of Rabenseifner when user's payload is View --- .../reduce/allreduce/data_handler.h | 30 +-- src/vt/collective/reduce/allreduce/helpers.h | 195 ++++++++++++++++++ .../reduce/allreduce/rabenseifner.h | 117 +++-------- .../reduce/allreduce/rabenseifner.impl.h | 109 +++++----- .../reduce/allreduce/rabenseifner_msg.h | 129 ++++++++++++ tests/unit/objgroup/test_objgroup_common.h | 2 +- 6 files changed, 417 insertions(+), 165 deletions(-) create mode 100644 src/vt/collective/reduce/allreduce/helpers.h create mode 100644 src/vt/collective/reduce/allreduce/rabenseifner_msg.h diff --git a/src/vt/collective/reduce/allreduce/data_handler.h b/src/vt/collective/reduce/allreduce/data_handler.h index d614da1168..8afcb69e3d 100644 --- a/src/vt/collective/reduce/allreduce/data_handler.h +++ b/src/vt/collective/reduce/allreduce/data_handler.h @@ -66,15 +66,11 @@ class DataHandler toVec(const ScalarType& data) { return std::vector{data}; } static ScalarType fromVec(const std::vector& data) { return data[0]; } - static ScalarType fromMemory(ScalarType* data, size_t) { + static ScalarType fromMemory(const ScalarType* data, size_t) { return *data; } - // static const ScalarType* data(const ScalarType& data) { return &data; } static size_t size(const ScalarType&) { return 1; } - // static ScalarType& at(ScalarType& data, size_t) { return data; } - // static void set(ScalarType& data, size_t, const ScalarType& value) { data = value; } - // static ScalarType split(ScalarType&, size_t, size_t) { return ScalarType{}; } }; template @@ -84,20 +80,11 @@ class DataHandler> { static const std::vector& toVec(const std::vector& data) { return data; } static std::vector fromVec(const std::vector& data) { return data; } - static std::vector fromMemory(T* data, size_t count) { + static std::vector fromMemory(const T* data, size_t count) { return std::vector(data, data + count); } - // static const T* data(const std::vector& data) {return data.data(); } static size_t size(const std::vector& data) { return data.size(); } - // static T at(const std::vector& data, size_t idx) { return data[idx]; } - // static T& at(std::vector& data, size_t idx) { return data[idx]; } - // static void set(std::vector& data, size_t idx, const T& value) { - // data[idx] = value; - // } - // static std::vector split(std::vector& data, size_t start, size_t end) { - // return std::vector{data.begin() + start, data.begin() + end}; - // } }; #if MAGISTRATE_KOKKOS_ENABLED @@ -129,20 +116,7 @@ class DataHandler> { return view; } - // static const T* data(const ViewType& data) {return data.data(); } static size_t size(const ViewType& data) { return data.extent(0); } - - // static T at(const ViewType& data, size_t idx) { return data(idx); } - - // static T& at(ViewType& data, size_t idx) { return data(idx); } - - // static void set(ViewType& data, size_t idx, const T& value) { - // data(idx) = value; - // } - - // static ViewType split(ViewType& data, size_t start, size_t end) { - // return Kokkos::subview(data, std::make_pair(start, end)); - // } }; #endif // MAGISTRATE_KOKKOS_ENABLED diff --git a/src/vt/collective/reduce/allreduce/helpers.h b/src/vt/collective/reduce/allreduce/helpers.h new file mode 100644 index 0000000000..ed848b4d93 --- /dev/null +++ b/src/vt/collective/reduce/allreduce/helpers.h @@ -0,0 +1,195 @@ +/* +//@HEADER +// ***************************************************************************** +// +// helpers.h +// DARMA/vt => Virtual Transport +// +// Copyright 2019-2021 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 darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#if !defined INCLUDED_VT_COLLECTIVE_REDUCE_ALLREDUCE_HELPERS_H +#define INCLUDED_VT_COLLECTIVE_REDUCE_ALLREDUCE_HELPERS_H +#include "data_handler.h" +#include "rabenseifner_msg.h" +#include "vt/messaging/message/shared_message.h" +#include + +namespace vt::collective::reduce::allreduce { + +template +struct DataHelper { + using DataType = DataHandler; + + template + static void assign(std::vector& dest, Args&&... data) { + dest = DataHandler::toVec(std::forward(data)...); + } + + static MsgPtr> createMessage( + const std::vector& payload, size_t begin, size_t count, size_t id, + int32_t step = 0) { + return vt::makeMessage>( + payload.data() + begin, count, id, step); + } + + static void copy( + std::vector& dest, size_t start_idx, RabenseifnerMsg* msg) { + for (uint32_t i = 0; i < msg->size_; i++) { + dest[start_idx + i] = msg->val_[i]; + } + } + + template