From 0ee495f310c99a0b073cbb04d8f48a5df41683b3 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 26 Jun 2023 14:07:47 -0400 Subject: [PATCH] Split the compilation of ContourMarchingCells into instantiations Although the contour filter was recently divided into 2 filters, flying edges and marching cubes, the marching cubes version still had many conditions and was the file that took the longest to compile on Frontier. To help speed up parallel compiles and prevent a single run of a compiler from being overwhelmed, the compilation of all the marching cubes conditions has been split up using instantiations. --- docs/changelog/split-contour-filters.md | 5 +- vtkm/filter/contour/CMakeLists.txt | 3 + vtkm/filter/contour/ContourMarchingCells.cxx | 5 +- .../contour/worklet/ContourMarchingCells.h | 177 +++++++++++++++--- 4 files changed, 157 insertions(+), 33 deletions(-) diff --git a/docs/changelog/split-contour-filters.md b/docs/changelog/split-contour-filters.md index 3dd58bfab..592cbd0c8 100644 --- a/docs/changelog/split-contour-filters.md +++ b/docs/changelog/split-contour-filters.md @@ -8,4 +8,7 @@ Although `Contour` is still the preferred option for most cases because it selec Deprecate functions `GetComputeFastNormalsForStructured`, `SetComputeFastNormalsForStructured`, `GetComputeFastNormalsForUnstructured` and `GetComputeFastNormalsForUnstructured`, to use the more general `GetComputeFastNormals` and `SetComputeFastNormals` instead. - By default, for the `Contour` filter, `GenerateNormals` is now `true`, and `ComputeFastNormals` is `false`. +By default, for the `Contour` filter, `GenerateNormals` is now `true`, and `ComputeFastNormals` is `false`. + +The marching cubes version of contour still has several possible compile paths, so it can still take a bit to compile. To help manage the compile time further, the contour filter compilation is broken up even further using the instantiation build capabilities. + diff --git a/vtkm/filter/contour/CMakeLists.txt b/vtkm/filter/contour/CMakeLists.txt index e9a85badd..9f45e5cb9 100644 --- a/vtkm/filter/contour/CMakeLists.txt +++ b/vtkm/filter/contour/CMakeLists.txt @@ -34,6 +34,9 @@ set(contour_sources Contour.cxx ) +vtkm_add_instantiations(contour_instantiations INSTANTIATIONS_FILE worklet/ContourMarchingCells.h) +list(APPEND contour_sources_device ${contour_instantiations}) + set_source_files_properties(Contour.cxx PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) vtkm_library( diff --git a/vtkm/filter/contour/ContourMarchingCells.cxx b/vtkm/filter/contour/ContourMarchingCells.cxx index 855e5b154..38a3ca500 100644 --- a/vtkm/filter/contour/ContourMarchingCells.cxx +++ b/vtkm/filter/contour/ContourMarchingCells.cxx @@ -59,12 +59,11 @@ vtkm::cont::DataSet ContourMarchingCells::DoExecute(const vtkm::cont::DataSet& i if (this->GenerateNormals && !this->GetComputeFastNormals()) { - outputCells = - worklet.Run(ivalues, inputCells, inputCoords.GetData(), concrete, vertices, normals); + outputCells = worklet.Run(ivalues, inputCells, inputCoords, concrete, vertices, normals); } else { - outputCells = worklet.Run(ivalues, inputCells, inputCoords.GetData(), concrete, vertices); + outputCells = worklet.Run(ivalues, inputCells, inputCoords, concrete, vertices); } }; diff --git a/vtkm/filter/contour/worklet/ContourMarchingCells.h b/vtkm/filter/contour/worklet/ContourMarchingCells.h index 1a27de5dc..9ecdde569 100644 --- a/vtkm/filter/contour/worklet/ContourMarchingCells.h +++ b/vtkm/filter/contour/worklet/ContourMarchingCells.h @@ -11,10 +11,19 @@ #ifndef vtk_m_worklet_ContourMarchingCells_h #define vtk_m_worklet_ContourMarchingCells_h +#include #include #include #include +#include +#include +#include +#include +#include + +#include + namespace vtkm { @@ -22,6 +31,7 @@ namespace worklet { namespace contour { + struct DeduceCoordType { template @@ -36,15 +46,41 @@ struct DeduceCoordType struct DeduceCellType { - template - void operator()(const CellSetType& cells, CoordinateType&& coordinateSystem, Args&&... args) const - { - vtkm::cont::CastAndCall( - coordinateSystem, contour::DeduceCoordType{}, cells, std::forward(args)...); - } + template + void operator()(const CellSetType& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const; }; + +// Declared outside of class, non-inline so that instantiations can be exported correctly. +template +void DeduceCellType::operator()(const CellSetType& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const +{ + vtkm::cont::CastAndCall(coordinateSystem, + contour::DeduceCoordType{}, + cells, + outputCells, + isovalues, + input, + vertices, + normals, + sharedState); } +} // namespace contour + /// \brief Compute the isosurface of a given 3D data set, supports all linear cell types class ContourMarchingCells { @@ -87,22 +123,18 @@ public: //---------------------------------------------------------------------------- void ReleaseCellMapArrays() { this->SharedState.CellIdMap.ReleaseResources(); } +public: // Filter called without normals generation - template - vtkm::cont::CellSetSingleType<> Run( + template + VTKM_CONT vtkm::cont::CellSetSingleType<> Run( const std::vector& isovalues, - const CellSetType& cells, - const CoordinateSystem& coordinateSystem, + const vtkm::cont::UnknownCellSet& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, const vtkm::cont::ArrayHandle& input, - vtkm::cont::ArrayHandle, StorageTagVertices>& vertices) + vtkm::cont::ArrayHandle& vertices) { this->SharedState.GenerateNormals = false; - vtkm::cont::ArrayHandle> normals; + vtkm::cont::ArrayHandle normals; vtkm::cont::CellSetSingleType<> outputCells; vtkm::cont::CastAndCall(cells, @@ -118,20 +150,14 @@ public: } // Filter called with normals generation - template - vtkm::cont::CellSetSingleType<> Run( + template + VTKM_CONT vtkm::cont::CellSetSingleType<> Run( const std::vector& isovalues, - const CellSetType& cells, - const CoordinateSystem& coordinateSystem, + const vtkm::cont::UnknownCellSet& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, const vtkm::cont::ArrayHandle& input, - vtkm::cont::ArrayHandle, StorageTagVertices>& vertices, - vtkm::cont::ArrayHandle, StorageTagNormals>& normals) + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals) { this->SharedState.GenerateNormals = true; @@ -152,7 +178,100 @@ public: private: vtkm::worklet::contour::CommonState SharedState; }; + } } // namespace vtkm::worklet +VTKM_INSTANTIATION_BEGIN +extern template void vtkm::worklet::contour::DeduceCellType::operator()( + const vtkm::cont::CellSetStructured<2>& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const; +VTKM_INSTANTIATION_END +VTKM_INSTANTIATION_BEGIN +extern template void vtkm::worklet::contour::DeduceCellType::operator()( + const vtkm::cont::CellSetStructured<2>& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const; +VTKM_INSTANTIATION_END + +VTKM_INSTANTIATION_BEGIN +extern template void vtkm::worklet::contour::DeduceCellType::operator()( + const vtkm::cont::CellSetStructured<3>& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const; +VTKM_INSTANTIATION_END +VTKM_INSTANTIATION_BEGIN +extern template void vtkm::worklet::contour::DeduceCellType::operator()( + const vtkm::cont::CellSetStructured<3>& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const; +VTKM_INSTANTIATION_END + +VTKM_INSTANTIATION_BEGIN +extern template void vtkm::worklet::contour::DeduceCellType::operator()( + const vtkm::cont::CellSetExplicit<>& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const; +VTKM_INSTANTIATION_END +VTKM_INSTANTIATION_BEGIN +extern template void vtkm::worklet::contour::DeduceCellType::operator()( + const vtkm::cont::CellSetExplicit<>& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const; +VTKM_INSTANTIATION_END + +VTKM_INSTANTIATION_BEGIN +extern template void vtkm::worklet::contour::DeduceCellType::operator()( + const vtkm::cont::CellSetSingleType<>& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const; +VTKM_INSTANTIATION_END +VTKM_INSTANTIATION_BEGIN +extern template void vtkm::worklet::contour::DeduceCellType::operator()( + const vtkm::cont::CellSetSingleType<>& cells, + const vtkm::cont::CoordinateSystem& coordinateSystem, + vtkm::cont::CellSetSingleType<>& outputCells, + const std::vector& isovalues, + const vtkm::cont::ArrayHandle& input, + vtkm::cont::ArrayHandle& vertices, + vtkm::cont::ArrayHandle& normals, + vtkm::worklet::contour::CommonState& sharedState) const; +VTKM_INSTANTIATION_END + #endif // vtk_m_worklet_ContourMarchingCells_h