Commit 5250c28f authored by Kenneth Moreland's avatar Kenneth Moreland

Swap call pattern of ArrayHandle::DeepCopy

The new method `ArrayHandle::DeepCopy` had the pattern such that the
data in the `this` array was pushed to the provided destination array.
However, this is the opposite pattern used in the equivalent method in
VTK, which takes the data from the provided array and copies it to
`this` array.

So, swap the pattern to match that of VTK. Also, make the method name
more descriptive by renaming it to `DeepCopyFrom`. Hopefully, users will
read that to mean given the `ArrayHandle`, you copy data from the other
provided `ArrayHandle`.
parent 05ec03b3
......@@ -108,7 +108,7 @@ VTKM_CONT void ArrayCopyImpl(const vtkm::cont::ArrayHandle<T, S>& source,
vtkm::cont::ArrayHandle<T, S>& destination,
std::true_type /* New style */)
{
source.DeepCopy(destination);
destination.DeepCopyFrom(source);
}
} // namespace detail
......
......@@ -1391,16 +1391,16 @@ public:
/// \brief Deep copies the data in the array.
///
/// Takes the data that is in this array and copies that data into the provided
/// \a destination.
/// Takes the data that is in \a source and copies that data into this array.
///
VTKM_CONT void DeepCopy(vtkm::cont::ArrayHandleNewStyle<ValueType, StorageTag>& destination) const
VTKM_CONT void DeepCopyFrom(
const vtkm::cont::ArrayHandleNewStyle<ValueType, StorageTag>& source) const
{
VTKM_ASSERT(this->Buffers.size() == destination.Buffers.size());
VTKM_ASSERT(this->Buffers.size() == source.Buffers.size());
for (std::size_t bufferIndex = 0; bufferIndex < this->Buffers.size(); ++bufferIndex)
{
this->Buffers[bufferIndex].DeepCopy(destination.Buffers[bufferIndex]);
this->Buffers[bufferIndex].DeepCopyFrom(source.Buffers[bufferIndex]);
}
}
......
......@@ -768,61 +768,64 @@ void Buffer::Enqueue(const vtkm::cont::Token& token) const
detail::BufferHelper::Enqueue(this->Internals, lock, token);
}
void Buffer::DeepCopy(vtkm::cont::internal::Buffer& dest) const
void Buffer::DeepCopyFrom(const vtkm::cont::internal::Buffer& src) const
{
// A Token should not be declared within the scope of a lock. when the token goes out of scope
// it will attempt to aquire the lock, which is undefined behavior of the thread already has
// the lock.
vtkm::cont::Token token;
{
LockType srcLock = this->Internals->GetLock();
const vtkm::cont::internal::Buffer& dest = *this;
LockType srcLock = src.Internals->GetLock();
LockType destLock = dest.Internals->GetLock();
detail::BufferHelper::WaitToRead(this->Internals, srcLock, token);
detail::BufferHelper::WaitToRead(src.Internals, srcLock, token);
// If we are on a device, copy there.
for (auto&& deviceBuffer : this->Internals->GetDeviceBuffers(srcLock))
for (auto&& deviceBuffer : src.Internals->GetDeviceBuffers(srcLock))
{
if (deviceBuffer.second.UpToDate)
{
detail::BufferHelper::CopyOnDevice(
deviceBuffer.first, this->Internals, srcLock, dest.Internals, destLock, token);
deviceBuffer.first, src.Internals, srcLock, dest.Internals, destLock, token);
return;
}
}
// If we are here, there were no devices to copy on. Copy on host if possible.
if (this->Internals->GetHostBuffer(srcLock).UpToDate)
if (src.Internals->GetHostBuffer(srcLock).UpToDate)
{
detail::BufferHelper::CopyOnHost(this->Internals, srcLock, dest.Internals, destLock, token);
detail::BufferHelper::CopyOnHost(src.Internals, srcLock, dest.Internals, destLock, token);
}
else
{
// Nothing actually allocated. Just create allocation for dest. (Allocation happens lazily.)
detail::BufferHelper::SetNumberOfBytes(dest.Internals,
destLock,
this->Internals->GetNumberOfBytes(srcLock),
src.Internals->GetNumberOfBytes(srcLock),
vtkm::CopyFlag::Off,
token);
if (this->Internals->MetaData)
if (src.Internals->MetaData)
{
dest.Internals->MetaData = this->Internals->MetaData->DeepCopy();
dest.Internals->MetaData = src.Internals->MetaData->DeepCopy();
}
}
}
}
void Buffer::DeepCopy(vtkm::cont::internal::Buffer& dest, vtkm::cont::DeviceAdapterId device) const
void Buffer::DeepCopyFrom(const vtkm::cont::internal::Buffer& src,
vtkm::cont::DeviceAdapterId device) const
{
// A Token should not be declared within the scope of a lock. when the token goes out of scope
// it will attempt to aquire the lock, which is undefined behavior of the thread already has
// the lock.
vtkm::cont::Token token;
{
LockType srcLock = this->Internals->GetLock();
LockType destLock = dest.Internals->GetLock();
LockType srcLock = src.Internals->GetLock();
LockType destLock = this->Internals->GetLock();
detail::BufferHelper::CopyOnDevice(
device, this->Internals, srcLock, dest.Internals, destLock, token);
device, this->Internals, srcLock, this->Internals, destLock, token);
}
}
......
......@@ -226,15 +226,15 @@ public:
VTKM_CONT void Enqueue(const vtkm::cont::Token& token) const;
/// @{
/// \brief Copies the data from this buffer to the target buffer.
/// \brief Copies the data from the provided buffer into this buffer.
///
/// If a device is given, then the copy will be preferred for that device. Otherwise, a device
/// already containing the data will be used for the copy. If no such device exists, the host
/// will be used.
///
VTKM_CONT void DeepCopy(vtkm::cont::internal::Buffer& dest) const;
VTKM_CONT void DeepCopy(vtkm::cont::internal::Buffer& dest,
vtkm::cont::DeviceAdapterId device) const;
VTKM_CONT void DeepCopyFrom(const vtkm::cont::internal::Buffer& source) const;
VTKM_CONT void DeepCopyFrom(const vtkm::cont::internal::Buffer& source,
vtkm::cont::DeviceAdapterId device) const;
/// @}
/// \brief Resets the `Buffer` to the memory allocated at the `BufferInfo`.
......
......@@ -119,7 +119,7 @@ void DoTest()
std::cout << "Copy uninitialized buffer" << std::endl;
{
vtkm::cont::internal::Buffer copy;
buffer.DeepCopy(copy);
copy.DeepCopyFrom(buffer);
VTKM_TEST_ASSERT(copy.GetNumberOfBytes() == 0);
VTKM_TEST_ASSERT(CheckMetaData(copy));
}
......@@ -135,7 +135,7 @@ void DoTest()
std::cout << "Copy sized but uninitialized buffer" << std::endl;
{
vtkm::cont::internal::Buffer copy;
buffer.DeepCopy(copy);
copy.DeepCopyFrom(buffer);
VTKM_TEST_ASSERT(copy.GetNumberOfBytes() == BUFFER_SIZE);
VTKM_TEST_ASSERT(CheckMetaData(copy));
VTKM_TEST_ASSERT(!copy.IsAllocatedOnHost());
......@@ -162,7 +162,7 @@ void DoTest()
{
vtkm::cont::Token token;
vtkm::cont::internal::Buffer copy;
buffer.DeepCopy(copy);
copy.DeepCopyFrom(buffer);
VTKM_TEST_ASSERT(copy.GetNumberOfBytes() == BUFFER_SIZE);
VTKM_TEST_ASSERT(CheckMetaData(copy));
VTKM_TEST_ASSERT(copy.IsAllocatedOnHost());
......@@ -225,7 +225,7 @@ void DoTest()
{
vtkm::cont::Token token;
vtkm::cont::internal::Buffer copy;
buffer.DeepCopy(copy);
copy.DeepCopyFrom(buffer);
VTKM_TEST_ASSERT(copy.GetNumberOfBytes() == BUFFER_SIZE);
VTKM_TEST_ASSERT(CheckMetaData(copy));
VTKM_TEST_ASSERT(!copy.IsAllocatedOnHost());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment