/* //@HEADER // ************************************************************************ // // Kokkos v. 3.0 // Copyright (2020) 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. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // 3. Neither the name of the Corporation nor the names of the // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Questions? Contact Christian R. Trott (crtrott@sandia.gov) // // ************************************************************************ //@HEADER */ #include #include #include #include #include #include namespace Test { struct SomeTag {}; template class TestRangePolicyConstruction { public: TestRangePolicyConstruction() { test_compile_time_parameters(); test_runtime_parameters(); } private: void test_compile_time_parameters() { { using policy_t = Kokkos::RangePolicy<>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, Kokkos::IndexType>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, ExecutionSpace, Kokkos::Schedule>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, Kokkos::IndexType, SomeTag>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, ExecutionSpace, Kokkos::IndexType, SomeTag>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, Kokkos::IndexType, ExecutionSpace>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, Kokkos::IndexType>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, Kokkos::Schedule>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, Kokkos::IndexType, SomeTag>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, Kokkos::IndexType, SomeTag>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::RangePolicy, Kokkos::IndexType>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } } void test_runtime_parameters() { using policy_t = Kokkos::RangePolicy<>; { policy_t p(5, 15); ASSERT_TRUE((p.begin() == 5)); ASSERT_TRUE((p.end() == 15)); } { policy_t p(Kokkos::DefaultExecutionSpace(), 5, 15); ASSERT_TRUE((p.begin() == 5)); ASSERT_TRUE((p.end() == 15)); } { policy_t p(5, 15, Kokkos::ChunkSize(10)); ASSERT_TRUE((p.begin() == 5)); ASSERT_TRUE((p.end() == 15)); ASSERT_TRUE((p.chunk_size() == 10)); } { policy_t p(Kokkos::DefaultExecutionSpace(), 5, 15, Kokkos::ChunkSize(10)); ASSERT_TRUE((p.begin() == 5)); ASSERT_TRUE((p.end() == 15)); ASSERT_TRUE((p.chunk_size() == 10)); } { policy_t p; ASSERT_TRUE((p.begin() == 0)); ASSERT_TRUE((p.end() == 0)); p = policy_t(5, 15, Kokkos::ChunkSize(10)); ASSERT_TRUE((p.begin() == 5)); ASSERT_TRUE((p.end() == 15)); ASSERT_TRUE((p.chunk_size() == 10)); } } }; template class TestTeamPolicyConstruction { public: TestTeamPolicyConstruction() { test_compile_time_parameters(); test_run_time_parameters(); } private: void test_compile_time_parameters() { { using policy_t = Kokkos::TeamPolicy<>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, Kokkos::IndexType>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, ExecutionSpace, Kokkos::Schedule>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, Kokkos::IndexType, SomeTag>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, ExecutionSpace, Kokkos::IndexType, SomeTag>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, Kokkos::IndexType, ExecutionSpace>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, Kokkos::IndexType>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, Kokkos::Schedule>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, Kokkos::IndexType, SomeTag>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, Kokkos::IndexType, SomeTag>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } { using policy_t = Kokkos::TeamPolicy, Kokkos::IndexType>; using execution_space = typename policy_t::execution_space; using index_type = typename policy_t::index_type; using schedule_type = typename policy_t::schedule_type; using work_tag = typename policy_t::work_tag; ASSERT_TRUE(( std::is_same::value)); ASSERT_TRUE((std::is_same::value)); ASSERT_TRUE((std::is_same>::value)); ASSERT_TRUE((std::is_same::value)); } } template void test_run_time_parameters_type() { int league_size = 131; int team_size = 4 < policy_t::execution_space::concurrency() ? 4 : policy_t::execution_space::concurrency(); #ifdef KOKKOS_ENABLE_HPX team_size = 1; #endif #ifdef KOKKOS_ENABLE_OPENMPTARGET if (std::is_same::value) team_size = 32; #endif int chunk_size = 4; int per_team_scratch = 1024; int per_thread_scratch = 16; int scratch_size = per_team_scratch + per_thread_scratch * team_size; policy_t p1(league_size, team_size); ASSERT_EQ(p1.league_size(), league_size); ASSERT_EQ(p1.team_size(), team_size); // FIXME_SYCL implement chunk_size #ifndef KOKKOS_ENABLE_SYCL ASSERT_TRUE(p1.chunk_size() > 0); #endif ASSERT_EQ(p1.scratch_size(0), 0); policy_t p2 = p1.set_chunk_size(chunk_size); ASSERT_EQ(p1.league_size(), league_size); ASSERT_EQ(p1.team_size(), team_size); ASSERT_EQ(p1.chunk_size(), chunk_size); ASSERT_EQ(p1.scratch_size(0), 0); ASSERT_EQ(p2.league_size(), league_size); ASSERT_EQ(p2.team_size(), team_size); ASSERT_EQ(p2.chunk_size(), chunk_size); ASSERT_EQ(p2.scratch_size(0), 0); policy_t p3 = p2.set_scratch_size(0, Kokkos::PerTeam(per_team_scratch)); ASSERT_EQ(p2.league_size(), league_size); ASSERT_EQ(p2.team_size(), team_size); ASSERT_EQ(p2.chunk_size(), chunk_size); ASSERT_EQ(p2.scratch_size(0), per_team_scratch); ASSERT_EQ(p3.league_size(), league_size); ASSERT_EQ(p3.team_size(), team_size); ASSERT_EQ(p3.chunk_size(), chunk_size); ASSERT_EQ(p3.scratch_size(0), per_team_scratch); policy_t p4 = p2.set_scratch_size(0, Kokkos::PerThread(per_thread_scratch)); ASSERT_EQ(p2.league_size(), league_size); ASSERT_EQ(p2.team_size(), team_size); ASSERT_EQ(p2.chunk_size(), chunk_size); ASSERT_EQ(p2.scratch_size(0), scratch_size); ASSERT_EQ(p4.league_size(), league_size); ASSERT_EQ(p4.team_size(), team_size); ASSERT_EQ(p4.chunk_size(), chunk_size); ASSERT_EQ(p4.scratch_size(0), scratch_size); policy_t p5 = p2.set_scratch_size(0, Kokkos::PerThread(per_thread_scratch), Kokkos::PerTeam(per_team_scratch)); ASSERT_EQ(p2.league_size(), league_size); ASSERT_EQ(p2.team_size(), team_size); ASSERT_EQ(p2.chunk_size(), chunk_size); ASSERT_EQ(p2.scratch_size(0), scratch_size); ASSERT_EQ(p5.league_size(), league_size); ASSERT_EQ(p5.team_size(), team_size); ASSERT_EQ(p5.chunk_size(), chunk_size); ASSERT_EQ(p5.scratch_size(0), scratch_size); policy_t p6 = p2.set_scratch_size(0, Kokkos::PerTeam(per_team_scratch), Kokkos::PerThread(per_thread_scratch)); ASSERT_EQ(p2.league_size(), league_size); ASSERT_EQ(p2.team_size(), team_size); ASSERT_EQ(p2.chunk_size(), chunk_size); ASSERT_EQ(p2.scratch_size(0), scratch_size); ASSERT_EQ(p6.league_size(), league_size); ASSERT_EQ(p6.team_size(), team_size); ASSERT_EQ(p6.chunk_size(), chunk_size); ASSERT_EQ(p6.scratch_size(0), scratch_size); policy_t p7 = p3.set_scratch_size(0, Kokkos::PerTeam(per_team_scratch), Kokkos::PerThread(per_thread_scratch)); ASSERT_EQ(p3.league_size(), league_size); ASSERT_EQ(p3.team_size(), team_size); ASSERT_EQ(p3.chunk_size(), chunk_size); ASSERT_EQ(p3.scratch_size(0), scratch_size); ASSERT_EQ(p7.league_size(), league_size); ASSERT_EQ(p7.team_size(), team_size); ASSERT_EQ(p7.chunk_size(), chunk_size); ASSERT_EQ(p7.scratch_size(0), scratch_size); policy_t p8; // default constructed ASSERT_EQ(p8.league_size(), 0); ASSERT_EQ(p8.scratch_size(0), 0); p8 = p3; // call assignment operator ASSERT_EQ(p3.league_size(), league_size); ASSERT_EQ(p3.team_size(), team_size); ASSERT_EQ(p3.chunk_size(), chunk_size); ASSERT_EQ(p3.scratch_size(0), scratch_size); ASSERT_EQ(p8.league_size(), league_size); ASSERT_EQ(p8.team_size(), team_size); ASSERT_EQ(p8.chunk_size(), chunk_size); ASSERT_EQ(p8.scratch_size(0), scratch_size); } void test_run_time_parameters() { test_run_time_parameters_type>(); test_run_time_parameters_type< Kokkos::TeamPolicy, Kokkos::IndexType>>(); test_run_time_parameters_type< Kokkos::TeamPolicy, ExecutionSpace, Kokkos::Schedule>>(); test_run_time_parameters_type< Kokkos::TeamPolicy, Kokkos::IndexType, ExecutionSpace, SomeTag>>(); } }; // semiregular is copyable and default initializable // (regular requires equality comparable) template void check_semiregular() { static_assert(std::is_default_constructible::value, ""); static_assert(std::is_copy_constructible::value, ""); static_assert(std::is_move_constructible::value, ""); static_assert(std::is_copy_assignable::value, ""); static_assert(std::is_move_assignable::value, ""); static_assert(std::is_destructible::value, ""); } TEST(TEST_CATEGORY, policy_construction) { check_semiregular>(); check_semiregular>(); check_semiregular>>(); TestRangePolicyConstruction(); TestTeamPolicyConstruction(); } template