Skip to content

Faster AD and builds by default - #54

Merged
auto-differentiation-dev merged 3 commits into
mainfrom
perf/fast-build-and-tests
Nov 12, 2026
Merged

auto-differentiation-dev merged 3 commits into
mainfrom
perf/fast-build-and-tests

Conversation

@auto-differentiation-dev

@auto-differentiation-dev auto-differentiation-dev commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

QuantLibAAD's defaults now give fast AD code and fast builds. QuantLibAAD sets XAD's fastest tape options before XAD is configured, builds QuantLib as a static library, with link-time optimisation when built with GCC, and speeds up QuantLib's build with precompiled headers, unity builds and ccache. Each setting can be switched off on the command line. QuantLibAAD now has to be listed before XAD in QL_EXTERNAL_SUBDIRECTORIES. The old order is now a configure error: pass -DQL_EXTERNAL_SUBDIRECTORIES="<path>/QuantLibAAD;<path>/xad" and reconfigure in a fresh build directory, or pass -DQLAAD_ALLOW_XAD_FIRST=ON to keep XAD's own settings, with a warning that QuantLibAAD's defaults don't reach XAD. An installed XAD package (find_package(XAD)) is not affected.

The default library type changes from shared to static on Linux and macOS, also when an existing build directory is reconfigured. Pass -DBUILD_SHARED_LIBS=ON to keep a shared QuantLib. When QuantLib is built inside another project, that project's BUILD_SHARED_LIBS decides. Users linking a static QuantLib through pkg-config or quantlib-config need -lxad too, and an older shared QuantLib should be removed from the install prefix.

Changes

  • XAD defaults set by QuantLibAAD: strong inlining (not with MSVC's cl.exe or in Debug builds), linear slots (not with copy elision, slot reuse or live-slot tracking), and on Linux huge pages and, for a static QuantLib, initial-exec TLS. They follow the current settings on every configure; an XAD option given on the command line wins, and other cached XAD settings (from an old-order configure, ccmake, cmake-gui or -C) are replaced by the defaults (for XAD_NO_THREADLOCAL, XAD's own default, OFF), with a warning naming each entry that changes; that includes -D options given in the old order, so pass them again. With an installed XAD package, XAD's own settings apply and CMake says so.
  • Static QuantLib by default, and link-time optimisation by default with GCC, except on Windows. QLAAD_LTO_FAT_OBJECTS=ON adds machine code to the installed libraries, for use by other toolchains.
  • Precompiled headers and unity builds for QuantLib's library and tests (QLAAD_FAST_BUILD), ccache when installed (QLAAD_USE_CCACHE), and one CTest test per QuantLib suite so ctest -j runs them in parallel (QLAAD_CTEST_PER_SUITE).
  • -ffp-contract=off for QuantLib and its users with GCC, Clang and AppleClang, so AD values match double exactly.
  • CI and the presets use the new order, and the presets no longer set XAD_NO_THREADLOCAL; the README describes the defaults and how to switch them off. CI now builds the new defaults, so it no longer builds the old default combination (shared QuantLib, no LTO), XAD with its own tape defaults, or QuantLib without precompiled headers and unity builds; the xad-ci-trigger dispatch now tests XAD changes only with the new options.

Testing

  • CMake checks of the defaults, the warnings, reconfigures and the switched-off settings (tools/check-build-defaults.cmake, tools/check-ctest-per-suite.cmake, tools/check-pch-select.cmake); CI runs the first two after the Linux configure step. All configure variants also pass with the check scripts run by CMake 3.25 (the configures themselves used CMake 4.2).
  • QuantLib's test suite, QuantLibAAD's tests and samples, and an installed-consumer build pass on Linux GCC 15 with XAD 2.2.0.

QuantLib master at cf74c9f65 with a fix for lambdas returning temporaries, XAD 2.2.0, AMD EPYC (Zen 5), GCC 15, one core per run, AD relative to double with the same build settings:

Before After
Test suite run time 2.28× 1.12×
Benchmark run time 2.20× 1.21×
Compile CPU 3.06× 2.03×
Compile wall time, 32 cores 2.87× 2.40×

With a compiler that contracts to FMA by default (e.g. GCC targeting x86-64-v3, as here), the "Before" AD build also fails one test, PiecewiseYieldCurveTests/testGlobalBootstrapInitialGuessFn; with the new defaults (-ffp-contract=off) it passes.

QuantLibAAD now comes before xad in QL_EXTERNAL_SUBDIRECTORIES and sets XAD's option defaults; with the old order it warns.
QLAAD_ALLOW_XAD_FIRST=ON keeps the old order, with XAD's own settings and a warning.
@auto-differentiation-dev

Copy link
Copy Markdown
Contributor Author

CI against QuantLib master plus lballabio/QuantLib#3068 (which fixes master's test suite with AD types): all jobs pass. https://github.com/auto-differentiation/QuantLibAAD/actions/runs/43245396216 The red checks on this PR come from QuantLib master's test suite not compiling with AD until #3068 is merged.

@auto-differentiation-dev
auto-differentiation-dev merged commit b6914cb into main Nov 12, 2026
26 of 40 checks passed
@auto-differentiation-dev
auto-differentiation-dev deleted the perf/fast-build-and-tests branch November 12, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant