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

Fix return value of deepcopy and restrict the parameters to borrowed … #92

Merged
Merged
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
22 changes: 10 additions & 12 deletions include/ddc/deepcopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,29 @@
#pragma once

#include <type_traits>
#include <utility>

#include <Kokkos_Core.hpp>

#include "ddc/chunk_span.hpp"
#include "ddc/for_each.hpp"

namespace ddc {

/** Copy the content of a view into another
* @param[out] dst the view in which to copy
* @param[in] src the view from which to copy
* @return to
*/
/** Copy the content of a borrowed chunk into another
* @param[out] dst the borrowed chunk in which to copy
* @param[in] src the borrowed chunk from which to copy
* @return dst as a ChunkSpan
*/
template <class ChunkDst, class ChunkSrc>
inline ChunkDst const& deepcopy(ChunkDst&& dst, ChunkSrc&& src) noexcept
auto deepcopy(ChunkDst&& dst, ChunkSrc&& src)
{
static_assert(is_chunk_v<ChunkDst>);
static_assert(is_chunk_v<ChunkSrc>);
static_assert(is_borrowed_chunk_v<ChunkDst>);
static_assert(is_borrowed_chunk_v<ChunkSrc>);
static_assert(
std::is_assignable_v<decltype(*dst.data()), decltype(*src.data())>,
std::is_assignable_v<chunk_reference_t<ChunkDst>, chunk_reference_t<ChunkSrc>>,
"Not assignable");
assert(dst.domain().extents() == src.domain().extents());
Kokkos::deep_copy(dst.allocation_kokkos_view(), src.allocation_kokkos_view());
return dst;
return dst.span_view();
}

} // namespace ddc