Commit deb9a3c4 authored by Kenneth Moreland's avatar Kenneth Moreland Committed by Kitware Robot

Merge topic 'field-tags-no-template'

871d3360 Add status update to update script
a52211e5 Fix conversion errors in benchmarking code
821925fb Update changedoc
b2e20bf9 Fix issues from removing field type templates
2e426ad5 Run the update-control-signature-tags.sh script
16c2dfd8 Add script to update control signature tags
42f810f7 Remove type lists from ControlSignature arguments for arrays
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Robert Maynard's avatarRobert Maynard <robert.maynard@kitware.com>
Merge-request: !1450
parents ac610444 871d3360
Pipeline #127508 failed with stage
in 0 seconds
#!/bin/sh
extentions_to_change="cxx cpp cu h hxx hpp"
tags_to_change=" \
FieldIn
FieldOut
FieldInOut
FieldInTo
FieldInFrom
FieldInCell
FieldOutCell
FieldInOutCell
FieldInPoint
FieldInOutPoint
FieldOutPoint
FieldInNeighborhood
ValuesIn
ValuesInOut
ValuesOut
ReducedValuesIn
ReducedValuesInOut
ReducedValuesOut
WholeArrayIn
WholeArrayOut
WholeArrayInOut
AtomicArrayInOut
"
if [ $# -ne 1 ]
then
echo "USAGE: $0 <directory>"
echo
echo "This script seaches for C++ source files and removes the template"
echo "arguments of select ControlSignature tags that have changed since"
echo "VTK-m 1.3. This script searches through all subdirectories of the"
echo "given directory. Files with the following extensions are processed:"
echo
echo " $extentions_to_change"
exit 1
fi
find_command="find '$1' -name 'not-a-name'"
for extention in $extentions_to_change
do
find_command="$find_command -o -name '*.$extention'"
done
sed_command="sed"
for tag in $tags_to_change
do
sed_command="$sed_command -e 's/\\([^a-zA-Z]\\)$tag<[^<>,]*>/\\1$tag/g'"
sed_command="$sed_command -e 's/\\([^a-zA-Z]\\)$tag<[^<>,]*<[^<>]*>[^<>,]*>/\\1$tag/g'"
sed_command="$sed_command -e 's/\\([^a-zA-Z]\\)$tag<[^<>,]*<[^<>]*<[^<>]*>[^<>]>[^<>,]*>/\\1$tag/g'"
done
echo -n "Converting files in `realpath $1`"
for file in `eval $find_command`
do
eval $sed_command $file > $file._do_update_sig
if diff $file $file._do_update_sig > /dev/null
then
rm $file._do_update_sig
else
rm $file
mv $file._do_update_sig $file
fi
echo -n "."
done
echo done
......@@ -66,8 +66,7 @@ class BlackScholes : public vtkm::worklet::WorkletMapField
T Volatility;
public:
using ControlSignature =
void(FieldIn<Scalar>, FieldIn<Scalar>, FieldIn<Scalar>, FieldOut<Scalar>, FieldOut<Scalar>);
using ControlSignature = void(FieldIn, FieldIn, FieldIn, FieldOut, FieldOut);
using ExecutionSignature = void(_1, _2, _3, _4, _5);
BlackScholes(T risk, T volatility)
......@@ -129,7 +128,7 @@ public:
class Mag : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Vec3>, FieldOut<Scalar>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename T, typename U>
......@@ -142,7 +141,7 @@ public:
class Square : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Scalar>, FieldOut<Scalar>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename T, typename U>
......@@ -155,7 +154,7 @@ public:
class Sin : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Scalar>, FieldOut<Scalar>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename T, typename U>
......@@ -168,7 +167,7 @@ public:
class Cos : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Scalar>, FieldOut<Scalar>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename T, typename U>
......@@ -181,7 +180,7 @@ public:
class FusedMath : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Vec3>, FieldOut<Scalar>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename T>
......@@ -201,7 +200,7 @@ public:
class GenerateEdges : public vtkm::worklet::WorkletMapPointToCell
{
public:
using ControlSignature = void(CellSetIn cellset, WholeArrayOut<> edgeIds);
using ControlSignature = void(CellSetIn cellset, WholeArrayOut edgeIds);
using ExecutionSignature = void(PointIndices, ThreadIndices, _2);
using InputDomain = _1;
......@@ -227,10 +226,10 @@ public:
class InterpolateField : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Id2Type> interpolation_ids,
FieldIn<Scalar> interpolation_weights,
WholeArrayIn<> inputField,
FieldOut<> output);
using ControlSignature = void(FieldIn interpolation_ids,
FieldIn interpolation_weights,
WholeArrayIn inputField,
FieldOut output);
using ExecutionSignature = void(_1, _2, _3, _4);
using InputDomain = _1;
......@@ -260,7 +259,7 @@ template <typename ImplicitFunction>
class EvaluateImplicitFunction : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Vec3>, FieldOut<Scalar>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
EvaluateImplicitFunction(const ImplicitFunction* function)
......@@ -282,7 +281,7 @@ template <typename T1, typename T2>
class Evaluate2ImplicitFunctions : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Vec3>, FieldOut<Scalar>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
Evaluate2ImplicitFunctions(const T1* f1, const T2* f2)
......@@ -321,7 +320,7 @@ class BenchmarkFieldAlgorithms
using ValueVariantHandle = vtkm::cont::VariantArrayHandleBase<ValueTypes>;
using InterpVariantHandle = vtkm::cont::VariantArrayHandleBase<InterpValueTypes>;
using IdVariantHandle = vtkm::cont::VariantArrayHandleBase<vtkm::TypeListTagIndex>;
using EdgeIdVariantHandle = vtkm::cont::VariantArrayHandleBase<vtkm::TypeListTagId2>;
private:
template <typename Value>
......@@ -663,8 +662,8 @@ private:
vtkm::Float64 operator()()
{
InterpVariantHandle dfield(this->FieldHandle);
InterpVariantHandle dweight(this->WeightHandle);
IdVariantHandle dedges(this->EdgePairHandle);
ValueVariantHandle dweight(this->WeightHandle);
EdgeIdVariantHandle dedges(this->EdgePairHandle);
vtkm::cont::ArrayHandle<Value> result;
Timer timer;
......
......@@ -799,7 +799,7 @@ public:
struct PointVectorGenerator : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Vec3>, FieldOut<Vec3>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = _2(_1);
vtkm::Bounds Bounds;
......
......@@ -55,9 +55,7 @@ enum BenchmarkName
class AveragePointToCell : public vtkm::worklet::WorkletMapPointToCell
{
public:
using ControlSignature = void(FieldInPoint<> inPoints,
CellSetIn cellset,
FieldOutCell<> outCells);
using ControlSignature = void(FieldInPoint inPoints, CellSetIn cellset, FieldOutCell outCells);
using ExecutionSignature = void(_1, PointCount, _3);
using InputDomain = _2;
......@@ -79,7 +77,7 @@ public:
class AverageCellToPoint : public vtkm::worklet::WorkletMapCellToPoint
{
public:
using ControlSignature = void(FieldInCell<> inCells, CellSetIn topology, FieldOut<> outPoints);
using ControlSignature = void(FieldInCell inCells, CellSetIn topology, FieldOut outPoints);
using ExecutionSignature = void(_1, _3, CellCount);
using InputDomain = _2;
......@@ -106,9 +104,7 @@ template <typename T>
class Classification : public vtkm::worklet::WorkletMapPointToCell
{
public:
using ControlSignature = void(FieldInPoint<> inNodes,
CellSetIn cellset,
FieldOutCell<IdComponentType> outCaseId);
using ControlSignature = void(FieldInPoint inNodes, CellSetIn cellset, FieldOutCell outCaseId);
using ExecutionSignature = void(_1, _3);
using InputDomain = _2;
......
# Remove templates from ControlSignature field tags
Previously, several of the `ControlSignature` tags had a template to
specify a type list. This was to specify potential valid value types for an
input array. The importance of this typelist was to limit the number of
code paths created when resolving a `vtkm::cont::VariantArrayHandle`
(formerly a `DynamicArrayHandle`). This (potentially) reduced the compile
time, the size of libraries/executables, and errors from unexpected types.
Much has changed since this feature was originally implemented. Since then,
the filter infrastructure has been created, and it is through this that
most dynamic worklet invocations happen. However, since the filter
infrastrcture does its own type resolution (and has its own policies) the
type arguments in `ControlSignature` are now of little value.
## Script to update code
This update requires changes to just about all code implementing a VTK-m
worklet. To facilitate the update of this code to these new changes (not to
mention all the code in VTK-m) a script is provided to automatically remove
these template parameters from VTK-m code.
This script is at
[Utilities/Scripts/update-control-signature-tags.sh](../../Utilities/Scripts/update-control-signature-tags.sh).
It needs to be run in a Unix-compatible shell. It takes a single argument,
which is a top level directory to modify files. The script processes all C++
source files recursively from that directory.
## Selecting data types for auxiliary filter fields
The main rational for making these changes is that the types of the inputs
to worklets is almost always already determined by the calling filter.
However, although it is straightforward to specify the type of the "main"
(active) scalars in a filter, it is less clear what to do for additional
fields if a filter needs a second or third field.
Typically, in the case of a second or third field, it is up to the
`DoExecute` method in the filter implementation to apply a policy to that
field. When applying a policy, you give it a policy object (nominally
passed by the user) and a traits of the filter. Generally, the accepted
list of types for a field should be part of the filter's traits. For
example, consider the `WarpVector` filter. This filter only works on
`Vec`s of size 3, so its traits class looks like this.
``` cpp
template <>
class FilterTraits<WarpVector>
{
public:
// WarpVector can only applies to Float and Double Vec3 arrays
using InputFieldTypeList = vtkm::TypeListTagFieldVec3;
};
```
However, the `WarpVector` filter also requires two fields instead of one.
The first (active) field is handled by its superclass (`FilterField`), but
the second (auxiliary) field must be managed in the `DoExecute`. Generally,
this can be done by simply applying the policy with the filter traits.
## The corner cases
Most of the calls to worklets happen within filter implementations, which
have their own way of narrowing down potential types (as previously
described). The majority of the remainder either use static types or work
with a variety of types.
However, there is a minority of corner cases that require a reduction of
types. Since the type argument of the worklet `ControlSignature` arguments
are no longer available, the narrowing of types must be done before the
call to `Invoke`.
This narrowing of arguments is not particularly difficult. Such type-unsure
arguments usually come from a `VariantArrayHandle` (or something that uses
one). You can select the types from a `VariantArrayHandle` simply by using
the `ResetTypes` method. For example, say you know that a variant array is
supposed to be a scalar.
``` cpp
dispatcher.Invoke(variantArray.ResetTypes(vtkm::TypeListTagFieldScalar()),
staticArray);
```
Even more common is to have a `vtkm::cont::Field` object. A `Field` object
internally holds a `VariantArrayHandle`, which is accessible via the
`GetData` method.
``` cpp
dispatcher.Invoke(field.GetData().ResetTypes(vtkm::TypeListTagFieldScalar()),
staticArray);
```
## Change in executable size
The whole intention of these template parameters in the first place was to
reduce the number of code paths compiled. The hypothesis of this change was
that in the current structure the code paths were not being reduced much
if at all. If that is true, the size of executables and libraries should
not change.
Here is a recording of the library and executable sizes before this change
(using `ds -h`).
```
3.0M libvtkm_cont-1.2.1.dylib
6.2M libvtkm_rendering-1.2.1.dylib
312K Rendering_SERIAL
312K Rendering_TBB
22M Worklets_SERIAL
23M Worklets_TBB
22M UnitTests_vtkm_filter_testing
5.7M UnitTests_vtkm_cont_serial_testing
6.0M UnitTests_vtkm_cont_tbb_testing
7.1M UnitTests_vtkm_cont_testing
```
After the changes, the executable sizes are as follows.
```
3.0M libvtkm_cont-1.2.1.dylib
6.0M libvtkm_rendering-1.2.1.dylib
312K Rendering_SERIAL
312K Rendering_TBB
21M Worklets_SERIAL
21M Worklets_TBB
22M UnitTests_vtkm_filter_testing
5.6M UnitTests_vtkm_cont_serial_testing
6.0M UnitTests_vtkm_cont_tbb_testing
7.1M UnitTests_vtkm_cont_testing
```
As we can see, the built sizes have not changed significantly. (If
anything, the build is a little smaller.)
......@@ -72,9 +72,9 @@ struct UpdateLifeState : public vtkm::worklet::WorkletPointNeighborhood
using CountingHandle = vtkm::cont::ArrayHandleCounting<vtkm::Id>;
using ControlSignature = void(CellSetIn,
FieldInNeighborhood<> prevstate,
FieldOut<> state,
FieldOut<> color);
FieldInNeighborhood prevstate,
FieldOut state,
FieldOut color);
using ExecutionSignature = void(_2, _3, _4);
......
......@@ -139,7 +139,7 @@ struct HelloVTKMInterop
{
}
using ControlSignature = void(FieldIn<>, FieldOut<>, FieldOut<>);
using ControlSignature = void(FieldIn, FieldOut, FieldOut);
using ExecutionSignature = void(_1, _2, _3);
VTKM_EXEC
......
......@@ -62,7 +62,7 @@ namespace
class TangleField : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<IdType> vertexId, FieldOut<Scalar> v);
using ControlSignature = void(FieldIn vertexId, FieldOut v);
using ExecutionSignature = void(_1, _2);
using InputDomain = _1;
......
......@@ -34,7 +34,7 @@
struct WaveField : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn<Vec3>, FieldOut<Vec3>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename T>
......
......@@ -68,7 +68,7 @@ using DeviceAdapter = VTKM_DEFAULT_DEVICE_ADAPTER_TAG;
class TangleField : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<IdType> vertexId, FieldOut<Scalar> v);
using ControlSignature = void(FieldIn vertexId, FieldOut v);
using ExecutionSignature = void(_1, _2);
using InputDomain = _1;
......
......@@ -37,7 +37,7 @@ namespace worklet
class SineWorklet : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<>, FieldOut<>);
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = _2(_1, WorkIndex);
VTKM_EXEC
......
......@@ -79,11 +79,11 @@ public:
DIM>;
public:
using ControlSignature = void(FieldIn<Vec3> points,
using ControlSignature = void(FieldIn points,
WholeCellSetIn<> cellSet,
WholeArrayIn<Vec3> coordinates,
FieldOut<IdType> cellIds,
FieldOut<Vec3> parametricCoordinates);
WholeArrayIn coordinates,
FieldOut cellIds,
FieldOut parametricCoordinates);
using ExecutionSignature = void(_1, _2, _3, _4, _5);
template <typename CoordsPortalType, vtkm::IdComponent DIM>
......
......@@ -280,9 +280,7 @@ public:
class CountBinsL1 : public vtkm::worklet::WorkletMapPointToCell
{
public:
using ControlSignature = void(CellSetIn cellset,
FieldInPoint<Vec3> coords,
FieldOutCell<IdType> bincount);
using ControlSignature = void(CellSetIn cellset, FieldInPoint coords, FieldOutCell bincount);
using ExecutionSignature = void(_2, _3);
CountBinsL1(const vtkm::exec::twolevelgrid::Grid& grid)
......@@ -306,9 +304,9 @@ public:
{
public:
using ControlSignature = void(CellSetIn cellset,
FieldInPoint<Vec3> coords,
FieldInCell<IdType> offsets,
WholeArrayOut<IdType> binIds);
FieldInPoint coords,
FieldInCell offsets,
WholeArrayOut binIds);
using ExecutionSignature = void(_2, _3, _4);
FindBinsL1(const vtkm::exec::twolevelgrid::Grid& grid)
......@@ -338,9 +336,7 @@ public:
class GenerateBinsL1 : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<IdType> binIds,
FieldIn<IdType> cellCounts,
WholeArrayOut<vtkm::ListTagBase<DimVec3>> dimensions);
using ControlSignature = void(FieldIn binIds, FieldIn cellCounts, WholeArrayOut dimensions);
using ExecutionSignature = void(_1, _2, _3);
using InputDomain = _1;
......@@ -368,9 +364,9 @@ public:
{
public:
using ControlSignature = void(CellSetIn cellset,
FieldInPoint<Vec3> coords,
WholeArrayIn<vtkm::ListTagBase<DimVec3>> binDimensions,
FieldOutCell<IdType> bincount);
FieldInPoint coords,
WholeArrayIn binDimensions,
FieldOutCell bincount);
using ExecutionSignature = void(_2, _3, _4);
CountBinsL2(const vtkm::exec::twolevelgrid::Grid& grid)
......@@ -404,12 +400,12 @@ public:
{
public:
using ControlSignature = void(CellSetIn cellset,
FieldInPoint<Vec3> coords,
WholeArrayIn<vtkm::ListTagBase<DimVec3>> binDimensions,
WholeArrayIn<IdType> binStarts,
FieldInCell<IdType> offsets,
WholeArrayOut<IdType> binIds,
WholeArrayOut<IdType> cellIds);
FieldInPoint coords,
WholeArrayIn binDimensions,
WholeArrayIn binStarts,
FieldInCell offsets,
WholeArrayOut binIds,
WholeArrayOut cellIds);
using ExecutionSignature = void(InputIndex, _2, _3, _4, _5, _6, _7);
FindBinsL2(const vtkm::exec::twolevelgrid::Grid& grid)
......@@ -456,11 +452,11 @@ public:
class GenerateBinsL2 : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<IdType> binIds,
FieldIn<IdType> startsIn,
FieldIn<IdType> countsIn,
WholeArrayOut<IdType> startsOut,
WholeArrayOut<IdType> countsOut);
using ControlSignature = void(FieldIn binIds,
FieldIn startsIn,
FieldIn countsIn,
WholeArrayOut startsOut,
WholeArrayOut countsOut);
using ExecutionSignature = void(_1, _2, _3, _4, _5);
using InputDomain = _1;
......@@ -622,12 +618,12 @@ public:
class FindCellWorklet : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<Vec3> points,
using ControlSignature = void(FieldIn points,
WholeCellSetIn<> cellSet,
WholeArrayIn<Vec3> coordinates,
WholeArrayIn coordinates,
ExecObject lookupStruct,
FieldOut<IdType> cellIds,
FieldOut<Vec3> parametricCoordinates);
FieldOut cellIds,
FieldOut parametricCoordinates);
using ExecutionSignature = void(_1, _2, _3, _4, _5, _6);
using InputDomain = _1;
......
......@@ -46,9 +46,7 @@ namespace internal
struct WriteConnectivity : public vtkm::worklet::WorkletMapPointToCell
{
using ControlSignature = void(CellSetIn cellset,
FieldInCell<IdType> offset,
WholeArrayOut<> connectivity);
using ControlSignature = void(CellSetIn cellset, FieldInCell offset, WholeArrayOut connectivity);
using ExecutionSignature = void(PointCount, PointIndices, _2, _3);
using InputDomain = _1;
......
......@@ -100,7 +100,7 @@ VTKM_CONT CellSetType* DynamicCellSetTryCast(
///
/// By default, \c DynamicCellSet will assume that the value type in the array
/// matches one of the types specified by \c VTKM_DEFAULT_CELL_SET_LIST_TAG.
/// This list can be changed by using the \c ResetTypeList method. It is
/// This list can be changed by using the \c ResetCellSetList method. It is
/// worthwhile to match these lists closely to the possible types that might be
/// used. If a type is missing you will get a runtime error. If there are more
/// types than necessary, then the template mechanism will create a lot of
......
......@@ -49,7 +49,7 @@ public:
class BinPointsWorklet : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn<> coord, FieldOut<> label);
using ControlSignature = void(FieldIn coord, FieldOut label);
using ExecutionSignature = void(_1, _2);
......
......@@ -36,39 +36,14 @@ namespace arg
/// The Array type check passes for any object that behaves like an \c
/// ArrayHandle class and can be passed to the ArrayIn and ArrayOut transports.
///
template <typename TypeList>
struct TypeCheckTagArray
{
VTKM_IS_LIST_TAG(TypeList);
};
namespace detail
template <typename ArrayType>
struct TypeCheck<TypeCheckTagArray, ArrayType>
{
template <typename TypeList, typename ArrayType, bool IsArray>
struct TypeCheckArrayValueType;
template <typename TypeList, typename ArrayType>
struct TypeCheckArrayValueType<TypeList, ArrayType, true>
{