//@HEADER // ************************************************************************ // // Kokkos v. 4.0 // Copyright (2022) National Technology & Engineering // Solutions of Sandia, LLC (NTESS). // // Under the terms of Contract DE-NA0003525 with NTESS, // the U.S. Government retains certain rights in this software. // // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. // See https://kokkos.org/LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //@HEADER #include #include #include #include namespace Test { namespace { template class MyArray { public: T values[N]; KOKKOS_INLINE_FUNCTION void operator+=(const MyArray& src) { for (int i = 0; i < N; i++) values[i] += src.values[i]; } }; template struct FunctorFor { double static_array[S]; KOKKOS_INLINE_FUNCTION void operator()(const typename PolicyType::member_type& /*team*/) const {} }; template struct FunctorReduce { double static_array[S]; KOKKOS_INLINE_FUNCTION void operator()(const typename PolicyType::member_type& /*team*/, MyArray& lval) const { for (int j = 0; j < N; j++) lval.values[j] += 1 + lval.values[0]; } }; } // namespace using policy_type = Kokkos::TeamPolicy; using policy_type_128_8 = Kokkos::TeamPolicy >; using policy_type_1024_2 = Kokkos::TeamPolicy >; template void test_team_policy_max_recommended_static_size(int scratch_size) { PolicyType p = PolicyType(10000, Kokkos::AUTO, 4) .set_scratch_size(0, Kokkos::PerTeam(scratch_size)); int team_size_max_for = p.team_size_max(FunctorFor(), Kokkos::ParallelForTag()); int team_size_rec_for = p.team_size_recommended( FunctorFor(), Kokkos::ParallelForTag()); int team_size_max_reduce = p.team_size_max( FunctorReduce(), Kokkos::ParallelReduceTag()); int team_size_rec_reduce = p.team_size_recommended( FunctorReduce(), Kokkos::ParallelReduceTag()); ASSERT_GE(team_size_max_for, team_size_rec_for); ASSERT_GE(team_size_max_reduce, team_size_rec_reduce); ASSERT_GE(team_size_max_for, team_size_max_reduce); Kokkos::parallel_for(PolicyType(10000, team_size_max_for, 4) .set_scratch_size(0, Kokkos::PerTeam(scratch_size)), FunctorFor()); Kokkos::parallel_for(PolicyType(10000, team_size_rec_for, 4) .set_scratch_size(0, Kokkos::PerTeam(scratch_size)), FunctorFor()); MyArray val; double n_leagues = 10000; Kokkos::parallel_reduce( PolicyType(n_leagues, team_size_max_reduce, 4) .set_scratch_size(0, Kokkos::PerTeam(scratch_size)), FunctorReduce(), val); Kokkos::parallel_reduce( PolicyType(n_leagues, team_size_rec_reduce, 4) .set_scratch_size(0, Kokkos::PerTeam(scratch_size)), FunctorReduce(), val); Kokkos::fence(); } template void test_team_policy_max_recommended(int scratch_size) { test_team_policy_max_recommended_static_size( scratch_size); // FIXME_SYCL prevent running out of total kernel argument size limit #ifdef KOKKOS_ENABLE_SYCL test_team_policy_max_recommended_static_size( scratch_size); #else test_team_policy_max_recommended_static_size( scratch_size); #endif } TEST(TEST_CATEGORY, team_policy_max_recommended) { int max_scratch_size = policy_type::scratch_size_max(0); test_team_policy_max_recommended(0); test_team_policy_max_recommended(max_scratch_size / 3); test_team_policy_max_recommended(max_scratch_size); test_team_policy_max_recommended(0); test_team_policy_max_recommended( max_scratch_size / 3 / 8); test_team_policy_max_recommended( max_scratch_size / 8); test_team_policy_max_recommended(0); test_team_policy_max_recommended( max_scratch_size / 3 / 2); test_team_policy_max_recommended( max_scratch_size / 2); test_team_policy_max_recommended(0); test_team_policy_max_recommended(max_scratch_size / 3); test_team_policy_max_recommended(max_scratch_size); test_team_policy_max_recommended(0); test_team_policy_max_recommended( max_scratch_size / 3 / 8); test_team_policy_max_recommended( max_scratch_size / 8); test_team_policy_max_recommended(0); test_team_policy_max_recommended( max_scratch_size / 3 / 2); test_team_policy_max_recommended( max_scratch_size / 2); } template struct MinMaxTeamLeagueRank { KOKKOS_FUNCTION void operator()(const TeamHandleType& team, ReducerValueType& update) const { int const x = team.league_rank(); if (x < update.min_val) { update.min_val = x; } if (x > update.max_val) { update.max_val = x; } } }; TEST(TEST_CATEGORY, team_policy_minmax_scalar_without_plus_equal_k) { using ExecSpace = TEST_EXECSPACE; using ReducerType = Kokkos::MinMax; using ReducerValueType = typename ReducerType::value_type; using DynamicScheduleType = Kokkos::Schedule; using TeamPolicyType = Kokkos::TeamPolicy; using TeamHandleType = typename TeamPolicyType::member_type; static constexpr int num_teams = 17; ReducerValueType val; ReducerType reducer(val); TeamPolicyType p(num_teams, Kokkos::AUTO); MinMaxTeamLeagueRank f1; Kokkos::parallel_reduce(p, f1, reducer); ASSERT_EQ(val.min_val, 0); ASSERT_EQ(val.max_val, num_teams - 1); } } // namespace Test