Merge topic 'scatter-on-dispatcher'

edc4c85f Move Scatter from Worklet to Dispatcher

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Robert Maynard <robert.maynard@kitware.com>
Merge-request: !1172
This commit is contained in:
Kenneth Moreland 2018-05-01 16:17:20 +00:00 committed by Kitware Robot
commit bb54d9d411
29 changed files with 181 additions and 358 deletions

@ -55,13 +55,12 @@ public:
using ScatterType = vtkm::worklet::ScatterPermutation<>;
explicit ParametricToWorldCoordinates(const vtkm::cont::ArrayHandle<vtkm::Id>& cellIds)
: Scatter(cellIds)
VTKM_CONT
static ScatterType MakeScatter(const vtkm::cont::ArrayHandle<vtkm::Id>& cellIds)
{
return ScatterType(cellIds);
}
const ScatterType& GetScatter() const { return this->Scatter; }
template <typename CellShapeTagType, typename PointsVecType>
VTKM_EXEC void operator()(CellShapeTagType cellShape,
PointsVecType points,
@ -70,9 +69,6 @@ public:
{
wc = vtkm::exec::CellInterpolate(points, pc, cellShape, *this);
}
private:
ScatterType Scatter;
};
template <vtkm::IdComponent DIMENSIONS, typename DeviceAdapter>
@ -185,9 +181,9 @@ void GenerateRandomInput(const vtkm::cont::DataSet& ds,
pcoords.GetPortalControl().Set(i, pc);
}
ParametricToWorldCoordinates pc2wc(cellIds);
vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates>(pc2wc).Invoke(
ds.GetCellSet(), ds.GetCoordinateSystem().GetData(), pcoords, wcoords);
vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates> dispatcher(
ParametricToWorldCoordinates::MakeScatter(cellIds));
dispatcher.Invoke(ds.GetCellSet(), ds.GetCoordinateSystem().GetData(), pcoords, wcoords);
}
template <vtkm::IdComponent DIMENSIONS, typename DeviceAdapter>

@ -177,13 +177,11 @@ struct EdgesExtracter : public vtkm::worklet::WorkletMapPointToCell
VTKM_CONT
template <typename CountArrayType, typename DeviceTag>
EdgesExtracter(const CountArrayType& counts, DeviceTag device)
: Scatter(counts, device)
static ScatterType MakeScatter(const CountArrayType& counts, DeviceTag device)
{
return ScatterType(counts, device);
}
VTKM_CONT ScatterType GetScatter() const { return this->Scatter; }
template <typename CellShapeTag, typename PointIndexVecType, typename EdgeIndexVecType>
VTKM_EXEC void operator()(CellShapeTag shape,
const PointIndexVecType& pointIndices,
@ -209,9 +207,6 @@ struct EdgesExtracter : public vtkm::worklet::WorkletMapPointToCell
edgeIndices[0] = p1 < p2 ? p1 : p2;
edgeIndices[1] = p1 < p2 ? p2 : p1;
}
private:
ScatterType Scatter;
}; // struct EdgesExtracter
#if defined(VTKM_MSVC)
@ -236,9 +231,8 @@ struct ExtractUniqueEdges
vtkm::cont::ArrayHandle<vtkm::IdComponent> counts;
vtkm::worklet::DispatcherMapTopology<EdgesCounter, DeviceTag>().Invoke(CellSet, counts);
EdgesExtracter extractWorklet(counts, DeviceTag());
vtkm::worklet::DispatcherMapTopology<EdgesExtracter, DeviceTag> extractDispatcher(
extractWorklet);
EdgesExtracter::MakeScatter(counts, DeviceTag()));
extractDispatcher.Invoke(CellSet, EdgeIndices);
vtkm::cont::DeviceAdapterAlgorithm<DeviceTag>::template Sort<vtkm::Id2>(EdgeIndices);
vtkm::cont::DeviceAdapterAlgorithm<DeviceTag>::template Unique<vtkm::Id2>(EdgeIndices);

@ -41,11 +41,24 @@ class DispatcherMapField
vtkm::worklet::internal::DispatcherBase<DispatcherMapField<WorkletType, Device>,
WorkletType,
vtkm::worklet::WorkletMapField>;
using ScatterType = typename Superclass::ScatterType;
public:
// If you get a compile error here about there being no appropriate constructor for ScatterType,
// then that probably means that the worklet you are trying to execute has defined a custom
// ScatterType and that you need to create one (because there is no default way to construct
// the scatter). By convention, worklets that define a custom scatter type usually provide a
// static method named MakeScatter that constructs a scatter object.
VTKM_CONT
DispatcherMapField(const WorkletType& worklet = WorkletType())
: Superclass(worklet)
DispatcherMapField(const WorkletType& worklet = WorkletType(),
const ScatterType& scatter = ScatterType())
: Superclass(worklet, scatter)
{
}
VTKM_CONT
DispatcherMapField(const ScatterType& scatter)
: Superclass(WorkletType(), scatter)
{
}

@ -42,11 +42,24 @@ class DispatcherMapTopology
vtkm::worklet::internal::DispatcherBase<DispatcherMapTopology<WorkletType, Device>,
WorkletType,
vtkm::worklet::detail::WorkletMapTopologyBase>;
using ScatterType = typename Superclass::ScatterType;
public:
// If you get a compile error here about there being no appropriate constructor for ScatterType,
// then that probably means that the worklet you are trying to execute has defined a custom
// ScatterType and that you need to create one (because there is no default way to construct
// the scatter). By convention, worklets that define a custom scatter type usually provide a
// static method named MakeScatter that constructs a scatter object.
VTKM_CONT
DispatcherMapTopology(const WorkletType& worklet = WorkletType())
: Superclass(worklet)
DispatcherMapTopology(const WorkletType& worklet = WorkletType(),
const ScatterType& scatter = ScatterType())
: Superclass(worklet, scatter)
{
}
VTKM_CONT
DispatcherMapTopology(const ScatterType& scatter)
: Superclass(WorkletType(), scatter)
{
}

