deep_copy
of View
of non-trivially copyable type leads to byte-wise copy
#6986
Labels
Question
For Kokkos internal and external contributors and users
Kokkos currently implements the
deep_copy
of aView
as a byte-wise copy under conditions summarized in this comment:kokkos/core/src/Kokkos_CopyViews.hpp
Lines 1758 to 1759 in d88e2a5
These conditions are made rigorous in the code that follows in
Kokkos_CopyViews.hpp
by using type traits.It is notable that these conditions do not guard for the value type of the
View
to be trivially copyable. This current behavior ofdeep_copy
for non-trivially copyable value types may be surprising. Especially between assignable memory spaces, it may be expected that the copy constructor/copy assignment operator is called.The behavior of
std::copy
is different. It carries out the copy as a byte-wise copy only for trivially copyable value types.If this current behavior is not intended, a solution may consist of leading the case of non-trivially copyable value types to an implementation that uses the
ViewCopy
functor:kokkos/core/src/Kokkos_CopyViews.hpp
Lines 272 to 292 in c6d8647
We have tested this behavior by using a helper class that we can make non trivially copyable and that can count the number of times its special functions are called:
The code of the helper class, called
tester_t
in the snippet, is in attachment:Joint work with @romintomasetti. Issue created after a brief discussion with @dalg24.
The text was updated successfully, but these errors were encountered: