DDC 0.1.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... DDims>
19auto ddc_to_kokkos_execution_policy(
20 ExecSpace const& execution_space,
21 DiscreteDomain<DDims...> const& domain)
22{
23 using work_tag = std::
24 conditional_t<need_annotated_operator<ExecSpace>(), use_annotated_operator, void>;
25 using index_type = Kokkos::IndexType<DiscreteElementType>;
26 if constexpr (sizeof...(DDims) == 0) {
27 return Kokkos::RangePolicy<ExecSpace, work_tag, index_type>(execution_space, 0, 1);
28 } else {
29 DiscreteElement<DDims...> const ddc_begin = domain.front();
30 DiscreteElement<DDims...> const ddc_end = domain.front() + domain.extents();
31 if constexpr (sizeof...(DDims) == 1) {
32 std::size_t const begin = ddc_begin.uid();
33 std::size_t const end = ddc_end.uid();
34 return Kokkos::
35 RangePolicy<ExecSpace, work_tag, index_type>(execution_space, begin, end);
36 } else {
37 using iteration_pattern = Kokkos::
38 Rank<sizeof...(DDims), Kokkos::Iterate::Right, Kokkos::Iterate::Right>;
39 Kokkos::Array<std::size_t, sizeof...(DDims)> const begin {
40 ddc::uid<DDims>(ddc_begin)...};
41 Kokkos::Array<std::size_t, sizeof...(DDims)> const end {ddc::uid<DDims>(ddc_end)...};
42 return Kokkos::MDRangePolicy<
43 ExecSpace,
44 iteration_pattern,
45 work_tag,
46 index_type>(execution_space, begin, end);
47 }
48 }
49}
50
51} // namespace ddc::detail
friend class DiscreteDomain
The top-level namespace of DDC.