From cbb5871eaea8b91dedbee9556ce471d19d4044d5 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 17 Sep 2024 14:03:28 -0400 Subject: [PATCH] Consolidate flying edges device cases The flying edges code has two main implementations: one where it traverses the mesh in the X direction (for CPU) and one where it traverses the mesh in the Y direction (for GPU). There were several places in the code where the device was checked for the case to use. This resulted in several places where the "GPU" devices had to be listed. Improve the code by consolidate the check to a single piece of code in `FlyingEdgesHelpers.h` where the axis to sum structure is selected. Make the overloads based on this structure rather than directly on the devices. --- .../worklet/contour/FlyingEdgesPass1.h | 84 +++++++------------ .../worklet/contour/FlyingEdgesPass4.h | 13 +-- 2 files changed, 36 insertions(+), 61 deletions(-) diff --git a/vtkm/filter/contour/worklet/contour/FlyingEdgesPass1.h b/vtkm/filter/contour/worklet/contour/FlyingEdgesPass1.h index cfea94c1d..498855d7c 100644 --- a/vtkm/filter/contour/worklet/contour/FlyingEdgesPass1.h +++ b/vtkm/filter/contour/worklet/contour/FlyingEdgesPass1.h @@ -45,8 +45,8 @@ namespace flying_edges * */ -template -inline VTKM_EXEC void write_edge(Device, +template +inline VTKM_EXEC void write_edge(SumXAxis, vtkm::Id write_index, WholeEdgeField& edges, vtkm::UInt8 edgeCase) @@ -55,7 +55,7 @@ inline VTKM_EXEC void write_edge(Device, } template -inline VTKM_EXEC void write_edge(vtkm::cont::DeviceAdapterTagCuda, +inline VTKM_EXEC void write_edge(SumYAxis, vtkm::Id write_index, WholeEdgeField& edges, vtkm::UInt8 edgeCase) @@ -98,7 +98,7 @@ struct ComputePass1 : public vtkm::worklet::WorkletVisitPointsWithCells vtkm::Id& axis_max, WholeEdgeField& edges, const WholeDataField& field, - Device device) const + Device) const { using AxisToSum = typename select_AxisToSum::type; @@ -129,7 +129,7 @@ struct ComputePass1 : public vtkm::worklet::WorkletVisitPointsWithCells edgeCase |= FlyingEdges3D::RightAbove; } - write_edge(device, startPos + (offset * i), edges, edgeCase); + write_edge(AxisToSum{}, startPos + (offset * i), edges, edgeCase); if (edgeCase == FlyingEdges3D::LeftAbove || edgeCase == FlyingEdges3D::RightAbove) { @@ -141,68 +141,42 @@ struct ComputePass1 : public vtkm::worklet::WorkletVisitPointsWithCells } } } - write_edge(device, startPos + (offset * end), edges, FlyingEdges3D::Below); + write_edge(AxisToSum{}, startPos + (offset * end), edges, FlyingEdges3D::Below); } }; struct launchComputePass1 { - template - VTKM_CONT bool LaunchXAxis(DeviceAdapterTag device, - const ComputePass1& worklet, - const vtkm::cont::ArrayHandle& inputField, - vtkm::cont::ArrayHandle& edgeCases, - vtkm::cont::CellSetStructured<2>& metaDataMesh2D, - Args&&... args) const + void FillEdgeCases(vtkm::cont::ArrayHandle&, SumXAxis) const { - vtkm::cont::Invoker invoke(device); - metaDataMesh2D = make_metaDataMesh2D(SumXAxis{}, worklet.PointDims); - - invoke(worklet, metaDataMesh2D, std::forward(args)..., edgeCases, inputField); - return true; + // Do nothing } - - template - VTKM_CONT bool LaunchYAxis(DeviceAdapterTag device, - const ComputePass1& worklet, - const vtkm::cont::ArrayHandle& inputField, - vtkm::cont::ArrayHandle& edgeCases, - vtkm::cont::CellSetStructured<2>& metaDataMesh2D, - Args&&... args) const + void FillEdgeCases(vtkm::cont::ArrayHandle& edgeCases, SumYAxis) const { - vtkm::cont::Invoker invoke(device); - metaDataMesh2D = make_metaDataMesh2D(SumYAxis{}, worklet.PointDims); - edgeCases.Fill(static_cast(FlyingEdges3D::Below)); + } + + template + VTKM_CONT bool operator()(DeviceAdapterTag device, + const ComputePass1& worklet, + const vtkm::cont::ArrayHandle& inputField, + vtkm::cont::ArrayHandle& edgeCases, + vtkm::cont::CellSetStructured<2>& metaDataMesh2D, + Args&&... args) const + { + using AxisToSum = typename select_AxisToSum::type; + + vtkm::cont::Invoker invoke(device); + metaDataMesh2D = make_metaDataMesh2D(AxisToSum{}, worklet.PointDims); + + this->FillEdgeCases(edgeCases, AxisToSum{}); invoke(worklet, metaDataMesh2D, std::forward(args)..., edgeCases, inputField); return true; } - - template - VTKM_CONT bool operator()(DeviceAdapterTag device, Args&&... args) const - { - return this->LaunchXAxis(device, std::forward(args)...); - } - - template - VTKM_CONT bool operator()(vtkm::cont::DeviceAdapterTagCuda device, Args&&... args) const - { - return this->LaunchYAxis(device, std::forward(args)...); - } - - template - VTKM_CONT bool operator()(vtkm::cont::DeviceAdapterTagKokkos device, Args&&... args) const - { - return this->LaunchYAxis(device, std::forward(args)...); - } }; } } diff --git a/vtkm/filter/contour/worklet/contour/FlyingEdgesPass4.h b/vtkm/filter/contour/worklet/contour/FlyingEdgesPass4.h index 088f12dd9..1deb99d9e 100644 --- a/vtkm/filter/contour/worklet/contour/FlyingEdgesPass4.h +++ b/vtkm/filter/contour/worklet/contour/FlyingEdgesPass4.h @@ -168,21 +168,22 @@ struct launchComputePass4 } template - VTKM_CONT bool operator()(DeviceAdapterTag device, Args&&... args) const + VTKM_CONT bool Launch(SumXAxis, DeviceAdapterTag device, Args&&... args) const { return this->LaunchXAxis(device, std::forward(args)...); } - template - VTKM_CONT bool operator()(vtkm::cont::DeviceAdapterTagCuda device, Args&&... args) const + template + VTKM_CONT bool Launch(SumYAxis, DeviceAdapterTag device, Args&&... args) const { return this->LaunchYAxis(device, std::forward(args)...); } - template - VTKM_CONT bool operator()(vtkm::cont::DeviceAdapterTagKokkos device, Args&&... args) const + template + VTKM_CONT bool operator()(DeviceAdapterTag device, Args&&... args) const { - return this->LaunchYAxis(device, std::forward(args)...); + return this->Launch( + (typename select_AxisToSum::type){}, device, std::forward(args)...); } }; }