DDC 0.10.0
Loading...
Searching...
No Matches
ddc_to_kokkos_execution_policy.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 <array>
8#include <cstddef>
9
10#include <Kokkos_Core.hpp>
11
12#include "discrete_vector.hpp"
13
14namespace ddc::detail {
15
16template <class ExecSpace, std::size_t N>
17auto ddc_to_kokkos_execution_policy(
18 ExecSpace const& execution_space,
19 std::array<DiscreteVectorElement, N> const& size)
20{
21 using work_tag = void;
22 using index_type = Kokkos::IndexType<DiscreteVectorElement>;
23 if constexpr (N == 0) {
24 return Kokkos::RangePolicy<ExecSpace, work_tag, index_type>(execution_space, 0, 1);
25 } else {
26 if constexpr (N == 1) {
27 return Kokkos::
28 RangePolicy<ExecSpace, work_tag, index_type>(execution_space, 0, size[0]);
29 } else {
30 using iteration_pattern
31 = Kokkos::Rank<N, Kokkos::Iterate::Right, Kokkos::Iterate::Right>;
32 Kokkos::Array<DiscreteVectorElement, N> const begin {};
33 Kokkos::Array<DiscreteVectorElement, N> end;
34 for (std::size_t i = 0; i < N; ++i) {
35 end[i] = size[i];
36 }
37 return Kokkos::MDRangePolicy<
38 ExecSpace,
39 iteration_pattern,
40 work_tag,
41 index_type>(execution_space, begin, end);
42 }
43 }
44}
45
46} // namespace ddc::detail
The top-level namespace of DDC.