diff --git a/vtkm/cont/ArrayHandle.h b/vtkm/cont/ArrayHandle.h index e2287c66c..1c5e581ef 100644 --- a/vtkm/cont/ArrayHandle.h +++ b/vtkm/cont/ArrayHandle.h @@ -245,11 +245,7 @@ public: /// Constructs an empty ArrayHandle. Typically used for output or /// intermediate arrays that will be filled by a VTKm algorithm. /// - VTKM_CONT ArrayHandle() : Internals(new InternalStruct) - { - this->Internals->ControlArrayValid = false; - this->Internals->ExecutionArrayValid = false; - } + VTKM_CONT ArrayHandle(); /// Copy constructor. /// @@ -258,22 +254,23 @@ public: /// with CUDA), then the automatically generated copy constructor could be /// created for all devices, and it would not be valid for all devices. /// - VTKM_CONT - ArrayHandle(const vtkm::cont::ArrayHandle &src) - : Internals(src.Internals) - { } + ArrayHandle(const vtkm::cont::ArrayHandle &src); + + /// Move constructor. + /// + /// Implemented so that it is defined exclusively in the control environment. + /// If there is a separate device for the execution environment (for example, + /// with CUDA), then the automatically generated move constructor could be + /// created for all devices, and it would not be valid for all devices. + /// + ArrayHandle(vtkm::cont::ArrayHandle &&src); + /// Special constructor for subclass specializations that need to set the /// initial state of the control array. When this constructor is used, it /// is assumed that the control array is valid. /// - ArrayHandle(const StorageType &storage) - : Internals(new InternalStruct) - { - this->Internals->ControlArray = storage; - this->Internals->ControlArrayValid = true; - this->Internals->ExecutionArrayValid = false; - } + ArrayHandle(const StorageType &storage); /// Destructs an empty ArrayHandle. /// @@ -282,17 +279,19 @@ public: /// with CUDA), then the automatically generated destructor could be /// created for all devices, and it would not be valid for all devices. /// - ~ArrayHandle() { } + ~ArrayHandle(); /// \brief Copies an ArrayHandle /// VTKM_CONT vtkm::cont::ArrayHandle & - operator=(const vtkm::cont::ArrayHandle &src) - { - this->Internals = src.Internals; - return *this; - } + operator=(const vtkm::cont::ArrayHandle &src); + + /// \brief Move and Assignment of an ArrayHandle + /// + VTKM_CONT + vtkm::cont::ArrayHandle & + operator=(vtkm::cont::ArrayHandle &&src); /// Like a pointer, two \c ArrayHandles are considered equal if they point /// to the same location in memory. diff --git a/vtkm/cont/ArrayHandle.hxx b/vtkm/cont/ArrayHandle.hxx index 66a73af2f..979388b8f 100644 --- a/vtkm/cont/ArrayHandle.hxx +++ b/vtkm/cont/ArrayHandle.hxx @@ -21,6 +21,54 @@ namespace vtkm { namespace cont { +template +ArrayHandle::ArrayHandle() + : Internals(new InternalStruct) +{ + this->Internals->ControlArrayValid = false; + this->Internals->ExecutionArrayValid = false; +} + +template +ArrayHandle::ArrayHandle(const ArrayHandle &src) + : Internals(src.Internals) +{ } + +template +ArrayHandle::ArrayHandle(ArrayHandle &&src) + : Internals(std::move(src.Internals)) +{ } + +template +ArrayHandle::ArrayHandle(const typename ArrayHandle::StorageType &storage) + : Internals(new InternalStruct) +{ + this->Internals->ControlArray = storage; + this->Internals->ControlArrayValid = true; + this->Internals->ExecutionArrayValid = false; +} + +template +ArrayHandle::~ArrayHandle() +{ +} + +template +ArrayHandle& +ArrayHandle::operator=(const ArrayHandle &src) +{ + this->Internals = src.Internals; + return *this; +} + +template +ArrayHandle& +ArrayHandle::operator=(ArrayHandle &&src) +{ + this->Internals = std::move(src.Internals); + return *this; +} + template typename ArrayHandle::StorageType& ArrayHandle::GetStorage() diff --git a/vtkm/internal/FunctionInterface.h b/vtkm/internal/FunctionInterface.h index d56de8962..313679ef9 100644 --- a/vtkm/internal/FunctionInterface.h +++ b/vtkm/internal/FunctionInterface.h @@ -25,6 +25,8 @@ #include #include +#include + namespace vtkm { namespace internal { @@ -42,30 +44,34 @@ struct IdentityFunctor { // These functions exist to help copy components of a FunctionInterface. -template -struct FunctionInterfaceCopyParameters { +template +struct FunctionInterfaceMoveParameters { VTKM_SUPPRESS_EXEC_WARNINGS template static VTKM_EXEC_CONT - void Copy(vtkm::internal::detail::ParameterContainer &dest, + void Move(vtkm::internal::detail::ParameterContainer &dest, const vtkm::internal::detail::ParameterContainer &src) { ParameterContainerAccess pca; - pca.Set( dest, pca.Get(src) ); - FunctionInterfaceCopyParameters::Copy(dest, src); + + // using forwarding_type = typename AtType::type; + pca.Move( dest, src ); + // std::forward(pca.Get(src)) ); + // pca.Get(src)); + FunctionInterfaceMoveParameters::Move(dest, src); } }; template -struct FunctionInterfaceCopyParameters<0, ParameterIndex> { +struct FunctionInterfaceMoveParameters<0, ParameterIndex> { template static VTKM_EXEC_CONT - void Copy(vtkm::internal::detail::ParameterContainer &, + void Move(vtkm::internal::detail::ParameterContainer &, const vtkm::internal::detail::ParameterContainer &) { - // Nothing left to copy. + // Nothing left to move. } }; @@ -539,13 +545,13 @@ public: typedef typename detail::ReplaceType::type ReplaceSigType; FunctionInterface< ReplaceSigType > replacedFuncInterface; - detail::FunctionInterfaceCopyParameters:: - Copy(replacedFuncInterface.Parameters, this->Parameters); + detail::FunctionInterfaceMoveParameters:: + Move(replacedFuncInterface.Parameters, this->Parameters); replacedFuncInterface.template SetParameter(newParameter); - detail::FunctionInterfaceCopyParameters:: - Copy(replacedFuncInterface.Parameters, this->Parameters); + detail::FunctionInterfaceMoveParameters:: + Move(replacedFuncInterface.Parameters, this->Parameters); return replacedFuncInterface; } diff --git a/vtkm/internal/FunctionInterfaceDetailPre.h b/vtkm/internal/FunctionInterfaceDetailPre.h index 402b2d14a..10268e75f 100644 --- a/vtkm/internal/FunctionInterfaceDetailPre.h +++ b/vtkm/internal/FunctionInterfaceDetailPre.h @@ -293,6 +293,14 @@ struct ParameterContainerAccess<1> { const typename AtType<1, FunctionSignature>::type &value) { parameters.Parameter1 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter1 = std::move(src.Parameter1); + } }; template<> @@ -313,6 +321,14 @@ struct ParameterContainerAccess<2> { const typename AtType<2, FunctionSignature>::type &value) { parameters.Parameter2 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter2 = std::move(src.Parameter2); + } }; template<> @@ -333,6 +349,14 @@ struct ParameterContainerAccess<3> { const typename AtType<3, FunctionSignature>::type &value) { parameters.Parameter3 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter3 = std::move(src.Parameter3); + } }; template<> @@ -353,6 +377,14 @@ struct ParameterContainerAccess<4> { const typename AtType<4, FunctionSignature>::type &value) { parameters.Parameter4 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter4 = std::move(src.Parameter4); + } }; template<> @@ -373,6 +405,14 @@ struct ParameterContainerAccess<5> { const typename AtType<5, FunctionSignature>::type &value) { parameters.Parameter5 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter5 = std::move(src.Parameter5); + } }; template<> @@ -393,6 +433,14 @@ struct ParameterContainerAccess<6> { const typename AtType<6, FunctionSignature>::type &value) { parameters.Parameter6 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter6 = std::move(src.Parameter6); + } }; template<> @@ -413,6 +461,14 @@ struct ParameterContainerAccess<7> { const typename AtType<7, FunctionSignature>::type &value) { parameters.Parameter7 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter7 = std::move(src.Parameter7); + } }; template<> @@ -433,6 +489,14 @@ struct ParameterContainerAccess<8> { const typename AtType<8, FunctionSignature>::type &value) { parameters.Parameter8 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter8 = std::move(src.Parameter8); + } }; template<> @@ -453,6 +517,14 @@ struct ParameterContainerAccess<9> { const typename AtType<9, FunctionSignature>::type &value) { parameters.Parameter9 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter9 = std::move(src.Parameter9); + } }; template<> @@ -473,6 +545,14 @@ struct ParameterContainerAccess<10> { const typename AtType<10, FunctionSignature>::type &value) { parameters.Parameter10 = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter10 = std::move(src.Parameter10); + } }; diff --git a/vtkm/internal/FunctionInterfaceDetailPre.h.in b/vtkm/internal/FunctionInterfaceDetailPre.h.in index 033afdd98..8766a638e 100644 --- a/vtkm/internal/FunctionInterfaceDetailPre.h.in +++ b/vtkm/internal/FunctionInterfaceDetailPre.h.in @@ -195,6 +195,14 @@ struct ParameterContainerAccess<$(param_index)> { const typename AtType<$(param_index), FunctionSignature>::type &value) { parameters.Parameter$(param_index) = value; } + + VTKM_SUPPRESS_EXEC_WARNINGS + template + VTKM_EXEC_CONT + void Move(ParameterContainer &dest, + const ParameterContainer &src) { + dest.Parameter$(param_index) = std::move(src.Parameter$(param_index)); + } }; $endfor\