//@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 #ifndef KOKKOS_ENABLE_CXX17 #include #endif template struct funky_data_handle { T* val; KOKKOS_FUNCTION operator T*() { return val; } KOKKOS_FUNCTION operator const T*() const { return val; } }; template struct FunkyAcc { using element_type = ElementType; using reference = std::conditional_t, element_type, element_type&>; using data_handle_type = funky_data_handle; using offset_policy = Kokkos::default_accessor; KOKKOS_FUNCTION reference access(data_handle_type p, size_t i) const { return p.val[i]; } KOKKOS_FUNCTION element_type* offset(data_handle_type p, size_t i) const { return p.val + i; } }; template void test_space_aware_accessor() { using memory_space_t = MemorySpace; using value_type = std::remove_const_t; Kokkos::View v("V", 100); Kokkos::parallel_for( Kokkos::RangePolicy(0, v.extent(0)), KOKKOS_LAMBDA(int i) { v(i) = i; }); int errors; using acc_t = Kokkos::Impl::SpaceAwareAccessor>; acc_t acc{}; typename acc_t::data_handle_type ptr{v.data()}; Kokkos::parallel_reduce( Kokkos::RangePolicy(0, v.extent(0)), KOKKOS_LAMBDA(int i, int& error) { if (acc.access(ptr, i) != ptr[i]) error++; if (acc.offset(ptr, i) != ptr + i) error++; static_assert(std::is_same_v); if constexpr (std::is_const_v) { static_assert(std::is_same_v); } else { static_assert(std::is_same_v); } static_assert(std::is_same_v>); static_assert( std::is_same_v>>); if constexpr (std::is_const_v) { static_assert(std::is_same_v>); } else { static_assert(std::is_same_v); } static_assert(std::is_same_v); static_assert(std::is_same_v&>); static_assert(std::is_nothrow_move_constructible_v); static_assert(std::is_nothrow_move_assignable_v); static_assert(std::is_nothrow_swappable_v); static_assert( std::is_same_v); static_assert( std::is_same_v>); #ifndef KOKKOS_ENABLE_CXX17 static_assert(std::copyable); static_assert(std::is_empty_v); #endif }, errors); ASSERT_EQ(errors, 0); } void test_space_aware_accessor_conversion() { using ExecutionSpace = TEST_EXECSPACE; using memory_space_t = typename ExecutionSpace::memory_space; using T = float; using acc_t = Kokkos::Impl::SpaceAwareAccessor>; using const_acc_t = Kokkos::Impl::SpaceAwareAccessor>; using int_acc_t = Kokkos::Impl::SpaceAwareAccessor>; using host_acc_t = Kokkos::Impl::SpaceAwareAccessor>; using anon_acc_t = Kokkos::Impl::SpaceAwareAccessor>; Kokkos::parallel_for( Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int) { static_assert(std::is_constructible_v); static_assert(std::is_convertible_v); static_assert(!std::is_constructible_v); static_assert(!std::is_constructible_v); static_assert( std::is_constructible_v == Kokkos::Impl::MemorySpaceAccess::assignable); static_assert( std::is_constructible_v == Kokkos::Impl::MemorySpaceAccess::assignable); static_assert(std::is_constructible_v); static_assert(std::is_constructible_v); static_assert(std::is_convertible_v); static_assert(std::is_convertible_v); }); } TEST(TEST_CATEGORY, mdspan_space_aware_accessor) { using ExecutionSpace = TEST_EXECSPACE; test_space_aware_accessor(); test_space_aware_accessor(); test_space_aware_accessor(); test_space_aware_accessor(); test_space_aware_accessor(); test_space_aware_accessor(); test_space_aware_accessor_conversion(); }