kokkos-execution 0.0.1
Loading...
Searching...
No Matches
make_policy.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_IMPL_MAKE_POLICY_HPP
2#define KOKKOS_EXECUTION_IMPL_MAKE_POLICY_HPP
3
5
6#include "Kokkos_Macros.hpp"
7#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
8import kokkos.core;
9import kokkos.core_impl;
10#else
11# include "Kokkos_Core.hpp"
12#endif
13
16
18
20template <typename ExecPolicy, typename Exec>
21concept updatable_to = Kokkos::ExecutionPolicy<ExecPolicy> && std::same_as<Exec, typename ExecPolicy::execution_space>
22 && requires(const ExecPolicy& policy, const Exec& exec) {
23 ExecPolicy{Kokkos::Impl::PolicyUpdate{}, policy, exec};
24 };
25
32template <Kokkos::ExecutionSpace Exec, typename... Properties>
34 [[nodiscard]]
35 auto operator()(const Exec& exec) const noexcept -> Kokkos::SinglePolicy<Exec, Properties...> {
36 return {exec};
37 }
38
39 template <extents Extents>
40 requires(Extents::rank() == 1)
41 [[nodiscard]]
42 auto operator()(const Exec& exec, const Extents& extents) const noexcept
43 -> Kokkos::RangePolicy<Exec, Properties...> {
44 return {exec, 0, extents.extent(0)};
45 }
46
47 template <range_slice_with_default_stride RangeSlice>
48 [[nodiscard]]
49 auto operator()(const Exec& exec, const RangeSlice& rgsl) const noexcept
50 -> Kokkos::RangePolicy<Exec, Properties...> {
51 return {exec, rgsl.first, rgsl.last};
52 }
53
54 template <updatable_to<Exec> ExecPolicy>
55 requires(sizeof...(Properties) == 0)
56 [[nodiscard]]
57 auto operator()(const Exec& exec, const ExecPolicy& policy) const noexcept -> ExecPolicy {
58 return ExecPolicy{Kokkos::Impl::PolicyUpdate{}, policy, exec};
59 }
60
61 static Exec default_instance() noexcept {
62 return Exec{};
63 }
64
65 template <typename... Args>
66 requires(!Kokkos::ExecutionSpace<std::remove_cvref_t<Args>> && ...)
67 [[nodiscard]]
68 auto operator()(Args&&... args) const
69 STDEXEC_AUTO_RETURN(this->operator()(default_instance(), std::forward<Args>(args)...))
70};
71
72template <Kokkos::ExecutionSpace Exec, typename... Properties>
73inline constexpr make_policy_t<Exec, Properties...> make_policy{};
74
75template <typename MakePolicy, typename... Args>
76requires stdexec::__is_instance_of<std::remove_cvref_t<MakePolicy>, make_policy_t>
77using make_policy_result_t = std::invoke_result_t<const MakePolicy&, Args...>;
78
79} // namespace Kokkos::Execution::Impl
80
81#endif // KOKKOS_EXECUTION_IMPL_MAKE_POLICY_HPP
Only the execution space instance, not its type, can be bound late.
constexpr make_policy_t< Exec, Properties... > make_policy
std::invoke_result_t< const MakePolicy &, Args... > make_policy_result_t
Utility functions that wrap constructors of Kokkos execution policies.
auto operator()(Args &&... args) const noexcept(noexcept(this->operator()(default_instance(), std::forward< Args >(args)...))) -> decltype(this->operator()(default_instance(), std::forward< Args >(args)...))
static Exec default_instance() noexcept
auto operator()(const Exec &exec) const noexcept -> Kokkos::SinglePolicy< Exec, Properties... >
auto operator()(const Exec &exec, const RangeSlice &rgsl) const noexcept -> Kokkos::RangePolicy< Exec, Properties... >