From 25962d7a58b542bfd708e97075e06bb0d688e44b Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Thu, 18 Jul 2024 16:36:54 +0900 Subject: [PATCH] fix: rename precision traits and improve comments --- common/src/KokkosFFT_traits.hpp | 26 ++-- common/unit_test/Test_Traits.cpp | 228 ++++++++++++++++++++----------- 2 files changed, 158 insertions(+), 96 deletions(-) diff --git a/common/src/KokkosFFT_traits.hpp b/common/src/KokkosFFT_traits.hpp index 9fa348f7..312797bd 100644 --- a/common/src/KokkosFFT_traits.hpp +++ b/common/src/KokkosFFT_traits.hpp @@ -131,10 +131,10 @@ inline constexpr bool is_operatable_view_v = // Traits for binary operations template -struct have_same_precision : std::false_type {}; +struct have_same_base_floating_point_type : std::false_type {}; template -struct have_same_precision< +struct have_same_base_floating_point_type< T1, T2, std::enable_if_t && !Kokkos::is_view_v && std::is_same_v, @@ -142,7 +142,7 @@ struct have_same_precision< : std::true_type {}; template -struct have_same_precision< +struct have_same_base_floating_point_type< InViewType, OutViewType, std::enable_if_t< Kokkos::is_view_v && Kokkos::is_view_v && @@ -152,12 +152,12 @@ struct have_same_precision< typename OutViewType::non_const_value_type>>>> : std::true_type {}; -/// \brief Helper to check if two value have the same base precision type. +/// \brief Helper to check if two value have the same base floating point type. /// When applied to Kokkos::View, then check if values of views have the same -/// base precision type. +/// base floating point type. template -inline constexpr bool have_same_precision_v = - have_same_precision::value; +inline constexpr bool have_same_base_floating_point_type_v = + have_same_base_floating_point_type::value; template struct have_same_layout : std::false_type {}; @@ -199,12 +199,12 @@ struct are_operatable_views : std::false_type {}; template struct are_operatable_views< ExecutionSpace, InViewType, OutViewType, - std::enable_if_t && - is_operatable_view_v && - have_same_precision_v && - have_same_layout_v && - have_same_rank_v>> - : std::true_type {}; + std::enable_if_t< + is_operatable_view_v && + is_operatable_view_v && + have_same_base_floating_point_type_v && + have_same_layout_v && + have_same_rank_v>> : std::true_type {}; /// \brief Helper to check if Views are acceptable View for Kokkos-FFT and /// memory space are accessible from the ExecutionSpace. diff --git a/common/unit_test/Test_Traits.cpp b/common/unit_test/Test_Traits.cpp index 5d5953a2..8d09753d 100644 --- a/common/unit_test/Test_Traits.cpp +++ b/common/unit_test/Test_Traits.cpp @@ -7,7 +7,7 @@ #include "Test_Utils.hpp" // All the tests in this file are compile time tests, so we skip all the tests -// by GTEST_SKIP(). +// by GTEST_SKIP(). gtest is used for type parameterization. // Define the types to combine using base_real_types = std::tuple; @@ -105,8 +105,11 @@ void test_get_real_type() { using real_type_from_ComplexType = KokkosFFT::Impl::base_floating_point_type; + // base floating point type of RealType is RealType static_assert(std::is_same_v, "Real type not deduced correctly from real type"); + + // base floating point type of Kokkos::complex is RealType static_assert(std::is_same_v, "Real type not deduced correctly from complex type"); } @@ -114,26 +117,32 @@ void test_get_real_type() { // Tests for admissible real types (float or double) template void test_admissible_real_type() { + // Tests that a real type is float or double if constexpr (std::is_same_v || std::is_same_v) { + // T is float or double static_assert(KokkosFFT::Impl::is_real_v, "Real type must be float or double"); } else { + // T is not float or double static_assert(!KokkosFFT::Impl::is_real_v, - "Real type must be float or double"); + "Real type must not be float or double"); } } template void test_admissible_complex_type() { using real_type = KokkosFFT::Impl::base_floating_point_type; + // Tests that a base floating point type of complex value is float or double if constexpr (std::is_same_v || std::is_same_v) { + // T is Kokkos::complex or Kokkos::complex static_assert(KokkosFFT::Impl::is_complex_v, "Complex type must be Kokkos::complex or " "Kokkos::complex"); } else { + // T is not Kokkos::complex or Kokkos::complex static_assert(!KokkosFFT::Impl::is_complex_v, - "Complex type must be Kokkos::complex or " + "Complex type must not be Kokkos::complex or " "Kokkos::complex"); } } @@ -162,26 +171,38 @@ template void test_admissible_value_type() { using ViewType = Kokkos::View; using real_type = KokkosFFT::Impl::base_floating_point_type; + // Tests that a Value or View has a addmissible value type if constexpr (std::is_same_v || std::is_same_v) { + // Base floating point type of a Value is float or double + static_assert(KokkosFFT::Impl::is_admissible_value_type_v, + "Base value type must be float or double"); + + // Base floating point type of a View is float or double static_assert(KokkosFFT::Impl::is_admissible_value_type_v, - "Real type must be float or double"); + "Base value type of a View must be float or double"); } else { + // Base floating point type of a Value is not float or double + static_assert(!KokkosFFT::Impl::is_admissible_value_type_v, + "Base value type of a View must not be float or double"); + + // Base floating point type of a View is not float or double static_assert(!KokkosFFT::Impl::is_admissible_value_type_v, - "Real type must be float or double"); + "Base value type of a View must not be float or double"); } } template void test_admissible_layout_type() { using ViewType = Kokkos::View; + // Tests that the View has a layout in LayoutLeft or LayoutRight if constexpr (std::is_same_v || std::is_same_v) { static_assert(KokkosFFT::Impl::is_layout_left_or_right_v, "View Layout must be either LayoutLeft or LayoutRight."); } else { static_assert(!KokkosFFT::Impl::is_layout_left_or_right_v, - "View Layout must be either LayoutLeft or LayoutRight."); + "View Layout must not be either LayoutLeft or LayoutRight."); } } @@ -189,19 +210,28 @@ template void test_admissible_view_type() { using ViewType = Kokkos::View; using real_type = KokkosFFT::Impl::base_floating_point_type; - if constexpr ( - (std::is_same_v || std::is_same_v)&&( - std::is_same_v || - std::is_same_v)) { - static_assert(KokkosFFT::Impl::is_admissible_view_v, - "View value type must be float, double, " - "Kokkos::Complex, Kokkos::Complex. Layout " - "must be either LayoutLeft or LayoutRight."); + + // Tests that the View has a base floating point type in float or double + if constexpr ((std::is_same_v || + std::is_same_v)) { + // Tests that the View has a layout in LayoutLeft or LayoutRight + if constexpr (std::is_same_v || + std::is_same_v) { + static_assert(KokkosFFT::Impl::is_admissible_view_v, + "View value type must be float, double, " + "Kokkos::Complex, Kokkos::Complex. Layout " + "must be either LayoutLeft or LayoutRight."); + } else { + // View is not admissible because layout is not in LayoutLeft or + // LayoutRight + static_assert(!KokkosFFT::Impl::is_admissible_view_v, + "Layout must be either LayoutLeft or LayoutRight."); + } } else { + // View is not admissible because the base floating point type is not in + // float or double static_assert(!KokkosFFT::Impl::is_admissible_view_v, - "View value type must be float, double, " - "Kokkos::Complex, Kokkos::Complex. Layout " - "must be either LayoutLeft or LayoutRight."); + "Base value type must be float or double"); } } @@ -215,32 +245,43 @@ template ; using real_type = KokkosFFT::Impl::base_floating_point_type; + + // Tests that a View is accessible from the ExecutionSpace if constexpr (Kokkos::SpaceAccessibility< ExecutionSpace1, typename ViewType::memory_space>::accessible) { + // Tests that the View has a base floating point type in float or double if constexpr ((std::is_same_v || - std::is_same_v< - real_type, - double>)&&(std::is_same_v || - std::is_same_v)) { - static_assert( - KokkosFFT::Impl::is_operatable_view_v, - "View value type must be float, double, " - "Kokkos::Complex, Kokkos::Complex. Layout " - "must be either LayoutLeft or LayoutRight."); + std::is_same_v)) { + // Tests that the View has a layout in LayoutLeft or LayoutRight + if constexpr (std::is_same_v || + std::is_same_v) { + // View is operatable + static_assert( + KokkosFFT::Impl::is_operatable_view_v, + "View value type must be float, double, " + "Kokkos::Complex, or Kokkos::Complex. Layout " + "must be either LayoutLeft or LayoutRight."); + } else { + // View is not operatable because layout is not in LayoutLeft or + // LayoutRight + static_assert( + !KokkosFFT::Impl::is_operatable_view_v, + "Layout must be either LayoutLeft or LayoutRight."); + } } else { + // View is not operatable because the base floating point type is not in + // float or double static_assert( !KokkosFFT::Impl::is_operatable_view_v, - "View value type must be float, double, " - "Kokkos::Complex, Kokkos::Complex. Layout " - "must be either LayoutLeft or LayoutRight."); + "Base value type must be float or double"); } } else { + // View is not operatable because it is not accessible from + // ExecutionSpace static_assert( !KokkosFFT::Impl::is_operatable_view_v, - "execution_space cannot access data in ViewType"); + "ExecutionSpace cannot access data in ViewType"); } } @@ -296,7 +337,7 @@ TYPED_TEST(RealAndComplexViewTypes, operatable_view_type) { // Tests for multiple Views template -void test_have_same_precision() { +void test_have_same_base_floating_point_type() { using real_type1 = RealType1; using real_type2 = RealType2; using complex_type1 = Kokkos::complex; @@ -307,53 +348,65 @@ void test_have_same_precision() { using RealViewType2 = Kokkos::View; using ComplexViewType2 = Kokkos::View; + // Tests that Values or Views have the same base floating point type if constexpr (std::is_same_v) { - // Tests for values + // Values must have the same base floating point type static_assert( - KokkosFFT::Impl::have_same_precision_v, - "Values have the same base precisions"); + KokkosFFT::Impl::have_same_base_floating_point_type_v, + "Values must have the same base floating point type"); static_assert( - KokkosFFT::Impl::have_same_precision_v, - "Values have the same base precisions"); + KokkosFFT::Impl::have_same_base_floating_point_type_v, + "Values must have the same base floating point type"); static_assert( - KokkosFFT::Impl::have_same_precision_v, - "Values have the same base precisions"); + KokkosFFT::Impl::have_same_base_floating_point_type_v, + "Values must have the same base floating point type"); - // Tests for Views + // Views must have the same base floating point type + static_assert( + KokkosFFT::Impl::have_same_base_floating_point_type_v, + "ViewTypes must have the same base floating point type"); static_assert( - KokkosFFT::Impl::have_same_precision_v, - "ViewTypes have the same base precisions"); + KokkosFFT::Impl::have_same_base_floating_point_type_v, + "ViewTypes must have the same base floating point type"); static_assert( - KokkosFFT::Impl::have_same_precision_v, - "ViewTypes have the same base precisions"); + KokkosFFT::Impl::have_same_base_floating_point_type_v, + "ViewTypes must have the same base floating point type"); static_assert( - KokkosFFT::Impl::have_same_precision_v, - "ViewTypes have the same base precisions"); - static_assert(KokkosFFT::Impl::have_same_precision_v, - "ViewTypes have the same base precisions"); + KokkosFFT::Impl::have_same_base_floating_point_type_v, + "ViewTypes must have the same base floating point type"); } else { - // Tests for values + // Values must not have the same base floating point type static_assert( - !KokkosFFT::Impl::have_same_precision_v, - "Values have the same base precisions"); + !KokkosFFT::Impl::have_same_base_floating_point_type_v, + "Values must not have the same base floating point type"); static_assert( - !KokkosFFT::Impl::have_same_precision_v, - "Values have the same base precisions"); + !KokkosFFT::Impl::have_same_base_floating_point_type_v, + "Values must not have the same base floating point type"); - // Tests for Views + // Views must not have the same base floating point type static_assert( - !KokkosFFT::Impl::have_same_precision_v, - "ViewTypes have the same base precisions"); - static_assert(!KokkosFFT::Impl::have_same_precision_v, - "ViewTypes have the same base precisions"); - static_assert(!KokkosFFT::Impl::have_same_precision_v, - "ViewTypes have the same base precisions"); - static_assert(!KokkosFFT::Impl::have_same_precision_v, - "ViewTypes have the same base precisions"); + !KokkosFFT::Impl::have_same_base_floating_point_type_v, + "ViewTypes must not have the same base floating point type"); + static_assert(!KokkosFFT::Impl::have_same_base_floating_point_type_v< + RealViewType1, ComplexViewType2>, + "ViewTypes must not have the same base floating point type"); + static_assert( + !KokkosFFT::Impl::have_same_base_floating_point_type_v, + "ViewTypes must not have the same base floating point type"); + static_assert(!KokkosFFT::Impl::have_same_base_floating_point_type_v< + ComplexViewType1, ComplexViewType2>, + "ViewTypes must not have the same base floating point type"); } } @@ -363,14 +416,15 @@ void test_have_same_layout() { using ViewType1 = Kokkos::View; using ViewType2 = Kokkos::View; + // Tests that Views have the same layout if constexpr (std::is_same_v) { - // Tests for Views + // Views must have the same layout static_assert(KokkosFFT::Impl::have_same_layout_v, - "ViewTypes have the same layout"); + "ViewTypes must have the same layout"); } else { - // Tests for Views + // Views must not have the same layout static_assert(!KokkosFFT::Impl::have_same_layout_v, - "ViewTypes have the same layout"); + "ViewTypes must not have the same layout"); } } @@ -382,34 +436,37 @@ void test_have_same_rank() { using StaticRank1ViewType = Kokkos::View; using StaticRank2ViewType = Kokkos::View; using DynamicStaticRank2ViewType = Kokkos::View; + + // Views must have the same rank static_assert(KokkosFFT::Impl::have_same_rank_v, - "ViewTypes have the same rank"); + "ViewTypes must have the same rank"); static_assert(KokkosFFT::Impl::have_same_rank_v, - "ViewTypes have the same rank"); + "ViewTypes must have the same rank"); static_assert(KokkosFFT::Impl::have_same_rank_v, - "ViewTypes have the same rank"); + "ViewTypes must have the same rank"); + // Views must not have the same rank static_assert(!KokkosFFT::Impl::have_same_rank_v, - "ViewTypes have the same rank"); + "ViewTypes must not have the same rank"); static_assert(!KokkosFFT::Impl::have_same_rank_v, - "ViewTypes have the same rank"); + "ViewTypes must not have the same rank"); static_assert(!KokkosFFT::Impl::have_same_rank_v, - "ViewTypes have the same rank"); + "ViewTypes must not have the same rank"); static_assert(!KokkosFFT::Impl::have_same_rank_v, - "ViewTypes have the same rank"); + "ViewTypes must not have the same rank"); static_assert(!KokkosFFT::Impl::have_same_rank_v, - "ViewTypes have the same rank"); + "ViewTypes must not have the same rank"); static_assert(!KokkosFFT::Impl::have_same_rank_v, - "ViewTypes have the same rank"); + "ViewTypes must not have the same rank"); } // \brief Test if two Views are operatable @@ -443,7 +500,8 @@ void test_are_operatable_views() { if constexpr (Kokkos::SpaceAccessibility< ExecutionSpace1, typename RealViewType1::memory_space>::accessible) { - // Tests that the Views have the same precision in float or double + // Tests that the Views have the same base floating point type in float or + // double if constexpr (std::is_same_v && (std::is_same_v || std::is_same_v)) { @@ -479,6 +537,8 @@ void test_are_operatable_views() { ExecutionSpace1, ComplexViewType1, ComplexViewType3>, "InViewType and OutViewType must have the same rank"); } else { + // Views are not operatable because they do not have the same layout in + // LayoutLeft or LayoutRight static_assert(!KokkosFFT::Impl::are_operatable_views_v< ExecutionSpace1, RealViewType1, RealViewType2>, "Layouts are not identical or one of them is not " @@ -497,6 +557,8 @@ void test_are_operatable_views() { "LayoutLeft or LayoutRight"); } } else { + // Views are not operatable because they do not have the same base + // floating point type in float or double static_assert(!KokkosFFT::Impl::are_operatable_views_v< ExecutionSpace1, RealViewType1, RealViewType2>, "Base value types are not identical or one of them is not " @@ -538,11 +600,11 @@ void test_are_operatable_views() { } } -TYPED_TEST(PairedValueTypes, have_same_precision) { +TYPED_TEST(PairedValueTypes, have_same_base_floating_point_type) { using real_type1 = typename TestFixture::real_type1; using real_type2 = typename TestFixture::real_type2; - test_have_same_precision(); + test_have_same_base_floating_point_type(); } TYPED_TEST(PairedLayoutTypes, have_same_layout) {