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.
|
|
|
|
//============================================================================
|
2019-02-26 19:23:18 +00:00
|
|
|
#define vtk_m_cont_StorageVirtual_cxx
|
2019-03-28 17:29:24 +00:00
|
|
|
#include <vtkm/cont/StorageVirtual.h>
|
2018-11-06 16:20:30 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/internal/DeviceAdapterError.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
2019-02-10 08:46:43 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
2018-11-06 16:20:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
StorageVirtual::StorageVirtual(const StorageVirtual& src)
|
2018-11-06 16:20:30 +00:00
|
|
|
: HostUpToDate(src.HostUpToDate)
|
|
|
|
, DeviceUpToDate(src.DeviceUpToDate)
|
|
|
|
, DeviceTransferState(src.DeviceTransferState)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
StorageVirtual::StorageVirtual(StorageVirtual&& src) noexcept
|
2018-11-06 16:20:30 +00:00
|
|
|
: HostUpToDate(src.HostUpToDate),
|
|
|
|
DeviceUpToDate(src.DeviceUpToDate),
|
|
|
|
DeviceTransferState(std::move(src.DeviceTransferState))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
StorageVirtual& StorageVirtual::operator=(const StorageVirtual& src)
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
this->HostUpToDate = src.HostUpToDate;
|
|
|
|
this->DeviceUpToDate = src.DeviceUpToDate;
|
|
|
|
this->DeviceTransferState = src.DeviceTransferState;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
StorageVirtual& StorageVirtual::operator=(StorageVirtual&& src) noexcept
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
this->HostUpToDate = src.HostUpToDate;
|
|
|
|
this->DeviceUpToDate = src.DeviceUpToDate;
|
|
|
|
this->DeviceTransferState = std::move(src.DeviceTransferState);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
StorageVirtual::~StorageVirtual()
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-25 18:31:52 +00:00
|
|
|
void StorageVirtual::DropExecutionPortal()
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
this->DeviceTransferState->releaseDevice();
|
|
|
|
this->DeviceUpToDate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-25 18:31:52 +00:00
|
|
|
void StorageVirtual::DropAllPortals()
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
this->DeviceTransferState->releaseAll();
|
|
|
|
this->HostUpToDate = false;
|
|
|
|
this->DeviceUpToDate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
std::unique_ptr<StorageVirtual> StorageVirtual::NewInstance() const
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
return this->MakeNewInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
const vtkm::internal::PortalVirtualBase* StorageVirtual::PrepareForInput(
|
2018-11-06 16:20:30 +00:00
|
|
|
vtkm::cont::DeviceAdapterId devId) const
|
|
|
|
{
|
|
|
|
if (devId == vtkm::cont::DeviceAdapterTagUndefined())
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_UNDEFINED");
|
|
|
|
}
|
|
|
|
if (devId == vtkm::cont::DeviceAdapterTagError())
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_ERROR");
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool needsUpload = !(this->DeviceTransferState->valid(devId) && this->DeviceUpToDate);
|
|
|
|
|
|
|
|
if (needsUpload)
|
|
|
|
{ //Either transfer state is pointing to another device, or has
|
|
|
|
//had the execution resources released. Either way we
|
|
|
|
//need to re-transfer the execution information
|
|
|
|
auto* payload = this->DeviceTransferState.get();
|
|
|
|
this->TransferPortalForInput(*payload, devId);
|
|
|
|
this->DeviceUpToDate = true;
|
|
|
|
}
|
|
|
|
return this->DeviceTransferState->devicePtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
const vtkm::internal::PortalVirtualBase* StorageVirtual::PrepareForOutput(
|
|
|
|
vtkm::Id numberOfValues,
|
|
|
|
vtkm::cont::DeviceAdapterId devId)
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
if (devId == vtkm::cont::DeviceAdapterTagUndefined())
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_UNDEFINED");
|
|
|
|
}
|
|
|
|
if (devId == vtkm::cont::DeviceAdapterTagError())
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_ERROR");
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool needsUpload = !(this->DeviceTransferState->valid(devId) && this->DeviceUpToDate);
|
|
|
|
if (needsUpload)
|
|
|
|
{
|
2018-11-28 15:36:45 +00:00
|
|
|
this->TransferPortalForOutput(
|
|
|
|
*(this->DeviceTransferState), OutputMode::WRITE, numberOfValues, devId);
|
|
|
|
this->HostUpToDate = false;
|
|
|
|
this->DeviceUpToDate = true;
|
|
|
|
}
|
|
|
|
return this->DeviceTransferState->devicePtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
const vtkm::internal::PortalVirtualBase* StorageVirtual::PrepareForInPlace(
|
|
|
|
vtkm::cont::DeviceAdapterId devId)
|
2018-11-28 15:36:45 +00:00
|
|
|
{
|
|
|
|
if (devId == vtkm::cont::DeviceAdapterTagUndefined())
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_UNDEFINED");
|
|
|
|
}
|
|
|
|
if (devId == vtkm::cont::DeviceAdapterTagError())
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("device should not be VTKM_DEVICE_ADAPTER_ERROR");
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool needsUpload = !(this->DeviceTransferState->valid(devId) && this->DeviceUpToDate);
|
|
|
|
if (needsUpload)
|
|
|
|
{
|
|
|
|
vtkm::Id numberOfValues = this->GetNumberOfValues();
|
|
|
|
this->TransferPortalForOutput(
|
|
|
|
*(this->DeviceTransferState), OutputMode::READ_WRITE, numberOfValues, devId);
|
2018-11-06 16:20:30 +00:00
|
|
|
this->HostUpToDate = false;
|
|
|
|
this->DeviceUpToDate = true;
|
|
|
|
}
|
|
|
|
return this->DeviceTransferState->devicePtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
const vtkm::internal::PortalVirtualBase* StorageVirtual::GetPortalControl()
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
if (!this->HostUpToDate)
|
|
|
|
{
|
|
|
|
//we need to prepare for input and grab the host ptr
|
|
|
|
auto* payload = this->DeviceTransferState.get();
|
|
|
|
this->ControlPortalForOutput(*payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->DeviceUpToDate = false;
|
|
|
|
this->HostUpToDate = true;
|
|
|
|
return this->DeviceTransferState->hostPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
const vtkm::internal::PortalVirtualBase* StorageVirtual::GetPortalConstControl() const
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
if (!this->HostUpToDate)
|
|
|
|
{
|
|
|
|
//we need to prepare for input and grab the host ptr
|
|
|
|
vtkm::cont::internal::TransferInfoArray* payload = this->DeviceTransferState.get();
|
|
|
|
this->ControlPortalForInput(*payload);
|
|
|
|
}
|
|
|
|
this->HostUpToDate = true;
|
|
|
|
return this->DeviceTransferState->hostPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
DeviceAdapterId StorageVirtual::GetDeviceAdapterId() const noexcept
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
|
|
|
return this->DeviceTransferState->deviceId();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
void StorageVirtual::ControlPortalForOutput(vtkm::cont::internal::TransferInfoArray&)
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
2018-11-28 15:36:45 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue(
|
|
|
|
"StorageTagVirtual by default doesn't support control side writes.");
|
2018-11-06 16:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2019-02-10 08:46:43 +00:00
|
|
|
void StorageVirtual::TransferPortalForOutput(vtkm::cont::internal::TransferInfoArray&,
|
|
|
|
OutputMode,
|
|
|
|
vtkm::Id,
|
|
|
|
vtkm::cont::DeviceAdapterId)
|
2018-11-06 16:20:30 +00:00
|
|
|
{
|
2018-11-28 15:36:45 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue("StorageTagVirtual by default doesn't support exec side writes.");
|
2018-11-06 16:20:30 +00:00
|
|
|
}
|
2019-02-26 19:23:18 +00:00
|
|
|
|
|
|
|
#define VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(T) \
|
|
|
|
template class VTKM_CONT_EXPORT ArrayTransferVirtual<T>; \
|
|
|
|
template class VTKM_CONT_EXPORT ArrayTransferVirtual<vtkm::Vec<T, 2>>; \
|
|
|
|
template class VTKM_CONT_EXPORT ArrayTransferVirtual<vtkm::Vec<T, 3>>; \
|
|
|
|
template class VTKM_CONT_EXPORT ArrayTransferVirtual<vtkm::Vec<T, 4>>
|
|
|
|
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(char);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::Int8);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::UInt8);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::Int16);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::UInt16);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::Int32);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::UInt32);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::Int64);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::UInt64);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::Float32);
|
|
|
|
VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE(vtkm::Float64);
|
|
|
|
|
|
|
|
#undef VTK_M_ARRAY_TRANSFER_VIRTUAL_INSTANTIATE
|
|
|
|
|
|
|
|
#define VTK_M_STORAGE_VIRTUAL_INSTANTIATE(T) \
|
|
|
|
template class VTKM_CONT_EXPORT StorageVirtualImpl<T, VTKM_DEFAULT_STORAGE_TAG>; \
|
|
|
|
template class VTKM_CONT_EXPORT StorageVirtualImpl<vtkm::Vec<T, 2>, VTKM_DEFAULT_STORAGE_TAG>; \
|
|
|
|
template class VTKM_CONT_EXPORT StorageVirtualImpl<vtkm::Vec<T, 3>, VTKM_DEFAULT_STORAGE_TAG>; \
|
|
|
|
template class VTKM_CONT_EXPORT StorageVirtualImpl<vtkm::Vec<T, 4>, VTKM_DEFAULT_STORAGE_TAG>
|
|
|
|
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(char);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::Int8);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::UInt8);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::Int16);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::UInt16);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::Int32);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::UInt32);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::Int64);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::UInt64);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::Float32);
|
|
|
|
VTK_M_STORAGE_VIRTUAL_INSTANTIATE(vtkm::Float64);
|
|
|
|
|
|
|
|
#undef VTK_M_STORAGE_VIRTUAL_INSTANTIATE
|
2018-11-06 16:20:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-26 19:23:18 +00:00
|
|
|
} // namespace vtkm::cont::internal::detail
|