@ -43,11 +43,24 @@ class DispatcherPointNeighborhood
vtkm::worklet::internal::DispatcherBase<DispatcherPointNeighborhood<WorkletType, Device>,
WorkletType,
vtkm::worklet::WorkletPointNeighborhoodBase>;
using ScatterType = typename Superclass::ScatterType;
public:
// If you get a compile error here about there being no appropriate constructor for ScatterType,
// then that probably means that the worklet you are trying to execute has defined a custom
// ScatterType and that you need to create one (because there is no default way to construct
// the scatter). By convention, worklets that define a custom scatter type usually provide a
// static method named MakeScatter that constructs a scatter object.
VTKM_CONT
DispatcherPointNeighborhood(const WorkletType& worklet = WorkletType())
: Superclass(worklet)
DispatcherPointNeighborhood(const WorkletType& worklet = WorkletType(),
const ScatterType& scatter = ScatterType())
: Superclass(worklet, scatter)
{
}
VTKM_CONT
DispatcherPointNeighborhood(const ScatterType& scatter)
: Superclass(WorkletType(), scatter)
{
}

@ -43,11 +43,24 @@ class DispatcherReduceByKey
vtkm::worklet::internal::DispatcherBase<DispatcherReduceByKey<WorkletType, Device>,
WorkletType,
vtkm::worklet::WorkletReduceByKey>;
using ScatterType = typename Superclass::ScatterType;
public:
// If you get a compile error here about there being no appropriate constructor for ScatterType,
// then that probably means that the worklet you are trying to execute has defined a custom
// ScatterType and that you need to create one (because there is no default way to construct
// the scatter). By convention, worklets that define a custom scatter type usually provide a
// static method named MakeScatter that constructs a scatter object.
VTKM_CONT
DispatcherReduceByKey(const WorkletType& worklet = WorkletType())
: Superclass(worklet)
DispatcherReduceByKey(const WorkletType& worklet = WorkletType(),
const ScatterType& scatter = ScatterType())
: Superclass(worklet, scatter)
{
}
VTKM_CONT
DispatcherReduceByKey(const ScatterType& scatter)
: Superclass(WorkletType(), scatter)
{
}

@ -173,11 +173,25 @@ class DispatcherStreamingMapField
vtkm::worklet::internal::DispatcherBase<DispatcherStreamingMapField<WorkletType, Device>,
WorkletType,
vtkm::worklet::WorkletMapField>;
using ScatterType = typename Superclass::ScatterType;
public:
// If you get a compile error here about there being no appropriate constructor for ScatterType,
// then that probably means that the worklet you are trying to execute has defined a custom
// ScatterType and that you need to create one (because there is no default way to construct
// the scatter). By convention, worklets that define a custom scatter type usually provide a
// static method named MakeScatter that constructs a scatter object.
VTKM_CONT
DispatcherStreamingMapField(const WorkletType& worklet = WorkletType())
: Superclass(worklet)
DispatcherStreamingMapField(const WorkletType& worklet = WorkletType(),
const ScatterType& scatter = ScatterType())
: Superclass(worklet, scatter)
, NumberOfBlocks(1)
{
}
VTKM_CONT
DispatcherStreamingMapField(const ScatterType& scatter)
: Superclass(WorkletType(), scatter)
, NumberOfBlocks(1)
{
}
@ -194,7 +208,7 @@ public:
this->InvokeTransportParameters(invocation,
numInstances,
globalIndexOffset,
this->Worklet.GetScatter().GetOutputRange(numInstances),
this->Scatter.GetOutputRange(numInstances),
device);
}
@ -275,10 +289,9 @@ private:
TransportFunctorType(invocation.GetInputDomain(), inputRange, outputRange));
// Get the arrays used for scattering input to output.
typename WorkletType::ScatterType::OutputToInputMapType outputToInputMap =
this->Worklet.GetScatter().GetOutputToInputMap(inputRange);
typename WorkletType::ScatterType::VisitArrayType visitArray =
this->Worklet.GetScatter().GetVisitArray(inputRange);
typename ScatterType::OutputToInputMapType outputToInputMap =
this->Scatter.GetOutputToInputMap(inputRange);
typename ScatterType::VisitArrayType visitArray = this->Scatter.GetVisitArray(inputRange);
// Replace the parameters in the invocation with the execution object and
// pass to next step of Invoke. Also add the scatter information.

