Skip to content

Commit

Permalink
kokkos#6805: fixe compilation with nvcc
Browse files Browse the repository at this point in the history
  • Loading branch information
nmm0 committed Mar 7, 2024
1 parent 6401ce2 commit de653dc
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 52 deletions.
2 changes: 1 addition & 1 deletion core/src/Kokkos_View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ template <class Traits>
struct MDSpanViewTraits<
Traits, std::void_t<typename Experimental::Impl::LayoutFromArrayLayout<
typename Traits::array_layout>::type>> {
using index_type = typename Traits::execution_space::size_type;
using index_type = std::size_t;
using extents_type = typename Experimental::Impl::ExtentsFromDataType<
index_type, typename Traits::data_type>::type;
using mdspan_layout_type = typename Experimental::Impl::LayoutFromArrayLayout<
Expand Down
6 changes: 3 additions & 3 deletions core/src/View/MDSpan/Kokkos_MDSpan_Layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ KOKKOS_INLINE_FUNCTION auto array_layout_leftright_from_mapping_impl(
template <>
struct ArrayLayoutFromMappingImpl<Kokkos::LayoutLeft> {
template <class MDSpanType>
static Kokkos::LayoutLeft construct(
KOKKOS_INLINE_FUNCTION static Kokkos::LayoutLeft construct(
const typename MDSpanType::mapping_type &mapping) {
return array_layout_leftright_from_mapping_impl<Kokkos::LayoutLeft,
MDSpanType>(mapping);
Expand All @@ -118,7 +118,7 @@ struct ArrayLayoutFromMappingImpl<Kokkos::LayoutLeft> {
template <>
struct ArrayLayoutFromMappingImpl<Kokkos::LayoutRight> {
template <class MDSpanType>
static Kokkos::LayoutRight construct(
KOKKOS_INLINE_FUNCTION static Kokkos::LayoutRight construct(
const typename MDSpanType::mapping_type &mapping) {
return array_layout_leftright_from_mapping_impl<Kokkos::LayoutRight,
MDSpanType>(mapping);
Expand All @@ -128,7 +128,7 @@ struct ArrayLayoutFromMappingImpl<Kokkos::LayoutRight> {
template <>
struct ArrayLayoutFromMappingImpl<Kokkos::LayoutStride> {
template <class MDSpanType>
static Kokkos::LayoutStride construct(
KOKKOS_INLINE_FUNCTION static Kokkos::LayoutStride construct(
const typename MDSpanType::mapping_type &mapping) {
using mapping_type = typename MDSpanType::mapping_type;
using extents_type = typename mapping_type::extents_type;
Expand Down
111 changes: 63 additions & 48 deletions core/unit_test/view/TestMDSpanConversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,126 +120,141 @@ struct TestViewMDSpanConversion {
value_type)>>::type,
Kokkos::LayoutRight>);

// nvcc doesn't do CTAD properly here, making this way more verbose..
// LayoutLeft
test_conversion_from_mdspan<Kokkos::LayoutLeft>(
Kokkos::View<value_type *, Kokkos::LayoutLeft>("ref", 7),
typename layout_left_padded<sizeof(value_type)>::mapping{
Kokkos::extents<std::size_t, Kokkos::dynamic_extent>(7)});
typename layout_left_padded<sizeof(
value_type)>::template mapping<Kokkos::dextents<std::size_t, 1>>{
Kokkos::dextents<std::size_t, 1>(7)});
test_conversion_from_mdspan<Kokkos::LayoutLeft>(
Kokkos::View<value_type[7], Kokkos::LayoutLeft>("ref"),
typename layout_left_padded<sizeof(value_type)>::mapping{
typename layout_left_padded<sizeof(
value_type)>::template mapping<Kokkos::extents<std::size_t, 7>>{
Kokkos::extents<std::size_t, 7>()});
test_conversion_from_mdspan<Kokkos::LayoutLeft>(
Kokkos::View<value_type[7], Kokkos::LayoutLeft>("ref"),
typename layout_left_padded<sizeof(value_type)>::mapping{
Kokkos::extents<std::size_t, Kokkos::dynamic_extent>(7)});
typename layout_left_padded<sizeof(
value_type)>::template mapping<Kokkos::dextents<std::size_t, 1>>{
Kokkos::dextents<std::size_t, 1>(7)});
test_conversion_from_mdspan<Kokkos::LayoutLeft>(
Kokkos::View<value_type *, Kokkos::LayoutLeft>("ref", 7),
typename layout_left_padded<sizeof(value_type)>::mapping{
typename layout_left_padded<sizeof(
value_type)>::template mapping<Kokkos::extents<std::size_t, 7>>{
Kokkos::extents<std::size_t, 7>()});

test_conversion_from_mdspan<Kokkos::LayoutLeft>(
Kokkos::View<value_type **, Kokkos::LayoutLeft>("ref", 7, 3),
typename layout_left_padded<sizeof(value_type)>::mapping{
typename layout_left_padded<sizeof(
value_type)>::template mapping<Kokkos::dextents<std::size_t, 2>>{
Kokkos::dextents<std::size_t, 2>(7, 3)});
test_conversion_from_mdspan<Kokkos::LayoutLeft>(
Kokkos::View<value_type[7][3], Kokkos::LayoutLeft>("ref"),
typename layout_left_padded<sizeof(value_type)>::mapping{
typename layout_left_padded<sizeof(
value_type)>::template mapping<Kokkos::extents<std::size_t, 7, 3>>{
Kokkos::extents<std::size_t, 7, 3>()});
test_conversion_from_mdspan<Kokkos::LayoutLeft>(
Kokkos::View<value_type[7][3], Kokkos::LayoutLeft>("ref"),
typename layout_left_padded<sizeof(value_type)>::mapping{
Kokkos::extents<std::size_t, Kokkos::dynamic_extent,
Kokkos::dynamic_extent>(7, 3)});
typename layout_left_padded<sizeof(
value_type)>::template mapping<Kokkos::dextents<std::size_t, 2>>{
Kokkos::dextents<std::size_t, 2>(7, 3)});
test_conversion_from_mdspan<Kokkos::LayoutLeft>(
Kokkos::View<value_type **, Kokkos::LayoutLeft>("ref", 7, 3),
typename layout_left_padded<sizeof(value_type)>::mapping{
typename layout_left_padded<sizeof(
value_type)>::template mapping<Kokkos::extents<std::size_t, 7, 3>>{
Kokkos::extents<std::size_t, 7, 3>()});

// LayoutRight
test_conversion_from_mdspan<Kokkos::LayoutRight>(
Kokkos::View<value_type *, Kokkos::LayoutRight>("ref", 7),
typename layout_right_padded<sizeof(value_type)>::mapping{
Kokkos::extents<std::size_t, Kokkos::dynamic_extent>(7)});
typename layout_right_padded<sizeof(
value_type)>::template mapping<Kokkos::dextents<std::size_t, 1>>{
Kokkos::dextents<std::size_t, 1>(7)});
test_conversion_from_mdspan<Kokkos::LayoutRight>(
Kokkos::View<value_type[7], Kokkos::LayoutRight>("ref"),
typename layout_right_padded<sizeof(value_type)>::mapping{
typename layout_right_padded<sizeof(
value_type)>::template mapping<Kokkos::extents<std::size_t, 7>>{
Kokkos::extents<std::size_t, 7>()});
test_conversion_from_mdspan<Kokkos::LayoutRight>(
Kokkos::View<value_type[7], Kokkos::LayoutRight>("ref"),
typename layout_right_padded<sizeof(value_type)>::mapping{
Kokkos::extents<std::size_t, Kokkos::dynamic_extent>(7)});
typename layout_right_padded<sizeof(
value_type)>::template mapping<Kokkos::dextents<std::size_t, 1>>{
Kokkos::dextents<std::size_t, 1>(7)});
test_conversion_from_mdspan<Kokkos::LayoutRight>(
Kokkos::View<value_type *, Kokkos::LayoutRight>("ref", 7),
typename layout_right_padded<sizeof(value_type)>::mapping{
typename layout_right_padded<sizeof(
value_type)>::template mapping<Kokkos::extents<std::size_t, 7>>{
Kokkos::extents<std::size_t, 7>()});

test_conversion_from_mdspan<Kokkos::LayoutRight>(
Kokkos::View<value_type **, Kokkos::LayoutRight>("ref", 7, 3),
typename layout_right_padded<sizeof(value_type)>::mapping{
typename layout_right_padded<sizeof(
value_type)>::template mapping<Kokkos::dextents<std::size_t, 2>>{
Kokkos::dextents<std::size_t, 2>(7, 3)});
test_conversion_from_mdspan<Kokkos::LayoutRight>(
Kokkos::View<value_type[7][3], Kokkos::LayoutRight>("ref"),
typename layout_right_padded<sizeof(value_type)>::mapping{
typename layout_right_padded<sizeof(
value_type)>::template mapping<Kokkos::extents<std::size_t, 7, 3>>{
Kokkos::extents<std::size_t, 7, 3>()});
test_conversion_from_mdspan<Kokkos::LayoutRight>(
Kokkos::View<value_type[7][3], Kokkos::LayoutRight>("ref"),
typename layout_right_padded<sizeof(value_type)>::mapping{
Kokkos::extents<std::size_t, Kokkos::dynamic_extent,
Kokkos::dynamic_extent>(7, 3)});
typename layout_right_padded<sizeof(
value_type)>::template mapping<Kokkos::dextents<std::size_t, 2>>{
Kokkos::dextents<std::size_t, 2>(7, 3)});
test_conversion_from_mdspan<Kokkos::LayoutRight>(
Kokkos::View<value_type **, Kokkos::LayoutRight>("ref", 7, 3),
typename layout_right_padded<sizeof(value_type)>::mapping{
typename layout_right_padded<sizeof(
value_type)>::template mapping<Kokkos::extents<std::size_t, 7, 3>>{
Kokkos::extents<std::size_t, 7, 3>()});

// LayoutStride
test_conversion_from_mdspan<Kokkos::LayoutStride>(
Kokkos::View<value_type *, Kokkos::LayoutStride>(
"ref", Kokkos::LayoutStride{7, 2}),
Kokkos::layout_stride::mapping{
Kokkos::extents<std::size_t, Kokkos::dynamic_extent>(7),
std::array{2}});
Kokkos::layout_stride::mapping<Kokkos::dextents<std::size_t, 1>>{
Kokkos::dextents<std::size_t, 1>{7},
std::array<std::size_t, 1>{2}});
test_conversion_from_mdspan<Kokkos::LayoutStride>(
Kokkos::View<value_type[7], Kokkos::LayoutStride>(
"ref", Kokkos::LayoutStride{7, 2}),
Kokkos::layout_stride::mapping{Kokkos::extents<std::size_t, 7>(),
std::array{2}});
Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 7>>{
{}, std::array<std::size_t, 1>{2}});
test_conversion_from_mdspan<Kokkos::LayoutStride>(
Kokkos::View<value_type[7], Kokkos::LayoutStride>(
"ref", Kokkos::LayoutStride{7, 2}),
Kokkos::layout_stride::mapping{
Kokkos::extents<std::size_t, Kokkos::dynamic_extent>(7),
std::array{2}});
Kokkos::layout_stride::mapping<Kokkos::dextents<std::size_t, 1>>{
Kokkos::dextents<std::size_t, 1>{7},
std::array<std::size_t, 1>{2}});
test_conversion_from_mdspan<Kokkos::LayoutStride>(
Kokkos::View<value_type *, Kokkos::LayoutStride>(
"ref", Kokkos::LayoutStride{7, 2}),
Kokkos::layout_stride::mapping{Kokkos::extents<std::size_t, 7>(),
std::array{2}});
Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 7>>{
Kokkos::extents<std::size_t, 7>(), std::array<std::size_t, 1>{2}});

test_conversion_from_mdspan<Kokkos::LayoutStride>(
Kokkos::View<value_type **, Kokkos::LayoutStride>(
"ref", Kokkos::LayoutStride{7, 2, 3, 4}),
Kokkos::layout_stride::mapping{
Kokkos::layout_stride::mapping<Kokkos::dextents<std::size_t, 2>>{
Kokkos::dextents<std::size_t, 2>(7, 3),
std::array{2, 4}});
std::array<std::size_t, 2>{2, 4}});
test_conversion_from_mdspan<Kokkos::LayoutStride>(
Kokkos::View<value_type[7][3], Kokkos::LayoutStride>(
"ref", Kokkos::LayoutStride{7, 2, 3, 4}),
Kokkos::layout_stride::mapping{
Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 7, 3>>{
Kokkos::extents<std::size_t, 7, 3>(),
std::array{2, 4}});
std::array<std::size_t, 2>{2, 4}});
test_conversion_from_mdspan<Kokkos::LayoutStride>(
Kokkos::View<value_type[7][3], Kokkos::LayoutStride>(
"ref", Kokkos::LayoutStride{7, 2, 3, 4}),
Kokkos::layout_stride::mapping{
Kokkos::layout_stride::mapping<Kokkos::dextents<std::size_t, 2>>{
Kokkos::dextents<std::size_t, 2>(7, 3),
std::array{2, 4}});
std::array<std::size_t, 2>{2, 4}});
test_conversion_from_mdspan<Kokkos::LayoutStride>(
Kokkos::View<value_type **, Kokkos::LayoutStride>(
"ref", Kokkos::LayoutStride{7, 2, 3, 4}),
Kokkos::layout_stride::mapping{
Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 7, 3>>{
Kokkos::extents<std::size_t, 7, 3>(),
std::array{2, 4}});
std::array<std::size_t, 2>{2, 4}});

// Conversion to mdspan
test_conversion_to_mdspan(layout_left_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4>>({}, 4), Kokkos::View<value_type *, Kokkos::LayoutLeft>("v", 4));
Expand All @@ -248,26 +263,26 @@ struct TestViewMDSpanConversion {
test_conversion_to_mdspan(layout_right_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4>>({}, 4), Kokkos::View<value_type *, Kokkos::LayoutRight>("v", 4));
test_conversion_to_mdspan(layout_right_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, 7), Kokkos::View<value_type **, Kokkos::LayoutRight>("v", 4, 7));

test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4>>({}, std::array{5}), Kokkos::View<value_type *, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5}));
test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, std::array{5, 9}), Kokkos::View<value_type **, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5, 7, 9}));
test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4>>({}, std::array<std::size_t, 1>{5}), Kokkos::View<value_type *, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5}));
test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, std::array<std::size_t, 2>{5, 9}), Kokkos::View<value_type **, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5, 7, 9}));

