Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
57 changes: 47 additions & 10 deletions src/Communicate/Archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// that they have type char and thus contain raw bytes, unlike other typed buffers
// such as detail::FieldBufferData used by HaloCells.
//
// On CUDA/HIP the internal buffer is allocated directly via cudaMalloc/hipMalloc
Comment thread
aaadelmann marked this conversation as resolved.
// so that the pointer is page-aligned (4K) and compatible with MPI IPC.
//
#ifndef IPPL_ARCHIVE_H
#define IPPL_ARCHIVE_H

Expand All @@ -32,6 +35,7 @@ namespace ippl {
using pointer_type = typename buffer_type::pointer_type;

Archive(size_type size = 0);
~Archive();

/*!
* Serialize.
Expand All @@ -40,6 +44,10 @@ namespace ippl {
template <typename T, class... ViewArgs>
void serialize(const Kokkos::View<T*, ViewArgs...>& view, size_type nsends);

template <typename T, class... ViewArgs, typename HashView>
void serialize(const Kokkos::View<T*, ViewArgs...>& view, const HashView& hash,
size_type nsends);

/*!
* Serialize vector attributes
*
Expand All @@ -52,13 +60,25 @@ namespace ippl {
void serialize(const Kokkos::View<Vector<T, Dim>*, ViewArgs...>& view,
size_type nsends);

template <typename T, unsigned Dim, class... ViewArgs, typename HashView>
void serialize(const Kokkos::View<Vector<T, Dim>*, ViewArgs...>& view,
const HashView& hash, size_type nsends);

/*!
* Deserialize.
* @param view to put data to
*/
template <typename T, class... ViewArgs>
void deserialize(Kokkos::View<T*, ViewArgs...>& view, size_type nrecvs);

template <typename T, class... ViewArgs>
void deserialize(Kokkos::View<T*, ViewArgs...>& view, size_type offset,
size_type nrecvs);

template <typename T, unsigned Dim, class... ViewArgs>
void deserialize(Kokkos::View<Vector<T, Dim>*, ViewArgs...>& view, size_type offset,
size_type nrecvs);

/*!
* Deserialize vector attributes
*
Expand All @@ -71,33 +91,50 @@ namespace ippl {
void deserialize(Kokkos::View<Vector<T, Dim>*, ViewArgs...>& view, size_type nrecvs);

/*!
* @returns a pointer to the data of the buffer
* @returns a pointer to the data of the buffer.
* On GPU this is a page-aligned device pointer from cudaMalloc/hipMalloc.
*/
pointer_type getBuffer() { return buffer_m.data(); }
pointer_type getBuffer() { return bufferData(); }

/*!
* @returns the size of the buffer
* @returns the number of bytes written so far
*/
size_type getSize() const { return writepos_m; }

size_type getBufferSize() const { return buffer_m.size(); }

void resizeBuffer(size_type size) { Kokkos::resize(buffer_m, size); }
/*!
* @returns the total capacity of the buffer in bytes
*/
size_type getBufferSize() const { return bufferSize(); }

void reallocBuffer(size_type size) { Kokkos::realloc(buffer_m, size); }
void resizeBuffer(size_type size);
void reallocBuffer(size_type size);

void resetWritePos() { writepos_m = 0; }
void resetReadPos() { readpos_m = 0; }

~Archive() = default;

private:
//! write position for serialization
size_type writepos_m;
//! read position for deserialization
size_type readpos_m;
//! serialized data

#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP)
//! Raw device pointer from cudaMalloc/hipMalloc (page-aligned, IPC-safe)
pointer_type buffer_ptr_m = nullptr;
size_type buffer_size_m = 0;

pointer_type bufferData() const { return buffer_ptr_m; }
size_type bufferSize() const { return buffer_size_m; }

void gpuAlloc(size_type size);
void gpuFree();
#else
//! serialized data (standard Kokkos view on CPU)
buffer_type buffer_m;

pointer_type bufferData() const { return buffer_m.data(); }
size_type bufferSize() const { return buffer_m.size(); }
#endif
};
} // namespace detail
} // namespace ippl
Expand Down
Loading
Loading