@ -141,28 +141,18 @@ struct ExternalFaces
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename Device>
VTKM_CONT BuildConnectivityStructured(const vtkm::Vec<vtkm::Float64, 3>& min_point,
const vtkm::Vec<vtkm::Float64, 3>& max_point,
const CountArrayType& countArray,
Device)
: MinPoint(min_point)
, MaxPoint(max_point)
, Scatter(countArray, Device())
VTKM_CONT static ScatterType MakeScatter(const CountArrayType& countArray, Device)
{
VTKM_IS_ARRAY_HANDLE(CountArrayType);
return ScatterType(countArray, Device());
}
VTKM_CONT
BuildConnectivityStructured(const vtkm::Vec<vtkm::Float64, 3>& min_point,
const vtkm::Vec<vtkm::Float64, 3>& max_point,
const ScatterType& scatter)
const vtkm::Vec<vtkm::Float64, 3>& max_point)
: MinPoint(min_point)
, MaxPoint(max_point)
, Scatter(scatter)
{
}
@ -325,7 +315,6 @@ struct ExternalFaces
private:
vtkm::Vec<vtkm::Float64, 3> MinPoint;
vtkm::Vec<vtkm::Float64, 3> MaxPoint;
ScatterType Scatter;
};
//Worklet that returns the number of faces for each cell/shape
@ -356,22 +345,6 @@ struct ExternalFaces
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename Device>
VTKM_CONT FaceHash(const CountArrayType& countArray, Device)
: Scatter(countArray, Device())
{
VTKM_IS_ARRAY_HANDLE(CountArrayType);
}
VTKM_CONT
FaceHash(const ScatterType& scatter)
: Scatter(scatter)
{
}
template <typename CellShapeTag, typename CellNodeVecType>
VTKM_EXEC void operator()(vtkm::HashType& faceHash,
vtkm::Id& cellIndex,
@ -386,9 +359,6 @@ struct ExternalFaces
cellIndex = inputIndex;
faceIndex = visitIndex;
}
private:
ScatterType Scatter;
};
// Worklet that identifies the number of cells written out per face.
@ -525,20 +495,11 @@ public:
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename Device>
VTKM_CONT NumPointsPerFace(const CountArrayType& countArray, Device)
: Scatter(countArray, Device())
VTKM_CONT static ScatterType MakeScatter(const CountArrayType& countArray, Device)
{
VTKM_IS_ARRAY_HANDLE(CountArrayType);
}
VTKM_CONT
NumPointsPerFace(const ScatterType& scatter)
: Scatter(scatter)
{
return ScatterType(countArray, Device());
}
template <typename CellSetType, typename OriginCellsType, typename OriginFacesType>
@ -553,9 +514,6 @@ public:
return vtkm::exec::CellFaceNumberOfPoints(
originFaces[myIndex], cellSet.GetCellShape(originCells[myIndex]), *this);
}
private:
ScatterType Scatter;
};
// Worklet that returns the shape and connectivity for each external face
@ -574,22 +532,6 @@ public:
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename Device>
VTKM_CONT BuildConnectivity(const CountArrayType& countArray, Device)
: Scatter(countArray, Device())
{
VTKM_IS_ARRAY_HANDLE(CountArrayType);
}
VTKM_CONT
BuildConnectivity(const ScatterType& scatter)
: Scatter(scatter)
{
}
template <typename CellSetType,
typename OriginCellsType,
typename OriginFacesType,
@ -624,9 +566,6 @@ public:
inCellIndices[vtkm::exec::CellFaceLocalIndex(facePointIndex, myFace, shapeIn, *this)];
}
}
private:
ScatterType Scatter;
};
class IsPolyDataCell : public vtkm::worklet::WorkletMapPointToCell
@ -648,29 +587,11 @@ public:
public:
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename Device>
VTKM_CONT CountPolyDataCellPoints(const CountArrayType& countArray, Device)
: Scatter(countArray, Device())
{
VTKM_IS_ARRAY_HANDLE(CountArrayType);
}
VTKM_CONT
CountPolyDataCellPoints(const ScatterType& scatter)
: Scatter(scatter)
{
}
typedef void ControlSignature(CellSetIn inCellSet, FieldOut<> numPoints);
typedef _2 ExecutionSignature(PointCount);
using InputDomain = _1;
VTKM_EXEC vtkm::Id operator()(vtkm::Id count) const { return count; }
private:
ScatterType Scatter;
};
class PassPolyDataCells : public vtkm::worklet::WorkletMapPointToCell
@ -678,22 +599,6 @@ public:
public:
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename Device>
VTKM_CONT PassPolyDataCells(const CountArrayType& countArray, Device)
: Scatter(countArray, Device())
{
VTKM_IS_ARRAY_HANDLE(CountArrayType);
}
VTKM_CONT
PassPolyDataCells(const ScatterType& scatter)
: Scatter(scatter)
{
}
typedef void ControlSignature(CellSetIn inputTopology,
FieldOut<> shapes,
FieldOut<> pointIndices,
@ -718,9 +623,6 @@ public:
outPoints[pointIndex] = inPoints[pointIndex];
}
}
private:
ScatterType Scatter;
};
template <typename T>
@ -843,7 +745,8 @@ public:
using DeviceAlgorithms = typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
vtkm::Id numberOfExternalFaces = DeviceAlgorithms::Reduce(numExternalFaces, 0, vtkm::Sum());
vtkm::worklet::ScatterCounting scatterCellToExternalFace(numExternalFaces, DeviceAdapter());
auto scatterCellToExternalFace =
BuildConnectivityStructured::MakeScatter(numExternalFaces, DeviceAdapter());
// Maps output cells to input cells. Store this for cell field mapping.
this->CellIdMap = scatterCellToExternalFace.GetOutputToInputMap();
@ -859,8 +762,8 @@ public:
faceConnectivity.Allocate(connectivitySize);
vtkm::worklet::DispatcherMapTopology<BuildConnectivityStructured, DeviceAdapter>
buildConnectivityStructuredDispatcher(
(BuildConnectivityStructured(MinPoint, MaxPoint, scatterCellToExternalFace)));
buildConnectivityStructuredDispatcher(BuildConnectivityStructured(MinPoint, MaxPoint),
scatterCellToExternalFace);
buildConnectivityStructuredDispatcher.Invoke(
inCellSet,
@ -921,7 +824,7 @@ public:
if (scatterPolyDataCells.GetOutputRange(inCellSet.GetNumberOfCells()) != 0)
{
vtkm::worklet::DispatcherMapTopology<CountPolyDataCellPoints, DeviceAdapter>
countPolyDataCellPointsDispatcher((CountPolyDataCellPoints(scatterPolyDataCells)));
countPolyDataCellPointsDispatcher(scatterPolyDataCells);
countPolyDataCellPointsDispatcher.Invoke(inCellSet, polyDataPointCount);
@ -929,7 +832,7 @@ public:
polyDataPointCount, polyDataOffsets, polyDataConnectivitySize);
vtkm::worklet::DispatcherMapTopology<PassPolyDataCells, DeviceAdapter>
passPolyDataCellsDispatcher((PassPolyDataCells(scatterPolyDataCells)));
passPolyDataCellsDispatcher(scatterPolyDataCells);
polyDataConnectivity.Allocate(polyDataConnectivitySize);
@ -967,7 +870,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::Id> originCells;
vtkm::cont::ArrayHandle<vtkm::IdComponent> originFaces;
vtkm::worklet::DispatcherMapTopology<FaceHash, DeviceAdapter> faceHashDispatcher(
(FaceHash(scatterCellToFace)));
scatterCellToFace);
faceHashDispatcher.Invoke(inCellSet, faceHashes, originCells, originFaces);
@ -978,7 +881,7 @@ public:
faceCountDispatcher.Invoke(faceKeys, inCellSet, originCells, originFaces, faceOutputCount);
vtkm::worklet::ScatterCounting scatterCullInternalFaces(faceOutputCount, DeviceAdapter());
auto scatterCullInternalFaces = NumPointsPerFace::MakeScatter(faceOutputCount, DeviceAdapter());
PointCountArrayType facePointCount;
vtkm::worklet::DispatcherReduceByKey<NumPointsPerFace, DeviceAdapter> pointsPerFaceDispatcher(

@ -198,8 +198,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::UInt8>& interpContourId,
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& edgeTable,
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numTriTable,
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& triTable,
const vtkm::worklet::ScatterCounting& scatter)
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& triTable)
: InterpWeightsPortal(interpWeights.PrepareForOutput(3 * size, DeviceAdapter()))
, InterpIdPortal(interpIds.PrepareForOutput(3 * size, DeviceAdapter()))
, InterpCellIdPortal(interpCellIds.PrepareForOutput(3 * size, DeviceAdapter()))
@ -207,7 +206,6 @@ public:
, EdgeTable(edgeTable.PrepareForInput(DeviceAdapter()))
, NumTriTable(numTriTable.PrepareForInput(DeviceAdapter()))
, TriTable(triTable.PrepareForInput(DeviceAdapter()))
, Scatter(scatter)
{
// Interp needs to be 3 times longer than size as they are per point of the
// output triangle
@ -219,7 +217,6 @@ public:
typename PortalTypes<vtkm::IdComponent>::PortalConst EdgeTable;
typename PortalTypes<vtkm::IdComponent>::PortalConst NumTriTable;
typename PortalTypes<vtkm::IdComponent>::PortalConst TriTable;
vtkm::worklet::ScatterCounting Scatter;
};
/// \brief Compute the weights for each edge that is used to generate
@ -235,6 +232,12 @@ public:
using ScatterType = vtkm::worklet::ScatterCounting;
template <typename ArrayHandleType>
VTKM_CONT static ScatterType MakeScatter(const ArrayHandleType& numOutputTrisPerCell)
{
return ScatterType(numOutputTrisPerCell, DeviceAdapter());
}
typedef void ControlSignature(
CellSetIn cellset, // Cell set
WholeArrayIn<ClassifyCellTagType> isoValues,
@ -349,9 +352,6 @@ public:
}
}
VTKM_CONT
ScatterType GetScatter() const { return this->MetaData.Scatter; }
private:
EdgeWeightGenerateMetaData<DeviceAdapter> MetaData;
@ -512,9 +512,10 @@ public:
using InputDomain = _1;
using ScatterType = vtkm::worklet::ScatterPermutation<typename PointIdsArray::StorageTag>;
NormalsWorkletPass1(const vtkm::cont::ArrayHandle<vtkm::Id2>& edges)
: Scatter(vtkm::cont::make_ArrayHandleTransform(edges, EdgeVertex<0>()))
VTKM_CONT
static ScatterType MakeScatter(const vtkm::cont::ArrayHandle<vtkm::Id2>& edges)
{
return ScatterType(vtkm::cont::make_ArrayHandleTransform(edges, EdgeVertex<0>()));
}
template <typename FromIndexType,
@ -563,11 +564,6 @@ public:
vtkm::worklet::gradient::StructuredPointGradient<T> gradient;
gradient(boundary, points, field, normal);
}
ScatterType GetScatter() const { return this->Scatter; }
private:
ScatterType Scatter;
};
class NormalsWorkletPass2 : public vtkm::worklet::WorkletMapCellToPoint
@ -590,9 +586,10 @@ public:
using InputDomain = _1;
using ScatterType = vtkm::worklet::ScatterPermutation<typename PointIdsArray::StorageTag>;
NormalsWorkletPass2(const vtkm::cont::ArrayHandle<vtkm::Id2>& edges)
: Scatter(vtkm::cont::make_ArrayHandleTransform(edges, EdgeVertex<1>()))
VTKM_CONT
static ScatterType MakeScatter(const vtkm::cont::ArrayHandle<vtkm::Id2>& edges)
{
return ScatterType(vtkm::cont::make_ArrayHandleTransform(edges, EdgeVertex<1>()));
}
template <typename FromIndexType,
@ -656,11 +653,6 @@ public:
auto weight = weights.Get(edgeId);
normal = vtkm::Normal(vtkm::Lerp(grad0, grad1, weight));
}
ScatterType GetScatter() const { return this->Scatter; }
private:
ScatterType Scatter;
};
template <typename NormalCType,
@ -685,12 +677,14 @@ struct GenerateNormalsDeduced
// The final normal is interpolated from the two gradient values and stored
// in the normals array.
//
NormalsWorkletPass1 pass1(*edges);
vtkm::worklet::DispatcherMapTopology<NormalsWorkletPass1>(pass1).Invoke(
vtkm::worklet::DispatcherMapTopology<NormalsWorkletPass1> dispatcherNormalsPass1(
NormalsWorkletPass1::MakeScatter(*edges));
dispatcherNormalsPass1.Invoke(
*cellset, *cellset, coordinates, marchingcubes::make_ScalarField(*field), *normals);
NormalsWorkletPass2 pass2(*edges);
vtkm::worklet::DispatcherMapTopology<NormalsWorkletPass2>(pass2).Invoke(
vtkm::worklet::DispatcherMapTopology<NormalsWorkletPass2> dispatcherNormalsPass2(
NormalsWorkletPass2::MakeScatter(*edges));
dispatcherNormalsPass2.Invoke(
*cellset, *cellset, coordinates, marchingcubes::make_ScalarField(*field), *weights, *normals);
}
};
@ -969,7 +963,8 @@ private:
vtkm::cont::ArrayHandle<vtkm::UInt8> contourIds;
vtkm::cont::ArrayHandle<vtkm::Id> originalCellIdsForPoints;
{
vtkm::worklet::ScatterCounting scatter(numOutputTrisPerCell, DeviceAdapter());
auto scatter =
EdgeWeightGenerate<ValueType, DeviceAdapter>::MakeScatter(numOutputTrisPerCell);
// Maps output cells to input cells. Store this for cell field mapping.
this->CellIdMap = scatter.GetOutputToInputMap();
@ -982,11 +977,10 @@ private:
contourIds,
this->EdgeTable,
this->NumTrianglesTable,
this->TriangleTable,
scatter);
this->TriangleTable);
EdgeWeightGenerate<ValueType, DeviceAdapter> weightGenerate(metaData);
GenerateDispatcher edgeDispatcher(weightGenerate);
GenerateDispatcher edgeDispatcher(weightGenerate, scatter);
edgeDispatcher.Invoke(
cells,
//cast to a scalar field if not one, as cellderivative only works on those

@ -180,11 +180,6 @@ struct ScatterCounting
this->BuildArrays(countArray, Device(), saveInputToOutputMap);
}
VTKM_CONT ScatterCounting()
: InputRange(0)
{
}
using OutputToInputMapType = vtkm::cont::ArrayHandle<vtkm::Id>;
template <typename RangeType>

