HostTuning

Choosing the BVH branching factor K and the SIMD width W (the number of triangles or points a leaf evaluates together): the portable defaults, which any code can use, against the values tuned to the SIMD flags of the build, which only host-only code should. It builds a point cloud (Point clouds) and a triangle mesh signed distance function both ways and times their queries, so you can see whether host tuning pays off on your machine. See Branching factor and SIMD width for the difference between the two and when to use which.

The example is host-only: device code always uses the defaults, so it has no GPU section. The source is at Examples/HostTuning/main.cpp, in the following sections.

The two choices

The defaults, BVH::DefaultBranchingRatio<T>() and TriangleSoA::DefaultWidth<T>() / PointSoA::DefaultWidth<T>(), are 4 whatever the compiler flags. A type spelled with them is the same type in every file and in both passes of a CUDA or HIP compile, so an object built on the host can be copied to a GPU and used there. Leaving K and W out of a type gives these:

static_assert(std::is_same_v<PointCloudBVH<T>,
                             PointCloudBVH<T, DefaultK, PointSoA::DefaultWidth<T>()>>);

The host-tuned values, BVH::HostBranchingRatio<T>(), TriangleSoA::HostWidth<T>() and PointSoA::HostWidth<T>(), fill one SIMD register under the flags the file is compiled with.

A point cloud, built both ways

The program builds a 200,000-point PointCloudBVH with the default and with the host-tuned K and W in one pool, and times 200,000 closestPoint() queries on each.

A triangle mesh, built both ways

It reads the mesh twice with Parser::readIntoTriMeshSDF, once with the defaults and once as readIntoTriMeshSDF<T, HostK, HostW>, and times 200,000 signedDistance() queries on each. The two group the triangles differently, so they give the same distances to rounding; the program prints the first query’s result from each, next to the times.

Building and running

Build it on its own (with CMake, make or a direct compiler invocation in its folder, all of which use -march=native) to compare with the portable defaults: EBGeometry’s own CMake build turns on EBGEOMETRY_HOST_TUNED_DEFAULTS, which makes the default triangle width the host-tuned one. See Building for the three ways to compile it.

Without an argument the mesh is the small dodecahedron in Examples/data, which is too small for the timing to mean much; pass a larger mesh to compare:

cd Examples/HostTuning
./HostTuning.ex ../../common-3d-test-models/data/armadillo.obj