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