@ -34,35 +34,21 @@ namespace worklet
namespace detail
{
template <vtkm::IdComponent Modulus>
struct FunctorModulus
{
vtkm::IdComponent Modulus;
VTKM_EXEC_CONT
FunctorModulus(vtkm::IdComponent modulus = 1)
: Modulus(modulus)
{
}
VTKM_EXEC_CONT
vtkm::IdComponent operator()(vtkm::Id index) const
{
return static_cast<vtkm::IdComponent>(index % this->Modulus);
return static_cast<vtkm::IdComponent>(index % Modulus);
}
};
template <vtkm::IdComponent Divisor>
struct FunctorDiv
{
vtkm::Id Divisor;
VTKM_EXEC_CONT
FunctorDiv(vtkm::Id divisor = 1)
: Divisor(divisor)
{
}
VTKM_EXEC_CONT
vtkm::Id operator()(vtkm::Id index) const { return index / this->Divisor; }
vtkm::Id operator()(vtkm::Id index) const { return index / Divisor; }
};
}
@ -74,43 +60,36 @@ struct FunctorDiv
/// elements associated with it where N is the same for every input. The output
/// elements are grouped by the input associated.
///
template <vtkm::IdComponent NumOutputsPerInput>
struct ScatterUniform
{
VTKM_CONT
ScatterUniform(vtkm::IdComponent numOutputsPerInput)
: NumOutputsPerInput(numOutputsPerInput)
{
}
VTKM_CONT ScatterUniform() = default;
VTKM_CONT
vtkm::Id GetOutputRange(vtkm::Id inputRange) const
{
return inputRange * this->NumOutputsPerInput;
}
vtkm::Id GetOutputRange(vtkm::Id inputRange) const { return inputRange * NumOutputsPerInput; }
VTKM_CONT
vtkm::Id GetOutputRange(vtkm::Id3 inputRange) const
{
return this->GetOutputRange(inputRange[0] * inputRange[1] * inputRange[2]);
}
using OutputToInputMapType = vtkm::cont::ArrayHandleImplicit<detail::FunctorDiv>;
using OutputToInputMapType =
vtkm::cont::ArrayHandleImplicit<detail::FunctorDiv<NumOutputsPerInput>>;
template <typename RangeType>
VTKM_CONT OutputToInputMapType GetOutputToInputMap(RangeType inputRange) const
{
return OutputToInputMapType(detail::FunctorDiv(this->NumOutputsPerInput),
return OutputToInputMapType(detail::FunctorDiv<NumOutputsPerInput>(),
this->GetOutputRange(inputRange));
}
using VisitArrayType = vtkm::cont::ArrayHandleImplicit<detail::FunctorModulus>;
using VisitArrayType =
vtkm::cont::ArrayHandleImplicit<detail::FunctorModulus<NumOutputsPerInput>>;
template <typename RangeType>
VTKM_CONT VisitArrayType GetVisitArray(RangeType inputRange) const
{
return VisitArrayType(detail::FunctorModulus(this->NumOutputsPerInput),
return VisitArrayType(detail::FunctorModulus<NumOutputsPerInput>(),
this->GetOutputRange(inputRange));
}
private:
vtkm::IdComponent NumOutputsPerInput;
};
}
} // namespace vtkm::worklet