test_conversion_to_mdspan(layout_left_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4>>({}, 4), Kokkos::View<value_type *, Kokkos::LayoutLeft>("v", 4), Kokkos::default_accessor<value_type>{});
test_conversion_to_mdspan(layout_left_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, 4), Kokkos::View<value_type **, Kokkos::LayoutLeft>("v", 4, 7), Kokkos::default_accessor<value_type>{});

test_conversion_to_mdspan(layout_right_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4>>({}, 4), Kokkos::View<value_type *, Kokkos::LayoutRight>("v", 4), Kokkos::default_accessor<value_type>{});
test_conversion_to_mdspan(layout_right_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, 7), Kokkos::View<value_type **, Kokkos::LayoutRight>("v", 4, 7), Kokkos::default_accessor<value_type>{});

test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4>>({}, std::array{5}), Kokkos::View<value_type *, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5}));
test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, std::array{5, 9}), Kokkos::View<value_type **, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5, 7, 9}), Kokkos::default_accessor<value_type>{});
test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4>>({}, std::array<std::size_t, 1>{5}), Kokkos::View<value_type *, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5}));
test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, std::array<std::size_t, 2>{5, 9}), Kokkos::View<value_type **, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5, 7, 9}), Kokkos::default_accessor<value_type>{});

test_conversion_to_mdspan(layout_left_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4>>({}, 4), Kokkos::View<value_type *, Kokkos::LayoutLeft>("v", 4), test_accessor{});
test_conversion_to_mdspan(layout_left_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, 4), Kokkos::View<value_type **, Kokkos::LayoutLeft>("v", 4, 7), test_accessor{});

test_conversion_to_mdspan(layout_right_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4>>({}, 4), Kokkos::View<value_type *, Kokkos::LayoutRight>("v", 4), test_accessor{});
test_conversion_to_mdspan(layout_right_padded<Kokkos::dynamic_extent>::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, 7), Kokkos::View<value_type **, Kokkos::LayoutRight>("v", 4, 7), test_accessor{});

test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4>>({}, std::array{5}), Kokkos::View<value_type *, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5}));
test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, std::array{5, 9}), Kokkos::View<value_type **, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5, 7, 9}), test_accessor{});
test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4>>({}, std::array<std::size_t, 1>{5}), Kokkos::View<value_type *, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5}));
test_conversion_to_mdspan(Kokkos::layout_stride::mapping<Kokkos::extents<std::size_t, 4, 7>>({}, std::array<std::size_t, 2>{5, 9}), Kokkos::View<value_type **, Kokkos::LayoutStride>("v", Kokkos::LayoutStride{4, 5, 7, 9}), test_accessor{});
}
};

Expand Down

0 comments on commit de653dc

Please sign in to comment.