-
Notifications
You must be signed in to change notification settings - Fork 436
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
#4913: Make View self-assignment not produce double-free #5024
Conversation
Only really can be triggered via reinterpret_casting a view
core/unit_test/TestViewAPI.hpp
Outdated
// Test self assignment | ||
dx = dx; | ||
ASSERT_EQ(dx.use_count(), 1); | ||
dx = reinterpret_cast<typename dView4::uniform_type &>(dx); |
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.
// Test self assignment | |
dx = dx; | |
ASSERT_EQ(dx.use_count(), 1); | |
dx = reinterpret_cast<typename dView4::uniform_type &>(dx); | |
// Test self assignment | |
dx = dx; // copy-assignement operator | |
ASSERT_EQ(dx.use_count(), 1); | |
dx = reinterpret_cast<typename dView4::uniform_type &>(dx); // conversion constructor |
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.
Actually why do we have both
kokkos/core/src/Kokkos_View.hpp
Lines 1426 to 1440 in b52f8c8
template <class RT, class... RP> | |
KOKKOS_INLINE_FUNCTION View( | |
const View<RT, RP...>& rhs, | |
typename std::enable_if<Kokkos::Impl::ViewMapping< | |
traits, typename View<RT, RP...>::traits, | |
typename traits::specialize>::is_assignable_data_type>::type* = | |
nullptr) | |
: m_track(rhs), m_map() { | |
using SrcTraits = typename View<RT, RP...>::traits; | |
using Mapping = Kokkos::Impl::ViewMapping<traits, SrcTraits, | |
typename traits::specialize>; | |
static_assert(Mapping::is_assignable, | |
"Incompatible View copy construction"); | |
Mapping::assign(m_map, rhs.m_map, rhs.m_track.m_tracker); | |
} |
and
kokkos/core/src/Kokkos_View.hpp
Lines 1442 to 1456 in b52f8c8
template <class RT, class... RP> | |
KOKKOS_INLINE_FUNCTION typename std::enable_if< | |
Kokkos::Impl::ViewMapping< | |
traits, typename View<RT, RP...>::traits, | |
typename traits::specialize>::is_assignable_data_type, | |
View>::type& | |
operator=(const View<RT, RP...>& rhs) { | |
using SrcTraits = typename View<RT, RP...>::traits; | |
using Mapping = Kokkos::Impl::ViewMapping<traits, SrcTraits, | |
typename traits::specialize>; | |
static_assert(Mapping::is_assignable, "Incompatible View copy assignment"); | |
Mapping::assign(m_map, rhs.m_map, rhs.m_track.m_tracker); | |
m_track.assign(rhs); | |
return *this; | |
} |
cc @nliber
Uh interesting:
|
OpenMPTarget-ROCm build has the failure reported in #5025
|
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! I had to double check that the reinterpret_cast
was valid, which it should be as long as we don't dereference it
Replacing #4914 because I can neither push to NexGenAnalytics organization nor, do a PR against that fork??
Fixes #4913