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