DDC 0.1.0
Loading...
Searching...
No Matches
parallel_fill.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 <type_traits>
8
9#include <Kokkos_Core.hpp>
10
11#include "ddc/chunk_traits.hpp"
12
13namespace ddc {
14
15/** Fill a borrowed chunk with a given value
16 * @param[out] dst the borrowed chunk in which to copy
17 * @param[in] value the value to fill `dst`
18 * @return dst as a ChunkSpan
19 */
20template <class ChunkDst, class T>
21auto parallel_fill(ChunkDst&& dst, T const& value)
22{
23 static_assert(is_borrowed_chunk_v<ChunkDst>);
24 static_assert(std::is_assignable_v<chunk_reference_t<ChunkDst>, T>, "Not assignable");
25 Kokkos::deep_copy(dst.allocation_kokkos_view(), value);
26 return dst.span_view();
27}
28
29/** Fill a borrowed chunk with a given value
30 * @param[in] execution_space a Kokkos execution space where the loop will be executed on
31 * @param[out] dst the borrowed chunk in which to copy
32 * @param[in] value the value to fill `dst`
33 * @return dst as a ChunkSpan
34 */
35template <class ExecSpace, class ChunkDst, class T>
36auto parallel_fill(ExecSpace const& execution_space, ChunkDst&& dst, T const& value)
37{
38 static_assert(is_borrowed_chunk_v<ChunkDst>);
39 static_assert(std::is_assignable_v<chunk_reference_t<ChunkDst>, T>, "Not assignable");
40 Kokkos::deep_copy(execution_space, dst.allocation_kokkos_view(), value);
41 return dst.span_view();
42}
43
44} // namespace ddc
The top-level namespace of DDC.
auto parallel_fill(ExecSpace const &execution_space, ChunkDst &&dst, T const &value)
Fill a borrowed chunk with a given value.
auto parallel_fill(ChunkDst &&dst, T const &value)
Fill a borrowed chunk with a given value.