@ -170,9 +170,7 @@ public:
typedef void ExecutionSignature(_1, _2, _3, _4, _5, VisitIndex);
using InputDomain = _1;
using ScatterType = vtkm::worklet::ScatterUniform;
VTKM_CONT
ScatterType GetScatter() const { return ScatterType(2); }
using ScatterType = vtkm::worklet::ScatterUniform<2>;
FieldPortalConstType field;
const vtkm::Id3 vdims;

@ -41,13 +41,10 @@ public:
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename DeviceAdapter>
VTKM_CONT DistributeCellData(const CountArrayType& countArray, DeviceAdapter device)
: Scatter(countArray, device)
VTKM_CONT static ScatterType MakeScatter(const CountArrayType& countArray, DeviceAdapter device)
{
return ScatterType(countArray, device);
}
template <typename T>
@ -55,9 +52,6 @@ public:
{
outputIndex = inputIndex;
}
private:
ScatterType Scatter;
};
Tetrahedralize()
@ -95,8 +89,8 @@ public:
{
vtkm::cont::ArrayHandle<T> output;
DistributeCellData distribute(this->OutCellsPerCell, device);
vtkm::worklet::DispatcherMapField<DistributeCellData, DeviceAdapter> dispatcher(distribute);
vtkm::worklet::DispatcherMapField<DistributeCellData, DeviceAdapter> dispatcher(
DistributeCellData::MakeScatter(this->OutCellsPerCell, device));
dispatcher.Invoke(input, output);
return output;

@ -41,13 +41,10 @@ public:
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename DeviceAdapter>
VTKM_CONT DistributeCellData(const CountArrayType& countArray, DeviceAdapter device)
: Scatter(countArray, device)
VTKM_CONT static ScatterType MakeScatter(const CountArrayType& countArray, DeviceAdapter device)
{
return ScatterType(countArray, device);
}
template <typename T>
@ -55,9 +52,6 @@ public:
{
outputIndex = inputIndex;
}
private:
ScatterType Scatter;
};
Triangulate()
@ -96,8 +90,8 @@ public:
{
vtkm::cont::ArrayHandle<ValueType> output;
DistributeCellData distribute(this->OutCellsPerCell, device);
vtkm::worklet::DispatcherMapField<DistributeCellData, DeviceAdapter> dispatcher(distribute);
vtkm::worklet::DispatcherMapField<DistributeCellData, DeviceAdapter> dispatcher(
DistributeCellData::MakeScatter(this->OutCellsPerCell, device));
dispatcher.Invoke(input, output);
return output;

@ -96,12 +96,6 @@ public:
/// All worklets must define their scatter operation.
using ScatterType = vtkm::worklet::ScatterIdentity;
/// In addition to defining the scatter type, the worklet must produce the
/// scatter. The default vtkm::worklet::ScatterIdentity has no state,
/// so just return an instance.
VTKM_CONT
ScatterType GetScatter() const { return ScatterType(); }
/// All neighborhood worklets must define their boundary type operation.
/// The boundary type determines how loading on boundaries will work.
using BoundaryType = vtkm::worklet::BoundaryClamp;

@ -49,12 +49,6 @@ struct EdgeExtract : public vtkm::worklet::WorkletMapPointToCell
using InputDomain = _1;
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT ScatterType GetScatter() const { return this->Scatter; }
VTKM_CONT EdgeExtract(const ScatterType& scatter)
: Scatter(scatter)
{
}
template <typename CellShapeTag,
typename CellIndexType,
@ -71,9 +65,6 @@ struct EdgeExtract : public vtkm::worklet::WorkletMapPointToCell
edgeIndices = vtkm::exec::CellEdgeCanonicalId(
pointIndices.GetNumberOfComponents(), visitIndex, cellShape, pointIndices, *this);
}
private:
ScatterType Scatter;
};
struct CellToCellConnectivity : public vtkm::worklet::WorkletMapField

