mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Add a common API for CoordinateSystem to unload execution resources
This commit also fixes a bug that ArrayTransfer of ArrayHandleVirtualCoordinate does not release execution resources properly.
This commit is contained in:
parent
bf8fcc9189
commit
7d226a4666
@ -0,0 +1,9 @@
|
||||
# Add a common API for CoordinateSystem to unload execution resources
|
||||
We now offer the ability to unload execution memory from ArrayHandleVirtualCoordinate
|
||||
and CoordinateSystem using the ReleaseResourcesExecution method.
|
||||
|
||||
Field now has a ReleaseResourcesExecution.
|
||||
|
||||
This commit also fixes a bug that ArrayTransfer of ArrayHandleVirtualCoordinate
|
||||
does not release execution resources properly.
|
||||
|
@ -181,6 +181,7 @@ public:
|
||||
VTKM_CONT virtual void Allocate(vtkm::Id numberOfValues) = 0;
|
||||
VTKM_CONT virtual void Shrink(vtkm::Id numberOfValues) = 0;
|
||||
VTKM_CONT virtual void ReleaseResources() = 0;
|
||||
VTKM_CONT virtual void ReleaseResourcesExecution() = 0;
|
||||
|
||||
VTKM_CONT virtual PortalConst PrepareForInput(vtkm::cont::DeviceAdapterId deviceId) = 0;
|
||||
VTKM_CONT virtual Portal PrepareForOutput(vtkm::Id numberOfValues,
|
||||
@ -241,6 +242,8 @@ public:
|
||||
|
||||
VTKM_CONT void ReleaseResources() override { this->Array.ReleaseResources(); }
|
||||
|
||||
VTKM_CONT void ReleaseResourcesExecution() override { this->Array.ReleaseResourcesExecution(); }
|
||||
|
||||
VTKM_CONT PortalConst PrepareForInput(vtkm::cont::DeviceAdapterId deviceId) override
|
||||
{
|
||||
PortalConst portal;
|
||||
@ -406,8 +409,10 @@ public:
|
||||
VTKM_CONT
|
||||
void Shrink(vtkm::Id numberOfValues) { this->Array->Shrink(numberOfValues); }
|
||||
|
||||
// ArrayTransfer should only be capable of releasing resources in the execution
|
||||
// environment
|
||||
VTKM_CONT
|
||||
void ReleaseResources() { this->Array->ReleaseResources(); }
|
||||
void ReleaseResources() { this->Array->ReleaseResourcesExecution(); }
|
||||
|
||||
private:
|
||||
CoordinatesArrayHandleBase* Array;
|
||||
|
@ -81,7 +81,15 @@ public:
|
||||
VTKM_CONT
|
||||
vtkm::Bounds GetBounds() const;
|
||||
|
||||
virtual void PrintSummary(std::ostream& out) const;
|
||||
virtual void PrintSummary(std::ostream& out) const override;
|
||||
|
||||
/// Releases any resources being used in the execution environment (that are
|
||||
/// not being shared by the control environment).
|
||||
VTKM_CONT void ReleaseResourcesExecution() override
|
||||
{
|
||||
this->Superclass::ReleaseResourcesExecution();
|
||||
this->GetData().ReleaseResourcesExecution();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Functor, typename... Args>
|
||||
|
@ -276,6 +276,14 @@ public:
|
||||
VTKM_CONT
|
||||
virtual void PrintSummary(std::ostream& out) const;
|
||||
|
||||
VTKM_CONT
|
||||
virtual void ReleaseResourcesExecution()
|
||||
{
|
||||
// TODO: Call ReleaseResourcesExecution on the data when
|
||||
// the DynamicArrayHandle class is able to do so.
|
||||
this->Range.ReleaseResourcesExecution();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string Name; ///< name of field
|
||||
|
||||
|
@ -49,6 +49,20 @@ struct CopyWorklet : public vtkm::worklet::WorkletMapField
|
||||
}
|
||||
};
|
||||
|
||||
// A dummy worklet
|
||||
struct DoubleWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
typedef void ControlSignature(FieldIn<FieldCommon> in);
|
||||
typedef void ExecutionSignature(_1);
|
||||
using InputDomain = _1;
|
||||
|
||||
template <typename T>
|
||||
VTKM_EXEC void operator()(T& in) const
|
||||
{
|
||||
in = in * 2;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename S, typename DeviceAdapter>
|
||||
inline void TestVirtualAccess(const vtkm::cont::ArrayHandle<T, S>& in,
|
||||
vtkm::cont::ArrayHandle<T>& out,
|
||||
@ -109,6 +123,23 @@ private:
|
||||
}
|
||||
TestVirtualAccess(
|
||||
vtkm::cont::make_ArrayHandleCartesianProduct(c1, c2, c3), out, DeviceAdapter{});
|
||||
|
||||
std::cout << "Testing resources releasing on ArrayHandleVirtualCoordinates\n";
|
||||
vtkm::cont::ArrayHandleVirtualCoordinates virtualC =
|
||||
vtkm::cont::ArrayHandleVirtualCoordinates(a1);
|
||||
vtkm::worklet::DispatcherMapField<DoubleWorklet, DeviceAdapter>().Invoke(a1);
|
||||
virtualC.ReleaseResourcesExecution();
|
||||
VTKM_TEST_ASSERT(a1.GetNumberOfValues() == length,
|
||||
"ReleaseResourcesExecution"
|
||||
" should not change the number of values on the Arrayhandle");
|
||||
VTKM_TEST_ASSERT(
|
||||
virtualC.GetNumberOfValues() == length,
|
||||
"ReleaseResources"
|
||||
" should set the number of values on the ArrayHandleVirtualCoordinates to be 0");
|
||||
virtualC.ReleaseResources();
|
||||
VTKM_TEST_ASSERT(a1.GetNumberOfValues() == 0,
|
||||
"ReleaseResources"
|
||||
" should set the number of values on the Arrayhandle to be 0");
|
||||
}
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user