-
Notifications
You must be signed in to change notification settings - Fork 407
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
dual view: update template types + Kokkos::is_dual_view
(#6085)
#6120
dual view: update template types + Kokkos::is_dual_view
(#6085)
#6120
Conversation
Can one of the admins verify this patch? |
14f3e57
to
c628a01
Compare
@ajpowelsnl There were a little more changes required... |
Please let us know if there's anything we can do to help ... |
c628a01
to
2e79a95
Compare
@ajpowelsnl I think this is ready for your approval to test 😄 |
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.
(peer reviewed with Daniel)
containers/src/Kokkos_DualView.hpp
Outdated
|
||
using type = Kokkos::DualView< | ||
typename dst_traits::data_type, typename dst_traits::array_layout, | ||
typename dst_traits::device_type, typename dst_traits::memory_traits>; | ||
typename dst_traits::device_type, typename dst_traits::hooks_policy, |
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.
Comment about that change.
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'm not sure if you mean commenting that in the code or in the PR...
I'll comment it here first.
The whole point of this PR is to allow a Kokkos::DualView
to accept any Properties...
that a Kokkos::View
can accept. Before this PR, it was hardcoded that DualView
only accepts 4 types:
DataType
Arg1Type
Arg2Type
Arg3Type
but there was no check enforcing the type of the last 3 (Arg1Type, Arg2Type, Arg3Type). So they could be anything that Kokkos::ViewTraits
would accept. However, DualViewSubview::type
would then "hardcode" that when taking a subview of a dual view, only data type, array layout, device type and memory traits would be set. If my understanding is correct, that could have lead to issues if for instance I had created my original dual view with some hooks policy and then took a subview of it because my subview would have the default hooks policy (please correct me if this isn't correct! 😉).
However, I must admit that I'm not satisfied of my solution because I only added hooks_policy
while Kokkos::ViewTraits
may also accept specialize
and others.
So my question for you @dalg24 is how I can ensure that all traits are passed to DualViewSubviewType::type
? I guess ideally one should be able to do:
template <class DV, class... Args>
struct DualViewSubviewType {
static_assert(Kokkos::is_dual_view_v<DV>);
using dst_traits = typename Kokkos::Impl::ViewMapping<
void, typename DV::traits, Args...>::traits_type;
using type = Kokkos::DualView<dst_traits>;
};
where dst_traits
is a Kokkos::ViewTraits
that would then embed all the traits given by the user and this would ensure that all types are passed. But I agree this would not work so I wonder how one can ensure that DualViewSubviewType::type
will always "forward" all types, even in the future when ViewTraits
would accept some more types...
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 would have tried something like
namespace Impl {
template <class V>
struct V2DV;
template <class D, class... P>
struct V2DV<View<D, P...>> {
using type = DualView<D, P...>;
};
} /* namespace Impl */
template <class DataType, class... Properties, class... Args>
auto subview(const DualView<DataType, Properties...>& src, Args... args) {
// leverage Kokkos::View facilities to deduce the properties of the subview
using deduce_subview_type =
decltype(subview(std::declval<View<DataType, Properties...>>(), args...));
// map it back to dual view
return typename Impl::V2DV<deduce_subview_type>::type(src, args...);
}
to defer the deduction to Kokkos Core.
Ping @nmm0 who introduced the view hooks and @masterleinad who recently refactored subview(View<...>, ...)
I grepped for "subview" in the containers unit test and the test coverage looks pretty light.
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.
@dalg24 This is indeed a much nicer solution!
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'm still wondering why these args...
are never perfect-forwarded though... (usually they are integer values but they could be e.g. pairs).
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.
You can use perfect forwarding if you like.
void deep_copy( | ||
const ExecutionSpace& exec, | ||
DualView<DT, DL, DD, DM> dst, // trust me, this must not be a reference |
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.
Comment about why this is ok to delete that comment and not trust whoever wrote that.
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.
Well, my first feeling was that this code was wrong because it was calling modify_host
/modify_device
on a (shallow) copy of dst
. But as the modified_flags
member is a (shared) view, it seems this is still OK.
Still I was not "trusting" such a comment like trust me, this must not be a reference (reminds me of "Trust me I'm an engineer") because to me this should work with a reference otherwise there must be other cases where taking a dual view by reference is dangerous.
So I wanted to put my hypothesis that in fact it works with a reference to the test.
On my side, it worked for OpenMP and Cuda (without UVM).
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 am leaning towards saying your change is fine.
My point was this needs to be discussed and not swept under the rug. It looks like the comment has been there since the initial commit in this project when the code was extracted from Sandia's Trilinos repository.
cc @crtrott
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.
It was introduced in trilinos/Trilinos@0806efc by @mhoemmen.
Kokkos::is_dual_view
(#6085)
65abe36
to
a034700
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.
Looks good to me given that we discuss changing the copy in deep_copy
to a reference some.
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 am ok with changing to a reference in deep_copy
OK to test |
containers/src/Kokkos_DualView.hpp
Outdated
void deep_copy( | ||
const ExecutionSpace& exec, | ||
DualView<DT, DL, DD, DM> dst, // trust me, this must not be a reference | ||
const DualView<ST, SL, SD, SM>& src) { | ||
DualView<DT, DP...>& dst, |
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 would prefer
DualView<DT, DP...>& dst, | |
const DualView<DT, DP...>& dst, |
to mirror the overloads for Kokkos::View
more closely.
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.
Done 😉
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'm reverting this because these functions are calling modify_host
on dst
that mustn't be const
:
In file included from /__w/kokkos/kokkos/containers/unit_tests/TestDualView.hpp:25:
/__w/kokkos/kokkos/containers/unit_tests/../src/Kokkos_DualView.hpp:1194:9: error: no matching member function for call to 'modify_host'
dst.modify_host();
~~~~^~~~~~~~~~~
/__w/kokkos/kokkos/containers/unit_tests/TestDualView.hpp:185:13: note: in instantiation of function template specialization 'Kokkos::deep_copy<int **, Kokkos::LayoutLeft, Kokkos::OpenMP, int **, Kokkos::LayoutLeft, Kokkos::OpenMP>' requested here
Kokkos::deep_copy(b, a);
95556cf
to
7b3859e
Compare
7b3859e
to
1767bfe
Compare
Ready to go 🚀 |
Compatibility update for kokkos/kokkos#6120 Solution provided by @dalg24 in kokkos/kokkos#6141 Co-authored-by: Damien L-G <dalg24@gmail.com@>
Compatibility update for kokkos/kokkos#6120 Solution provided by @dalg24 in kokkos/kokkos#6141 Co-authored-by: Damien L-G <dalg24@gmail.com@>
Compatibility update for kokkos/kokkos#6120 Solution provided by @dalg24 in kokkos/kokkos#6141 Co-authored-by: Damien L-G <dalg24@gmail.com>
Compatibility update for kokkos/kokkos#6120 Solution provided by @dalg24 in kokkos/kokkos#6141 Co-authored-by: Damien L-G <dalg24@gmail.com>
Compatibility update for kokkos/kokkos#6120 Solution provided by @dalg24 in kokkos/kokkos#6141 Co-authored-by: Damien L-G <dalg24@gmail.com>
Kokkos::DualView
is still on<DataType, class, class, class>
instead of<DataType, Properties...>
#6085.Kokkos::is_dual_view
trait andKokkos::is_dual_view_v
helper variable template for consistency with otherKokkos
containers.