@ -47,15 +47,6 @@ public:
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
VTKM_CONT
Merge(const ScatterType& scatter)
: Scatter(scatter)
{
}
// TODO: type trait for array portal?
template <typename KeyType, typename ValueType1, typename InPortalType, typename ValueType2>
VTKM_EXEC void operator()(KeyType key,
@ -72,9 +63,6 @@ public:
value1Out = value1;
value2Out = v2;
}
private:
ScatterType Scatter;
};
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
@ -101,8 +89,7 @@ public:
Algorithm::Transform(ubs, lbs, counts, vtkm::Subtract());
vtkm::worklet::ScatterCounting scatter{ counts, DeviceAdapter() };
Merge merge(scatter);
vtkm::worklet::DispatcherMapField<Merge, DeviceAdapter> mergeDisp(merge);
vtkm::worklet::DispatcherMapField<Merge, DeviceAdapter> mergeDisp(scatter);
mergeDisp.Invoke(key1, value1, lbs, value2, keyOut, value1Out, value2Out);
}
};

@ -152,19 +152,8 @@ struct ScatterWorklet : public vtkm::worklet::WorkletMapField
typedef void ExecutionSignature(_1, _2);
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
VTKM_CONT
ScatterWorklet(const vtkm::worklet::ScatterCounting& scatter)
: Scatter(scatter)
{
}
VTKM_EXEC
void operator()(T inputIndex, T& outputIndex) const { outputIndex = inputIndex; }
private:
ScatterType Scatter;
};
///////////////////////////////////////////////////////////////////////////////

