mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Deprecate ArrayHandleVirtualCoordinates
We are in the process of deprecating virtual classes in VTK-m (that run in the execution environment).
This commit is contained in:
parent
be7f06bbe7
commit
453e314044
39
docs/changelog/deprecate-arrayhandlevirtualcoordinates.md
Normal file
39
docs/changelog/deprecate-arrayhandlevirtualcoordinates.md
Normal file
@ -0,0 +1,39 @@
|
||||
# Deprecate ArrayHandleVirtualCoordinates
|
||||
|
||||
As we port VTK-m to more types of accelerator architectures, supporting
|
||||
virtual methods is becoming more problematic. Thus, we are working to back
|
||||
out of using virtual methods in the execution environment.
|
||||
|
||||
One of the most widespread users of virtual methods in the execution
|
||||
environment is `ArrayHandleVirtual`. As a first step of deprecating this
|
||||
class, we first deprecate the `ArrayHandleVirtualCoordinates` subclass.
|
||||
|
||||
Not surprisingly, `ArrayHandleVirtualCoordinates` is used directly by
|
||||
`CoordinateSystem`. The biggest change necessary was that the `GetData`
|
||||
method returned an `ArrayHandleVirtualCoordinates`, which obviously would
|
||||
not work if that class is deprecated.
|
||||
|
||||
An oddness about this return type is that it is quite different from the
|
||||
superclass's method of the same name. Rather, `Field` returns a
|
||||
`VariantArrayHandle`. Since this had to be corrected anyway, it was decided
|
||||
to change `CoordinateSystem`'s `GetData` to also return a
|
||||
`VariantArrayHandle`, although its typelist is set to just `vtkm::Vec3f`.
|
||||
|
||||
To try to still support old code that expects the deprecated behavior of
|
||||
returning an `ArrayHandleVirtualCoordinates`, `CoordinateSystem::GetData`
|
||||
actually returns a "hidden" subclass of `VariantArrayHandle` that
|
||||
automatically converts itself to an `ArrayHandleVirtualCoordinates`. (A
|
||||
deprecation warning is given if this is done.)
|
||||
|
||||
This approach to support deprecated code is not perfect. The returned value
|
||||
for `CoordinateSystem::GetData` can only be used as an `ArrayHandle` if a
|
||||
method is directly called on it or if it is cast specifically to
|
||||
`ArrayHandleVirtualCoordinates` or its superclass. For example, if passing
|
||||
it to a method argument typed as `vtkm::cont::ArrayHandle<T, S>` where `T`
|
||||
and `S` are template parameters, then the conversion will fail.
|
||||
|
||||
To continue to support ease of use, `CoordinateSystem` now has a method
|
||||
named `GetDataAsMultiplexer` that returns the data as an
|
||||
`ArrayHandleMultiplexer`. This can be employed to quickly use the
|
||||
`CoordinateSystem` as an array without the overhead of a `CastAndCall`.
|
||||
|
@ -28,20 +28,24 @@ namespace cont
|
||||
{
|
||||
|
||||
/// ArrayHandleVirtualCoordinates is a specialization of ArrayHandle.
|
||||
class VTKM_ALWAYS_EXPORT ArrayHandleVirtualCoordinates final
|
||||
: public vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>
|
||||
class VTKM_ALWAYS_EXPORT VTKM_DEPRECATED(1.6, "Virtual ArrayHandles are being phased out.")
|
||||
ArrayHandleVirtualCoordinates final : public vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>
|
||||
{
|
||||
public:
|
||||
VTKM_ARRAY_HANDLE_SUBCLASS_NT(ArrayHandleVirtualCoordinates,
|
||||
(vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>));
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
template <typename T, typename S>
|
||||
explicit ArrayHandleVirtualCoordinates(const vtkm::cont::ArrayHandle<T, S>& ah)
|
||||
: vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>(vtkm::cont::make_ArrayHandleCast<ValueType>(ah))
|
||||
{
|
||||
}
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
};
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
|
||||
template <typename Functor, typename... Args>
|
||||
void CastAndCall(const vtkm::cont::ArrayHandleVirtualCoordinates& coords,
|
||||
Functor&& f,
|
||||
@ -66,6 +70,8 @@ struct SerializableTypeString<vtkm::cont::ArrayHandleVirtualCoordinates>
|
||||
static VTKM_CONT const std::string Get() { return "AH_VirtualCoordinates"; }
|
||||
};
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
} // namespace cont
|
||||
} // namespace vtkm
|
||||
|
||||
@ -75,6 +81,8 @@ struct SerializableTypeString<vtkm::cont::ArrayHandleVirtualCoordinates>
|
||||
namespace mangled_diy_namespace
|
||||
{
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
|
||||
template <>
|
||||
struct Serialization<vtkm::cont::ArrayHandleVirtualCoordinates>
|
||||
{
|
||||
@ -173,6 +181,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
} // diy
|
||||
/// @endcond SERIALIZATION
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
|
||||
#include <vtkm/cont/ArrayHandleCompositeVector.h>
|
||||
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
||||
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h>
|
||||
#include <vtkm/cont/ArrayHandleVirtual.h>
|
||||
#include <vtkm/cont/DeviceAdapterTag.h>
|
||||
|
||||
namespace vtkm
|
||||
|
@ -19,10 +19,12 @@ namespace cont
|
||||
namespace detail
|
||||
{
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
vtkm::cont::ArrayHandleVirtualCoordinates CoordDataDepWrapper::ToArray() const
|
||||
{
|
||||
return this->Cast<vtkm::cont::ArrayHandleVirtualCoordinates>();
|
||||
}
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
@ -37,13 +37,15 @@ class VTKM_ALWAYS_EXPORT CoordDataDepWrapper
|
||||
{
|
||||
using Superclass = vtkm::cont::VariantArrayHandleBase<vtkm::List<vtkm::Vec3f>>;
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
VTKM_CONT_EXPORT VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates ToArray() const;
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
public:
|
||||
using Superclass::Superclass;
|
||||
|
||||
// Make the return also behave as ArrayHandleVirtualCoordiantes
|
||||
// TODO: Deprecate this behavior
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
|
||||
VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
|
||||
operator vtkm::cont::ArrayHandleVirtualCoordinates() const
|
||||
@ -96,6 +98,8 @@ public:
|
||||
{
|
||||
return this->ToArray().PrepareForOutput(numberOfValues, device, token);
|
||||
}
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
@ -10,6 +10,9 @@
|
||||
#ifndef vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h
|
||||
#define vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h
|
||||
|
||||
// This is testing deprecated functionality. It is left to make sure that old code
|
||||
// still works, but will be removed if ArrayHandleVirtualCoordinates is removed.
|
||||
|
||||
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
|
||||
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
||||
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h>
|
||||
@ -17,6 +20,8 @@
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
@ -142,5 +147,6 @@ public:
|
||||
}
|
||||
} // vtkm::cont::testing
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
#endif // vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h
|
||||
|
@ -141,7 +141,9 @@ void TestContDataTypesHaveMoveSemantics()
|
||||
is_noexcept_movable<vtkm::cont::DataSet>();
|
||||
is_noexcept_movable<vtkm::cont::Field>();
|
||||
is_noexcept_movable<vtkm::cont::CoordinateSystem>();
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
is_noexcept_movable<vtkm::cont::ArrayHandleVirtualCoordinates>();
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
//verify the CellSetStructured, and CellSetExplicit
|
||||
//have efficient storage in containers such as std::vector
|
||||
|
@ -417,6 +417,7 @@ void TestArrayHandleUniformPointCoordinates()
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
void TestArrayHandleVirtualCoordinates()
|
||||
{
|
||||
int type = RandomValue<int>::Make(0, 2);
|
||||
@ -444,6 +445,7 @@ void TestArrayHandleVirtualCoordinates()
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
struct TestArrayHandleZip
|
||||
{
|
||||
|
@ -381,7 +381,7 @@ void WriteDataSetAsStructured(std::ostream& out,
|
||||
///\todo: support rectilinear
|
||||
|
||||
// Type of structured grid (uniform, rectilinear, curvilinear) is determined by coordinate system
|
||||
vtkm::cont::ArrayHandleVirtualCoordinates coordSystem = dataSet.GetCoordinateSystem().GetData();
|
||||
auto coordSystem = dataSet.GetCoordinateSystem().GetData();
|
||||
if (coordSystem.IsType<vtkm::cont::ArrayHandleUniformPointCoordinates>())
|
||||
{
|
||||
// uniform is written as "structured points"
|
||||
|
@ -44,6 +44,13 @@ struct CheckSameCoordinateSystem
|
||||
CheckSameField{}(originalArray, fileCoords);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(const vtkm::cont::ArrayHandleVirtual<T>& originalArray,
|
||||
const vtkm::cont::CoordinateSystem& fileCoords) const
|
||||
{
|
||||
CheckSameField{}(originalArray, fileCoords);
|
||||
}
|
||||
|
||||
void operator()(const vtkm::cont::ArrayHandleUniformPointCoordinates& originalArray,
|
||||
const vtkm::cont::CoordinateSystem& fileCoords) const
|
||||
{
|
||||
@ -76,23 +83,6 @@ struct CheckSameCoordinateSystem
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal_portals(originalPortal.GetThirdPortal(), filePortal.GetThirdPortal()));
|
||||
}
|
||||
|
||||
void operator()(const vtkm::cont::ArrayHandleVirtualCoordinates& originalArray,
|
||||
const vtkm::cont::CoordinateSystem& fileCoords) const
|
||||
{
|
||||
if (originalArray.IsType<vtkm::cont::ArrayHandleUniformPointCoordinates>())
|
||||
{
|
||||
(*this)(originalArray.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>(), fileCoords);
|
||||
}
|
||||
else if (originalArray.IsType<ArrayHandleRectilinearCoords>())
|
||||
{
|
||||
(*this)(originalArray.Cast<ArrayHandleRectilinearCoords>(), fileCoords);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckSameField{}(originalArray, fileCoords);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void CheckWrittenReadData(const vtkm::cont::DataSet& originalData,
|
||||
@ -111,8 +101,9 @@ void CheckWrittenReadData(const vtkm::cont::DataSet& originalData,
|
||||
}
|
||||
|
||||
VTKM_TEST_ASSERT(fileData.GetNumberOfCoordinateSystems() > 0);
|
||||
CheckSameCoordinateSystem{}(originalData.GetCoordinateSystem().GetData(),
|
||||
fileData.GetCoordinateSystem());
|
||||
vtkm::cont::CastAndCall(originalData.GetCoordinateSystem().GetData(),
|
||||
CheckSameCoordinateSystem{},
|
||||
fileData.GetCoordinateSystem());
|
||||
}
|
||||
|
||||
void TestVTKWriteTestData(const std::string& methodName, const vtkm::cont::DataSet& data)
|
||||
|
Loading…
Reference in New Issue
Block a user