DDC 0.1.0
Loading...
Searching...
No Matches
parallel_deepcopy.hpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <cassert>
8#include <type_traits>
9
10#include <Kokkos_Core.hpp>
11
12#include "ddc/chunk_traits.hpp"
13
14namespace ddc {
15
16/** Copy the content of a borrowed chunk into another
17 * @param[out] dst the borrowed chunk in which to copy
18 * @param[in] src the borrowed chunk from which to copy
19 * @return dst as a ChunkSpan
20*/
21template <class ChunkDst, class ChunkSrc>
22auto parallel_deepcopy(ChunkDst&& dst, ChunkSrc&& src)
23{
24 static_assert(is_borrowed_chunk_v<ChunkDst>);
25 static_assert(is_borrowed_chunk_v<ChunkSrc>);
26 static_assert(
27 std::is_assignable_v<chunk_reference_t<ChunkDst>, chunk_reference_t<ChunkSrc>>,
28 "Not assignable");
29 assert(dst.domain().extents() == src.domain().extents());
30 Kokkos::deep_copy(dst.allocation_kokkos_view(), src.allocation_kokkos_view());
31 return dst.span_view();
32}
33
34/** Copy the content of a borrowed chunk into another
35 * @param[in] execution_space a Kokkos execution space where the loop will be executed on
36 * @param[out] dst the borrowed chunk in which to copy
37 * @param[in] src the borrowed chunk from which to copy
38 * @return dst as a ChunkSpan
39*/
40template <class ExecSpace, class ChunkDst, class ChunkSrc>
41auto parallel_deepcopy(ExecSpace const& execution_space, ChunkDst&& dst, ChunkSrc&& src)
42{
43 static_assert(is_borrowed_chunk_v<ChunkDst>);
44 static_assert(is_borrowed_chunk_v<ChunkSrc>);
45 static_assert(
46 std::is_assignable_v<chunk_reference_t<ChunkDst>, chunk_reference_t<ChunkSrc>>,
47 "Not assignable");
48 assert(dst.domain().extents() == src.domain().extents());
49 Kokkos::deep_copy(execution_space, dst.allocation_kokkos_view(), src.allocation_kokkos_view());
50 return dst.span_view();
51}
52
53} // namespace ddc
The top-level namespace of DDC.
auto parallel_deepcopy(ChunkDst &&dst, ChunkSrc &&src)
Copy the content of a borrowed chunk into another.
auto parallel_deepcopy(ExecSpace const &execution_space, ChunkDst &&dst, ChunkSrc &&src)
Copy the content of a borrowed chunk into another.