diff --git a/vtkm/cont/testing/TestingCellLocatorTwoLevelUniformGrid.h b/vtkm/cont/testing/TestingCellLocatorTwoLevelUniformGrid.h index 11fd55fb9..33ed148c2 100644 --- a/vtkm/cont/testing/TestingCellLocatorTwoLevelUniformGrid.h +++ b/vtkm/cont/testing/TestingCellLocatorTwoLevelUniformGrid.h @@ -55,13 +55,12 @@ public: using ScatterType = vtkm::worklet::ScatterPermutation<>; - explicit ParametricToWorldCoordinates(const vtkm::cont::ArrayHandle& cellIds) - : Scatter(cellIds) + VTKM_CONT + static ScatterType MakeScatter(const vtkm::cont::ArrayHandle& cellIds) { + return ScatterType(cellIds); } - const ScatterType& GetScatter() const { return this->Scatter; } - template 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 @@ -185,9 +181,9 @@ void GenerateRandomInput(const vtkm::cont::DataSet& ds, pcoords.GetPortalControl().Set(i, pc); } - ParametricToWorldCoordinates pc2wc(cellIds); - vtkm::worklet::DispatcherMapTopology(pc2wc).Invoke( - ds.GetCellSet(), ds.GetCoordinateSystem().GetData(), pcoords, wcoords); + vtkm::worklet::DispatcherMapTopology dispatcher( + ParametricToWorldCoordinates::MakeScatter(cellIds)); + dispatcher.Invoke(ds.GetCellSet(), ds.GetCoordinateSystem().GetData(), pcoords, wcoords); } template diff --git a/vtkm/rendering/MapperWireframer.cxx b/vtkm/rendering/MapperWireframer.cxx index a9ef36b83..9db253ac1 100644 --- a/vtkm/rendering/MapperWireframer.cxx +++ b/vtkm/rendering/MapperWireframer.cxx @@ -177,13 +177,11 @@ struct EdgesExtracter : public vtkm::worklet::WorkletMapPointToCell VTKM_CONT template - 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 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 counts; vtkm::worklet::DispatcherMapTopology().Invoke(CellSet, counts); - EdgesExtracter extractWorklet(counts, DeviceTag()); vtkm::worklet::DispatcherMapTopology extractDispatcher( - extractWorklet); + EdgesExtracter::MakeScatter(counts, DeviceTag())); extractDispatcher.Invoke(CellSet, EdgeIndices); vtkm::cont::DeviceAdapterAlgorithm::template Sort(EdgeIndices); vtkm::cont::DeviceAdapterAlgorithm::template Unique(EdgeIndices); diff --git a/vtkm/worklet/DispatcherMapField.h b/vtkm/worklet/DispatcherMapField.h index 14356a0e9..5fb26475b 100644 --- a/vtkm/worklet/DispatcherMapField.h +++ b/vtkm/worklet/DispatcherMapField.h @@ -41,11 +41,24 @@ class DispatcherMapField vtkm::worklet::internal::DispatcherBase, 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) { } diff --git a/vtkm/worklet/DispatcherMapTopology.h b/vtkm/worklet/DispatcherMapTopology.h index f7fbffd65..2ed32ea0b 100644 --- a/vtkm/worklet/DispatcherMapTopology.h +++ b/vtkm/worklet/DispatcherMapTopology.h @@ -42,11 +42,24 @@ class DispatcherMapTopology vtkm::worklet::internal::DispatcherBase, 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) { } diff --git a/vtkm/worklet/DispatcherPointNeighborhood.h b/vtkm/worklet/DispatcherPointNeighborhood.h index 2859caf8c..d33650ca0 100644 --- a/vtkm/worklet/DispatcherPointNeighborhood.h +++ b/vtkm/worklet/DispatcherPointNeighborhood.h @@ -43,11 +43,24 @@ class DispatcherPointNeighborhood vtkm::worklet::internal::DispatcherBase, 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) { } diff --git a/vtkm/worklet/DispatcherReduceByKey.h b/vtkm/worklet/DispatcherReduceByKey.h index ad1016469..756df2883 100644 --- a/vtkm/worklet/DispatcherReduceByKey.h +++ b/vtkm/worklet/DispatcherReduceByKey.h @@ -43,11 +43,24 @@ class DispatcherReduceByKey vtkm::worklet::internal::DispatcherBase, 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) { } diff --git a/vtkm/worklet/DispatcherStreamingMapField.h b/vtkm/worklet/DispatcherStreamingMapField.h index 2fe7fc356..15fc3dd28 100644 --- a/vtkm/worklet/DispatcherStreamingMapField.h +++ b/vtkm/worklet/DispatcherStreamingMapField.h @@ -173,11 +173,25 @@ class DispatcherStreamingMapField vtkm::worklet::internal::DispatcherBase, 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. diff --git a/vtkm/worklet/ExternalFaces.h b/vtkm/worklet/ExternalFaces.h index 3b52b6de2..31e5638a9 100644 --- a/vtkm/worklet/ExternalFaces.h +++ b/vtkm/worklet/ExternalFaces.h @@ -141,28 +141,18 @@ struct ExternalFaces using ScatterType = vtkm::worklet::ScatterCounting; - VTKM_CONT - ScatterType GetScatter() const { return this->Scatter; } - template - VTKM_CONT BuildConnectivityStructured(const vtkm::Vec& min_point, - const vtkm::Vec& 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& min_point, - const vtkm::Vec& max_point, - const ScatterType& scatter) + const vtkm::Vec& max_point) : MinPoint(min_point) , MaxPoint(max_point) - , Scatter(scatter) { } @@ -325,7 +315,6 @@ struct ExternalFaces private: vtkm::Vec MinPoint; vtkm::Vec 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 - VTKM_CONT FaceHash(const CountArrayType& countArray, Device) - : Scatter(countArray, Device()) - { - VTKM_IS_ARRAY_HANDLE(CountArrayType); - } - - VTKM_CONT - FaceHash(const ScatterType& scatter) - : Scatter(scatter) - { - } - template 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 - 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 @@ -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 - VTKM_CONT BuildConnectivity(const CountArrayType& countArray, Device) - : Scatter(countArray, Device()) - { - VTKM_IS_ARRAY_HANDLE(CountArrayType); - } - - VTKM_CONT - BuildConnectivity(const ScatterType& scatter) - : Scatter(scatter) - { - } - template Scatter; } - - template - 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 - 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 @@ -843,7 +745,8 @@ public: using DeviceAlgorithms = typename vtkm::cont::DeviceAdapterAlgorithm; 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 - 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 - countPolyDataCellPointsDispatcher((CountPolyDataCellPoints(scatterPolyDataCells))); + countPolyDataCellPointsDispatcher(scatterPolyDataCells); countPolyDataCellPointsDispatcher.Invoke(inCellSet, polyDataPointCount); @@ -929,7 +832,7 @@ public: polyDataPointCount, polyDataOffsets, polyDataConnectivitySize); vtkm::worklet::DispatcherMapTopology - passPolyDataCellsDispatcher((PassPolyDataCells(scatterPolyDataCells))); + passPolyDataCellsDispatcher(scatterPolyDataCells); polyDataConnectivity.Allocate(polyDataConnectivitySize); @@ -967,7 +870,7 @@ public: vtkm::cont::ArrayHandle originCells; vtkm::cont::ArrayHandle originFaces; vtkm::worklet::DispatcherMapTopology 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 pointsPerFaceDispatcher( diff --git a/vtkm/worklet/MarchingCubes.h b/vtkm/worklet/MarchingCubes.h index 945584e6a..79cffb4ae 100644 --- a/vtkm/worklet/MarchingCubes.h +++ b/vtkm/worklet/MarchingCubes.h @@ -198,8 +198,7 @@ public: vtkm::cont::ArrayHandle& interpContourId, const vtkm::cont::ArrayHandle& edgeTable, const vtkm::cont::ArrayHandle& numTriTable, - const vtkm::cont::ArrayHandle& triTable, - const vtkm::worklet::ScatterCounting& scatter) + const vtkm::cont::ArrayHandle& 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::PortalConst EdgeTable; typename PortalTypes::PortalConst NumTriTable; typename PortalTypes::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 + VTKM_CONT static ScatterType MakeScatter(const ArrayHandleType& numOutputTrisPerCell) + { + return ScatterType(numOutputTrisPerCell, DeviceAdapter()); + } + typedef void ControlSignature( CellSetIn cellset, // Cell set WholeArrayIn isoValues, @@ -349,9 +352,6 @@ public: } } - VTKM_CONT - ScatterType GetScatter() const { return this->MetaData.Scatter; } - private: EdgeWeightGenerateMetaData MetaData; @@ -512,9 +512,10 @@ public: using InputDomain = _1; using ScatterType = vtkm::worklet::ScatterPermutation; - NormalsWorkletPass1(const vtkm::cont::ArrayHandle& edges) - : Scatter(vtkm::cont::make_ArrayHandleTransform(edges, EdgeVertex<0>())) + VTKM_CONT + static ScatterType MakeScatter(const vtkm::cont::ArrayHandle& edges) { + return ScatterType(vtkm::cont::make_ArrayHandleTransform(edges, EdgeVertex<0>())); } template 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; - NormalsWorkletPass2(const vtkm::cont::ArrayHandle& edges) - : Scatter(vtkm::cont::make_ArrayHandleTransform(edges, EdgeVertex<1>())) + VTKM_CONT + static ScatterType MakeScatter(const vtkm::cont::ArrayHandle& edges) { + return ScatterType(vtkm::cont::make_ArrayHandleTransform(edges, EdgeVertex<1>())); } template Scatter; } - -private: - ScatterType Scatter; }; template (pass1).Invoke( + vtkm::worklet::DispatcherMapTopology dispatcherNormalsPass1( + NormalsWorkletPass1::MakeScatter(*edges)); + dispatcherNormalsPass1.Invoke( *cellset, *cellset, coordinates, marchingcubes::make_ScalarField(*field), *normals); - NormalsWorkletPass2 pass2(*edges); - vtkm::worklet::DispatcherMapTopology(pass2).Invoke( + vtkm::worklet::DispatcherMapTopology dispatcherNormalsPass2( + NormalsWorkletPass2::MakeScatter(*edges)); + dispatcherNormalsPass2.Invoke( *cellset, *cellset, coordinates, marchingcubes::make_ScalarField(*field), *weights, *normals); } }; @@ -969,7 +963,8 @@ private: vtkm::cont::ArrayHandle contourIds; vtkm::cont::ArrayHandle originalCellIdsForPoints; { - vtkm::worklet::ScatterCounting scatter(numOutputTrisPerCell, DeviceAdapter()); + auto scatter = + EdgeWeightGenerate::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 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 diff --git a/vtkm/worklet/ScatterCounting.h b/vtkm/worklet/ScatterCounting.h index 07036c368..9ff0924f1 100644 --- a/vtkm/worklet/ScatterCounting.h +++ b/vtkm/worklet/ScatterCounting.h @@ -180,11 +180,6 @@ struct ScatterCounting this->BuildArrays(countArray, Device(), saveInputToOutputMap); } - VTKM_CONT ScatterCounting() - : InputRange(0) - { - } - using OutputToInputMapType = vtkm::cont::ArrayHandle; template diff --git a/vtkm/worklet/ScatterUniform.h b/vtkm/worklet/ScatterUniform.h index 2ae7c80f3..17a82213e 100644 --- a/vtkm/worklet/ScatterUniform.h +++ b/vtkm/worklet/ScatterUniform.h @@ -34,35 +34,21 @@ namespace worklet namespace detail { +template 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(index % this->Modulus); + return static_cast(index % Modulus); } }; +template 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 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; + using OutputToInputMapType = + vtkm::cont::ArrayHandleImplicit>; template VTKM_CONT OutputToInputMapType GetOutputToInputMap(RangeType inputRange) const { - return OutputToInputMapType(detail::FunctorDiv(this->NumOutputsPerInput), + return OutputToInputMapType(detail::FunctorDiv(), this->GetOutputRange(inputRange)); } - using VisitArrayType = vtkm::cont::ArrayHandleImplicit; + using VisitArrayType = + vtkm::cont::ArrayHandleImplicit>; template VTKM_CONT VisitArrayType GetVisitArray(RangeType inputRange) const { - return VisitArrayType(detail::FunctorModulus(this->NumOutputsPerInput), + return VisitArrayType(detail::FunctorModulus(), this->GetOutputRange(inputRange)); } - -private: - vtkm::IdComponent NumOutputsPerInput; }; } } // namespace vtkm::worklet diff --git a/vtkm/worklet/StreamLineUniformGrid.h b/vtkm/worklet/StreamLineUniformGrid.h index 253115e28..6a934659a 100644 --- a/vtkm/worklet/StreamLineUniformGrid.h +++ b/vtkm/worklet/StreamLineUniformGrid.h @@ -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; diff --git a/vtkm/worklet/Tetrahedralize.h b/vtkm/worklet/Tetrahedralize.h index 0f2759417..90df88d1f 100644 --- a/vtkm/worklet/Tetrahedralize.h +++ b/vtkm/worklet/Tetrahedralize.h @@ -41,13 +41,10 @@ public: using ScatterType = vtkm::worklet::ScatterCounting; - VTKM_CONT - ScatterType GetScatter() const { return this->Scatter; } - template - 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 @@ -55,9 +52,6 @@ public: { outputIndex = inputIndex; } - - private: - ScatterType Scatter; }; Tetrahedralize() @@ -95,8 +89,8 @@ public: { vtkm::cont::ArrayHandle output; - DistributeCellData distribute(this->OutCellsPerCell, device); - vtkm::worklet::DispatcherMapField dispatcher(distribute); + vtkm::worklet::DispatcherMapField dispatcher( + DistributeCellData::MakeScatter(this->OutCellsPerCell, device)); dispatcher.Invoke(input, output); return output; diff --git a/vtkm/worklet/Triangulate.h b/vtkm/worklet/Triangulate.h index 0cceaf3c5..1b43dc48f 100644 --- a/vtkm/worklet/Triangulate.h +++ b/vtkm/worklet/Triangulate.h @@ -41,13 +41,10 @@ public: using ScatterType = vtkm::worklet::ScatterCounting; - VTKM_CONT - ScatterType GetScatter() const { return this->Scatter; } - template - 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 @@ -55,9 +52,6 @@ public: { outputIndex = inputIndex; } - - private: - ScatterType Scatter; }; Triangulate() @@ -96,8 +90,8 @@ public: { vtkm::cont::ArrayHandle output; - DistributeCellData distribute(this->OutCellsPerCell, device); - vtkm::worklet::DispatcherMapField dispatcher(distribute); + vtkm::worklet::DispatcherMapField dispatcher( + DistributeCellData::MakeScatter(this->OutCellsPerCell, device)); dispatcher.Invoke(input, output); return output; diff --git a/vtkm/worklet/WorkletPointNeighborhood.h b/vtkm/worklet/WorkletPointNeighborhood.h index 07d32115d..729b2af0e 100644 --- a/vtkm/worklet/WorkletPointNeighborhood.h +++ b/vtkm/worklet/WorkletPointNeighborhood.h @@ -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; diff --git a/vtkm/worklet/connectivities/CellSetDualGraph.h b/vtkm/worklet/connectivities/CellSetDualGraph.h index 5fdfc00b1..9d6834412 100644 --- a/vtkm/worklet/connectivities/CellSetDualGraph.h +++ b/vtkm/worklet/connectivities/CellSetDualGraph.h @@ -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 Scatter; } - - VTKM_CONT - Merge(const ScatterType& scatter) - : Scatter(scatter) - { - } - // TODO: type trait for array portal? template VTKM_EXEC void operator()(KeyType key, @@ -72,9 +63,6 @@ public: value1Out = value1; value2Out = v2; } - - private: - ScatterType Scatter; }; using Algorithm = vtkm::cont::DeviceAdapterAlgorithm; @@ -101,8 +89,7 @@ public: Algorithm::Transform(ubs, lbs, counts, vtkm::Subtract()); vtkm::worklet::ScatterCounting scatter{ counts, DeviceAdapter() }; - Merge merge(scatter); - vtkm::worklet::DispatcherMapField mergeDisp(merge); + vtkm::worklet::DispatcherMapField mergeDisp(scatter); mergeDisp.Invoke(key1, value1, lbs, value2, keyOut, value1Out, value2Out); } }; diff --git a/vtkm/worklet/cosmotools/CosmoTools.h b/vtkm/worklet/cosmotools/CosmoTools.h index bf782acf4..9bf1cd4a3 100644 --- a/vtkm/worklet/cosmotools/CosmoTools.h +++ b/vtkm/worklet/cosmotools/CosmoTools.h @@ -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; }; /////////////////////////////////////////////////////////////////////////////// diff --git a/vtkm/worklet/cosmotools/CosmoToolsHaloFinder.h b/vtkm/worklet/cosmotools/CosmoToolsHaloFinder.h index 8e7bdfabb..dab9ba15c 100644 --- a/vtkm/worklet/cosmotools/CosmoToolsHaloFinder.h +++ b/vtkm/worklet/cosmotools/CosmoToolsHaloFinder.h @@ -331,11 +331,8 @@ void CosmoTools::MBPCenterFindingByHalo( // Setup the ScatterCounting worklets needed to expand the ReduceByKeyResults vtkm::worklet::ScatterCounting scatter(particlesPerHalo, DeviceAdapter()); - ScatterWorklet scatterWorkletId(scatter); - ScatterWorklet scatterWorklet(scatter); - vtkm::worklet::DispatcherMapField> scatterWorkletIdDispatcher( - scatterWorkletId); - vtkm::worklet::DispatcherMapField> scatterWorkletDispatcher(scatterWorklet); + vtkm::worklet::DispatcherMapField> scatterWorkletIdDispatcher(scatter); + vtkm::worklet::DispatcherMapField> scatterWorkletDispatcher(scatter); // Calculate the minimum particle index per halo id and scatter DeviceAlgorithm::ScanExclusive(particlesPerHalo, tempI); diff --git a/vtkm/worklet/internal/DispatcherBase.h b/vtkm/worklet/internal/DispatcherBase.h index 6f8ca6667..2818b954b 100644 --- a/vtkm/worklet/internal/DispatcherBase.h +++ b/vtkm/worklet/internal/DispatcherBase.h @@ -500,6 +500,8 @@ private: public: + using ScatterType = typename WorkletType::ScatterType; + template 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 @@ -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. diff --git a/vtkm/worklet/internal/WorkletBase.h b/vtkm/worklet/internal/WorkletBase.h index be89c39ca..bb6e2ee99 100644 --- a/vtkm/worklet/internal/WorkletBase.h +++ b/vtkm/worklet/internal/WorkletBase.h @@ -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 diff --git a/vtkm/worklet/internal/testing/UnitTestDispatcherBase.cxx b/vtkm/worklet/internal/testing/UnitTestDispatcherBase.cxx index e5a6a320b..71cf77c02 100644 --- a/vtkm/worklet/internal/testing/UnitTestDispatcherBase.cxx +++ b/vtkm/worklet/internal/testing/UnitTestDispatcherBase.cxx @@ -252,11 +252,13 @@ class TestDispatcher : public vtkm::worklet::internal::DispatcherBase, 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) { } diff --git a/vtkm/worklet/testing/UnitTestScatterCounting.cxx b/vtkm/worklet/testing/UnitTestScatterCounting.cxx index e45f749f6..d9fa7ed42 100644 --- a/vtkm/worklet/testing/UnitTestScatterCounting.cxx +++ b/vtkm/worklet/testing/UnitTestScatterCounting.cxx @@ -120,25 +120,10 @@ struct TestScatterCountingWorklet : public vtkm::worklet::WorkletMapField using ScatterType = vtkm::worklet::ScatterCounting; - VTKM_CONT - ScatterType GetScatter() const { return this->Scatter; } - - template - VTKM_CONT TestScatterCountingWorklet(const CountArrayType& countArray) - : Scatter(countArray, VTKM_DEFAULT_DEVICE_ADAPTER_TAG()) - { - } - template - 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 @@ -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 dispatcher(worklet); + vtkm::worklet::DispatcherMapField dispatcher( + TestScatterCountingWorklet::MakeScatter(arrays.CountArray, VTKM_DEFAULT_DEVICE_ADAPTER_TAG())); vtkm::Id inputSize = arrays.CountArray.GetNumberOfValues(); vtkm::cont::ArrayHandleIndex inputIndices(inputSize); diff --git a/vtkm/worklet/testing/UnitTestScatterPermutation.cxx b/vtkm/worklet/testing/UnitTestScatterPermutation.cxx index 7851c3039..84edd93a8 100644 --- a/vtkm/worklet/testing/UnitTestScatterPermutation.cxx +++ b/vtkm/worklet/testing/UnitTestScatterPermutation.cxx @@ -44,9 +44,10 @@ public: using ScatterType = vtkm::worklet::ScatterPermutation<>; - Worklet(const vtkm::cont::ArrayHandle& permutation) - : Scatter(permutation) + VTKM_CONT + static ScatterType MakeScatter(const vtkm::cont::ArrayHandle& 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 @@ -71,8 +66,8 @@ void RunTest(const CellSetType& cellset, const vtkm::cont::ArrayHandle vtkm::cont::ArrayHandle outPointId; vtkm::cont::ArrayHandle outVisit; - Worklet worklet(permutation); - vtkm::worklet::DispatcherMapTopology(worklet).Invoke(cellset, outPointId, outVisit); + vtkm::worklet::DispatcherMapTopology dispatcher(Worklet::MakeScatter(permutation)); + dispatcher.Invoke(cellset, outPointId, outVisit); for (vtkm::Id i = 0; i < permutation.GetNumberOfValues(); ++i) { diff --git a/vtkm/worklet/testing/UnitTestWorkletMapPointNeighborhood.cxx b/vtkm/worklet/testing/UnitTestWorkletMapPointNeighborhood.cxx index 489708676..e51ddbdbc 100644 --- a/vtkm/worklet/testing/UnitTestWorkletMapPointNeighborhood.cxx +++ b/vtkm/worklet/testing/UnitTestWorkletMapPointNeighborhood.cxx @@ -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>; }; } diff --git a/vtkm/worklet/tetrahedralize/TetrahedralizeExplicit.h b/vtkm/worklet/tetrahedralize/TetrahedralizeExplicit.h index 39e8155b2..b3d87835b 100644 --- a/vtkm/worklet/tetrahedralize/TetrahedralizeExplicit.h +++ b/vtkm/worklet/tetrahedralize/TetrahedralizeExplicit.h @@ -86,13 +86,11 @@ public: using InputDomain = _1; using ScatterType = vtkm::worklet::ScatterCounting; - VTKM_CONT - ScatterType GetScatter() const { return this->Scatter; } template - 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 @@ -137,9 +132,8 @@ public: tetPerCellDispatcher.Invoke(inShapes, tables.PrepareForInput(DeviceAdapter()), outCellsPerCell); // Build new cells - TetrahedralizeCell tetrahedralizeWorklet(outCellsPerCell); vtkm::worklet::DispatcherMapTopology - tetrahedralizeDispatcher(tetrahedralizeWorklet); + tetrahedralizeDispatcher(TetrahedralizeCell::MakeScatter(outCellsPerCell)); tetrahedralizeDispatcher.Invoke(cellSet, tables.PrepareForInput(DeviceAdapter()), vtkm::cont::make_ArrayHandleGroupVec<4>(outConnectivity)); diff --git a/vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h b/vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h index 792138e1e..942d57b88 100644 --- a/vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h +++ b/vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h @@ -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 diff --git a/vtkm/worklet/triangulate/TriangulateExplicit.h b/vtkm/worklet/triangulate/TriangulateExplicit.h index 0876efad6..7176bf2cc 100644 --- a/vtkm/worklet/triangulate/TriangulateExplicit.h +++ b/vtkm/worklet/triangulate/TriangulateExplicit.h @@ -89,13 +89,11 @@ public: using InputDomain = _1; using ScatterType = vtkm::worklet::ScatterCounting; - VTKM_CONT - ScatterType GetScatter() const { return this->Scatter; } template - 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 @@ -140,9 +135,8 @@ public: inShapes, inNumIndices, tables.PrepareForInput(DeviceAdapter()), outCellsPerCell); // Build new cells - TriangulateCell triangulateWorklet(outCellsPerCell); vtkm::worklet::DispatcherMapTopology triangulateDispatcher( - triangulateWorklet); + TriangulateCell::MakeScatter(outCellsPerCell)); triangulateDispatcher.Invoke(cellSet, tables.PrepareForInput(DeviceAdapter()), vtkm::cont::make_ArrayHandleGroupVec<3>(outConnectivity)); diff --git a/vtkm/worklet/triangulate/TriangulateStructured.h b/vtkm/worklet/triangulate/TriangulateStructured.h index 98d819abd..f9136d69c 100644 --- a/vtkm/worklet/triangulate/TriangulateStructured.h +++ b/vtkm/worklet/triangulate/TriangulateStructured.h @@ -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