Skip to content

Commit

Permalink
Add a CTAD to ChunkSpan from a Chunk (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau authored Dec 13, 2024
1 parent 0f8473c commit f225f2b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/ddc/chunk_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,22 @@ ChunkSpan(KokkosView const& view, DiscreteDomain<DDims...> domain)
detail::kokkos_to_mdspan_layout_t<typename KokkosView::array_layout>,
typename KokkosView::memory_space>;

template <class ElementType, class SupportType, class Allocator>
ChunkSpan(Chunk<ElementType, SupportType, Allocator>& other)
-> ChunkSpan<
ElementType,
SupportType,
Kokkos::layout_right,
typename Allocator::memory_space>;

template <class ElementType, class SupportType, class Allocator>
ChunkSpan(Chunk<ElementType, SupportType, Allocator> const& other)
-> ChunkSpan<
const ElementType,
SupportType,
Kokkos::layout_right,
typename Allocator::memory_space>;

template <
class ElementType,
class SupportType,
Expand Down
27 changes: 27 additions & 0 deletions tests/chunk_span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

#include <type_traits>
#include <utility>

#include <ddc/ddc.hpp>

Expand Down Expand Up @@ -33,3 +34,29 @@ TEST(ChunkSpan1DTest, ConstructionFromChunk)
EXPECT_TRUE((std::is_constructible_v<ChunkSpanX<const double>, ChunkX<double>&>));
EXPECT_TRUE((std::is_constructible_v<ChunkSpanX<const double>, ChunkX<double> const&>));
}

TEST(ChunkSpan1DTest, CtadFromChunk)
{
using LvalueRefChunkType = ChunkX<int>&;
EXPECT_TRUE((std::is_same_v<
decltype(ddc::ChunkSpan(std::declval<LvalueRefChunkType>())),
ddc::ChunkSpan<int, DDomX, Kokkos::layout_right, Kokkos::HostSpace>>));

using ConstLvalueRefChunkType = ChunkX<int> const&;
EXPECT_TRUE((std::is_same_v<
decltype(ddc::ChunkSpan(std::declval<ConstLvalueRefChunkType>())),
ddc::ChunkSpan<const int, DDomX, Kokkos::layout_right, Kokkos::HostSpace>>));
}

TEST(ChunkSpan1DTest, CtadFromKokkosView)
{
using ViewType = Kokkos::View<int*>;
EXPECT_TRUE((std::is_same_v<
decltype(ddc::ChunkSpan(std::declval<ViewType>(), std::declval<DDomX>())),
ddc::ChunkSpan<int, DDomX, Kokkos::layout_right, Kokkos::HostSpace>>));

using ConstViewType = Kokkos::View<const int*>;
EXPECT_TRUE((std::is_same_v<
decltype(ddc::ChunkSpan(std::declval<ConstViewType>(), std::declval<DDomX>())),
ddc::ChunkSpan<const int, DDomX, Kokkos::layout_right, Kokkos::HostSpace>>));
}

0 comments on commit f225f2b

Please sign in to comment.