How to evaluate if I'd benefit from using Intel TBB with VTK?

(Sean McBride) #1

Hi all,

How can I evaluate if I’d benefit from using Intel TBB with VTK?

That is, is there a list of VTK classes that use it? Or is there some TBB bottleneck function that I could put a breakpoint on to see if my app’s use of VTK involves anything that uses TBB?

Thanks,

Sean

(Andras Lasso) #2

If you have an application that is large enough so that you cannot manually tune number of threads in each filter then you must use a backend that supports thread pools (TBB or OpenMP). See for example why we had to switch to TBB in Slicer: https://github.com/Slicer/Slicer/pull/930

(Sean McBride) #3

My question is more like: VTK is a big library. I only use parts of it. Maybe the parts I use don’t ever use TBB, how can I tell? For a silly example, if the only VTK class I use is vtkMatrix4x4, then (I assume) I’d be wasting my time adding TBB.

(Andras Lasso) #4

If you use any multi-threaded filter then you may benefit from using a non-sequential backend, because creation of hundreds of threads per second (this is what the sequential backend does) may have an enormous overhead on its own and it may also interfere with NVidia’s threaded optimization heuristics.

If you use VTK in a product where you control all the hardware, drivers, operating system settings, and other concurrently running applications then you can just test in that environment to see if benefits of using TBB are significant. If you develop a product that the user can install on his own computer then your best bet is to use TBB to prevent any surprises.

There are also a few filters that are specifically designed for parallel backends (flying edge filter, etc.) that are very slow if you use the sequential backend.

(Sean McBride) #5

That just pushes my question to: how do I know if I “use any multi-threaded filter”? :slight_smile:

I guess I can put a breakpoint on pthread_create and see if it’s ever called from VTK…

Sean

(Andras Lasso) #6

If you look at the source code of a filter then it is obvious if it is multi-threaded or not. For example, if vtkMultiThreader.h is included in the .cxx file then most likely it is a multi-threaded filter.

(Mathieu Westphal (Kitware)) #7

Hi Sean,

You can first look into the documentation of VTK, most classes using vtkSMPTools indicate it in their doc :
https://vtk.org/doc/nightly/html/classvtkSimpleElevationFilter.html#details

If you want the list of filter, then you can search this in google :
site:https://vtk.org/doc/nightly/html/ "with vtkSMPTools"

Some filter are not reporting the use of SMP, so in this case only a exaustive search in the source code will give you the whole picture.

cd vtk/Filters
grep -rl vtkSMPTools | grep cxx
Modeling/vtkSelectEnclosedPoints.cxx
Modeling/vtkFitToHeightMapFilter.cxx
Modeling/vtkTrimmedExtrusionFilter.cxx
Extraction/vtkFrustumSelector.cxx
Extraction/vtkValueSelector.cxx
Extraction/vtkLocationSelector.cxx
Extraction/vtkExtractCells.cxx
Points/vtkUnsignedDistance.cxx
Points/vtkFitImplicitFunction.cxx
Points/vtkStatisticalOutlierRemoval.cxx
Points/vtkSignedDistance.cxx
Points/vtkVoxelGrid.cxx
Points/vtkPointInterpolator2D.cxx
Points/vtkPointOccupancyFilter.cxx
Points/vtkRadiusOutlierRemoval.cxx
Points/vtkDensifyPointCloudFilter.cxx
Points/vtkPointInterpolator.cxx
Points/vtkExtractEnclosedPoints.cxx
Points/vtkSPHInterpolator.cxx
Points/vtkPointDensityFilter.cxx
Points/vtkPCANormalEstimation.cxx
Points/vtkPCACurvatureEstimation.cxx
Points/vtkPointCloudFilter.cxx
Points/vtkExtractSurface.cxx
Points/vtkHierarchicalBinningFilter.cxx
Points/vtkMaskPointsFilter.cxx
Points/vtkExtractPoints.cxx
General/vtkSampleImplicitFunctionFilter.cxx
General/vtkPointConnectivityFilter.cxx
General/vtkDiscreteFlyingEdgesClipper2D.cxx
General/vtkDiscreteFlyingEdges2D.cxx
General/vtkDiscreteFlyingEdges3D.cxx
SMP/vtkSMPTransform.cxx
SMP/vtkSMPContourGrid.cxx
SMP/vtkSMPMergePolyDataHelper.cxx
SMP/vtkSMPContourGridManyPieces.cxx
SMP/vtkThreadedSynchronizedTemplatesCutter3D.cxx
SMP/vtkSMPWarpVector.cxx
SMP/vtkThreadedSynchronizedTemplates3D.cxx
Core/vtkFlyingEdges3D.cxx
Core/vtkVectorNorm.cxx
Core/vtkPlaneCutter.cxx
Core/vtkElevationFilter.cxx
Core/vtkStaticCleanPolyData.cxx
Core/Testing/Cxx/TestSMPPipelineContour.cxx
Core/vtkSimpleElevationFilter.cxx
Core/vtkFlyingEdgesPlaneCutter.cxx
Core/vtkFlyingEdges2D.cxx
Core/vtkVectorDot.cxx
Core/vtkResampleToImage.cxx
Core/vtkProbeFilter.cxx
Core/vtkMultiObjectMassProperties.cxx
Core/vtkResampleWithDataSet.cxx
Core/vtkContour3DLinearGrid.cxx
Core/vtkVoronoi2D.cxx

I hope this helps

(David Gobbi) #8

In addition to the classes that use vtkSMPTools directly, all classes derived from vtkThreadedImageFilter will also use TBB if VTK is built with it.

So if you build with TBB and use image filters, you have a choice:

  • SetGlobalDefaultEnableSMP(1) to use TBB for all threaded image filters
  • SetGlobalDefaultEnableSMP(0) to use vtkMultiThreader (which is what you’re using now)

It’s also possible to use SetEnableSMP(bool) to choose TBB vs vtkMultiThreader for individual image filters (or use SetNumberOfThreads(1) to turn off threading completely).