//@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 namespace Test { namespace Impl { template struct TestAssignability { using mapping_type = Kokkos::Impl::ViewMapping; template static void try_assign( ViewTypeDst& dst, ViewTypeSrc& src, std::enable_if_t* = nullptr) { dst = src; } template static void try_assign( ViewTypeDst&, ViewTypeSrc&, std::enable_if_t* = nullptr) { FAIL() << "TestAssignability::try_assign: Unexpected call path"; } template static void test(bool always, bool sometimes, Dimensions... dims) { ViewTypeDst dst; ViewTypeSrc src("SRC", dims...); bool is_always_assignable = Kokkos::is_always_assignable::value; bool is_assignable = Kokkos::is_assignable(dst, src); if (sometimes) { try_assign(dst, src); } ASSERT_EQ(always, is_always_assignable) << Kokkos::Impl::TypeInfo::name() << " to " << Kokkos::Impl::TypeInfo::name(); ASSERT_EQ(sometimes, is_assignable) << Kokkos::Impl::TypeInfo::name() << " to " << Kokkos::Impl::TypeInfo::name(); } }; } // namespace Impl TEST(TEST_CATEGORY, view_is_assignable) { using namespace Kokkos; using h_exec = typename DefaultHostExecutionSpace::memory_space; using d_exec = typename TEST_EXECSPACE::memory_space; using left = LayoutLeft; using right = LayoutRight; using stride = LayoutStride; // Static/Dynamic Extents Impl::TestAssignability, View>::test(true, true, 10); Impl::TestAssignability, View>::test(false, true, 10); Impl::TestAssignability, View>::test(false, false, 10); Impl::TestAssignability, View>::test(true, true); Impl::TestAssignability, View>::test(true, true); Impl::TestAssignability, View>::test(false, false); Impl::TestAssignability, View>::test(true, true, 10, 10); Impl::TestAssignability, View>::test(false, true, 10, 10); Impl::TestAssignability, View>::test(false, false, 10, 10); Impl::TestAssignability, View>::test(true, true, 10); Impl::TestAssignability, View>::test(true, true, 10); Impl::TestAssignability, View>::test(false, false, 10); // Mismatch value_type Impl::TestAssignability, View>::test(false, false, 10); // Layout assignment Impl::TestAssignability, View>::test(true, true); Impl::TestAssignability, View>::test(true, true, 10); Impl::TestAssignability, View>::test(false, false, 10); Impl::TestAssignability, View>::test(false, true, 10); Impl::TestAssignability, View>::test(true, true); Impl::TestAssignability, View>::test(false, false); // This could be made possible (due to the degenerate nature of the views) but // we do not allow this yet // TestAssignability,View>::test(false,true,10,1); Impl::TestAssignability, View>::test(false, false, 10, 2); Impl::TestAssignability, View>::test(true, true, 10, 2); Impl::TestAssignability, View>::test(true, true, 10, 2); // Space Assignment bool expected = Kokkos::Impl::MemorySpaceAccess::assignable; Impl::TestAssignability, View>::test(expected, expected, 10); expected = Kokkos::Impl::MemorySpaceAccess::assignable; Impl::TestAssignability, View>::test(expected, expected, 10); // reference type and const-qualified types using SomeViewType = View; static_assert(is_always_assignable_v); static_assert(is_always_assignable_v); static_assert(is_always_assignable_v); static_assert(is_always_assignable_v); static_assert(is_always_assignable_v); static_assert(is_always_assignable_v); static_assert(is_always_assignable_v); static_assert(is_always_assignable_v); } } // namespace Test