Skip to content

Commit

Permalink
Adapt tests to new View implementation
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Morales <[email protected]>
  • Loading branch information
crtrott and nmm0 committed Oct 10, 2024
1 parent 3ac1f7c commit be5a910
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 15 deletions.
18 changes: 13 additions & 5 deletions containers/src/Kokkos_DynRankView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,11 @@ class DynRankView : private View<DataType*******, Properties...> {
using view_type = View<DataType*******, Properties...>;

private:
using drdtraits = Impl::DynRankDimTraits<typename view_type::specialize>;

#ifndef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
using drdtraits = Impl::DynRankDimTraits<void>;
#else
using drdtraits = Impl::DynRankDimTraits<typename view_type::specialize>;
#endif
public:
// typedefs from ViewTraits, overriden
using data_type = typename drvtraits::data_type;
Expand Down Expand Up @@ -452,7 +455,11 @@ class DynRankView : private View<DataType*******, Properties...> {
using scalar_array_type = value_type;
using const_scalar_array_type = const_value_type;
using non_const_scalar_array_type = non_const_value_type;
using specialize = typename view_type::specialize;
#ifndef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
using specialize = void;
#else
using specialize = typename view_type::specialize;
#endif

// typedefs in View for mdspan compatibility
// cause issues with MSVC+CUDA
Expand Down Expand Up @@ -613,8 +620,9 @@ class DynRankView : private View<DataType*******, Properties...> {
return *this;
}

#if 0 // TODO: this will later be swapped in depending on whether the new View
// impl is active
#ifndef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
// TODO: this will later be swapped in depending on whether the new View
// impl is active
private:
template <class Ext>
KOKKOS_FUNCTION typename view_type::extents_type create_rank7_extents(
Expand Down
2 changes: 1 addition & 1 deletion containers/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ foreach(Tag Threads;Serial;OpenMP;HPX;Cuda;HIP;SYCL)
WithoutInitializing
UnorderedMap
Vector
ViewCtorPropEmbeddedDim
# ViewCtorPropEmbeddedDim
)
if(NOT Kokkos_ENABLE_DEPRECATED_CODE_4 AND Name STREQUAL "Vector")
continue() # skip Kokkos::vector test if deprecated code 4 is not enabled
Expand Down
7 changes: 6 additions & 1 deletion containers/unit_tests/TestDynRankViewTypedefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,13 @@ namespace TestIntAtomic {
std::conditional_t<!has_unified_mem_space, Kokkos::HostSpace,
// otherwise its the following Device type
Kokkos::Device<Kokkos::DefaultHostExecutionSpace, typename Kokkos::DefaultExecutionSpace::memory_space>>>;
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
using expected_ref_type = Kokkos::Impl::AtomicDataElement<Kokkos::ViewTraits<int*******, Kokkos::MemoryTraits<Kokkos::Atomic>>>;
#else
using expected_ref_type = desul::AtomicRef<int, desul::MemoryOrderRelaxed, desul::MemoryScopeDevice>;
#endif
static_assert(test_view_typedefs<layout_type, space, memory_traits, host_mirror_space, int,
Kokkos::Impl::AtomicDataElement<Kokkos::ViewTraits<int*******, Kokkos::MemoryTraits<Kokkos::Atomic>>>>(
expected_ref_type>(
ViewParams<int, Kokkos::MemoryTraits<Kokkos::Atomic>>{}));
}
// clang-format on
Expand Down
3 changes: 3 additions & 0 deletions core/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ foreach(Tag Threads;Serial;OpenMP;Cuda;HPX;OpenMPTarget;OpenACC;HIP;SYCL)
if(KOKKOS_CXX_COMPILER_ID STREQUAL Intel)
list(REMOVE_ITEM ${Tag}_TESTNAMES2A ViewCopy_c)
endif()
if(NOT Kokkos_ENABLE_IMPL_VIEW_LEGACY)
list(REMOVE_ITEM ${Tag}_TESTNAMES2A ViewHooks)
endif()
foreach(Name IN LISTS ${Tag}_TESTNAMES2A)
set(file ${dir}/Test${Tag}_${Name}.cpp)
# Write to a temporary intermediate file and call configure_file to avoid
Expand Down
5 changes: 5 additions & 0 deletions core/unit_test/TestAtomicViews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ class TestAtomicViewAPI {

dView4_unmanaged unmanaged_dx = dx;
ASSERT_EQ(dx.use_count(), 2);
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
ASSERT_EQ(unmanaged_dx.use_count(), 2);
#else
ASSERT_EQ(unmanaged_dx.use_count(), 0);
#endif

az = ax;
ASSERT_EQ(dx.use_count(), 3);
Expand Down
4 changes: 2 additions & 2 deletions core/unit_test/TestMDSpanConversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct TestViewMDSpanConversion {
static_assert(std::is_constructible_v<natural_mdspan_type, mdspan_type>);
static_assert(std::is_convertible_v<mdspan_type, natural_mdspan_type> ==
std::is_convertible_v<mdspan_type, unmanaged_view_type>);
// Manually create an mdspan from ref so we have a valid pointer to play
// with
// Manually create an mdspan from ref so we have a valid pointer to play
// with
const auto &exts = mapping.extents();
auto mds = mdspan_type{ref.data(), mapping};

Expand Down
2 changes: 2 additions & 0 deletions core/unit_test/TestOther.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@
#include <TestMemoryPool.hpp>
#include <TestCXX11.hpp>

#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
#include <TestViewCtorPropEmbeddedDim.hpp>
#endif
#endif
11 changes: 9 additions & 2 deletions core/unit_test/TestViewIsAssignable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ template <class ViewTypeDst, class ViewTypeSrc>
struct TestAssignability {
using mapping_type =
Kokkos::Impl::ViewMapping<typename ViewTypeDst::traits,
typename ViewTypeSrc::traits,
typename ViewTypeDst::specialize>;
typename ViewTypeSrc::traits
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
,
typename ViewTypeDst::specialize
#else
,
void
#endif
>;

template <class MappingType>
static void try_assign(
Expand Down
2 changes: 2 additions & 0 deletions core/unit_test/TestViewLayoutStrideAssignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,4 +888,6 @@ TEST(TEST_CATEGORY_DEATH, view_layoutstride_left_to_layoutright_assignment) {

} // namespace Test

#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
#include <TestIrregularLayout.hpp>
#endif
11 changes: 11 additions & 0 deletions core/unit_test/TestViewMapping_a.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,14 +991,25 @@ void test_view_mapping() {

ASSERT_EQ(a.use_count(), 2);
ASSERT_EQ(b.use_count(), 2);
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
ASSERT_EQ(c.use_count(), 2);
#else
ASSERT_EQ(c.use_count(), 0);
#endif

V d = c; // 'd' is run-time unmanaged.

ASSERT_EQ(a.use_count(), 2);
ASSERT_EQ(b.use_count(), 2);
// FIXME: Legacy View is weird: it passes on use count even through compile time
// unmanaged transition
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
ASSERT_EQ(c.use_count(), 2);
ASSERT_EQ(d.use_count(), 2);
#else
ASSERT_EQ(c.use_count(), 0);
ASSERT_EQ(d.use_count(), 0);
#endif
}

ASSERT_EQ(a.use_count(), 2);
Expand Down
13 changes: 12 additions & 1 deletion core/unit_test/TestViewTypedefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ constexpr bool test_view_typedefs_impl() {
static_assert(std::is_same_v<typename ViewType::scalar_array_type, DataType>);
static_assert(std::is_same_v<typename ViewType::const_scalar_array_type, typename data_analysis<DataType>::const_data_type>);
static_assert(std::is_same_v<typename ViewType::non_const_scalar_array_type, typename data_analysis<DataType>::non_const_data_type>);
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
static_assert(std::is_same_v<typename ViewType::specialize, void>);
#endif

// FIXME: value_type definition conflicts with mdspan value_type
static_assert(std::is_same_v<typename ViewType::value_type, ValueType>);
Expand All @@ -73,7 +75,9 @@ constexpr bool test_view_typedefs_impl() {
static_assert(std::is_same_v<typename ViewType::array_layout, Layout>);

// FIXME: should be deprecated and is some complicated impl type
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
static_assert(!std::is_void_v<typename ViewType::dimension>);
#endif

static_assert(std::is_same_v<typename ViewType::execution_space, typename Space::execution_space>);
static_assert(std::is_same_v<typename ViewType::memory_space, typename Space::memory_space>);
Expand Down Expand Up @@ -163,7 +167,9 @@ constexpr bool test_view_typedefs_impl() {
static_assert(std::is_same_v<typename ViewType::rank_type, size_t>);

// FIXME: should come from accessor_type
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
static_assert(std::is_same_v<typename ViewType::data_handle_type, typename ViewType::pointer_type>);
#endif
static_assert(std::is_same_v<typename ViewType::reference, typename ViewType::reference_type>);
return true;
}
Expand Down Expand Up @@ -267,7 +273,12 @@ namespace TestIntAtomic {
// otherwise its the following Device type
Kokkos::Device<Kokkos::DefaultHostExecutionSpace, typename Kokkos::DefaultExecutionSpace::memory_space>>>;
static_assert(test_view_typedefs<layout_type, space, memory_traits, host_mirror_space, int,
Kokkos::Impl::AtomicDataElement<Kokkos::ViewTraits<int, Kokkos::MemoryTraits<Kokkos::Atomic>>>>(
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
Kokkos::Impl::AtomicDataElement<Kokkos::ViewTraits<int, Kokkos::MemoryTraits<Kokkos::Atomic>>>
#else
desul::AtomicRef<int, desul::MemoryOrderRelaxed, desul::MemoryScopeDevice>
#endif
>(
ViewParams<int, Kokkos::MemoryTraits<Kokkos::Atomic>>{}));
}
// clang-format on
Expand Down
6 changes: 5 additions & 1 deletion core/unit_test/cuda/TestCuda_Spaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,16 @@ struct TestViewCudaTexture {

static void run() {
EXPECT_TRUE((std::is_same<typename V::reference_type, double &>::value));
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
EXPECT_TRUE(
(std::is_same<typename T::reference_type, const double>::value));
#endif

EXPECT_TRUE(V::reference_type_is_lvalue_reference); // An ordinary view.
EXPECT_TRUE(V::reference_type_is_lvalue_reference); // An ordinary view.
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
EXPECT_FALSE(T::reference_type_is_lvalue_reference); // Texture fetch
// returns by value.
#endif

TestViewCudaTexture self;
Kokkos::parallel_for(Kokkos::RangePolicy<Kokkos::Cuda, TagInit>(0, N),
Expand Down
3 changes: 1 addition & 2 deletions core/unit_test/default/TestDefaultDeviceDevelop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

#include <TestDefaultDeviceType_Category.hpp>

#include <TestViewIsAssignable.hpp>
namespace Test {

TEST(defaultdevicetype, development_test) {}

} // namespace Test

0 comments on commit be5a910

Please sign in to comment.