2018-11-06 16:20:30 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-11-06 16:20:30 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
#include <vtkm/cont/internal/TransferInfo.h>
|
|
|
|
|
|
|
|
#include <vtkm/internal/ArrayPortalVirtual.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
|
|
|
|
bool TransferInfoArray::valid(vtkm::cont::DeviceAdapterId devId) const noexcept
|
|
|
|
{
|
|
|
|
return this->DeviceId == devId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferInfoArray::updateHost(
|
|
|
|
std::unique_ptr<vtkm::internal::PortalVirtualBase>&& host) noexcept
|
|
|
|
{
|
|
|
|
this->Host = std::move(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferInfoArray::updateDevice(vtkm::cont::DeviceAdapterId devId,
|
|
|
|
std::unique_ptr<vtkm::internal::PortalVirtualBase>&& hostCopy,
|
|
|
|
const vtkm::internal::PortalVirtualBase* device,
|
|
|
|
const std::shared_ptr<void>& deviceState) noexcept
|
|
|
|
{
|
|
|
|
this->HostCopyOfDevice = std::move(hostCopy);
|
|
|
|
this->DeviceId = devId;
|
|
|
|
this->Device = device;
|
|
|
|
this->DeviceTransferState = deviceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferInfoArray::releaseDevice()
|
|
|
|
{
|
|
|
|
this->DeviceId = vtkm::cont::DeviceAdapterTagUndefined{};
|
2019-04-29 19:51:19 +00:00
|
|
|
this->Device = nullptr; //The device transfer state own this pointer
|
|
|
|
if (this->DeviceTransferState == nullptr)
|
|
|
|
{ //When the DeviceTransferState is a nullptr it means that
|
|
|
|
//that the device and host share memory. In that case we need to free
|
|
|
|
//the host copy
|
|
|
|
this->HostCopyOfDevice.reset(nullptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//The DeviceTransferState holds ownership of HostCopyOfDevice so we only
|
|
|
|
//need to delete DeviceTransferState, as it will do the rest
|
|
|
|
this->DeviceTransferState = nullptr; //release the device transfer state
|
|
|
|
this->HostCopyOfDevice.release();
|
|
|
|
}
|
2018-11-06 16:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransferInfoArray::releaseAll()
|
|
|
|
{
|
|
|
|
this->Host.release(); //we own this pointer so release it
|
|
|
|
this->releaseDevice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|