Skip to content

Accumulate/Broadcast: reject bStep values that hang or give wrong sums - #35

Open
seyfal wants to merge 2 commits into
CAPS-UMU:mainfrom
seyfal:fix/accumulate-bstep-validation
Open

seyfal wants to merge 2 commits into
CAPS-UMU:mainfrom
seyfal:fix/accumulate-bstep-validation

Conversation

@seyfal

@seyfal seyfal commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Accumulate, Broadcast and the two Get*RotationIndices helpers advance the rotation stride by logbStep = bit_width(bStep) - 1 and issue bStep - 1 hoisted rotations per round. That is only correct when bStep is a power of two >= 2, which the header already states. Two invalid values currently fail silently:

  • bStep == 1 gives logbStep == 0, so the round loop s <<= logbStep never terminates. We lost several hours to this in an extraction stage before finding it.
  • A bStep that is not a power of two (e.g. 3) sums some shifts twice and returns a wrong result without any error.

This PR validates bStep once, in a small helper, and throws std::invalid_argument with the offending value (the exception type the library already uses for bad arguments). The cascade variant's silent early return for bStep <= 1 becomes the same error; its startFactor/size guards are unchanged. Nothing changes for valid arguments: the library's own callers use 2 or 4 (bootstrap precomputation, bert-tiny example). A host-only gtest covers the accepted and rejected values.

Tested on v2.1.3 (786c760), CUDA 13.0, H200: full build with FIDESLIB_COMPILE_TESTS=ON, new test passes. The commit also applies cleanly on OpenFHECompatTests.

Fable 5.1 on behalf of Seyfal

seyfal and others added 2 commits September 5, 2026 05:16
Accumulate, Broadcast and the two Get*RotationIndices helpers advance the
rotation stride by logbStep = bit_width(bStep) - 1 and issue bStep - 1
hoisted rotations per round, which is only correct when bStep is a power of
two >= 2 (as the header already states). bStep == 1 makes logbStep 0, so
the round loop `s <<= logbStep` never terminates; a non-power-of-two bStep
such as 3 sums some shifts twice and returns a wrong result without any
error. Validate bStep once, in one helper, and throw std::invalid_argument
(the exception type the library already uses for bad arguments). The
cascade variant's silent early return for bStep <= 1 becomes the same error.
No change for valid arguments.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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