Skip to content

Commit

Permalink
Add a test about ctad on device and remove CTAD SFINAE (#746)
Browse files Browse the repository at this point in the history
* Add a test about CTAD on device and remove CTAD SFINAE

* Add deduction guide annotation
  • Loading branch information
tpadioleau authored Jan 9, 2025
1 parent d6b6c54 commit ab6203a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
14 changes: 9 additions & 5 deletions include/ddc/chunk_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,17 @@ class ChunkSpan<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy, Memo
}
};

template <class KokkosView, class... DDims, class = std::enable_if_t<Kokkos::is_view_v<KokkosView>>>
ChunkSpan(KokkosView const& view, DiscreteDomain<DDims...> domain)
template <class DataType, class... Properties, class... DDims>
KOKKOS_DEDUCTION_GUIDE ChunkSpan(
Kokkos::View<DataType, Properties...> const& view,
DiscreteDomain<DDims...> domain)
-> ChunkSpan<
detail::kokkos_to_mdspan_element_t<typename KokkosView::data_type>,
detail::kokkos_to_mdspan_element_t<
typename Kokkos::View<DataType, Properties...>::data_type>,
DiscreteDomain<DDims...>,
detail::kokkos_to_mdspan_layout_t<typename KokkosView::array_layout>,
typename KokkosView::memory_space>;
detail::kokkos_to_mdspan_layout_t<
typename Kokkos::View<DataType, Properties...>::array_layout>,
typename Kokkos::View<DataType, Properties...>::memory_space>;

template <class ElementType, class SupportType, class Allocator>
ChunkSpan(Chunk<ElementType, SupportType, Allocator>& other)
Expand Down
26 changes: 26 additions & 0 deletions tests/chunk_span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ TEST(ChunkSpan1DTest, CtadFromKokkosView)
ddc::ChunkSpan<const int, DDomX, Kokkos::layout_right, Kokkos::HostSpace>>));
}

namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(CHUNK_SPAN_CPP) {

void TestChunkSpan1DTestCtadOnDevice()
{
Kokkos::View<int*, Kokkos::LayoutRight> const view("view", 3);
Kokkos::deep_copy(view, 1);
ddc::DiscreteElement<DDimX> const ix(0);
ddc::DiscreteDomain<DDimX> const ddom_x(ix, ddc::DiscreteVector<DDimX>(view.extent(0)));
int sum;
Kokkos::parallel_reduce(
view.extent(0),
KOKKOS_LAMBDA(int i, int& local_sum) {
ddc::ChunkSpan const chk_span(view, ddom_x);
local_sum += chk_span(ix + i);
},
sum);
EXPECT_EQ(sum, view.size());
}

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(CHUNK_SPAN_CPP)

TEST(ChunkSpan1DTest, CtadOnDevice)
{
TestChunkSpan1DTestCtadOnDevice();
}

TEST(ChunkSpan2DTest, CtorContiguousLayoutRightKokkosView)
{
Kokkos::View<int**, Kokkos::LayoutRight> const view("view", 133, 189);
Expand Down

0 comments on commit ab6203a

Please sign in to comment.