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