New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mdspan converting constructors #6830
base: develop
Are you sure you want to change the base?
Conversation
Besides separating PRs for moving stuff and adding the new functionality: can't we have this all simpler? This code snippet here defines natural mdspan template<class L>
struct LayoutMap;
template<>
struct LayoutMap<Kokkos::LayoutRight> { using type = Kokkos::layout_right; };
template<>
struct LayoutMap<Kokkos::LayoutLeft> { using type = Kokkos::layout_left; };
template<>
struct LayoutMap<Kokkos::LayoutStride> { using type = Kokkos::layout_stride; };
template<class ViewType>
void foo() {
using element_type = typename ViewType::value_type;
using index_type = typename ViewType::execution_space::size_type;
using extents_type = typename Kokkos::Experimental::Impl::ExtentsFromDataType<index_type, typename ViewType::data_type>::type;
using layout_type = typename LayoutMap<typename ViewType::array_layout>::type;
using mdspan_type = Kokkos::mdspan<element_type, extents_type, layout_type>;
printf("%s\n", typeid(ViewType).name());
printf("%s\n", typeid(mdspan_type).name());
} And then the constructor we would need is simply: MDSPAN_CONDITIONAL_EXPLICIT(traits::is_managed)
View(mdspan_type mds):View(mds.data_handle(), kokkos_layout_from_mapping(mds.mapping()) ) {} Do you see anything wrong with this approach? The mdspan convertability and constructibility should enforce all the desired "this constructor works" properties wouldn't it? |
@crtrott Yeah I think the simpler approach is better, I was trying to make the API like mdarray but thinking about it a bit more I realized that's not what we want. Actually the approach I have right now doesn't have the right constraints anyway. |
Also it still needs to be constrained on |
I think conditional explicit is fine. We allow construction from pointer of a "managed" view. |
7960ee0
to
f41c2f7
Compare
@@ -106,6 +107,14 @@ struct DataTypeFromExtents { | |||
// Will cause a compile error if it is malformed (i.e. dynamic after static) | |||
using type = typename ::Kokkos::Impl::ViewDataType<T, dimension_type>::type; | |||
}; | |||
|
|||
/// Convert from a mdspan extent to a Kokkos extent, inserting 0s for static | |||
/// extents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want 0s for static extents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that's what currently the ViewOffset does, so this would have a similar behavior
Please expand the description. Referring to an issue that in turn point to an ISO C++ paper makes it difficult to audit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few extra minor comments on the tests
a6c304c
to
bc07459
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests were in alphabetic order and there is a MDSpan test.
I suppose you meant to define it in the same exe as the other view tests but I tend to think you should define it L187 in sources 1B.
Other than that looks good
Retest this please |
Failure in the
|
This explicit construction: View<int[8]> a(mdspan<int,dextents<int,1>>(ptr,8)) needs the new ctor, because the mdspan provided is not implicitly convertible to the natural mdspan type.
… gives incorrect C++
…layouts rather than 0
…ck on C++ version and a comment
…or undesirable implicit conversions
…ersion from mdspan
c143450
to
53efc51
Compare
Retest this please! |
Closes #6805
This PR adds constructors for
Kokkos::View
that convert fromstd::mdspan
.Kokkos::LayoutLeft
->std::layout_left_padded<N>::mapping
Kokkos::LayoutRight
->std::layout_right_padded<N>::mapping
Kokkos::LayoutStride
->std::layout_stride
It also adds
to_mdspan
andoperator mdspan
that converts to the "natural" mdspan type, that is the type that closely represents the internal view state.Requirements for this PR (currently based on top of these changes):