From b0b34310533c89790b8999c6cf00f0238df50f65 Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Tue, 8 Oct 2024 18:31:10 -0600 Subject: [PATCH] Clang-format --- containers/src/Kokkos_DynRankView.hpp | 8 +- core/src/Kokkos_View.hpp | 138 +++++++----------- core/src/View/Kokkos_BasicView.hpp | 35 ++--- core/src/View/MDSpan/Kokkos_MDSpan_Header.hpp | 24 +-- core/src/View/MDSpan/Kokkos_MDSpan_Layout.hpp | 6 +- core/unit_test/TestMDSpanConversion.hpp | 10 +- core/unit_test/TestViewIsAssignable.hpp | 8 +- core/unit_test/TestViewMapping_a.hpp | 7 +- 8 files changed, 106 insertions(+), 130 deletions(-) diff --git a/containers/src/Kokkos_DynRankView.hpp b/containers/src/Kokkos_DynRankView.hpp index d027e80d304..1035c4953c7 100644 --- a/containers/src/Kokkos_DynRankView.hpp +++ b/containers/src/Kokkos_DynRankView.hpp @@ -424,9 +424,9 @@ class DynRankView : private View { private: #ifndef KOKKOS_ENABLE_IMPL_VIEW_LEGACY - using drdtraits = Impl::DynRankDimTraits; + using drdtraits = Impl::DynRankDimTraits; #else - using drdtraits = Impl::DynRankDimTraits; + using drdtraits = Impl::DynRankDimTraits; #endif public: // typedefs from ViewTraits, overriden @@ -456,9 +456,9 @@ class DynRankView : private View { using const_scalar_array_type = const_value_type; using non_const_scalar_array_type = non_const_value_type; #ifndef KOKKOS_ENABLE_IMPL_VIEW_LEGACY - using specialize = void; + using specialize = void; #else - using specialize = typename view_type::specialize; + using specialize = typename view_type::specialize; #endif // typedefs in View for mdspan compatibility diff --git a/core/src/Kokkos_View.hpp b/core/src/Kokkos_View.hpp index fa66e6c1aad..8029c6d6814 100644 --- a/core/src/Kokkos_View.hpp +++ b/core/src/Kokkos_View.hpp @@ -172,7 +172,7 @@ class View : public Impl::BasicViewFromTraits::type { using index_type = typename traits::memory_space::size_type; // FIXME: Should be unsigned - using size_type = typename memory_space::size_type; + using size_type = typename memory_space::size_type; using scalar_array_type = typename traits::scalar_array_type; using const_scalar_array_type = typename traits::const_scalar_array_type; @@ -333,7 +333,8 @@ class View : public Impl::BasicViewFromTraits::type { template static KOKKOS_FUNCTION void check_access_member_function_valid_args(Is...) { // cast to int to work around pointless comparison of unsigned to 0 warning - static_assert(static_cast(sizeof...(Is)) <= static_cast(8 - rank)); + static_assert(static_cast(sizeof...(Is)) <= + static_cast(8 - rank)); static_assert(Kokkos::Impl::are_integral::value); } #endif @@ -495,10 +496,14 @@ class View : public Impl::BasicViewFromTraits::type { // may assign unmanaged from managed. template -// requires(std::is_constructible_v< -// mdspan_type, typename View::mdspan_type>) - KOKKOS_INLINE_FUNCTION View(const View& other, std::enable_if_t::mdspan_type>, void*> = nullptr) + // requires(std::is_constructible_v< + // mdspan_type, typename View::mdspan_type>) + KOKKOS_INLINE_FUNCTION View( + const View& other, + std::enable_if_t< + std::is_constructible_v< + mdspan_type, typename View::mdspan_type>, + void*> = nullptr) : base_t(static_cast( other.data_handle()), static_cast(other.mapping()), @@ -521,18 +526,21 @@ class View : public Impl::BasicViewFromTraits::type { // Allocation according to allocation properties and array layout template - explicit inline View( - const Impl::ViewCtorProp& arg_prop, - std::enable_if_t::has_pointer, const typename traits::array_layout&> arg_layout) + explicit inline View(const Impl::ViewCtorProp& arg_prop, + std::enable_if_t::has_pointer, + const typename traits::array_layout&> + arg_layout) : base_t( arg_prop, Impl::mapping_from_array_layout( arg_layout)) {} - + template KOKKOS_FUNCTION explicit inline View( const Impl::ViewCtorProp& arg_prop, - std::enable_if_t::has_pointer, const typename traits::array_layout&> arg_layout) + std::enable_if_t::has_pointer, + const typename traits::array_layout&> + arg_layout) : base_t( arg_prop, Impl::mapping_from_array_layout( @@ -548,21 +556,23 @@ class View : public Impl::BasicViewFromTraits::type { arg_layout)) {} #ifdef KOKKOS_ENABLE_CXX17 - template - KOKKOS_FUNCTION - explicit inline View(const typename base_t::data_handle_type& handle, - const Layout& arg_layout, std::enable_if_t< - (std::is_same_v && - std::is_same_v) || - (std::is_same_v && - std::is_same_v) || - (std::is_same_v && - std::is_same_v>) || - (std::is_same_v && - std::is_same_v) || - (std::is_same_v && - std::is_same_v>) - , void*> = nullptr) + template + KOKKOS_FUNCTION explicit inline View( + const typename base_t::data_handle_type& handle, const Layout& arg_layout, + std::enable_if_t< + (std::is_same_v && + std::is_same_v) || + (std::is_same_v && + std::is_same_v) || + (std::is_same_v && + std::is_same_v >) || + (std::is_same_v && + std::is_same_v) || + (std::is_same_v && + std::is_same_v >), + void*> = nullptr) : base_t( handle, Impl::mapping_from_array_layout( @@ -637,80 +647,37 @@ class View : public Impl::BasicViewFromTraits::type { // Special function to be preferred over the above for passing in 0, NULL or // nullptr when pointer type is char* template -// requires(std::is_same_v) explicit View(decltype(nullptr), Args... args) : View(Kokkos::view_wrap(pointer_type(nullptr)), args...) {} #else -#if 1 - template , size_t> = 0ul> + template < + class P, class... Args, + std::enable_if_t, size_t> = 0ul> KOKKOS_FUNCTION View(P ptr_, Args... args) : View(Kokkos::view_wrap(static_cast(ptr_)), args...) {} // Special function to be preferred over the above for string literals // when pointer type is char* - template && - std::is_same_v), size_t> = 0ul> + template && + std::is_same_v), + size_t> = 0ul> explicit View(L label, Args... args) : View(Kokkos::view_alloc(std::string(label)), args...) {} // Special function to be preferred over the above for passing in 0, NULL or // nullptr when pointer type is char* template -// requires(std::is_same_v) explicit View(decltype(nullptr), Args... args) : View(Kokkos::view_wrap(pointer_type(nullptr)), args...) {} -#else - private: - KOKKOS_FUNCTION - static constexpr std::true_type matches_nullptr(decltype(nullptr)) { - return std::true_type{}; - } - template - KOKKOS_FUNCTION - static constexpr std::enable_if_t,std::true_type> matches_nullptr(T) { - return std::true_type{}; - } - template - KOKKOS_FUNCTION - static constexpr std::enable_if_t,std::false_type> matches_nullptr(T) { - return std::false_type{}; - } - - public: - template || - std::is_convertible_v - , size_t> = 0ul> - KOKKOS_FUNCTION View(Arg1 arg1, Args... args) { - if constexpr (std::is_same_v) { - if constexpr(std::is_same_v) { - // Label - KOKKOS_IF_ON_HOST(View(Kokkos::view_alloc(std::string(arg1)), args...);) - KOKKOS_IF_ON_DEVICE(Kokkos::abort("Calling allocating View constructor on device");) - return; - } else if constexpr(decltype(matches_nullptr(arg1))::value) { - // Nullptr - View(Kokkos::view_wrap(pointer_type(nullptr)), args...); - if constexpr (std::is_integral_v) { - if(arg1 != Arg1(0)) Kokkos::abort("Passing non-zero integer as first View ctor argument"); - } - return; - } - } - if constexpr(std::is_convertible_v) { - View(Kokkos::view_wrap(pointer_type(nullptr)), args...); - return; - } - Kokkos::abort("Unexpected View Ctor callpath"); - } -#endif #endif // Constructor which allows always 8 sizes should be deprecated template explicit inline View( const Impl::ViewCtorProp& arg_prop, - std::enable_if_t::has_pointer, const size_t> arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, + std::enable_if_t::has_pointer, const size_t> + arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, @@ -731,7 +698,8 @@ class View : public Impl::BasicViewFromTraits::type { template KOKKOS_FUNCTION explicit inline View( const Impl::ViewCtorProp& arg_prop, - std::enable_if_t::has_pointer, const size_t> arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, + std::enable_if_t::has_pointer, const size_t> + arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, @@ -931,14 +899,18 @@ class View : public Impl::BasicViewFromTraits::type { KOKKOS_FUNCTION constexpr typename base_t::index_type extent(size_t r) const noexcept { - // casting to int to avoid warning for pointeless comparison of unsigned with 0 - if (static_cast(r) >= static_cast(base_t::extents_type::rank())) return 1; + // casting to int to avoid warning for pointeless comparison of unsigned + // with 0 + if (static_cast(r) >= static_cast(base_t::extents_type::rank())) + return 1; return base_t::extent(r); } KOKKOS_FUNCTION static constexpr size_t static_extent(size_t r) noexcept { - // casting to int to avoid warning for pointeless comparison of unsigned with 0 - if (static_cast(r) >= static_cast(base_t::extents_type::rank())) return 1; + // casting to int to avoid warning for pointeless comparison of unsigned + // with 0 + if (static_cast(r) >= static_cast(base_t::extents_type::rank())) + return 1; size_t value = base_t::extents_type::static_extent(r); return value == Kokkos::dynamic_extent ? 0 : value; } diff --git a/core/src/View/Kokkos_BasicView.hpp b/core/src/View/Kokkos_BasicView.hpp index b76408fa36d..e19b5258df2 100644 --- a/core/src/View/Kokkos_BasicView.hpp +++ b/core/src/View/Kokkos_BasicView.hpp @@ -407,25 +407,26 @@ class BasicView { "execution space"); } if constexpr (has_exec) { - using prop_exec_space_t = std::remove_cv_t(prop_copy))>>; - return data_handle_type(Impl::make_shared_allocation_record( - arg_mapping.required_span_size(), - Impl::get_property(prop_copy), - Impl::get_property(prop_copy), - std::optional{Impl::get_property(prop_copy)}, - std::integral_constant(), - std::integral_constant())); + using prop_exec_space_t = std::remove_cv_t(prop_copy))>>; + return data_handle_type(Impl::make_shared_allocation_record( + arg_mapping.required_span_size(), + Impl::get_property(prop_copy), + Impl::get_property(prop_copy), + std::optional{ + Impl::get_property(prop_copy)}, + std::integral_constant(), + std::integral_constant())); } else { - return data_handle_type(Impl::make_shared_allocation_record( - arg_mapping.required_span_size(), - Impl::get_property(prop_copy), - Impl::get_property(prop_copy), - std::optional{std::nullopt}, - std::integral_constant(), - std::integral_constant())); + return data_handle_type(Impl::make_shared_allocation_record( + arg_mapping.required_span_size(), + Impl::get_property(prop_copy), + Impl::get_property(prop_copy), + std::optional{std::nullopt}, + std::integral_constant(), + std::integral_constant())); } - } + } public: template diff --git a/core/src/View/MDSpan/Kokkos_MDSpan_Header.hpp b/core/src/View/MDSpan/Kokkos_MDSpan_Header.hpp index b467647cd1c..aff77208da9 100644 --- a/core/src/View/MDSpan/Kokkos_MDSpan_Header.hpp +++ b/core/src/View/MDSpan/Kokkos_MDSpan_Header.hpp @@ -46,26 +46,26 @@ using std::mdspan; #else // Opt in for Kokkos::pair to submdspan/subview // submdspan does only take index_pair_like which is derived from tuple_like -// tuple_like is an enumerated list: tuple, pair, array, complex, ranges::subrange -// Needs to be defined before including mdspan header +// tuple_like is an enumerated list: tuple, pair, array, complex, +// ranges::subrange Needs to be defined before including mdspan header #include namespace Kokkos { namespace detail { -template -KOKKOS_INLINE_FUNCTION -constexpr auto first_of(const pair &slice) { +template +KOKKOS_INLINE_FUNCTION constexpr auto first_of( + const pair &slice) { return slice.first; } -template -KOKKOS_INLINE_FUNCTION -constexpr auto last_of(std::integral_constant, const Extents &, - const pair &slice) { +template +KOKKOS_INLINE_FUNCTION constexpr auto last_of(std::integral_constant, + const Extents &, + const pair &slice) { return slice.second; } -template +template struct index_pair_like; template @@ -73,8 +73,8 @@ struct index_pair_like, IndexType> { static constexpr bool value = std::is_convertible_v && std::is_convertible_v; }; -} -} +} // namespace detail +} // namespace Kokkos #include #endif diff --git a/core/src/View/MDSpan/Kokkos_MDSpan_Layout.hpp b/core/src/View/MDSpan/Kokkos_MDSpan_Layout.hpp index 60a005e5750..7382153ee26 100644 --- a/core/src/View/MDSpan/Kokkos_MDSpan_Layout.hpp +++ b/core/src/View/MDSpan/Kokkos_MDSpan_Layout.hpp @@ -47,7 +47,6 @@ template struct is_layout_left_padded> : public std::true_type {}; - template struct LayoutFromArrayLayout; @@ -258,9 +257,10 @@ struct Padding { } }; -template +template KOKKOS_INLINE_FUNCTION auto mapping_from_ctor_and_sizes( - const ViewCtorProperties&, const Sizes... args) { + const ViewCtorProperties &, const Sizes... args) { using layout_t = typename MappingType::layout_type; using ext_t = typename MappingType::extents_type; ext_t ext{args...}; diff --git a/core/unit_test/TestMDSpanConversion.hpp b/core/unit_test/TestMDSpanConversion.hpp index 3c1f0e7fb5f..a90cb932e54 100644 --- a/core/unit_test/TestMDSpanConversion.hpp +++ b/core/unit_test/TestMDSpanConversion.hpp @@ -65,11 +65,11 @@ struct TestViewMDSpanConversion { using mdspan_type = Kokkos::mdspan; - //static_assert(std::is_constructible_v); - //static_assert(std::is_convertible_v == - // std::is_convertible_v); - // Manually create an mdspan from ref so we have a valid pointer to play - // with + // static_assert(std::is_constructible_v); + // static_assert(std::is_convertible_v == + // std::is_convertible_v); + // Manually create an mdspan from ref so we have a valid pointer to play + // with const auto &exts = mapping.extents(); auto mds = mdspan_type{ref.data(), mapping}; diff --git a/core/unit_test/TestViewIsAssignable.hpp b/core/unit_test/TestViewIsAssignable.hpp index ddbbbf0bd92..5d1e4eaaa94 100644 --- a/core/unit_test/TestViewIsAssignable.hpp +++ b/core/unit_test/TestViewIsAssignable.hpp @@ -26,11 +26,13 @@ struct TestAssignability { Kokkos::Impl::ViewMapping; + >; template static void try_assign( diff --git a/core/unit_test/TestViewMapping_a.hpp b/core/unit_test/TestViewMapping_a.hpp index dc9641bd676..396c1a34f66 100644 --- a/core/unit_test/TestViewMapping_a.hpp +++ b/core/unit_test/TestViewMapping_a.hpp @@ -991,7 +991,7 @@ void test_view_mapping() { ASSERT_EQ(a.use_count(), 2); ASSERT_EQ(b.use_count(), 2); - #ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY +#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY ASSERT_EQ(c.use_count(), 2); #else ASSERT_EQ(c.use_count(), 0); @@ -1001,8 +1001,9 @@ void test_view_mapping() { ASSERT_EQ(a.use_count(), 2); ASSERT_EQ(b.use_count(), 2); - // FIXME: Legacy View is weird: it passes on use count even through compile time unmanaged transition - #ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY +// FIXME: Legacy View is weird: it passes on use count even through compile time +// unmanaged transition +#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY ASSERT_EQ(c.use_count(), 2); ASSERT_EQ(d.use_count(), 2); #else