Save host portal for ArrayHandleVirtual in array instead of portal

Previously, when you got a host/control portal from
`ArrayHandleVirtual`, you got a version of an `ArrayPortal` that manged
its own reference to the virtual structure that was implementing the
portal. This was not done for device/execution portals because those
objects could not do the appropriate resource management from the
execution environment.

Rather than releasing the host object to the portal, keep the host
object managed by `StorageVirtual`. This allows the control and
execution portals to be the same type, which we will need to be friendly
with new array objects.
This commit is contained in:
Kenneth Moreland 2020-11-30 16:39:56 -07:00
parent bc3a7d8e25
commit 62c5095209
3 changed files with 9 additions and 47 deletions

@ -138,7 +138,7 @@ const vtkm::internal::PortalVirtualBase* StorageVirtual::PrepareForInPlace(
}
//--------------------------------------------------------------------
std::unique_ptr<vtkm::internal::PortalVirtualBase>&& StorageVirtual::WritePortal()
const vtkm::internal::PortalVirtualBase* StorageVirtual::WritePortal()
{
//we need to prepare for input and grab the host ptr
auto* payload = this->DeviceTransferState.get();
@ -149,7 +149,7 @@ std::unique_ptr<vtkm::internal::PortalVirtualBase>&& StorageVirtual::WritePortal
}
//--------------------------------------------------------------------
std::unique_ptr<vtkm::internal::PortalVirtualBase>&& StorageVirtual::ReadPortal() const
const vtkm::internal::PortalVirtualBase* StorageVirtual::ReadPortal() const
{
//we need to prepare for input and grab the host ptr
vtkm::cont::internal::TransferInfoArray* payload = this->DeviceTransferState.get();

@ -29,39 +29,6 @@ namespace vtkm
namespace cont
{
// A control-side version of ArrayPortalRef that also manages the object created.
template <typename T>
class VTKM_ALWAYS_EXPORT ArrayPortalRef : public vtkm::ArrayPortalRef<T>
{
std::shared_ptr<vtkm::ArrayPortalVirtual<T>> ManagedPortal;
public:
ArrayPortalRef() = default;
ArrayPortalRef(std::shared_ptr<vtkm::ArrayPortalVirtual<T>> portal, vtkm::Id numValues) noexcept
: vtkm::ArrayPortalRef<T>(portal.get(), numValues)
, ManagedPortal(portal)
{
}
};
} // namespace cont
template <typename T>
inline vtkm::cont::ArrayPortalRef<T> make_ArrayPortalRef(
std::shared_ptr<vtkm::ArrayPortalVirtual<T>> portal,
vtkm::Id numValues)
{
return vtkm::cont::ArrayPortalRef<T>(portal, numValues);
}
} // namespace vtkm
namespace vtkm
{
namespace cont
{
struct VTKM_ALWAYS_EXPORT VTKM_DEPRECATED(1.6) StorageTagVirtual
{
};
@ -159,11 +126,11 @@ public:
//This needs to cause a host side sync!
//This needs to work before we execute on a device
std::unique_ptr<vtkm::internal::PortalVirtualBase>&& WritePortal();
const vtkm::internal::PortalVirtualBase* WritePortal();
//This needs to cause a host side sync!
//This needs to work before we execute on a device
std::unique_ptr<vtkm::internal::PortalVirtualBase>&& ReadPortal() const;
const vtkm::internal::PortalVirtualBase* ReadPortal() const;
/// Returns the DeviceAdapterId for the current device. If there is no device
/// with an up-to-date copy of the data, VTKM_DEVICE_ADAPTER_UNDEFINED is
@ -267,8 +234,8 @@ class VTKM_ALWAYS_EXPORT Storage<T, vtkm::cont::StorageTagVirtual>
public:
using ValueType = T;
using PortalType = vtkm::cont::ArrayPortalRef<T>;
using PortalConstType = vtkm::cont::ArrayPortalRef<T>;
using PortalType = vtkm::ArrayPortalRef<T>;
using PortalConstType = vtkm::ArrayPortalRef<T>;
Storage() = default;
@ -286,16 +253,14 @@ public:
PortalType GetPortal()
{
return make_ArrayPortalRef(
std::shared_ptr<vtkm::ArrayPortalVirtual<T>>(reinterpret_cast<vtkm::ArrayPortalVirtual<T>*>(
this->VirtualStorage->WritePortal().release())),
reinterpret_cast<const vtkm::ArrayPortalVirtual<T>*>(this->VirtualStorage->WritePortal()),
this->GetNumberOfValues());
}
PortalConstType GetPortalConst() const
{
return make_ArrayPortalRef(
std::shared_ptr<vtkm::ArrayPortalVirtual<T>>(reinterpret_cast<vtkm::ArrayPortalVirtual<T>*>(
this->VirtualStorage->ReadPortal().release())),
reinterpret_cast<const vtkm::ArrayPortalVirtual<T>*>(this->VirtualStorage->ReadPortal()),
this->GetNumberOfValues());
}

@ -44,10 +44,7 @@ struct VTKM_CONT_EXPORT TransferInfoArray
void releaseDevice();
void releaseAll();
std::unique_ptr<vtkm::internal::PortalVirtualBase>&& hostPtr() noexcept
{
return std::move(this->Host);
}
const vtkm::internal::PortalVirtualBase* hostPtr() noexcept { return this->Host.get(); }
const vtkm::internal::PortalVirtualBase* devicePtr() const noexcept { return this->Device; }
vtkm::cont::DeviceAdapterId deviceId() const noexcept { return this->DeviceId; }