From 0e76448b372ac0e6d563bb36a279c703e7edde4a Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Thu, 29 Aug 2024 21:55:10 +0900 Subject: [PATCH 1/3] fix: conflicts --- common/src/KokkosFFT_layouts.hpp | 41 +++---- common/src/KokkosFFT_normalization.hpp | 5 + common/src/KokkosFFT_padding.hpp | 38 +++---- common/src/KokkosFFT_transpose.hpp | 38 +++---- common/src/KokkosFFT_utils.hpp | 150 +++++++++++-------------- common/unit_test/Test_Padding.cpp | 44 ++++---- 6 files changed, 137 insertions(+), 179 deletions(-) diff --git a/common/src/KokkosFFT_layouts.hpp b/common/src/KokkosFFT_layouts.hpp index 4aaed717..bbd4d851 100644 --- a/common/src/KokkosFFT_layouts.hpp +++ b/common/src/KokkosFFT_layouts.hpp @@ -26,12 +26,8 @@ auto get_extents(const InViewType& in, const OutViewType& out, using out_value_type = typename OutViewType::non_const_value_type; using array_layout_type = typename InViewType::array_layout; - static_assert(InViewType::rank() >= DIM, - "KokkosFFT::get_map_axes: Rank of View must be larger thane or " - "equal to the Rank of FFT axes."); - static_assert(DIM > 0, - "KokkosFFT::get_map_axes: Rank of FFT axes must be larger than " - "or equal to 1."); + KOKKOSFFT_EXPECTS(KokkosFFT::Impl::are_valid_axes(in, axes), + "input axes are not valid for the view"); constexpr std::size_t rank = InViewType::rank; [[maybe_unused]] int inner_most_axis = @@ -64,32 +60,25 @@ auto get_extents(const InViewType& in, const OutViewType& out, _fft_extents.push_back(fft_extent); } + static_assert(!(is_real_v && is_real_v), + "get_extents: real to real transform is not supported"); + if (is_real_v) { // Then R2C - if (is_complex_v) { - KOKKOSFFT_EXPECTS( - _out_extents.at(inner_most_axis) == - _in_extents.at(inner_most_axis) / 2 + 1, - "For R2C, the 'output extent' of transform must be equal to " - "'input extent'/2 + 1"); - } else { - throw std::runtime_error( - "If the input type is real, the output type should be complex"); - } + KOKKOSFFT_EXPECTS( + _out_extents.at(inner_most_axis) == + _in_extents.at(inner_most_axis) / 2 + 1, + "For R2C, the 'output extent' of transform must be equal to " + "'input extent'/2 + 1"); } if (is_real_v) { // Then C2R - if (is_complex_v) { - KOKKOSFFT_EXPECTS( - _in_extents.at(inner_most_axis) == - _out_extents.at(inner_most_axis) / 2 + 1, - "For C2R, the 'input extent' of transform must be equal to " - "'output extent' / 2 + 1"); - } else { - throw std::runtime_error( - "If the output type is real, the input type should be complex"); - } + KOKKOSFFT_EXPECTS( + _in_extents.at(inner_most_axis) == + _out_extents.at(inner_most_axis) / 2 + 1, + "For C2R, the 'input extent' of transform must be equal to " + "'output extent' / 2 + 1"); } if (std::is_same_v) { diff --git a/common/src/KokkosFFT_normalization.hpp b/common/src/KokkosFFT_normalization.hpp index 9e9c01ea..14ed2d56 100644 --- a/common/src/KokkosFFT_normalization.hpp +++ b/common/src/KokkosFFT_normalization.hpp @@ -62,6 +62,11 @@ template void normalize(const ExecutionSpace& exec_space, ViewType& inout, Direction direction, Normalization normalization, std::size_t fft_size) { + static_assert(KokkosFFT::Impl::is_operatable_view_v, + "normalize: View value type must be float, double, " + "Kokkos::Complex, or Kokkos::Complex. " + "Layout must be either LayoutLeft or LayoutRight. " + "ExecutionSpace must be able to access data in ViewType"); auto [coef, to_normalize] = get_coefficients(inout, direction, normalization, fft_size); if (to_normalize) normalize_impl(exec_space, inout, coef); diff --git a/common/src/KokkosFFT_padding.hpp b/common/src/KokkosFFT_padding.hpp index 3fc059be..42bb1b22 100644 --- a/common/src/KokkosFFT_padding.hpp +++ b/common/src/KokkosFFT_padding.hpp @@ -27,16 +27,11 @@ namespace Impl { template auto get_modified_shape(const InViewType in, const OutViewType /* out */, shape_type shape, axis_type axes) { - static_assert(InViewType::rank() >= DIM, - "get_modified_shape: Rank of Input View must be larger " - "than or equal to the Rank of new shape"); - static_assert(OutViewType::rank() >= DIM, - "get_modified_shape: Rank of Output View must be larger " - "than or equal to the Rank of new shape"); - static_assert(DIM > 0, - "get_modified_shape: Rank of FFT axes must be " - "larger than or equal to 1"); - constexpr int rank = static_cast(InViewType::rank()); + static_assert( + KokkosFFT::Impl::have_same_rank_v, + "get_modified_shape: Input View and Output View must have the same rank"); + KOKKOSFFT_EXPECTS(KokkosFFT::Impl::are_valid_axes(in, axes), + "input axes are not valid for the view"); shape_type zeros = {0}; // default shape means no crop or pad if (shape == zeros) { @@ -50,14 +45,7 @@ auto get_modified_shape(const InViewType in, const OutViewType /* out */, positive_axes.push_back(axis); } - // Assert if the elements are overlapped - KOKKOSFFT_EXPECTS(!KokkosFFT::Impl::has_duplicate_values(positive_axes), - "Axes overlap"); - KOKKOSFFT_EXPECTS( - !KokkosFFT::Impl::is_out_of_range_value_included(positive_axes, rank), - "Axes include an out-of-range index." - "Axes must be in the range of [-rank, rank-1]."); - + constexpr int rank = static_cast(InViewType::rank()); using full_shape_type = shape_type; full_shape_type modified_shape; for (int i = 0; i < rank; i++) { @@ -346,12 +334,14 @@ template void crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out, shape_type s) { - static_assert(InViewType::rank() == DIM, - "crop_or_pad: Rank of View must be equal to Rank " - "of extended shape."); - static_assert(OutViewType::rank() == DIM, - "crop_or_pad: Rank of View must be equal to Rank " - "of extended shape."); + static_assert( + KokkosFFT::Impl::are_operatable_views_v, + "crop_or_pad: InViewType and OutViewType must have the same base " + "floating point " + "type (float/double), the same layout (LayoutLeft/LayoutRight), and the " + "same rank. ExecutionSpace must be accessible to the data in InViewType " + "and OutViewType."); crop_or_pad_impl(exec_space, in, out, s); } } // namespace Impl diff --git a/common/src/KokkosFFT_transpose.hpp b/common/src/KokkosFFT_transpose.hpp index a05be798..6809ee95 100644 --- a/common/src/KokkosFFT_transpose.hpp +++ b/common/src/KokkosFFT_transpose.hpp @@ -14,15 +14,8 @@ namespace KokkosFFT { namespace Impl { template auto get_map_axes(const ViewType& view, axis_type _axes) { - static_assert(ViewType::rank() >= DIM, - "get_map_axes: Rank of View must be larger thane or " - "equal to the Rank of FFT axes."); - static_assert(DIM > 0, - "get_map_axes: Rank of FFT axes must be larger than " - "or equal to 1."); - - constexpr int rank = static_cast(ViewType::rank()); - using array_layout_type = typename ViewType::array_layout; + KOKKOSFFT_EXPECTS(KokkosFFT::Impl::are_valid_axes(view, _axes), + "get_map_axes: input axes are not valid for the view"); // Convert the input axes to be in the range of [0, rank-1] std::vector axes; @@ -31,16 +24,14 @@ auto get_map_axes(const ViewType& view, axis_type _axes) { axes.push_back(axis); } - // Assert if the elements are overlapped - assert(!KokkosFFT::Impl::has_duplicate_values(axes)); - // how indices are map // For 5D View and axes are (2,3), map would be (0, 1, 4, 2, 3) + constexpr int rank = static_cast(ViewType::rank()); std::vector map, map_inv; map.reserve(rank); map_inv.reserve(rank); - if (std::is_same_v) { + if (std::is_same_v) { // Stack axes not specified by axes (0, 1, 4) for (int i = 0; i < rank; i++) { if (!is_found(axes, i)) { @@ -396,22 +387,21 @@ template void transpose(const ExecutionSpace& exec_space, InViewType& in, OutViewType& out, axis_type map) { - static_assert(Kokkos::is_view::value, - "transpose: InViewType is not a Kokkos::View."); - static_assert(Kokkos::is_view::value, - "transpose: OutViewType is not a Kokkos::View."); - - static_assert(InViewType::rank() == OutViewType::rank(), - "transpose: InViewType and OutViewType must have " - "the same rank."); + static_assert( + KokkosFFT::Impl::are_operatable_views_v, + "transpose: InViewType and OutViewType must have the same base floating " + "point " + "type (float/double), the same layout (LayoutLeft/LayoutRight), and the " + "same rank. ExecutionSpace must be accessible to the data in InViewType " + "and OutViewType."); static_assert(InViewType::rank() == DIM, "transpose: Rank of View must be equal to Rank of " "transpose axes."); - if (!KokkosFFT::Impl::is_transpose_needed(map)) { - throw std::runtime_error("transpose: transpose not necessary"); - } + KOKKOSFFT_EXPECTS(KokkosFFT::Impl::is_transpose_needed(map), + "transpose: transpose not necessary"); // in order not to call transpose_impl for 1D case if constexpr (DIM > 1) { diff --git a/common/src/KokkosFFT_utils.hpp b/common/src/KokkosFFT_utils.hpp index fd820f8a..59cbd279 100644 --- a/common/src/KokkosFFT_utils.hpp +++ b/common/src/KokkosFFT_utils.hpp @@ -54,7 +54,7 @@ inline void check_precondition(const bool expression, template auto convert_negative_axis(ViewType, int _axis = -1) { - static_assert(Kokkos::is_view::value, + static_assert(Kokkos::is_view_v, "convert_negative_axis: ViewType is not a Kokkos::View."); int rank = static_cast(ViewType::rank()); @@ -67,7 +67,7 @@ auto convert_negative_axis(ViewType, int _axis = -1) { template auto convert_negative_shift(const ViewType& view, int _shift, int _axis) { - static_assert(Kokkos::is_view::value, + static_assert(Kokkos::is_view_v, "convert_negative_shift: ViewType is not a Kokkos::View."); int axis = convert_negative_axis(view, _axis); int extent = view.extent(axis); @@ -118,14 +118,12 @@ bool is_out_of_range_value_included(const ContainerType& values, IntType max) { template < typename ViewType, template class ArrayType, typename IntType, std::size_t DIM = 1, - std::enable_if_t, std::nullptr_t> = nullptr> + std::enable_if_t && std::is_integral_v, + std::nullptr_t> = nullptr> bool are_valid_axes(const ViewType& view, const ArrayType& axes) { static_assert( - DIM >= 1 && DIM <= KokkosFFT::MAX_FFT_DIM, - "are_valid_axes: the Rank of FFT axes must be between 1 and MAX_FFT_DIM"); - static_assert(ViewType::rank() >= DIM, - "are_valid_axes: View rank must be larger than or equal to the " - "Rank of FFT axes"); + DIM >= 1 && DIM <= ViewType::rank(), + "are_valid_axes: the Rank of FFT axes must be between 1 and View rank"); // Convert the input axes to be in the range of [0, rank-1] // int type is choosen for consistency with the rest of the code @@ -160,15 +158,9 @@ std::size_t get_index(ContainerType& values, const ValueType& value) { using value_type = KokkosFFT::Impl::base_container_value_type; static_assert(std::is_same_v, "Container value type must match ValueType"); - auto it = std::find(values.begin(), values.end(), value); - std::size_t index = 0; - if (it != values.end()) { - index = it - values.begin(); - } else { - throw std::runtime_error("value is not included in values"); - } - - return index; + auto it = std::find(values.begin(), values.end(), value); + KOKKOSFFT_EXPECTS(it != values.end(), "value is not included in values"); + return it - values.begin(); } template @@ -203,14 +195,17 @@ inline std::vector arange(const ElementType start, template void conjugate(const ExecutionSpace& exec_space, const InViewType& in, OutViewType& out) { - static_assert(Kokkos::is_view::value, - "conjugate: InViewType is not a Kokkos::View."); - static_assert(Kokkos::is_view::value, - "conjugate: OutViewType is not a Kokkos::View."); + static_assert( + KokkosFFT::Impl::are_operatable_views_v, + "conjugate: InViewType and OutViewType must have the same base floating " + "point " + "type (float/double), the same layout (LayoutLeft/LayoutRight), and the " + "same rank. ExecutionSpace must be accessible to the data in InViewType " + "and OutViewType."); using out_value_type = typename OutViewType::non_const_value_type; - - static_assert(KokkosFFT::Impl::is_complex::value, + static_assert(KokkosFFT::Impl::is_complex_v, "conjugate: OutViewType must be complex"); std::size_t size = in.size(); out = OutViewType("out", in.layout()); @@ -226,7 +221,7 @@ void conjugate(const ExecutionSpace& exec_space, const InViewType& in, template auto extract_extents(const ViewType& view) { - static_assert(Kokkos::is_view::value, + static_assert(Kokkos::is_view_v, "extract_extents: ViewType is not a Kokkos::View."); constexpr std::size_t rank = ViewType::rank(); std::array extents; @@ -290,93 +285,82 @@ void create_view(ViewType& out, const Label& label, template void reshape_view(ViewType& out, const std::array& extents) { - if (ViewType::required_allocation_size(out.layout()) >= - ViewType::required_allocation_size(extents[0])) { - out = ViewType(out.data(), extents[0]); - } else { - throw std::runtime_error("reshape_view: insufficient memory"); - } + KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >= + ViewType::required_allocation_size(extents[0]), + "reshape_view: insufficient memory"); + out = ViewType(out.data(), extents[0]); } template void reshape_view(ViewType& out, const std::array& extents) { - if (ViewType::required_allocation_size(out.layout()) >= - ViewType::required_allocation_size(extents[0], extents[1])) { - out = ViewType(out.data(), extents[0], extents[1]); - } else { - throw std::runtime_error("reshape_view: insufficient memory"); - } + KOKKOSFFT_EXPECTS( + ViewType::required_allocation_size(out.layout()) >= + ViewType::required_allocation_size(extents[0], extents[1]), + "reshape_view: insufficient memory"); + out = ViewType(out.data(), extents[0], extents[1]); } template void reshape_view(ViewType& out, const std::array& extents) { - if (ViewType::required_allocation_size(out.layout()) >= - ViewType::required_allocation_size(extents[0], extents[1], extents[2])) { - out = ViewType(out.data(), extents[0], extents[1], extents[2]); - } else { - throw std::runtime_error("reshape_view: insufficient memory"); - } + KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >= + ViewType::required_allocation_size( + extents[0], extents[1], extents[2]), + "reshape_view: insufficient memory"); + out = ViewType(out.data(), extents[0], extents[1], extents[2]); } template void reshape_view(ViewType& out, const std::array& extents) { - if (ViewType::required_allocation_size(out.layout()) >= - ViewType::required_allocation_size(extents[0], extents[1], extents[2], - extents[3])) { - out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3]); - } else { - throw std::runtime_error("reshape_view: insufficient memory"); - } + KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >= + ViewType::required_allocation_size( + extents[0], extents[1], extents[2], extents[3]), + "reshape_view: insufficient memory"); + + out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3]); } template void reshape_view(ViewType& out, const std::array& extents) { - if (ViewType::required_allocation_size(out.layout()) >= - ViewType::required_allocation_size(extents[0], extents[1], extents[2], - extents[3], extents[4])) { - out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3], - extents[4]); - } else { - throw std::runtime_error("reshape_view: insufficient memory"); - } + KOKKOSFFT_EXPECTS( + ViewType::required_allocation_size(out.layout()) >= + ViewType::required_allocation_size(extents[0], extents[1], extents[2], + extents[3], extents[4]), + "reshape_view: insufficient memory"); + out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3], + extents[4]); } template void reshape_view(ViewType& out, const std::array& extents) { - if (ViewType::required_allocation_size(out.layout()) >= - ViewType::required_allocation_size(extents[0], extents[1], extents[2], - extents[3], extents[4], extents[5])) { - out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3], - extents[4], extents[5]); - } else { - throw std::runtime_error("reshape_view: insufficient memory"); - } + KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >= + ViewType::required_allocation_size( + extents[0], extents[1], extents[2], extents[3], + extents[4], extents[5]), + "reshape_view: insufficient memory"); + out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3], + extents[4], extents[5]); } template void reshape_view(ViewType& out, const std::array& extents) { - if (ViewType::required_allocation_size(out.layout()) >= - ViewType::required_allocation_size(extents[0], extents[1], extents[2], - extents[3], extents[4], extents[5], - extents[6])) { - out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3], - extents[4], extents[5], extents[6]); - } else { - throw std::runtime_error("reshape_view: insufficient memory"); - } + KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >= + ViewType::required_allocation_size( + extents[0], extents[1], extents[2], extents[3], + extents[4], extents[5], extents[6]), + "reshape_view: insufficient memory"); + out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3], + extents[4], extents[5], extents[6]); } template void reshape_view(ViewType& out, const std::array& extents) { - if (ViewType::required_allocation_size(out.layout()) >= - ViewType::required_allocation_size(extents[0], extents[1], extents[2], - extents[3], extents[4], extents[5], - extents[6], extents[7])) { - out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3], - extents[4], extents[5], extents[6], extents[7]); - } else { - throw std::runtime_error("reshape_view: insufficient memory"); - } + KOKKOSFFT_EXPECTS(ViewType::required_allocation_size(out.layout()) >= + ViewType::required_allocation_size( + extents[0], extents[1], extents[2], extents[3], + extents[4], extents[5], extents[6], extents[7]), + "reshape_view: insufficient memory"); + out = ViewType(out.data(), extents[0], extents[1], extents[2], extents[3], + extents[4], extents[5], extents[6], extents[7]); } } // namespace Impl diff --git a/common/unit_test/Test_Padding.cpp b/common/unit_test/Test_Padding.cpp index 933a632c..21ddab59 100644 --- a/common/unit_test/Test_Padding.cpp +++ b/common/unit_test/Test_Padding.cpp @@ -44,7 +44,7 @@ auto get_c2r_shape(std::size_t len, bool is_C2R) { template void test_reshape1D_1DView() { const int len = 30, len_pad = 32, len_crop = 28; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View1D x_out("x_out", len); View1D> x_in("x_in", get_c2r_shape(len, is_C2R)); @@ -68,7 +68,7 @@ void test_reshape1D_1DView() { template void test_reshape1D_2DView() { const int n0 = 30, n1 = 15; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View2D x_out("x_out", n0, n1); constexpr int DIM = 2; @@ -95,7 +95,7 @@ void test_reshape1D_2DView() { template void test_reshape1D_3DView() { const int n0 = 30, n1 = 15, n2 = 8; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View3D x_out("x_out", n0, n1, n2); constexpr int DIM = 3; @@ -122,7 +122,7 @@ void test_reshape1D_3DView() { template void test_reshape1D_4DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View4D x_out("x_out", n0, n1, n2, n3); constexpr int DIM = 4; @@ -148,7 +148,7 @@ void test_reshape1D_4DView() { template void test_reshape1D_5DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View5D x_out("x_out", n0, n1, n2, n3, n4); constexpr int DIM = 5; @@ -175,7 +175,7 @@ void test_reshape1D_5DView() { template void test_reshape1D_6DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3, n5 = 4; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View6D x_out("x_out", n0, n1, n2, n3, n4, n5); constexpr int DIM = 6; @@ -201,7 +201,7 @@ void test_reshape1D_6DView() { template void test_reshape1D_7DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3, n5 = 4, n6 = 7; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View7D x_out("x_out", n0, n1, n2, n3, n4, n5, n6); constexpr int DIM = 7; @@ -228,7 +228,7 @@ void test_reshape1D_7DView() { template void test_reshape1D_8DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3, n5 = 4, n6 = 7, n7 = 9; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View8D x_out("x_out", n0, n1, n2, n3, n4, n5, n6, n7); constexpr int DIM = 8; @@ -295,7 +295,7 @@ TYPED_TEST(GetModifiedShape1D, 8DView) { template void test_reshape2D_2DView() { const int n0 = 30, n1 = 15; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View2D x_out("x_out", n0, n1); constexpr int DIM = 2; shape_type<2> default_shape({n0, n1}); @@ -330,7 +330,7 @@ void test_reshape2D_2DView() { template void test_reshape2D_3DView() { const int n0 = 30, n1 = 15, n2 = 8; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View3D x_out("x_out", n0, n1, n2); constexpr int DIM = 3; shape_type<3> default_shape({n0, n1, n2}); @@ -365,7 +365,7 @@ void test_reshape2D_3DView() { template void test_reshape2D_4DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View4D x_out("x_out", n0, n1, n2, n3); constexpr int DIM = 4; shape_type<4> default_shape({n0, n1, n2, n3}); @@ -400,7 +400,7 @@ void test_reshape2D_4DView() { template void test_reshape2D_5DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View5D x_out("x_out", n0, n1, n2, n3, n4); constexpr int DIM = 5; shape_type<5> default_shape({n0, n1, n2, n3, n4}); @@ -435,7 +435,7 @@ void test_reshape2D_5DView() { template void test_reshape2D_6DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3, n5 = 4; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View6D x_out("x_out", n0, n1, n2, n3, n4, n5); constexpr int DIM = 6; shape_type<6> default_shape({n0, n1, n2, n3, n4, n5}); @@ -471,7 +471,7 @@ void test_reshape2D_6DView() { template void test_reshape2D_7DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3, n5 = 4, n6 = 7; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View7D x_out("x_out", n0, n1, n2, n3, n4, n5, n6); constexpr int DIM = 7; shape_type<7> default_shape({n0, n1, n2, n3, n4, n5, n6}); @@ -507,7 +507,7 @@ void test_reshape2D_7DView() { template void test_reshape2D_8DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3, n5 = 4, n6 = 7, n7 = 9; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View8D x_out("x_out", n0, n1, n2, n3, n4, n5, n6, n7); constexpr int DIM = 8; shape_type<8> default_shape({n0, n1, n2, n3, n4, n5, n6, n7}); @@ -578,7 +578,7 @@ TYPED_TEST(GetModifiedShape2D, 8DView) { template void test_reshape3D_3DView() { const int n0 = 30, n1 = 15, n2 = 8; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View3D x_out("x_out", n0, n1, n2); constexpr int DIM = 3; @@ -607,7 +607,7 @@ void test_reshape3D_3DView() { shape_type<3> new_shape = {n0_new, n1_new, n2_new}; auto modified_shape = KokkosFFT::Impl::get_modified_shape( - x_in, x_out, new_shape, axes); + x_in, x_out, new_shape, axes); EXPECT_TRUE(modified_shape == ref_shape); } @@ -621,7 +621,7 @@ void test_reshape3D_3DView() { template void test_reshape3D_4DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View4D x_out("x_out", n0, n1, n2, n3); constexpr int DIM = 4; @@ -664,7 +664,7 @@ void test_reshape3D_4DView() { template void test_reshape3D_5DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View5D x_out("x_out", n0, n1, n2, n3, n4); constexpr int DIM = 5; shape_type<5> default_shape({n0, n1, n2, n3, n4}); @@ -706,7 +706,7 @@ void test_reshape3D_5DView() { template void test_reshape3D_6DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3, n5 = 4; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View6D x_out("x_out", n0, n1, n2, n3, n4, n5); constexpr int DIM = 6; shape_type<6> default_shape({n0, n1, n2, n3, n4, n5}); @@ -749,7 +749,7 @@ void test_reshape3D_6DView() { template void test_reshape3D_7DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3, n5 = 4, n6 = 7; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View7D x_out("x_out", n0, n1, n2, n3, n4, n5, n6); constexpr int DIM = 7; shape_type<7> default_shape({n0, n1, n2, n3, n4, n5, n6}); @@ -792,7 +792,7 @@ void test_reshape3D_7DView() { template void test_reshape3D_8DView() { const int n0 = 5, n1 = 11, n2 = 10, n3 = 8, n4 = 3, n5 = 4, n6 = 7, n7 = 9; - bool is_C2R = !KokkosFFT::Impl::is_complex::value; + bool is_C2R = !KokkosFFT::Impl::is_complex_v; View8D x_out("x_out", n0, n1, n2, n3, n4, n5, n6, n7); constexpr int DIM = 8; shape_type<8> default_shape({n0, n1, n2, n3, n4, n5, n6, n7}); From 6a184447f22794ac455659cca9b744db05cf3eb1 Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Thu, 29 Aug 2024 22:09:06 +0900 Subject: [PATCH 2/3] format --- common/unit_test/Test_Padding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/unit_test/Test_Padding.cpp b/common/unit_test/Test_Padding.cpp index 21ddab59..b0f261da 100644 --- a/common/unit_test/Test_Padding.cpp +++ b/common/unit_test/Test_Padding.cpp @@ -607,7 +607,7 @@ void test_reshape3D_3DView() { shape_type<3> new_shape = {n0_new, n1_new, n2_new}; auto modified_shape = KokkosFFT::Impl::get_modified_shape( - x_in, x_out, new_shape, axes); + x_in, x_out, new_shape, axes); EXPECT_TRUE(modified_shape == ref_shape); } From 0e087b2d0d39e60db7559c441c3dda6697e414a9 Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Fri, 6 Sep 2024 18:43:43 +0900 Subject: [PATCH 3/3] ix: based on reviews --- common/src/KokkosFFT_utils.hpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/common/src/KokkosFFT_utils.hpp b/common/src/KokkosFFT_utils.hpp index 59cbd279..a0fae657 100644 --- a/common/src/KokkosFFT_utils.hpp +++ b/common/src/KokkosFFT_utils.hpp @@ -13,12 +13,7 @@ #include "KokkosFFT_traits.hpp" #include "KokkosFFT_common_types.hpp" -#if defined(KOKKOS_ENABLE_CXX17) -#include -#define KOKKOSFFT_EXPECTS(expression, msg) \ - KokkosFFT::Impl::check_precondition((expression), msg, __FILE__, __LINE__, \ - __FUNCTION__) -#else +#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L #include #define KOKKOSFFT_EXPECTS(expression, msg) \ KokkosFFT::Impl::check_precondition( \ @@ -26,6 +21,11 @@ std::source_location::current().line(), \ std::source_location::current().function_name(), \ std::source_location::current().column()) +#else +#include +#define KOKKOSFFT_EXPECTS(expression, msg) \ + KokkosFFT::Impl::check_precondition((expression), msg, __FILE__, __LINE__, \ + __FUNCTION__) #endif namespace KokkosFFT { @@ -55,7 +55,7 @@ inline void check_precondition(const bool expression, template auto convert_negative_axis(ViewType, int _axis = -1) { static_assert(Kokkos::is_view_v, - "convert_negative_axis: ViewType is not a Kokkos::View."); + "convert_negative_axis: ViewType must be a Kokkos::View."); int rank = static_cast(ViewType::rank()); KOKKOSFFT_EXPECTS(_axis >= -rank && _axis < rank, @@ -68,7 +68,7 @@ auto convert_negative_axis(ViewType, int _axis = -1) { template auto convert_negative_shift(const ViewType& view, int _shift, int _axis) { static_assert(Kokkos::is_view_v, - "convert_negative_shift: ViewType is not a Kokkos::View."); + "convert_negative_shift: ViewType must be a Kokkos::View."); int axis = convert_negative_axis(view, _axis); int extent = view.extent(axis); [[maybe_unused]] int shift0 = 0, shift1 = 0, shift2 = extent / 2; @@ -90,7 +90,7 @@ template bool is_found(ContainerType& values, const ValueType& value) { using value_type = KokkosFFT::Impl::base_container_value_type; static_assert(std::is_same_v, - "Container value type must match ValueType"); + "is_found: Container value type must match ValueType"); return std::find(values.begin(), values.end(), value) != values.end(); } @@ -101,13 +101,15 @@ bool has_duplicate_values(const ContainerType& values) { return set_values.size() < values.size(); } -template < - typename ContainerType, typename IntType, - std::enable_if_t, std::nullptr_t> = nullptr> +template bool is_out_of_range_value_included(const ContainerType& values, IntType max) { + static_assert( + std::is_integral_v, + "is_out_of_range_value_included: IntType must be an integral type"); using value_type = KokkosFFT::Impl::base_container_value_type; static_assert(std::is_same_v, - "Container value type must match IntType"); + "is_out_of_range_value_included: Container value type must " + "match IntType"); bool is_included = false; for (auto value : values) { is_included = value >= max; @@ -121,6 +123,10 @@ template < std::enable_if_t && std::is_integral_v, std::nullptr_t> = nullptr> bool are_valid_axes(const ViewType& view, const ArrayType& axes) { + static_assert(Kokkos::is_view_v, + "are_valid_axes: ViewType must be a Kokkos::View"); + static_assert(std::is_integral_v, + "are_valid_axes: IntType must be an integral type"); static_assert( DIM >= 1 && DIM <= ViewType::rank(), "are_valid_axes: the Rank of FFT axes must be between 1 and View rank"); @@ -157,7 +163,7 @@ template std::size_t get_index(ContainerType& values, const ValueType& value) { using value_type = KokkosFFT::Impl::base_container_value_type; static_assert(std::is_same_v, - "Container value type must match ValueType"); + "get_index: Container value type must match ValueType"); auto it = std::find(values.begin(), values.end(), value); KOKKOSFFT_EXPECTS(it != values.end(), "value is not included in values"); return it - values.begin();