From 62c5095209ba7dd31f7edcc52c3d432cf4eec54b Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 30 Nov 2020 16:39:56 -0700 Subject: [PATCH] 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. --- vtkm/cont/StorageVirtual.cxx | 4 +-- vtkm/cont/StorageVirtual.h | 47 ++++--------------------------- vtkm/cont/internal/TransferInfo.h | 5 +--- 3 files changed, 9 insertions(+), 47 deletions(-) diff --git a/vtkm/cont/StorageVirtual.cxx b/vtkm/cont/StorageVirtual.cxx index 493e39292..ae39fb663 100644 --- a/vtkm/cont/StorageVirtual.cxx +++ b/vtkm/cont/StorageVirtual.cxx @@ -138,7 +138,7 @@ const vtkm::internal::PortalVirtualBase* StorageVirtual::PrepareForInPlace( } //-------------------------------------------------------------------- -std::unique_ptr&& 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&& StorageVirtual::WritePortal } //-------------------------------------------------------------------- -std::unique_ptr&& 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(); diff --git a/vtkm/cont/StorageVirtual.h b/vtkm/cont/StorageVirtual.h index 5212d421d..626e674ec 100644 --- a/vtkm/cont/StorageVirtual.h +++ b/vtkm/cont/StorageVirtual.h @@ -29,39 +29,6 @@ namespace vtkm namespace cont { -// A control-side version of ArrayPortalRef that also manages the object created. -template -class VTKM_ALWAYS_EXPORT ArrayPortalRef : public vtkm::ArrayPortalRef -{ - std::shared_ptr> ManagedPortal; - -public: - ArrayPortalRef() = default; - - ArrayPortalRef(std::shared_ptr> portal, vtkm::Id numValues) noexcept - : vtkm::ArrayPortalRef(portal.get(), numValues) - , ManagedPortal(portal) - { - } -}; - -} // namespace cont - -template -inline vtkm::cont::ArrayPortalRef make_ArrayPortalRef( - std::shared_ptr> portal, - vtkm::Id numValues) -{ - return vtkm::cont::ArrayPortalRef(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&& 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&& 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 public: using ValueType = T; - using PortalType = vtkm::cont::ArrayPortalRef; - using PortalConstType = vtkm::cont::ArrayPortalRef; + using PortalType = vtkm::ArrayPortalRef; + using PortalConstType = vtkm::ArrayPortalRef; Storage() = default; @@ -286,16 +253,14 @@ public: PortalType GetPortal() { return make_ArrayPortalRef( - std::shared_ptr>(reinterpret_cast*>( - this->VirtualStorage->WritePortal().release())), + reinterpret_cast*>(this->VirtualStorage->WritePortal()), this->GetNumberOfValues()); } PortalConstType GetPortalConst() const { return make_ArrayPortalRef( - std::shared_ptr>(reinterpret_cast*>( - this->VirtualStorage->ReadPortal().release())), + reinterpret_cast*>(this->VirtualStorage->ReadPortal()), this->GetNumberOfValues()); } diff --git a/vtkm/cont/internal/TransferInfo.h b/vtkm/cont/internal/TransferInfo.h index be1a9d5ae..886055139 100644 --- a/vtkm/cont/internal/TransferInfo.h +++ b/vtkm/cont/internal/TransferInfo.h @@ -44,10 +44,7 @@ struct VTKM_CONT_EXPORT TransferInfoArray void releaseDevice(); void releaseAll(); - std::unique_ptr&& 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; }