Skip to content

nav tests: build nav_material_ext_test without FMA contraction, as the rollouts are - #750

Merged
transfix merged 1 commit into
masterfrom
fix/nav-material-ext-macos-fp
Oct 20, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/nav-material-ext-macos-fp

Conversation

@transfix

Copy link
Copy Markdown
Owner

NavMaterialExt.ACallbackGivingThePatchIsThePatch (added by #734) has failed recipe / macos-latest / Release on every PR since: run 39470314473 on #746 and run 39478176362 on #725. The failures are all for the dynamic vehicle: the outputs, the coefficient gradients (gp vs gc) and dL/dF_ext (fp vs fc) of the patch source and of a callback giving the same patch came out 1-2 ulp apart.

Cause

Both sources sample with the same inline functions, detail::patch_sample_channel and patch_sample_channel_grad, but in different TUs:

  • The patch source samples in material_bike_rollout.cpp, which is built with -ffp-contract=off.
  • The test's patch_callback samples in nav_material_ext_test.cpp, which was built with the compiler's default.

On aarch64 the default turns the sampler's bilinear sum into 3 FMAs and each Jacobian sum into 1, so the callback's F and J were not the patch's.

The other lanes were exact for these reasons:

  • x86-64 with no -march has no FMA instructions.
  • MSVC does not contract.
  • macOS Debug inlines nothing, so most likely both sides called one copy of the sampler.

Fix

The design promises bit for bit here: #734's table and docs/NAV_MATERIAL.md say "A callback giving the patch's own values and J: the patch, bit for bit". The library side already is. So the test TU is now built as the rollouts are, with -ffp-contract=off (/fp:precise on MSVC), the same way tests/CMakeLists.txt already builds det_math.cpp. There is no tolerance, and the library is unchanged.

The doc's table row now says the callback is bit for bit when it is built as the rollouts are.

How this was checked (there is no macOS here)

  • clang 18 on the test TU, with its own compile flags. By default, patch_sample_channel has 3 fmuladd and patch_sample_channel_grad has 2. With -ffp-contract=off there are none.
  • The callback compiled for arm64-apple-macosx. It has 6 fmadd by default and none with the flag.
  • An FMA emulation on Linux. A copy of the test whose callback does those FMAs with std::fma fails the same three assertions, for the dynamic vehicle only, by 1-2 ulp. One gradient pair is exactly the macOS log's (-0.126325145 vs -0.12632513). The surrogate's and the bicycle's callback F and J are an ulp off at many samples too, but those ulps round away where F_ext joins larger sums.
  • Linux, GCC 13, Release and Debug. nav_material_ext_test passes (11/11), and the compile line has -ffp-contract=off.
  • NavMaterialExt.Golden. It compares at 1e-5 relative, so it is unaffected.

recipe / macos-latest / Release on this PR is the check that matters.

…e rollouts are

NavMaterialExt.ACallbackGivingThePatchIsThePatch has failed on recipe / macos-latest / Release
since #734. For the dynamic vehicle, the outputs, the coefficient gradients and dL/dF_ext of the
patch source and of a callback giving the same patch came out 1-2 ulp apart.

Both sources sample with the same inline functions (detail/material_rollout.h's
patch_sample_channel and patch_sample_channel_grad), but in different TUs. The rollouts' TU,
material_bike_rollout.cpp, is built with -ffp-contract=off. The test's TU, where patch_callback
is, was built with the compiler's default. On aarch64 that turns the sampler's bilinear sum into
3 FMAs and each Jacobian sum into 1, so the callback's F and J were not the patch's. x86-64 with
no -march has no FMA and MSVC does not contract, so Linux and Windows were exact. macOS Debug
inlines nothing, so most likely both sides called one copy of the sampler there.

The design promises bit for bit here (#734 and docs/NAV_MATERIAL.md's table), and the library
side already is. So the test TU is now built as the rollouts are, with -ffp-contract=off
(/fp:precise on MSVC), as tests/CMakeLists.txt already does for det_math.cpp. No tolerance.

How this was checked (there is no macOS here):
- clang 18 on the test TU with its own flags: by default, 3 fmuladd in patch_sample_channel and 2
  in patch_sample_channel_grad; none with -ffp-contract=off. Compiled for arm64-apple-macosx,
  the callback has 6 fmadd by default and none with the flag.
- On Linux, a copy of the test whose callback does those FMAs with std::fma fails the same three
  assertions, for the dynamic vehicle only, by 1-2 ulp. One gradient pair is the macOS log's
  exactly (-0.126325145 vs -0.12632513). The surrogate's and the bicycle's callback F and J are an
  ulp off at many samples too, but those ulps round away where F_ext joins larger sums.
- Linux Release and Debug: nav_material_ext_test passes (11/11).
@transfix
transfix enabled auto-merge (squash) October 20, 2026 21:27
@transfix
transfix merged commit 65e7230 into master Oct 20, 2026
24 checks passed
@transfix
transfix deleted the fix/nav-material-ext-macos-fp branch October 29, 2026 20:53
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