diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.cpp b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp index b4d9079a..0f9e4638 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.cpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp @@ -56,14 +56,34 @@ void pFlow::VectorSingle::changeCapacity bool withInit ) { - if(withInit) + if constexpr( isTriviallyCopyable_ ) { - resizeInit(view_, actualCap); + if(withInit) + { + resizeInit(view_, actualCap); + } + else + { + resizeNoInit(view_, actualCap); + } + } + else if constexpr( isHostAccessible_ ) + { + viewType newView(view_.label(), actualCap); + + for(auto i=0u; i @@ -74,7 +94,16 @@ pFlow::uint32 pFlow::VectorSingle::reallocateCapacitySize uint32 s ) { - reallocNoInit(view_, cap); + if constexpr (isTriviallyCopyable_) + { + reallocNoInit(view_, cap); + } + else + { + viewType newView(view_.label(), cap); + view_ = newView; + } + return setSize(s); } @@ -183,7 +212,21 @@ pFlow::VectorSingle::VectorSingle : VectorSingle(name, src.capacity(), src.size(), RESERVE()) { - copy(deviceView(), src.deviceView()); + if constexpr(isTriviallyCopyable_) + { + copy(deviceView(), src.deviceView()); + } + else if constexpr( isHostAccessible_) + { + for(auto i=0u; i @@ -259,7 +302,18 @@ INLINE_FUNCTION_H auto pFlow::VectorSingle::hostViewAll()const { auto hView = Kokkos::create_mirror_view(view_); - copy(hView, view_); + if constexpr(isTriviallyCopyable_) + { + copy(hView, view_); + } + else if constexpr( isHostAccessible_ ) + { + // nothing to be done, since it is already a host memory + } + else + { + static_assert("hostViewAll is not valid for non-trivially copyable data type on device memory"); + } return hView; } @@ -268,7 +322,19 @@ INLINE_FUNCTION_H auto pFlow::VectorSingle::hostView()const { auto hView = Kokkos::create_mirror_view(deviceView()); - copy(hView, deviceView()); + if constexpr(isTriviallyCopyable_) + { + copy(hView, deviceView()); + } + else if constexpr( isHostAccessible_ ) + { + // nothing to be done, since it is already a host memory + } + else + { + static_assert("hostView is not valid for non-trivially copyable data type on device memory"); + } + return hView; } @@ -351,7 +417,7 @@ INLINE_FUNCTION_H void pFlow::VectorSingle::fill(const T& val) { if(empty())return; - pFlow::fill(view_, rangeU32(0 ,size_) ,val); + pFlow::fill(view_, rangeU32(0 ,size_) ,val); } template @@ -407,9 +473,28 @@ void pFlow::VectorSingle::assign setSize(srcSize); } - // - unmanaged view in the host - hostViewType1D temp(src.data(), srcSize ); - copy(deviceView(), temp); + + + if constexpr( isTriviallyCopyable_ ) + { + // - unmanaged view in the host + hostViewType1D temp(src.data(), srcSize ); + copy(deviceView(), temp); + } + else if constexpr( isHostAccessible_) + { + + for(auto i=0u; i @@ -421,6 +506,7 @@ void pFlow::VectorSingle::assign { assign(src, this->capacity()); } + template INLINE_FUNCTION_H void pFlow::VectorSingle::assign(const VectorTypeHost& src) @@ -436,7 +522,22 @@ void pFlow::VectorSingle::assign(const VectorTypeHost& src) { setSize(srcSize); } - copy(deviceView(), src.hostView()); + + if constexpr(isTriviallyCopyable_) + { + copy(deviceView(), src.hostView()); + } + else if constexpr( isHostAccessible_) + { + for(auto i=0u; i @@ -456,8 +557,22 @@ void pFlow::VectorSingle::append hostViewType1D temp(appVec.data(), srcSize ); auto dest = Kokkos::subview(view_, Kokkos::make_pair(oldSize,newSize)); - copy(dest, temp); - + if constexpr( isTriviallyCopyable_) + { + copy(dest, temp); + } + else if constexpr( isHostAccessible_) + { + for(auto i=0u; i diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp index 137d3a46..1461503f 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp @@ -102,6 +102,9 @@ private: static constexpr bool isDeviceAccessible_ = isDeviceAccessible(); + static constexpr + bool isTriviallyCopyable_ = std::is_trivially_copyable_v; + /// Evaluate capacity based on the input size static INLINE_FUNCTION_H uint32 evalCapacity(uint32 n) { @@ -397,7 +400,6 @@ public: { std::vector vecFromFile; if(! readStdVector(is, vecFromFile, iop)) return false; - this->assign(vecFromFile); return true;