DDC 0.4.1
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 static_assert(std::is_same_v<decltype(dst.domain()), decltype(src.domain())>);
30 assert(dst.domain() == src.domain());
31 Kokkos::deep_copy(dst.allocation_kokkos_view(), src.allocation_kokkos_view());
32 return dst.span_view();
33}
34
35/** Copy the content of a borrowed chunk into another
36 * @param[in] execution_space a Kokkos execution space where the loop will be executed on
37 * @param[out] dst the borrowed chunk in which to copy
38 * @param[in] src the borrowed chunk from which to copy
39 * @return dst as a ChunkSpan
40*/
41template <class ExecSpace, class ChunkDst, class ChunkSrc>
42auto parallel_deepcopy(ExecSpace const& execution_space, ChunkDst&& dst, ChunkSrc&& src)
43{
44 static_assert(is_borrowed_chunk_v<ChunkDst>);
45 static_assert(is_borrowed_chunk_v<ChunkSrc>);
46 static_assert(
47 std::is_assignable_v<chunk_reference_t<ChunkDst>, chunk_reference_t<ChunkSrc>>,
48 "Not assignable");
49 static_assert(
50 std::is_same_v<decltype(dst.domain()), decltype(src.domain())>,
51 "ddc::parallel_deepcopy only supports domains whose dimensions are of the same order");
52 assert(dst.domain() == src.domain());
53 Kokkos::deep_copy(execution_space, dst.allocation_kokkos_view(), src.allocation_kokkos_view());
54 return dst.span_view();
55}
56
57} // 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.