1 /* 2 //@HEADER 3 // ************************************************************************ 4 // 5 // Kokkos v. 3.0 6 // Copyright (2020) National Technology & Engineering 7 // Solutions of Sandia, LLC (NTESS). 8 // 9 // Under the terms of Contract DE-NA0003525 with NTESS, 10 // the U.S. Government retains certain rights in this software. 11 // 12 // Redistribution and use in source and binary forms, with or without 13 // modification, are permitted provided that the following conditions are 14 // met: 15 // 16 // 1. Redistributions of source code must retain the above copyright 17 // notice, this list of conditions and the following disclaimer. 18 // 19 // 2. Redistributions in binary form must reproduce the above copyright 20 // notice, this list of conditions and the following disclaimer in the 21 // documentation and/or other materials provided with the distribution. 22 // 23 // 3. Neither the name of the Corporation nor the names of the 24 // contributors may be used to endorse or promote products derived from 25 // this software without specific prior written permission. 26 // 27 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY 28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE 31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 // 39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov) 40 // 41 // ************************************************************************ 42 //@HEADER 43 */ 44 45 #ifndef KOKKOS_IMPL_ANALYZE_POLICY_HPP 46 #define KOKKOS_IMPL_ANALYZE_POLICY_HPP 47 48 #include <Kokkos_Core_fwd.hpp> 49 #include <Kokkos_Concepts.hpp> // IndexType 50 #include <traits/Kokkos_Traits_fwd.hpp> 51 #include <traits/Kokkos_PolicyTraitAdaptor.hpp> 52 53 #include <traits/Kokkos_ExecutionSpaceTrait.hpp> 54 #include <traits/Kokkos_GraphKernelTrait.hpp> 55 #include <traits/Kokkos_IndexTypeTrait.hpp> 56 #include <traits/Kokkos_IterationPatternTrait.hpp> 57 #include <traits/Kokkos_LaunchBoundsTrait.hpp> 58 #include <traits/Kokkos_OccupancyControlTrait.hpp> 59 #include <traits/Kokkos_ScheduleTrait.hpp> 60 #include <traits/Kokkos_WorkItemPropertyTrait.hpp> 61 #include <traits/Kokkos_WorkTagTrait.hpp> 62 63 namespace Kokkos { 64 namespace Impl { 65 66 //------------------------------------------------------------------------------ 67 68 using execution_policy_trait_specifications = 69 type_list<ExecutionSpaceTrait, GraphKernelTrait, IndexTypeTrait, 70 IterationPatternTrait, LaunchBoundsTrait, OccupancyControlTrait, 71 ScheduleTrait, WorkItemPropertyTrait, WorkTagTrait>; 72 73 //------------------------------------------------------------------------------ 74 // Ignore void for backwards compatibility purposes, though hopefully no one is 75 // using this in application code 76 template <class... Traits> 77 struct AnalyzeExecPolicy<void, void, Traits...> 78 : AnalyzeExecPolicy<void, Traits...> { 79 using base_t = AnalyzeExecPolicy<void, Traits...>; 80 using base_t::base_t; 81 }; 82 83 //------------------------------------------------------------------------------ 84 // Mix in the defaults (base_traits) for the traits that aren't yet handled 85 86 template <class TraitSpecList> 87 struct KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION AnalyzeExecPolicyBaseTraits; 88 template <class... TraitSpecifications> 89 struct KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION 90 AnalyzeExecPolicyBaseTraits<type_list<TraitSpecifications...>> 91 : TraitSpecifications::base_traits... {}; 92 93 template <> 94 struct AnalyzeExecPolicy<void> 95 : AnalyzeExecPolicyBaseTraits<execution_policy_trait_specifications> { 96 // Ensure default constructibility since a converting constructor causes it to 97 // be deleted. 98 AnalyzeExecPolicy() = default; 99 100 // Base converting constructor and assignment operator: unless an individual 101 // policy analysis deletes a constructor, assume it's convertible 102 template <class Other> AnalyzeExecPolicyKokkos::Impl::AnalyzeExecPolicy103 AnalyzeExecPolicy(ExecPolicyTraitsWithDefaults<Other> const&) {} 104 105 template <class Other> operator =Kokkos::Impl::AnalyzeExecPolicy106 AnalyzeExecPolicy& operator=(ExecPolicyTraitsWithDefaults<Other> const&) { 107 return *this; 108 } 109 }; 110 111 //------------------------------------------------------------------------------ 112 // Used for defaults that depend on other analysis results 113 template <class AnalysisResults> 114 struct ExecPolicyTraitsWithDefaults : AnalysisResults { 115 using base_t = AnalysisResults; 116 using base_t::base_t; 117 // The old code turned this into an integral type for backwards compatibility, 118 // so that's what we're doing here. The original comment was: 119 // nasty hack to make index_type into an integral_type 120 // instead of the wrapped IndexType<T> for backwards compatibility 121 using index_type = typename std::conditional_t< 122 base_t::index_type_is_defaulted, 123 Kokkos::IndexType<typename base_t::execution_space::size_type>, 124 typename base_t::index_type>::type; 125 }; 126 127 //------------------------------------------------------------------------------ 128 template <typename... Traits> 129 struct PolicyTraits 130 : ExecPolicyTraitsWithDefaults<AnalyzeExecPolicy<void, Traits...>> { 131 using base_t = 132 ExecPolicyTraitsWithDefaults<AnalyzeExecPolicy<void, Traits...>>; 133 using base_t::base_t; 134 }; 135 136 } // namespace Impl 137 } // namespace Kokkos 138 139 #endif // KOKKOS_IMPL_ANALYZE_POLICY_HPP 140