Improve Threshold runtime and compile performance

Using GCC 9.2 the pre change vtkm::filter::Threshold would
take 31.84sec to compile and use 1.1GB of memory. After
these changes the filter takes 24.16sec to compile and
uses 885MB of memory.
This commit is contained in:
Robert Maynard 2019-11-26 16:53:56 -05:00
parent 291f3527b1
commit a92ad22c73
6 changed files with 32 additions and 60 deletions

@ -31,9 +31,19 @@ public:
template <typename T>
VTKM_EXEC bool operator()(const T& value) const
{
return value >= static_cast<T>(this->Lower) && value <= static_cast<T>(this->Upper);
}
//Needed to work with ArrayHandleVirtual
template <typename PortalType>
VTKM_EXEC bool operator()(
const vtkm::internal::ArrayPortalValueReference<PortalType>& value) const
{
using T = typename PortalType::ValueType;
return value.Get() >= static_cast<T>(this->Lower) && value.Get() <= static_cast<T>(this->Upper);
}
private:
vtkm::Float64 Lower;
vtkm::Float64 Upper;

@ -29,10 +29,6 @@ namespace worklet
class ExtractGeometry
{
public:
struct BoolType : vtkm::ListTagBase<bool>
{
};
////////////////////////////////////////////////////////////////////////////////////
// Worklet to identify cells within volume of interest
class ExtractCellsByVOI : public vtkm::worklet::WorkletVisitCellsWithPoints

@ -28,10 +28,6 @@ namespace worklet
class ExtractPoints
{
public:
struct BoolType : vtkm::ListTagBase<bool>
{
};
////////////////////////////////////////////////////////////////////////////////////
// Worklet to identify points within volume of interest
class ExtractPointsByVOI : public vtkm::worklet::WorkletVisitPointsWithCells

@ -29,10 +29,6 @@ namespace worklet
class Mask
{
public:
struct BoolType : vtkm::ListTagBase<bool>
{
};
template <typename CellSetType>
vtkm::cont::CellSetPermutation<CellSetType> Run(const CellSetType& cellSet, const vtkm::Id stride)
{

@ -11,8 +11,8 @@
#define vtkm_m_worklet_Threshold_h
#include <vtkm/worklet/CellDeepCopy.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayCopy.h>
@ -37,10 +37,6 @@ public:
Cell
};
struct BoolType : vtkm::ListTagBase<bool>
{
};
template <typename UnaryPredicate>
class ThresholdByPointField : public vtkm::worklet::WorkletVisitCellsWithPoints
{
@ -76,36 +72,20 @@ public:
UnaryPredicate Predicate;
};
template <typename UnaryPredicate>
class ThresholdByCellField : public vtkm::worklet::WorkletVisitCellsWithPoints
struct ThresholdCopy : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(CellSetIn cellset, FieldInCell scalars, FieldOut passFlags);
using ControlSignature = void(FieldIn, FieldOut, WholeArrayIn);
using ExecutionSignature = _3(_2);
VTKM_CONT
ThresholdByCellField()
: Predicate()
template <typename ScalarType, typename WholeFieldIn>
VTKM_EXEC void operator()(vtkm::Id& index,
ScalarType& output,
const WholeFieldIn& inputField) const
{
output = inputField.Get(index);
}
VTKM_CONT
explicit ThresholdByCellField(const UnaryPredicate& predicate)
: Predicate(predicate)
{
}
template <typename ScalarType>
VTKM_EXEC bool operator()(const ScalarType& scalar) const
{
return this->Predicate(scalar);
}
private:
UnaryPredicate Predicate;
};
template <typename CellSetType, typename ValueType, typename StorageType, typename UnaryPredicate>
vtkm::cont::CellSetPermutation<CellSetType> Run(
const CellSetType& cellSet,
@ -115,25 +95,29 @@ public:
{
using OutputType = vtkm::cont::CellSetPermutation<CellSetType>;
vtkm::cont::ArrayHandle<bool> passFlags;
switch (fieldType)
{
case vtkm::cont::Field::Association::POINTS:
{
using ThresholdWorklet = ThresholdByPointField<UnaryPredicate>;
vtkm::cont::ArrayHandle<bool> passFlags;
ThresholdWorklet worklet(predicate);
DispatcherMapTopology<ThresholdWorklet> dispatcher(worklet);
dispatcher.Invoke(cellSet, field, passFlags);
vtkm::cont::Algorithm::CopyIf(vtkm::cont::ArrayHandleIndex(passFlags.GetNumberOfValues()),
passFlags,
this->ValidCellIds);
break;
}
case vtkm::cont::Field::Association::CELL_SET:
{
using ThresholdWorklet = ThresholdByCellField<UnaryPredicate>;
ThresholdWorklet worklet(predicate);
DispatcherMapTopology<ThresholdWorklet> dispatcher(worklet);
dispatcher.Invoke(cellSet, field, passFlags);
vtkm::cont::Algorithm::CopyIf(vtkm::cont::ArrayHandleIndex(field.GetNumberOfValues()),
field,
this->ValidCellIds,
predicate);
break;
}
@ -141,9 +125,6 @@ public:
throw vtkm::cont::ErrorBadValue("Expecting point or cell field.");
}
vtkm::cont::Algorithm::CopyIf(
vtkm::cont::ArrayHandleIndex(passFlags.GetNumberOfValues()), passFlags, this->ValidCellIds);
return OutputType(this->ValidCellIds, cellSet);
}
@ -195,14 +176,11 @@ public:
template <typename ValueType, typename StorageTag>
vtkm::cont::ArrayHandle<ValueType> ProcessCellField(
const vtkm::cont::ArrayHandle<ValueType, StorageTag> in) const
const vtkm::cont::ArrayHandle<ValueType, StorageTag>& in) const
{
// Use a temporary permutation array to simplify the mapping:
auto tmp = vtkm::cont::make_ArrayHandlePermutation(this->ValidCellIds, in);
// Copy into an array with default storage:
vtkm::cont::ArrayHandle<ValueType> result;
vtkm::cont::ArrayCopy(tmp, result);
DispatcherMapField<ThresholdCopy> dispatcher;
dispatcher.Invoke(this->ValidCellIds, result, in);
return result;
}

@ -25,10 +25,6 @@ namespace worklet
class ThresholdPoints
{
public:
struct BoolType : vtkm::ListTagBase<bool>
{
};
template <typename UnaryPredicate>
class ThresholdPointField : public vtkm::worklet::WorkletVisitPointsWithCells
{