diff --git a/common/unit_test/Test_Layouts.cpp b/common/unit_test/Test_Layouts.cpp index 27cffb2f..6b347899 100644 --- a/common/unit_test/Test_Layouts.cpp +++ b/common/unit_test/Test_Layouts.cpp @@ -5,6 +5,26 @@ #include "Test_Types.hpp" #include "Test_Utils.hpp" +using test_types = ::testing::Types< + Kokkos::LayoutLeft, + Kokkos::LayoutRight +>; + +// Basically the same fixtures, used for labeling tests +template +struct Layouts1D : public ::testing::Test { + using layout_type = T; +}; + +template +struct Layouts2D : public ::testing::Test { + using layout_type = T; +}; + +TYPED_TEST_SUITE(Layouts1D, test_types); +TYPED_TEST_SUITE(Layouts2D, test_types); + +// Tests for 1D FFT template void test_layouts_1d() { const int n0 = 6; @@ -49,77 +69,6 @@ void test_layouts_1d() { EXPECT_TRUE( fft_extents_c2c == ref_fft_extents_c2c ); } -TEST(Layouts, 1DLeftView) { - test_layouts_1d(); -} - -TEST(Layouts, 1DRightView) { - test_layouts_1d(); -} - -template -void test_layouts_2d() { - const int n0 = 6, n1 = 10; - using RealView2Dtype = Kokkos::View; - using ComplexView2Dtype = Kokkos::View**, LayoutType, execution_space>; - - RealView2Dtype xr2("xr2", n0, n1); - ComplexView2Dtype xc2_axis0("xc2_axis0", n0/2+1, n1); - ComplexView2Dtype xc2_axis1("xc2_axis1", n0, n1/2+1); - ComplexView2Dtype xcin2("xcin2", n0, n1), xcout2("xcout2", n0, n1); - - std::vector ref_in_extents_r2c_axis0{n1, n0}; - std::vector ref_in_extents_r2c_axis1{n0, n1}; - std::vector ref_fft_extents_r2c_axis0{n1, n0}; - std::vector ref_fft_extents_r2c_axis1{n0, n1}; - std::vector ref_out_extents_r2c_axis0{n1, n0/2+1}; - std::vector ref_out_extents_r2c_axis1{n0, n1/2+1}; - - // R2C - auto [in_extents_r2c_axis0, out_extents_r2c_axis0, fft_extents_r2c_axis0] = KokkosFFT::Impl::get_extents(xr2, xc2_axis0, 0); - auto [in_extents_r2c_axis1, out_extents_r2c_axis1, fft_extents_r2c_axis1] = KokkosFFT::Impl::get_extents(xr2, xc2_axis1, 1); - EXPECT_TRUE( in_extents_r2c_axis0 == ref_in_extents_r2c_axis0 ); - EXPECT_TRUE( in_extents_r2c_axis1 == ref_in_extents_r2c_axis1 ); - - EXPECT_TRUE( fft_extents_r2c_axis0 == ref_fft_extents_r2c_axis0 ); - EXPECT_TRUE( fft_extents_r2c_axis1 == ref_fft_extents_r2c_axis1 ); - - EXPECT_TRUE( out_extents_r2c_axis0 == ref_out_extents_r2c_axis0 ); - EXPECT_TRUE( out_extents_r2c_axis1 == ref_out_extents_r2c_axis1 ); - - // C2R - auto [in_extents_c2r_axis0, out_extents_c2r_axis0, fft_extents_c2r_axis0] = KokkosFFT::Impl::get_extents(xc2_axis0, xr2, 0); - auto [in_extents_c2r_axis1, out_extents_c2r_axis1, fft_extents_c2r_axis1] = KokkosFFT::Impl::get_extents(xc2_axis1, xr2, 1); - EXPECT_TRUE( in_extents_c2r_axis0 == ref_out_extents_r2c_axis0 ); - EXPECT_TRUE( in_extents_c2r_axis1 == ref_out_extents_r2c_axis1 ); - - EXPECT_TRUE( fft_extents_c2r_axis0 == ref_fft_extents_r2c_axis0 ); - EXPECT_TRUE( fft_extents_c2r_axis1 == ref_fft_extents_r2c_axis1 ); - - EXPECT_TRUE( out_extents_c2r_axis0 == ref_in_extents_r2c_axis0 ); - EXPECT_TRUE( out_extents_c2r_axis1 == ref_in_extents_r2c_axis1 ); - - // C2C - auto [in_extents_c2c_axis0, out_extents_c2c_axis0, fft_extents_c2c_axis0] = KokkosFFT::Impl::get_extents(xcin2, xcout2, 0); - auto [in_extents_c2c_axis1, out_extents_c2c_axis1, fft_extents_c2c_axis1] = KokkosFFT::Impl::get_extents(xcin2, xcout2, 1); - EXPECT_TRUE( in_extents_c2c_axis0 == ref_in_extents_r2c_axis0 ); - EXPECT_TRUE( in_extents_c2c_axis1 == ref_in_extents_r2c_axis1 ); - - EXPECT_TRUE( fft_extents_c2c_axis0 == ref_fft_extents_r2c_axis0 ); - EXPECT_TRUE( fft_extents_c2c_axis1 == ref_fft_extents_r2c_axis1 ); - - EXPECT_TRUE( out_extents_c2c_axis0 == ref_in_extents_r2c_axis0 ); - EXPECT_TRUE( out_extents_c2c_axis1 == ref_in_extents_r2c_axis1 ); -} - -TEST(Layouts, 2DLeftView) { - test_layouts_2d(); -} - -TEST(Layouts, 2DRightView) { - test_layouts_2d(); -} - template void test_layouts_1d_batched_FFT_2d() { const int n0 = 6, n1 = 10; @@ -178,14 +127,6 @@ void test_layouts_1d_batched_FFT_2d() { EXPECT_EQ( howmany_c2c_axis1, ref_howmany_r2c_axis1 ); } -TEST(Layouts, 1DBatchedFFT_2DLeftView) { - test_layouts_1d_batched_FFT_2d(); -} - -TEST(Layouts, 1DBatchedFFT_2DRightView) { - test_layouts_1d_batched_FFT_2d(); -} - template void test_layouts_1d_batched_FFT_3d() { const int n0 = 6, n1 = 10, n2 = 8; @@ -272,12 +213,78 @@ void test_layouts_1d_batched_FFT_3d() { EXPECT_EQ( howmany_c2c_axis2, ref_howmany_r2c_axis2 ); } -TEST(Layouts, 1DBatchedFFT_3DLeftView) { - test_layouts_1d_batched_FFT_3d(); +TYPED_TEST(Layouts1D, 1DFFT_1DView) { + using layout_type = typename TestFixture::layout_type; + + test_layouts_1d(); +} + +TYPED_TEST(Layouts1D, 1DFFT_batched_2DView) { + using layout_type = typename TestFixture::layout_type; + + test_layouts_1d_batched_FFT_2d(); +} + +TYPED_TEST(Layouts1D, 1DFFT_batched_3DView) { + using layout_type = typename TestFixture::layout_type; + + test_layouts_1d_batched_FFT_3d(); } -TEST(Layouts, 1DBatchedFFT_3DRightView) { - test_layouts_1d_batched_FFT_3d(); +// Tests for 2D FFT +template +void test_layouts_2d() { + const int n0 = 6, n1 = 10; + using RealView2Dtype = Kokkos::View; + using ComplexView2Dtype = Kokkos::View**, LayoutType, execution_space>; + + RealView2Dtype xr2("xr2", n0, n1); + ComplexView2Dtype xc2_axis0("xc2_axis0", n0/2+1, n1); + ComplexView2Dtype xc2_axis1("xc2_axis1", n0, n1/2+1); + ComplexView2Dtype xcin2("xcin2", n0, n1), xcout2("xcout2", n0, n1); + + std::vector ref_in_extents_r2c_axis0{n1, n0}; + std::vector ref_in_extents_r2c_axis1{n0, n1}; + std::vector ref_fft_extents_r2c_axis0{n1, n0}; + std::vector ref_fft_extents_r2c_axis1{n0, n1}; + std::vector ref_out_extents_r2c_axis0{n1, n0/2+1}; + std::vector ref_out_extents_r2c_axis1{n0, n1/2+1}; + + // R2C + auto [in_extents_r2c_axis0, out_extents_r2c_axis0, fft_extents_r2c_axis0] = KokkosFFT::Impl::get_extents(xr2, xc2_axis0, 0); + auto [in_extents_r2c_axis1, out_extents_r2c_axis1, fft_extents_r2c_axis1] = KokkosFFT::Impl::get_extents(xr2, xc2_axis1, 1); + EXPECT_TRUE( in_extents_r2c_axis0 == ref_in_extents_r2c_axis0 ); + EXPECT_TRUE( in_extents_r2c_axis1 == ref_in_extents_r2c_axis1 ); + + EXPECT_TRUE( fft_extents_r2c_axis0 == ref_fft_extents_r2c_axis0 ); + EXPECT_TRUE( fft_extents_r2c_axis1 == ref_fft_extents_r2c_axis1 ); + + EXPECT_TRUE( out_extents_r2c_axis0 == ref_out_extents_r2c_axis0 ); + EXPECT_TRUE( out_extents_r2c_axis1 == ref_out_extents_r2c_axis1 ); + + // C2R + auto [in_extents_c2r_axis0, out_extents_c2r_axis0, fft_extents_c2r_axis0] = KokkosFFT::Impl::get_extents(xc2_axis0, xr2, 0); + auto [in_extents_c2r_axis1, out_extents_c2r_axis1, fft_extents_c2r_axis1] = KokkosFFT::Impl::get_extents(xc2_axis1, xr2, 1); + EXPECT_TRUE( in_extents_c2r_axis0 == ref_out_extents_r2c_axis0 ); + EXPECT_TRUE( in_extents_c2r_axis1 == ref_out_extents_r2c_axis1 ); + + EXPECT_TRUE( fft_extents_c2r_axis0 == ref_fft_extents_r2c_axis0 ); + EXPECT_TRUE( fft_extents_c2r_axis1 == ref_fft_extents_r2c_axis1 ); + + EXPECT_TRUE( out_extents_c2r_axis0 == ref_in_extents_r2c_axis0 ); + EXPECT_TRUE( out_extents_c2r_axis1 == ref_in_extents_r2c_axis1 ); + + // C2C + auto [in_extents_c2c_axis0, out_extents_c2c_axis0, fft_extents_c2c_axis0] = KokkosFFT::Impl::get_extents(xcin2, xcout2, 0); + auto [in_extents_c2c_axis1, out_extents_c2c_axis1, fft_extents_c2c_axis1] = KokkosFFT::Impl::get_extents(xcin2, xcout2, 1); + EXPECT_TRUE( in_extents_c2c_axis0 == ref_in_extents_r2c_axis0 ); + EXPECT_TRUE( in_extents_c2c_axis1 == ref_in_extents_r2c_axis1 ); + + EXPECT_TRUE( fft_extents_c2c_axis0 == ref_fft_extents_r2c_axis0 ); + EXPECT_TRUE( fft_extents_c2c_axis1 == ref_fft_extents_r2c_axis1 ); + + EXPECT_TRUE( out_extents_c2c_axis0 == ref_in_extents_r2c_axis0 ); + EXPECT_TRUE( out_extents_c2c_axis1 == ref_in_extents_r2c_axis1 ); } template @@ -439,10 +446,14 @@ void test_layouts_2d_batched_FFT_3d() { EXPECT_EQ( howmany_c2c_axis_21, ref_howmany_r2c_axis_21 ); } -TEST(Layouts, 2DBatchedFFT_3DLeftView) { - test_layouts_2d_batched_FFT_3d(); +TYPED_TEST(Layouts2D, 2DFFT_2DView) { + using layout_type = typename TestFixture::layout_type; + + test_layouts_2d(); } -TEST(Layouts, 2DBatchedFFT_3DRightView) { - test_layouts_2d_batched_FFT_3d(); +TYPED_TEST(Layouts2D, 2DFFT_3DView) { + using layout_type = typename TestFixture::layout_type; + + test_layouts_2d_batched_FFT_3d(); } \ No newline at end of file diff --git a/common/unit_test/Test_Transpose.cpp b/common/unit_test/Test_Transpose.cpp index 3a695c70..ceb2b392 100644 --- a/common/unit_test/Test_Transpose.cpp +++ b/common/unit_test/Test_Transpose.cpp @@ -7,6 +7,26 @@ template using axes_type = std::array; +using test_types = ::testing::Types< + Kokkos::LayoutLeft, + Kokkos::LayoutRight +>; + +// Basically the same fixtures, used for labeling tests +template +struct MapAxes : public ::testing::Test { + using layout_type = T; +}; + +template +struct Transpose : public ::testing::Test { + using layout_type = T; +}; + +TYPED_TEST_SUITE(MapAxes, test_types); +TYPED_TEST_SUITE(Transpose, test_types); + +// Tests for map axes over ND views template void test_map_axes1d() { const int len = 30; @@ -25,14 +45,6 @@ void test_map_axes1d() { EXPECT_TRUE( map_inv_axes == ref_map_axes ); } -TEST(MapAxes, 1DLeftView) { - test_map_axes1d(); -} - -TEST(MapAxes, 1DRightView) { - test_map_axes1d(); -} - template void test_map_axes2d() { const int n0 = 3, n1 = 5; @@ -115,14 +127,6 @@ void test_map_axes2d() { EXPECT_TRUE( map_inv_axes_1_0 == ref_map_inv_axes_1_0 ); } -TEST(MapAxes, 2DLeftView) { - test_map_axes2d(); -} - -TEST(MapAxes, 2DRightView) { - test_map_axes2d(); -} - template void test_map_axes3d() { const int n0 = 3, n1 = 5, n2 = 8; @@ -266,14 +270,28 @@ void test_map_axes3d() { EXPECT_TRUE( map_inv_axes_2_1_0 == ref_map_inv_axes_2_1_0 ); } -TEST(MapAxes, 3DLeftView) { - test_map_axes3d(); +// Tests for 1D View +TYPED_TEST(MapAxes, 1DView) { + using layout_type = typename TestFixture::layout_type; + + test_map_axes1d(); +} + +// Tests for 2D View +TYPED_TEST(MapAxes, 2DView) { + using layout_type = typename TestFixture::layout_type; + + test_map_axes2d(); } -TEST(MapAxes, 3DRightView) { - test_map_axes3d(); +// Tests for 3D View +TYPED_TEST(MapAxes, 3DView) { + using layout_type = typename TestFixture::layout_type; + + test_map_axes3d(); } +// Tests for transpose template void test_transpose_1d() { // When transpose is not necessary, we should not call transpose method @@ -294,6 +312,13 @@ void test_transpose_1d() { ); } +TYPED_TEST(Transpose, 1DView) { + using layout_type = typename TestFixture::layout_type; + + test_transpose_1d(); +} + +/* TEST(Transpose, 1DLeftView) { test_transpose_1d(); } @@ -301,6 +326,7 @@ TEST(Transpose, 1DLeftView) { TEST(Transpose, 1DRightView) { test_transpose_1d(); } +*/ TEST(Transpose, 2DLeftView) { const int n0 = 3, n1 = 5; diff --git a/common/unit_test/Test_Utils.cpp b/common/unit_test/Test_Utils.cpp index 9cd60bcd..19c757ac 100644 --- a/common/unit_test/Test_Utils.cpp +++ b/common/unit_test/Test_Utils.cpp @@ -2,6 +2,20 @@ #include "KokkosFFT_utils.hpp" #include "Test_Types.hpp" +using test_types = ::testing::Types< + Kokkos::LayoutLeft, + Kokkos::LayoutRight +>; + +// Basically the same fixtures, used for labeling tests +template +struct ConvertNegativeAxis : public ::testing::Test { + using layout_type = T; +}; + +TYPED_TEST_SUITE(ConvertNegativeAxis, test_types); + +// Tests for convert_negative_axes over ND views template void test_convert_negative_axes_1d() { const int len = 30; @@ -18,14 +32,6 @@ void test_convert_negative_axes_1d() { EXPECT_EQ( converted_axis_minus1, ref_converted_axis_minus1 ); } -TEST(ConvertNegativeAxis, 1DLeftView) { - test_convert_negative_axes_1d(); -} - -TEST(ConvertNegativeAxis, 1DRightView) { - test_convert_negative_axes_1d(); -} - template void test_convert_negative_axes_2d() { const int n0 = 3, n1 = 5; @@ -45,14 +51,6 @@ void test_convert_negative_axes_2d() { EXPECT_EQ( converted_axis_minus1, ref_converted_axis_minus1 ); } -TEST(ConvertNegativeAxis, 2DLeftView) { - test_convert_negative_axes_2d(); -} - -TEST(ConvertNegativeAxis, 2DRightView) { - test_convert_negative_axes_2d(); -} - template void test_convert_negative_axes_3d() { const int n0 = 3, n1 = 5, n2 = 8; @@ -78,14 +76,6 @@ void test_convert_negative_axes_3d() { EXPECT_EQ( converted_axis_minus2, ref_converted_axis_minus2 ); } -TEST(ConvertNegativeAxis, 3DLeftView) { - test_convert_negative_axes_3d(); -} - -TEST(ConvertNegativeAxis, 3DRightView) { - test_convert_negative_axes_3d(); -} - template void test_convert_negative_axes_4d() { const int n0 = 3, n1 = 5, n2 = 8, n3 = 13; @@ -117,12 +107,32 @@ void test_convert_negative_axes_4d() { EXPECT_EQ( converted_axis_minus3, ref_converted_axis_minus3 ); } -TEST(ConvertNegativeAxis, 4DLeftView) { - test_convert_negative_axes_4d(); +// Tests for 1D View +TYPED_TEST(ConvertNegativeAxis, 1DView) { + using layout_type = typename TestFixture::layout_type; + + test_convert_negative_axes_1d(); } -TEST(ConvertNegativeAxis, 4DRightView) { - test_convert_negative_axes_4d(); +// Tests for 2D View +TYPED_TEST(ConvertNegativeAxis, 2DView) { + using layout_type = typename TestFixture::layout_type; + + test_convert_negative_axes_2d(); +} + +// Tests for 3D View +TYPED_TEST(ConvertNegativeAxis, 3DView) { + using layout_type = typename TestFixture::layout_type; + + test_convert_negative_axes_3d(); +} + +// Tests for 4D View +TYPED_TEST(ConvertNegativeAxis, 4DView) { + using layout_type = typename TestFixture::layout_type; + + test_convert_negative_axes_4d(); } TEST(IsTransposeNeeded, 1Dto3D) {