SIMD acceleration

EBGeometry vectorizes its innermost loops with compiler intrinsics rather than relying on the compiler to auto-vectorize scalar code: the test of a point or a ray against the child boxes of a BVH::PackedBVH node, and the leaf computations of the triangle groups (TriMeshSDF) and point groups (PointCloudBVH). Everything else in the library is scalar code. Vectorizing the leaves of another primitive type mostly requires storing the primitives in a structure-of-arrays (SoA) layout. SIMD-accelerated classes describes each of the vectorized classes.

How it is enabled

EBGeometry detects the available SIMD instruction set at compile time, using the standard pre-defined compiler macros __AVX512F__, __AVX__ and __SSE4_1__ — there is no runtime dispatch. Whichever of these macros your compiler flags define, that is the code path compiled in.

Target ISA

Compiler macro(s) required

AVX-512F (recent server/HEDT CPUs)

__AVX512F__

AVX (recommended on x86-64 since ~2013)

__AVX__

SSE 4.1 (older or constrained targets)

__SSE4_1__

No SIMD (portable fallback)

(none of the above)

See Building for the exact compiler/CMake/Makefile flags that define these macros for each of the three build methods.

Under the hood

The ISA macros select which SIMD code paths are compiled in. On their own they do not change the defaults: the BVH branching factor K and the SIMD width W of the leaf primitives’ SoA layout default to 4 on every machine, so a type spelled with them is the same in every translation unit and on a GPU. The ISA-tuned values (BVH::HostBranchingRatio<T>(), TriangleSoA::HostWidth<T>(), PointSoA::HostWidth<T>()) are opt-in, either spelled into a type or, for the triangle-group width, through the EBGEOMETRY_HOST_TUNED_DEFAULTS build switch; see Branching factor and SIMD width. How to pass K and W explicitly is documented alongside the SIMD-supported classes in SIMD-accelerated classes.