@ -331,11 +331,8 @@ void CosmoTools<T, StorageType, DeviceAdapter>::MBPCenterFindingByHalo(
// Setup the ScatterCounting worklets needed to expand the ReduceByKeyResults
vtkm::worklet::ScatterCounting scatter(particlesPerHalo, DeviceAdapter());
ScatterWorklet<vtkm::Id> scatterWorkletId(scatter);
ScatterWorklet<T> scatterWorklet(scatter);
vtkm::worklet::DispatcherMapField<ScatterWorklet<vtkm::Id>> scatterWorkletIdDispatcher(
scatterWorkletId);
vtkm::worklet::DispatcherMapField<ScatterWorklet<T>> scatterWorkletDispatcher(scatterWorklet);
vtkm::worklet::DispatcherMapField<ScatterWorklet<vtkm::Id>> scatterWorkletIdDispatcher(scatter);
vtkm::worklet::DispatcherMapField<ScatterWorklet<T>> scatterWorkletDispatcher(scatter);
// Calculate the minimum particle index per halo id and scatter
DeviceAlgorithm::ScanExclusive(particlesPerHalo, tempI);

@ -500,6 +500,8 @@ private:
public:
using ScatterType = typename WorkletType::ScatterType;
template <typename... Args>
VTKM_CONT void Invoke(Args&&... args) const
{
@ -508,8 +510,9 @@ public:
protected:
VTKM_CONT
DispatcherBase(const WorkletType& worklet)
DispatcherBase(const WorkletType& worklet, const ScatterType& scatter)
: Worklet(worklet)
, Scatter(scatter)
{
}
@ -519,7 +522,7 @@ protected:
DeviceAdapter device) const
{
this->InvokeTransportParameters(
invocation, numInstances, this->Worklet.GetScatter().GetOutputRange(numInstances), device);
invocation, numInstances, this->Scatter.GetOutputRange(numInstances), device);
}
template <typename Invocation, typename DeviceAdapter>
@ -536,10 +539,11 @@ protected:
DeviceAdapter device) const
{
this->InvokeTransportParameters(
invocation, dimensions, this->Worklet.GetScatter().GetOutputRange(dimensions), device);
invocation, dimensions, this->Scatter.GetOutputRange(dimensions), device);
}
WorkletType Worklet;
ScatterType Scatter;
private:
// Dispatchers cannot be copied
@ -579,9 +583,9 @@ private:
// Get the arrays used for scattering input to output.
typename WorkletType::ScatterType::OutputToInputMapType outputToInputMap =
this->Worklet.GetScatter().GetOutputToInputMap(inputRange);
this->Scatter.GetOutputToInputMap(inputRange);
typename WorkletType::ScatterType::VisitArrayType visitArray =
this->Worklet.GetScatter().GetVisitArray(inputRange);
this->Scatter.GetVisitArray(inputRange);
// Replace the parameters in the invocation with the execution object and
// pass to next step of Invoke. Also add the scatter information.

@ -191,12 +191,6 @@ public:
/// identity scatter (1-to-1 input to output).
using ScatterType = vtkm::worklet::ScatterIdentity;
/// In addition to defining the scatter type, the worklet must produce the
/// scatter. The default ScatterIdentity has no state, so just return an
/// instance.
VTKM_CONT
ScatterType GetScatter() const { return ScatterType(); }
/// \brief A type list containing the type vtkm::Id.
///
/// This is a convenience type to use as template arguments to \c

@ -252,11 +252,13 @@ class TestDispatcher : public vtkm::worklet::internal::DispatcherBase<TestDispat
using Superclass = vtkm::worklet::internal::DispatcherBase<TestDispatcher<WorkletType>,
WorkletType,
TestWorkletBase>;
using ScatterType = typename Superclass::ScatterType;
public:
VTKM_CONT
TestDispatcher(const WorkletType& worklet = WorkletType())
: Superclass(worklet)
TestDispatcher(const WorkletType& worklet = WorkletType(),
const ScatterType& scatter = ScatterType())
: Superclass(worklet, scatter)
{
}

@ -120,25 +120,10 @@ struct TestScatterCountingWorklet : public vtkm::worklet::WorkletMapField
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType>
VTKM_CONT TestScatterCountingWorklet(const CountArrayType& countArray)
: Scatter(countArray, VTKM_DEFAULT_DEVICE_ADAPTER_TAG())
{
}
template <typename CountArrayType, typename Device>
VTKM_CONT TestScatterCountingWorklet(const CountArrayType& countArray, Device)
: Scatter(countArray, Device())
{
}
VTKM_CONT
TestScatterCountingWorklet(const vtkm::worklet::ScatterCounting& scatter)
: Scatter(scatter)
VTKM_CONT static ScatterType MakeScatter(const CountArrayType& countArray, Device)
{
return ScatterType(countArray, Device());
}
VTKM_EXEC
@ -153,9 +138,6 @@ struct TestScatterCountingWorklet : public vtkm::worklet::WorkletMapField
writeVisit = visitIndex;
captureWorkId = TestValue(workId, vtkm::Float32());
}
private:
ScatterType Scatter;
};
template <typename T>
@ -203,9 +185,8 @@ void TestScatterWorklet(const TestScatterArrays& arrays)
{
std::cout << " Testing scatter counting in a worklet." << std::endl;
vtkm::worklet::ScatterCounting scatter(arrays.CountArray, VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
TestScatterCountingWorklet worklet(scatter);
vtkm::worklet::DispatcherMapField<TestScatterCountingWorklet> dispatcher(worklet);
vtkm::worklet::DispatcherMapField<TestScatterCountingWorklet> dispatcher(
TestScatterCountingWorklet::MakeScatter(arrays.CountArray, VTKM_DEFAULT_DEVICE_ADAPTER_TAG()));
vtkm::Id inputSize = arrays.CountArray.GetNumberOfValues();
vtkm::cont::ArrayHandleIndex inputIndices(inputSize);

@ -44,9 +44,10 @@ public:
using ScatterType = vtkm::worklet::ScatterPermutation<>;
Worklet(const vtkm::cont::ArrayHandle<vtkm::Id>& permutation)
: Scatter(permutation)
VTKM_CONT
static ScatterType MakeScatter(const vtkm::cont::ArrayHandle<vtkm::Id>& permutation)
{
return ScatterType(permutation);
}
VTKM_EXEC void operator()(vtkm::Id pointId,
@ -57,12 +58,6 @@ public:
outPointId = pointId;
outVisit = visit;
}
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
private:
ScatterType Scatter;
};
template <typename CellSetType>
@ -71,8 +66,8 @@ void RunTest(const CellSetType& cellset, const vtkm::cont::ArrayHandle<vtkm::Id>
vtkm::cont::ArrayHandle<vtkm::Id> outPointId;
vtkm::cont::ArrayHandle<vtkm::IdComponent> outVisit;
Worklet worklet(permutation);
vtkm::worklet::DispatcherMapTopology<Worklet>(worklet).Invoke(cellset, outPointId, outVisit);
vtkm::worklet::DispatcherMapTopology<Worklet> dispatcher(Worklet::MakeScatter(permutation));
dispatcher.Invoke(cellset, outPointId, outVisit);
for (vtkm::Id i = 0; i < permutation.GetNumberOfValues(); ++i)
{

@ -152,9 +152,6 @@ struct ScatterIdentityNeighbor : public vtkm::worklet::WorkletPointNeighborhood5
using ScatterType = vtkm::worklet::ScatterIdentity;
VTKM_CONT
ScatterType GetScatter() const { return ScatterType(); }
};
struct ScatterUniformNeighbor : public vtkm::worklet::WorkletPointNeighborhood5x5x5
@ -194,10 +191,7 @@ struct ScatterUniformNeighbor : public vtkm::worklet::WorkletPointNeighborhood5x
}
using ScatterType = vtkm::worklet::ScatterUniform;
VTKM_CONT
ScatterType GetScatter() const { return ScatterType(3); }
using ScatterType = vtkm::worklet::ScatterUniform<3>;
};
}

