/* * (C) Copyright 2025- ECMWF. * * This software is licensed under the terms of the Apache Licence Version 2.0 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. * In applying this licence, ECMWF does not waive the privileges and immunities * granted to it by virtue of its status as an intergovernmental organisation * nor does it submit to any jurisdiction. */ #pragma once #include #include #include #include "atlas/array/ArrayView.h" #include "atlas/array/SVector.h" #include "atlas/runtime/Exception.h" namespace atlas::parallel::detail { template struct HostPacker { static void pack(const int sendcnt, array::SVector const& sendmap, const array::ArrayView& array, DATA_TYPE* send_buffer, int send_buffer_size); static void unpack(const int recvcnt, array::SVector const& recvmap, const DATA_TYPE* recv_buffer, int recv_buffer_size, array::ArrayView& array); }; template struct HostAdjointPacker { static void unpack(const int recvcnt, array::SVector const& recvmap, const DATA_TYPE* recv_buffer, int recv_buffer_size, array::ArrayView& array); }; template struct HostZeroer { static void zero(const int sendcnt, array::SVector const& sendmap, array::ArrayView& array, DATA_TYPE* recv_buffer, int recv_buffer_size); }; #if ATLAS_HAVE_GPU template struct DevicePacker { static void pack(const int sendcnt, array::SVector const& sendmap, const array::ArrayView& array, DATA_TYPE* send_buffer, int send_buffer_size); static void unpack(const int sendcnt, array::SVector const& recvmap, const DATA_TYPE* recv_buffer, int recv_buffer_size, array::ArrayView& array); }; #else template using DevicePacker = HostPacker; #endif template struct Packer { static void pack(const int sendcnt, array::SVector const& sendmap, const array::ArrayView& array, DATA_TYPE* send_buffer, int send_buffer_size, bool on_device) { if (not on_device) { HostPacker::pack(sendcnt, sendmap, array, send_buffer, send_buffer_size); } else { DevicePacker::pack(sendcnt, sendmap, array, send_buffer, send_buffer_size); } } static void unpack(const int recvcnt, array::SVector const& recvmap, const DATA_TYPE* recv_buffer, int recv_buffer_size, array::ArrayView& array, bool on_device) { if (not on_device) { HostPacker::unpack(recvcnt, recvmap, recv_buffer, recv_buffer_size, array); } else { DevicePacker::unpack(recvcnt, recvmap, recv_buffer, recv_buffer_size, array); } } }; template struct AdjointPacker { static void pack(const int sendcnt, array::SVector const& sendmap, const array::ArrayView& array, DATA_TYPE* send_buffer, int send_buffer_size, bool on_device) { Packer::pack(sendcnt, sendmap, array, send_buffer, send_buffer_size, on_device); } static void unpack(const int recvcnt, array::SVector const& recvmap, const DATA_TYPE* recv_buffer, int recv_buffer_size, array::ArrayView& array, bool on_device) { if (on_device) { ATLAS_NOTIMPLEMENTED; } else { HostAdjointPacker::unpack(recvcnt, recvmap, recv_buffer, recv_buffer_size, array); } } }; template struct Zeroer { static void zero(const int sendcnt, array::SVector const& sendmap, array::ArrayView& array, DATA_TYPE* recv_buffer, int recv_buffer_size, bool on_device) { if (on_device) { ATLAS_NOTIMPLEMENTED; } else { HostZeroer::zero(sendcnt, sendmap, array, recv_buffer, recv_buffer_size); } } }; //---------------------------------------------------------------------------------------------------------------------- } // namespace atlas::parallel::detail