Skip to content

Commit

Permalink
Unit test for issue 3371 (negative vector length should not yield a n…
Browse files Browse the repository at this point in the history
…egative max_team_size) (kokkos#6076)

* kokkos#3371: Added TeamPolicy construction test

* Check recommended team size

* Move size_max and size_recommended tests to TeamPolicy constructor test

* Define tag type outside of test body

* Add missing overload

* tests: remove spurious check

* Remove redundant qualifier

Co-authored-by: Damien L-G <dalg24+github@gmail.com>

* Fix formatting

---------

Co-authored-by: Cezary Skrzyński <cezary.skrzynski@ng-analytics.com>
Co-authored-by: Cezary Skrzyński <czars1988@gmail.com>
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
  • Loading branch information
4 people committed Dec 11, 2023
1 parent 843fca3 commit ed08974
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions core/unit_test/TestTeamPolicyConstructors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,24 @@

namespace {

struct SomeTag {};

struct FunctorFor {
KOKKOS_FUNCTION
void operator()(
Kokkos::TeamPolicy<TEST_EXECSPACE>::member_type const&) const {}

KOKKOS_FUNCTION
void operator()(
SomeTag, Kokkos::TeamPolicy<TEST_EXECSPACE>::member_type const&) const {}
};

template <typename Policy>
void test_run_time_parameters() {
int league_size = 131;

using ExecutionSpace = typename Policy::execution_space;
using ParallelTag = Kokkos::ParallelForTag;
int team_size =
4 < ExecutionSpace().concurrency() ? 4 : ExecutionSpace().concurrency();
#ifdef KOKKOS_ENABLE_HPX
Expand All @@ -44,6 +57,8 @@ void test_run_time_parameters() {
ASSERT_EQ(p1.team_size(), team_size);
ASSERT_GT(p1.chunk_size(), 0);
ASSERT_EQ(p1.scratch_size(0), 0u);
ASSERT_GT(p1.team_size_max(FunctorFor(), ParallelTag()), 0);
ASSERT_GT(p1.team_size_recommended(FunctorFor(), ParallelTag()), 0);

Policy p2 = p1.set_chunk_size(chunk_size);
ASSERT_EQ(p1.league_size(), league_size);
Expand Down Expand Up @@ -112,6 +127,8 @@ void test_run_time_parameters() {
Policy p8; // default constructed
ASSERT_EQ(p8.league_size(), 0);
ASSERT_EQ(p8.scratch_size(0), 0u);
ASSERT_GT(p8.team_size_max(FunctorFor(), ParallelTag()), 0);
ASSERT_GT(p8.team_size_recommended(FunctorFor(), ParallelTag()), 0);
p8 = p3; // call assignment operator
ASSERT_EQ(p3.league_size(), league_size);
ASSERT_EQ(p3.team_size(), team_size);
Expand All @@ -121,11 +138,25 @@ void test_run_time_parameters() {
ASSERT_EQ(p8.team_size(), team_size);
ASSERT_EQ(p8.chunk_size(), chunk_size);
ASSERT_EQ(p8.scratch_size(0), size_t(scratch_size));

Policy p9(league_size, Kokkos::AUTO);
ASSERT_EQ(p9.league_size(), league_size);
ASSERT_GT(p9.team_size_max(FunctorFor(), ParallelTag()), 0);
ASSERT_GT(p9.team_size_recommended(FunctorFor(), ParallelTag()), 0);

Policy p10(league_size, team_size, Kokkos::AUTO);
ASSERT_EQ(p10.league_size(), league_size);
ASSERT_EQ(p10.team_size(), team_size);
ASSERT_GT(p10.team_size_max(FunctorFor(), ParallelTag()), 0);
ASSERT_GT(p10.team_size_recommended(FunctorFor(), ParallelTag()), 0);

Policy p11(league_size, Kokkos::AUTO, Kokkos::AUTO);
ASSERT_EQ(p11.league_size(), league_size);
ASSERT_GT(p11.team_size_max(FunctorFor(), ParallelTag()), 0);
ASSERT_GT(p11.team_size_recommended(FunctorFor(), ParallelTag()), 0);
}

TEST(TEST_CATEGORY, team_policy_runtime_parameters) {
struct SomeTag {};

using TestExecSpace = TEST_EXECSPACE;
using DynamicSchedule = Kokkos::Schedule<Kokkos::Dynamic>;
using LongIndex = Kokkos::IndexType<long>;
Expand Down

0 comments on commit ed08974

Please sign in to comment.