diff --git a/core/src/View/MDSpan/Kokkos_MDSpan_Accessor.hpp b/core/src/View/MDSpan/Kokkos_MDSpan_Accessor.hpp index 732050a20a4..03db33a9bf8 100644 --- a/core/src/View/MDSpan/Kokkos_MDSpan_Accessor.hpp +++ b/core/src/View/MDSpan/Kokkos_MDSpan_Accessor.hpp @@ -227,7 +227,12 @@ class ReferenceCountedDataHandle { m_tracker.assign_allocated_record_to_uninitialized(rec); m_handle = static_cast(get_record()->data()); } - ReferenceCountedDataHandle(pointer ptr): m_tracker(), m_handle(ptr) {} + + template >> + ReferenceCountedDataHandle(OtherElementType* ptr) + : m_tracker(), m_handle(ptr) {} ReferenceCountedDataHandle(const ReferenceCountedDataHandle&) = default; ReferenceCountedDataHandle(ReferenceCountedDataHandle&&) noexcept = default; @@ -270,7 +275,12 @@ class ReferenceCountedDataHandle { m_tracker.assign_allocated_record_to_uninitialized(rec); m_handle = static_cast(get_record()->data()); } - ReferenceCountedDataHandle(pointer ptr) : m_tracker(), m_handle(ptr) {} + + template >> + ReferenceCountedDataHandle(OtherElementType* ptr) + : m_tracker(), m_handle(ptr) {} ReferenceCountedDataHandle(const ReferenceCountedDataHandle&) = default; ReferenceCountedDataHandle(ReferenceCountedDataHandle&&) noexcept = default; @@ -313,6 +323,12 @@ class ReferenceCountedAccessor { constexpr ReferenceCountedAccessor() noexcept = default; + template >> + constexpr ReferenceCountedAccessor( + const ReferenceCountedAccessor&) {} + constexpr reference access(data_handle_type p, size_t i) const { return p.get()[i]; } @@ -337,6 +353,12 @@ class ReferenceCountedAccessor { constexpr ReferenceCountedAccessor( const ReferenceCountedAccessor&) {} + template >> + constexpr ReferenceCountedAccessor( + const ReferenceCountedAccessor&) {} + constexpr reference access(data_handle_type p, size_t i) const { return p.get()[i]; } diff --git a/core/unit_test/CMakeLists.txt b/core/unit_test/CMakeLists.txt index 51a94897019..3ad36ab7b2c 100644 --- a/core/unit_test/CMakeLists.txt +++ b/core/unit_test/CMakeLists.txt @@ -97,6 +97,7 @@ SET(COMPILE_ONLY_SOURCES TestTeamMDRangePolicyCTAD.cpp TestNestedReducerCTAD.cpp view/TestExtentsDatatypeConversion.cpp + view/TestBasicViewMDSpanConversion.cpp ) #testing if windows.h and Kokkos_Core.hpp can be included diff --git a/core/unit_test/view/TestBasicViewMDSpanConversion.cpp b/core/unit_test/view/TestBasicViewMDSpanConversion.cpp new file mode 100644 index 00000000000..4866297ff51 --- /dev/null +++ b/core/unit_test/view/TestBasicViewMDSpanConversion.cpp @@ -0,0 +1,45 @@ +//@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 + +#ifdef KOKKOS_ENABLE_IMPL_MDSPAN +static_assert( + std::is_convertible_v< + Kokkos::View, + Kokkos::BasicView, + Kokkos::Experimental::layout_right_padded<>, + Kokkos::Impl::checked_reference_counted_accessor< + long long, Kokkos::HostSpace>>>); +static_assert( + std::is_convertible_v< + Kokkos::BasicView, + Kokkos::Experimental::layout_right_padded<>, + Kokkos::Impl::checked_reference_counted_accessor< + long long, Kokkos::HostSpace>>, + Kokkos::BasicView, + Kokkos::Experimental::layout_right_padded<>, + Kokkos::Impl::checked_reference_counted_accessor< + const long long, Kokkos::HostSpace>>>); +static_assert( + std::is_convertible_v< + Kokkos::View, + Kokkos::BasicView, + Kokkos::Experimental::layout_right_padded<>, + Kokkos::Impl::checked_reference_counted_accessor< + const long long, Kokkos::HostSpace>>>); +#endif