-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify ddc::parallel_for_each and ddc::parallel_transform_reduce im…
…plementations (#645)
- Loading branch information
1 parent
e285b32
commit 371ffb8
Showing
3 changed files
with
71 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (C) The DDC development team, see COPYRIGHT.md file | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <type_traits> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "ddc/detail/kokkos.hpp" | ||
#include "ddc/discrete_domain.hpp" | ||
#include "ddc/discrete_element.hpp" | ||
|
||
namespace ddc::detail { | ||
|
||
template <class ExecSpace, class... DDims> | ||
auto ddc_to_kokkos_execution_policy( | ||
ExecSpace const& execution_space, | ||
DiscreteDomain<DDims...> const& domain) | ||
{ | ||
using work_tag = std:: | ||
conditional_t<need_annotated_operator<ExecSpace>(), use_annotated_operator, void>; | ||
using index_type = Kokkos::IndexType<DiscreteElementType>; | ||
if constexpr (sizeof...(DDims) == 0) { | ||
return Kokkos::RangePolicy<ExecSpace, work_tag, index_type>(execution_space, 0, 1); | ||
} else { | ||
DiscreteElement<DDims...> const ddc_begin = domain.front(); | ||
DiscreteElement<DDims...> const ddc_end = domain.front() + domain.extents(); | ||
if constexpr (sizeof...(DDims) == 1) { | ||
std::size_t const begin = ddc_begin.uid(); | ||
std::size_t const end = ddc_end.uid(); | ||
return Kokkos:: | ||
RangePolicy<ExecSpace, work_tag, index_type>(execution_space, begin, end); | ||
} else { | ||
using iteration_pattern = Kokkos:: | ||
Rank<sizeof...(DDims), Kokkos::Iterate::Right, Kokkos::Iterate::Right>; | ||
Kokkos::Array<std::size_t, sizeof...(DDims)> const begin { | ||
ddc::uid<DDims>(ddc_begin)...}; | ||
Kokkos::Array<std::size_t, sizeof...(DDims)> const end {ddc::uid<DDims>(ddc_end)...}; | ||
return Kokkos::MDRangePolicy< | ||
ExecSpace, | ||
iteration_pattern, | ||
work_tag, | ||
index_type>(execution_space, begin, end); | ||
} | ||
} | ||
} | ||
|
||
} // namespace ddc::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters