//@HEADER // ************************************************************************ // // Kokkos v. 4.0 // Copyright (2022) National Technology & Engineering // Solutions of Sandia, LLC (NTESS). // // Under the terms of Contract DE-NA0003525 with NTESS, // the U.S. Government retains certain rights in this software. // // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. // See https://kokkos.org/LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //@HEADER #ifndef KOKKOS_IMPL_ANALYZE_POLICY_HPP #define KOKKOS_IMPL_ANALYZE_POLICY_HPP #include #include // IndexType #include #include #include #include #include #include #include #include #include #include #include namespace Kokkos { namespace Impl { //============================================================================== // {{{1 // Mix in the defaults (base_traits) for the traits that aren't yet handled //------------------------------------------------------------------------------ // {{{2 template struct KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION AnalyzeExecPolicyBaseTraits; template struct KOKKOS_IMPL_ENFORCE_EMPTY_BASE_OPTIMIZATION AnalyzeExecPolicyBaseTraits> : TraitSpecifications::base_traits... {}; // end AnalyzePolicyBaseTraits }}}1 //============================================================================== //============================================================================== // {{{1 //------------------------------------------------------------------------------ // Note: unspecialized, so that the default pathway is to fall back to using // the PolicyTraitMatcher. See AnalyzeExecPolicyUseMatcher below template struct AnalyzeExecPolicy : AnalyzeExecPolicyUseMatcher { using base_t = AnalyzeExecPolicyUseMatcher; using base_t::base_t; }; //------------------------------------------------------------------------------ // Ignore void for backwards compatibility purposes, though hopefully no one is // using this in application code template struct AnalyzeExecPolicy : AnalyzeExecPolicy { using base_t = AnalyzeExecPolicy; using base_t::base_t; }; //------------------------------------------------------------------------------ template <> struct AnalyzeExecPolicy : AnalyzeExecPolicyBaseTraits { // Ensure default constructibility since a converting constructor causes it to // be deleted. AnalyzeExecPolicy() = default; // Base converting constructor and assignment operator: unless an individual // policy analysis deletes a constructor, assume it's convertible template AnalyzeExecPolicy(ExecPolicyTraitsWithDefaults const&) {} template AnalyzeExecPolicy& operator=(ExecPolicyTraitsWithDefaults const&) { return *this; } }; // end AnalyzeExecPolicy specializations }}}1 //============================================================================== //============================================================================== // {{{1 // We can avoid having to have policies specialize AnalyzeExecPolicy themselves // by piggy-backing off of the PolicyTraitMatcher that we need to have for // things like require() anyway. We mixin the effects of the trait using // the `mixin_matching_trait` nested alias template in the trait specification // General PolicyTraitMatcher version // Matching case template struct AnalyzeExecPolicyUseMatcher< std::enable_if_t::value>, type_list, Trait, Traits...> : TraitSpec::template mixin_matching_trait< Trait, AnalyzeExecPolicy> { using base_t = typename TraitSpec::template mixin_matching_trait< Trait, AnalyzeExecPolicy>; using base_t::base_t; }; // Non-matching case template struct AnalyzeExecPolicyUseMatcher< std::enable_if_t::value>, type_list, Trait, Traits...> : AnalyzeExecPolicyUseMatcher, Trait, Traits...> { using base_t = AnalyzeExecPolicyUseMatcher, Trait, Traits...>; using base_t::base_t; }; // No match found case: template struct show_name_of_invalid_execution_policy_trait; template struct AnalyzeExecPolicyUseMatcher, Trait, Traits...> { static constexpr auto trigger_error_message = show_name_of_invalid_execution_policy_trait{}; static_assert( /* always false: */ std::is_void::value, "Unknown execution policy trait. Search compiler output for " "'show_name_of_invalid_execution_policy_trait' to see the type of the " "invalid trait."); }; // All traits matched case: template <> struct AnalyzeExecPolicyUseMatcher> : AnalyzeExecPolicy { using base_t = AnalyzeExecPolicy; using base_t::base_t; }; // end AnalyzeExecPolicyUseMatcher }}}1 //============================================================================== //------------------------------------------------------------------------------ // Used for defaults that depend on other analysis results template struct ExecPolicyTraitsWithDefaults : AnalysisResults { using base_t = AnalysisResults; using base_t::base_t; // The old code turned this into an integral type for backwards compatibility, // so that's what we're doing here. The original comment was: // nasty hack to make index_type into an integral_type // instead of the wrapped IndexType for backwards compatibility using index_type = typename std::conditional_t< base_t::index_type_is_defaulted, Kokkos::IndexType, typename base_t::index_type>::type; }; //------------------------------------------------------------------------------ template struct PolicyTraits : ExecPolicyTraitsWithDefaults> { using base_t = ExecPolicyTraitsWithDefaults>; using base_t::base_t; }; } // namespace Impl } // namespace Kokkos #endif // KOKKOS_IMPL_ANALYZE_POLICY_HPP