Skip to content

Commit

Permalink
Keep temporary Isend views alive
Browse files Browse the repository at this point in the history
  • Loading branch information
cwpearson committed Dec 18, 2023
1 parent 762d803 commit 266c1ad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# kokkos-comm
MPI Wrapper for [Kokkos](https://github.com/kokkos/kokkos).
A toy MPI wrapper for [Kokkos](https://github.com/kokkos/kokkos).

```
mkdir -p build && cd build
Expand All @@ -8,6 +8,11 @@ make
ctest
```

## Design

- [x] use `Kokkos::deep_copy` to handle packing and unpacking of non-contiguous views
- When non-contiguous views are passed to an MPI function, a temporary contiguous view of matching extent is allocated, and `Kokkos::deep_copy` is used to pack the data.


## Considerations

Expand Down
31 changes: 30 additions & 1 deletion src/KokkosComm_request.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
#pragma once

#include <memory>

#include <mpi.h>

namespace KokkosComm {





class Req {
private:

// a type-erased view. Request uses these to keep temporary views alive for the lifetime of "Immediate" MPI operations
struct ViewHolderBase {
virtual ~ViewHolderBase(){}
};
template <typename V>
struct ViewHolder : ViewHolderBase {
ViewHolder(const V &v) : v_(v) {}
V v_;
};

public:
Req() : req_(MPI_REQUEST_NULL) {}

MPI_Request &mpi_req() { return req_; }

void wait() { MPI_Wait(&req_, MPI_STATUS_IGNORE); }
void wait() {
MPI_Wait(&req_, MPI_STATUS_IGNORE);
until_waits_.clear(); // drop any views we're keeping alive until wait()
}

// keep a reference to this view around until wait() is called
template <typename View>
void keep_until_wait(const View &v) {
until_waits_.push_back(std::make_shared<ViewHolder<View>>(v));
}

private:
MPI_Request req_;

std::vector<std::shared_ptr<ViewHolderBase>> until_waits_;
};

} // namespace KokkosComm
1 change: 1 addition & 0 deletions src/impl/KokkosComm_isend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ KokkosComm::Req isend(const ExecSpace &space, const SendView &sv, int dest,
space.fence();
MPI_Isend(packed.data(), packed.span() * sizeof(value_type), MPI_PACKED,
dest, tag, comm, &req.mpi_req());
req.keep_until_wait(packed);
return req;
} else {
static_assert(std::is_void_v<SendView>,
Expand Down

0 comments on commit 266c1ad

Please sign in to comment.