Repository navigation
Improve performance of the {Norm}Distance and dotProduct functions - #106007
Conversation
The project sets `-ffp-contract=off` globally in the top-level `CMakeLists.txt` for numerical determinism across CPUs, which blocks the compiler from fusing `a*b + c` into `vfmadd*` in every TU. The dot-product and distance kernels in `arrayDotProduct.cpp` / `arrayDistance.cpp` have hot inner loops that depend on FMA generation to saturate the FP pipeline. A comment in `arrayDotProduct.cpp` even claims "compiler auto-vectorizes with FMA", which is currently false because of the global flag. Re-enable FMA fusion only for these two TUs via per-file `COMPILE_FLAGS "-ffp-contract=fast"`. Per-source `COMPILE_FLAGS` are appended after `CMAKE_CXX_FLAGS`, so this override wins over the global setting without touching any other TU. Picked Option B (per-source `set_source_files_properties` in `src/Functions/array/CMakeLists.txt`) over Option A (in-source `#pragma clang fp contract(fast)`) because (a) the convention is already used in this same file for `array.cpp`, (b) each file has multiple FMA-eligible scopes (the leaf `accumulate` functions plus the templated dispatch loops that inline them), and a file-scope override cannot miss any of them, and (c) this leaves the existing source comments untouched and makes them accurate. The override is a no-op for distance kernels that don't have `a*b + c` patterns (`L1` uses `fabs`, `Linf` uses `fmax`, `Lp` uses `pow`).
|
Workflow [PR], commit [03ec248] Summary: ✅
AI ReviewSummaryThis PR enables PR Metadata
Missing context / blind spots
Findings
Tests
Final VerdictStatus: Minimum required actions: provide completed performance evidence for the claimed speedup and update the changelog entry to be user-facing and explicit about the floating-point result change. |
{Norm}Distance and dotProduct functions
alexey-milovidov
left a comment
There was a problem hiding this comment.
Good.
But I'd risk and try to enable fp-contract fast everywhere.
ok, will do |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improved performance of the
{Norm}DistanceanddotProductfunctions.Version info
26.6.1.260