From 5bf92e844b425ff42a216322da5e94e5ed4b4cef Mon Sep 17 00:00:00 2001 From: "Brendan K. Krueger" Date: Wed, 20 Nov 2024 09:43:49 -0700 Subject: [PATCH] format --- ports-of-call/portability.hpp | 46 +++++++++++++------------ ports-of-call/span.hpp | 21 +++++------- test/test_portability.cpp | 2 +- test/test_span.cpp | 3 +- test/test_static_vector.cpp | 54 ++++++++++++------------------ test/test_static_vector_kokkos.cpp | 2 +- 6 files changed, 58 insertions(+), 70 deletions(-) diff --git a/ports-of-call/portability.hpp b/ports-of-call/portability.hpp index 8d57b7c0..eb5f3540 100644 --- a/ports-of-call/portability.hpp +++ b/ports-of-call/portability.hpp @@ -153,7 +153,8 @@ void portableCopyToHost(T *const to, T const *const from, size_t const size_byte } template -void portableFor([[maybe_unused]] const char *name, int start, int stop, Function function) { +void portableFor([[maybe_unused]] const char *name, int start, int stop, + Function function) { #ifdef PORTABILITY_STRATEGY_KOKKOS using policy = Kokkos::RangePolicy<>; Kokkos::parallel_for(name, policy(start, stop), function); @@ -165,8 +166,8 @@ void portableFor([[maybe_unused]] const char *name, int start, int stop, Functio } template -void portableFor([[maybe_unused]] const char *name, int starty, int stopy, int startx, int stopx, - Function function) { +void portableFor([[maybe_unused]] const char *name, int starty, int stopy, int startx, + int stopx, Function function) { #ifdef PORTABILITY_STRATEGY_KOKKOS using Policy2D = Kokkos::MDRangePolicy>; Kokkos::parallel_for(name, Policy2D({starty, startx}, {stopy, stopx}), function); @@ -180,8 +181,8 @@ void portableFor([[maybe_unused]] const char *name, int starty, int stopy, int s } template -void portableFor([[maybe_unused]] const char *name, int startz, int stopz, int starty, int stopy, - int startx, int stopx, Function function) { +void portableFor([[maybe_unused]] const char *name, int startz, int stopz, int starty, + int stopy, int startx, int stopx, Function function) { #ifdef PORTABILITY_STRATEGY_KOKKOS using Policy3D = Kokkos::MDRangePolicy>; Kokkos::parallel_for(name, Policy3D({startz, starty, startx}, {stopz, stopy, stopx}), @@ -198,8 +199,9 @@ void portableFor([[maybe_unused]] const char *name, int startz, int stopz, int s } template -void portableFor([[maybe_unused]] const char *name, int starta, int stopa, int startz, int stopz, - int starty, int stopy, int startx, int stopx, Function function) { +void portableFor([[maybe_unused]] const char *name, int starta, int stopa, int startz, + int stopz, int starty, int stopy, int startx, int stopx, + Function function) { #ifdef PORTABILITY_STRATEGY_KOKKOS using Policy4D = Kokkos::MDRangePolicy>; Kokkos::parallel_for( @@ -219,9 +221,9 @@ void portableFor([[maybe_unused]] const char *name, int starta, int stopa, int s } template -void portableFor([[maybe_unused]] const char *name, int startb, int stopb, int starta, int stopa, - int startz, int stopz, int starty, int stopy, int startx, int stopx, - Function function) { +void portableFor([[maybe_unused]] const char *name, int startb, int stopb, int starta, + int stopa, int startz, int stopz, int starty, int stopy, int startx, + int stopx, Function function) { #ifdef PORTABILITY_STRATEGY_KOKKOS using Policy5D = Kokkos::MDRangePolicy>; Kokkos::parallel_for(name, @@ -244,8 +246,8 @@ void portableFor([[maybe_unused]] const char *name, int startb, int stopb, int s } template -void portableReduce([[maybe_unused]] const char *name, int start, int stop, Function function, - T &reduced) { +void portableReduce([[maybe_unused]] const char *name, int start, int stop, + Function function, T &reduced) { #ifdef PORTABILITY_STRATEGY_KOKKOS using Policy = Kokkos::RangePolicy<>; Kokkos::parallel_reduce(name, Policy(start, stop), function, reduced); @@ -257,8 +259,8 @@ void portableReduce([[maybe_unused]] const char *name, int start, int stop, Func } template -void portableReduce([[maybe_unused]] const char *name, int starty, int stopy, int startx, int stopx, - Function function, T &reduced) { +void portableReduce([[maybe_unused]] const char *name, int starty, int stopy, int startx, + int stopx, Function function, T &reduced) { #ifdef PORTABILITY_STRATEGY_KOKKOS using Policy2D = Kokkos::MDRangePolicy>; Kokkos::parallel_reduce(name, Policy2D({starty, startx}, {stopy, stopx}), function, @@ -273,8 +275,8 @@ void portableReduce([[maybe_unused]] const char *name, int starty, int stopy, in } template -void portableReduce([[maybe_unused]] const char *name, int startz, int stopz, int starty, int stopy, - int startx, int stopx, Function function, T &reduced) { +void portableReduce([[maybe_unused]] const char *name, int startz, int stopz, int starty, + int stopy, int startx, int stopx, Function function, T &reduced) { #ifdef PORTABILITY_STRATEGY_KOKKOS using Policy3D = Kokkos::MDRangePolicy>; Kokkos::parallel_reduce(name, Policy3D({startz, starty, startx}, {stopz, stopy, stopx}), @@ -291,9 +293,9 @@ void portableReduce([[maybe_unused]] const char *name, int startz, int stopz, in } template -void portableReduce([[maybe_unused]] const char *name, int starta, int stopa, int startz, int stopz, - int starty, int stopy, int startx, int stopx, Function function, - T &reduced) { +void portableReduce([[maybe_unused]] const char *name, int starta, int stopa, int startz, + int stopz, int starty, int stopy, int startx, int stopx, + Function function, T &reduced) { #ifdef PORTABILITY_STRATEGY_KOKKOS using Policy4D = Kokkos::MDRangePolicy>; Kokkos::parallel_reduce( @@ -313,9 +315,9 @@ void portableReduce([[maybe_unused]] const char *name, int starta, int stopa, in } template -void portableReduce([[maybe_unused]] const char *name, int startb, int stopb, int starta, int stopa, - int startz, int stopz, int starty, int stopy, int startx, int stopx, - Function function, T &reduced) { +void portableReduce([[maybe_unused]] const char *name, int startb, int stopb, int starta, + int stopa, int startz, int stopz, int starty, int stopy, int startx, + int stopx, Function function, T &reduced) { #ifdef PORTABILITY_STRATEGY_KOKKOS using Policy5D = Kokkos::MDRangePolicy>; Kokkos::parallel_reduce(name, diff --git a/ports-of-call/span.hpp b/ports-of-call/span.hpp index 23b69141..2739e1e1 100644 --- a/ports-of-call/span.hpp +++ b/ports-of-call/span.hpp @@ -56,17 +56,13 @@ using std::data; using std::size; // type-safe check against 0 (prevents warnings about comparing an unsigned against 0) -template ::value, bool> = true> -PORTABLE_FUNCTION constexpr bool check_nonnegative(const T) -{ +template ::value, bool> = true> +PORTABLE_FUNCTION constexpr bool check_nonnegative(const T) { return true; } -template ::value, bool> = true> -PORTABLE_FUNCTION constexpr bool check_nonnegative(const T t) -{ - return t >= 0; +template ::value, bool> = true> +PORTABLE_FUNCTION constexpr bool check_nonnegative(const T t) { + return t >= 0; } // object to handle storage of span @@ -210,7 +206,7 @@ class span { // NB: iterator concepts to further restrict overload resolution constexpr span(pointer ptr, size_type count) : storage_(ptr, count) { span_EXPECTS((ptr == nullptr && count == 0) || - (ptr != nullptr && detail::check_nonnegative(count))); + (ptr != nullptr && detail::check_nonnegative(count))); } // constructs a span that is a view over the range [first, last) @@ -321,7 +317,8 @@ class span { template constexpr subspan_return_t subspan() const { span_EXPECTS((detail::check_nonnegative(Offset) && Offset <= size()) && - (Count == dynamic_extent || (detail::check_nonnegative(Count) && Count + Offset <= size()))); + (Count == dynamic_extent || + (detail::check_nonnegative(Count) && Count + Offset <= size()))); return {data() + Offset, Count != dynamic_extent ? Count : size() - Offset}; } @@ -396,7 +393,7 @@ span(const std::array &) -> span; template span(Container &) -> span()))>::type>; + decltype(*detail::data(std::declval()))>::type>; template span(const Container &) -> span; diff --git a/test/test_portability.cpp b/test/test_portability.cpp index 8f81e624..04d4dad0 100644 --- a/test/test_portability.cpp +++ b/test/test_portability.cpp @@ -102,7 +102,7 @@ TEST_CASE("portableCopy works with all portability strategies", "[portableCopy]" int sum{0}; portableReduce( "check portableCopy", 0, N, 0, 0, 0, 0, - PORTABLE_LAMBDA(const int &i, const int &/*j*/, const int &/*k*/, int &isum) { + PORTABLE_LAMBDA(const int &i, const int & /*j*/, const int & /*k*/, int &isum) { if (a[i] != index_func(i)) { isum += 1; } diff --git a/test/test_span.cpp b/test/test_span.cpp index 20e4693f..090a730e 100644 --- a/test/test_span.cpp +++ b/test/test_span.cpp @@ -61,8 +61,7 @@ constexpr void generate(ForwardIt first, ForwardIt last, Generator g) { } template -[[nodiscard]] -constexpr auto slide(span s, std::size_t offset, std::size_t width) { +[[nodiscard]] constexpr auto slide(span s, std::size_t offset, std::size_t width) { return s.subspan(offset, offset + width <= s.size() ? width : 0U); } diff --git a/test/test_static_vector.cpp b/test/test_static_vector.cpp index cadfb050..815c3baa 100644 --- a/test/test_static_vector.cpp +++ b/test/test_static_vector.cpp @@ -17,34 +17,25 @@ constexpr static bool really_const = std::is_const>:: // This doesn't do anything interesting. It just needs to be non-trivial to // test that static_vector works for non-trivial types. struct NonTrivialType { - int n; - int * p; - PORTABLE_FUNCTION NonTrivialType(int nn) - : n{nn} - , p{&n} - {} - PORTABLE_FUNCTION NonTrivialType(const NonTrivialType & other) - : n{other.n} - , p{&n} - {} - PORTABLE_FUNCTION NonTrivialType(NonTrivialType && other) - : n{other.n} - , p{&n} - {} - PORTABLE_FUNCTION NonTrivialType& operator=(const NonTrivialType & other) { - n = other.n; - p = &n; - return *this; - } - PORTABLE_FUNCTION NonTrivialType& operator=(NonTrivialType && other) { - n = other.n; - p = &n; - return *this; - } - PORTABLE_FUNCTION ~NonTrivialType() {} + int n; + int *p; + PORTABLE_FUNCTION NonTrivialType(int nn) : n{nn}, p{&n} {} + PORTABLE_FUNCTION NonTrivialType(const NonTrivialType &other) : n{other.n}, p{&n} {} + PORTABLE_FUNCTION NonTrivialType(NonTrivialType &&other) : n{other.n}, p{&n} {} + PORTABLE_FUNCTION NonTrivialType &operator=(const NonTrivialType &other) { + n = other.n; + p = &n; + return *this; + } + PORTABLE_FUNCTION NonTrivialType &operator=(NonTrivialType &&other) { + n = other.n; + p = &n; + return *this; + } + PORTABLE_FUNCTION ~NonTrivialType() {} }; -} +} // namespace static_vector_test static_assert(!std::is_trivial::value); @@ -54,8 +45,8 @@ TEST_CASE("static_vector", "[util][static_vector]") { using std::cend; using std::end; - using static_vector_test::really_const; using static_vector_test::NonTrivialType; + using static_vector_test::really_const; SECTION("begin/end iteration") { SECTION("with non-zero size") { @@ -226,13 +217,12 @@ TEST_CASE("static_vector", "[util][static_vector]") { SECTION("with non-trivial type") { using test_t = PortsOfCall::static_vector; - test_t data = {NonTrivialType(1), NonTrivialType(2), - NonTrivialType(3), NonTrivialType(4), - NonTrivialType(5)}; + test_t data = {NonTrivialType(1), NonTrivialType(2), NonTrivialType(3), + NonTrivialType(4), NonTrivialType(5)}; data.pop_back(); - test_t const expected = {NonTrivialType(1), NonTrivialType(2), - NonTrivialType(3), NonTrivialType(4)}; + test_t const expected = {NonTrivialType(1), NonTrivialType(2), NonTrivialType(3), + NonTrivialType(4)}; auto size_check = std::equal(begin(data), end(data), begin(expected), end(expected), diff --git a/test/test_static_vector_kokkos.cpp b/test/test_static_vector_kokkos.cpp index 12097cdf..03389374 100644 --- a/test/test_static_vector_kokkos.cpp +++ b/test/test_static_vector_kokkos.cpp @@ -114,4 +114,4 @@ TEST_CASE("static vector GPU", "[reaction_network]") { // ================================================================================================ -#endif //PORTABILITY_STRATEGY_KOKKOS +#endif // PORTABILITY_STRATEGY_KOKKOS