Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: MPI support for openMP and GPU. #109

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions include/NeoFOAM/core/mpi/halfDuplexCommBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include <mpi.h>
#include <Kokkos_Core.hpp>

#include "NeoFOAM/core/error.hpp"
#include "NeoFOAM/core/mpi/environment.hpp"
Expand Down Expand Up @@ -35,6 +36,16 @@ inline int bufferHash(const std::string& str)
return (static_cast<int>(tag) % maxTagValue) + 10;
}


template<typename Type>
concept MemorySpace = requires {
typename Type::execution_space;
{
Type::is_memory_space
} -> std::convertible_to<bool>;
requires Type::is_memory_space == true;
};

/**
* @class HalfDuplexCommBuffer
* @brief A data buffer for half-duplex communication in a distributed system using MPI.
Expand All @@ -45,6 +56,7 @@ inline int bufferHash(const std::string& str)
* memory reallocation and improving memory efficiency. The class operates in a half-duplex mode,
* meaning it is either sending or receiving data at any given time.
*/
template<class MemorySpace = Kokkos::HostSpace>
class HalfDuplexCommBuffer
{

Expand Down Expand Up @@ -206,6 +218,10 @@ class HalfDuplexCommBuffer
std::vector<std::size_t>
rankOffset_; /*< The offset (in bytes) for a rank data in the buffer. */

Kokkos::View<char*, MemorySpace> rankBufferKokkos_; // duplication for now - will replace above
Kokkos::View<std::size_t*, MemorySpace>
rankOffsetKokkos_; // duplication for now - will replace above
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For MPI these arrays needs to stay on the host. Only the send or recv buffer may be on the device, everything else has to be on the host.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this would be a problem then, because you would have to copy from host to device to make the MPI call no? Or does MPI realise that the buffer is on the device and the rest on the host?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't make MPI calls on the device (as in during kernels), if that is what you are asking. Other than that, the ranks, sizes, offsets, etc., are always on the host, regardless of where the buffer memory is located. MPI can automatically determine if a buffer is on the device or not.


/**
* @brief Set the data type for the buffer.
*/
Expand Down Expand Up @@ -236,13 +252,20 @@ class HalfDuplexCommBuffer
void updateDataSize(func rankSize, std::size_t newSize)
{
std::size_t dataSize = 0;

// UPDATE FOR LOOP TO KOKKOS
for (auto rank = 0; rank < mpiEnviron_.sizeRank(); ++rank)
{
rankOffset_[rank] = dataSize;
rankOffsetKokkos_(rank) = dataSize;
dataSize += rankSize(rank) * newSize;
}

rankOffset_.back() = dataSize;
rankOffsetKokkos_(mpiEnviron_.sizeRank()) = dataSize;

if (rankBuffer_.size() < dataSize) rankBuffer_.resize(dataSize); // we never size down.
if (rankBuffer_.size() < dataSize) Kokkos::resize(rankBufferKokkos_, dataSize);
}
};

Expand Down
Loading