@ -86,13 +86,11 @@ public:
using InputDomain = _1;
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CellArrayType>
VTKM_CONT TetrahedralizeCell(const CellArrayType& cellArray)
: Scatter(cellArray, DeviceAdapter())
VTKM_CONT static ScatterType MakeScatter(const CellArrayType& cellArray)
{
return ScatterType(cellArray, DeviceAdapter());
}
// Each cell produces tetrahedra and write result at the offset
@ -110,9 +108,6 @@ public:
connectivityOut[2] = connectivityIn[tetIndices[2]];
connectivityOut[3] = connectivityIn[tetIndices[3]];
}
private:
ScatterType Scatter;
};
template <typename CellSetType>
@ -137,9 +132,8 @@ public:
tetPerCellDispatcher.Invoke(inShapes, tables.PrepareForInput(DeviceAdapter()), outCellsPerCell);
// Build new cells
TetrahedralizeCell tetrahedralizeWorklet(outCellsPerCell);
vtkm::worklet::DispatcherMapTopology<TetrahedralizeCell, DeviceAdapter>
tetrahedralizeDispatcher(tetrahedralizeWorklet);
tetrahedralizeDispatcher(TetrahedralizeCell::MakeScatter(outCellsPerCell));
tetrahedralizeDispatcher.Invoke(cellSet,
tables.PrepareForInput(DeviceAdapter()),
vtkm::cont::make_ArrayHandleGroupVec<4>(outConnectivity));

@ -53,10 +53,7 @@ public:
typedef void ExecutionSignature(PointIndices, _2, ThreadIndices);
using InputDomain = _1;
using ScatterType = vtkm::worklet::ScatterUniform;
VTKM_CONT
ScatterType GetScatter() const { return ScatterType(5); }
using ScatterType = vtkm::worklet::ScatterUniform<5>;
// Each hexahedron cell produces five tetrahedron cells
template <typename ConnectivityInVec, typename ConnectivityOutVec, typename ThreadIndicesType>

@ -89,13 +89,11 @@ public:
using InputDomain = _1;
using ScatterType = vtkm::worklet::ScatterCounting;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType>
VTKM_CONT TriangulateCell(const CountArrayType& countArray)
: Scatter(countArray, DeviceAdapter())
VTKM_CONT static ScatterType MakeScatter(const CountArrayType& countArray)
{
return ScatterType(countArray, DeviceAdapter());
}
// Each cell produces triangles and write result at the offset
@ -112,9 +110,6 @@ public:
connectivityOut[1] = connectivityIn[triIndices[1]];
connectivityOut[2] = connectivityIn[triIndices[2]];
}
private:
ScatterType Scatter;
};
template <typename CellSetType>
@ -140,9 +135,8 @@ public:
inShapes, inNumIndices, tables.PrepareForInput(DeviceAdapter()), outCellsPerCell);
// Build new cells
TriangulateCell triangulateWorklet(outCellsPerCell);
vtkm::worklet::DispatcherMapTopology<TriangulateCell, DeviceAdapter> triangulateDispatcher(
triangulateWorklet);
TriangulateCell::MakeScatter(outCellsPerCell));
triangulateDispatcher.Invoke(cellSet,
tables.PrepareForInput(DeviceAdapter()),
vtkm::cont::make_ArrayHandleGroupVec<3>(outConnectivity));

@ -52,9 +52,7 @@ public:
typedef void ExecutionSignature(PointIndices, _2, VisitIndex);
using InputDomain = _1;
using ScatterType = vtkm::worklet::ScatterUniform;
VTKM_CONT
ScatterType GetScatter() const { return ScatterType(2); }
using ScatterType = vtkm::worklet::ScatterUniform<2>;
// Each quad cell produces 2 triangle cells
template <typename ConnectivityInVec, typename ConnectivityOutVec>