Skip to content

[HLSL] Allow rounding error in LinAlg float multiply tests - #9096

Draft
Jack Elliott (JoeCitizen) wants to merge 1 commit into
microsoft:mainfrom
JoeCitizen:linalg-hlk-fp-multiply-tolerance
Draft

Jack Elliott (JoeCitizen) wants to merge 1 commit into
microsoft:mainfrom
JoeCitizen:linalg-hlk-fp-multiply-tolerance

Conversation

@JoeCitizen

Copy link
Copy Markdown
Collaborator

The LinAlg float matrix multiply and MatVec tests compared results exactly. Proposal 0035 doesn't require correctly rounded results or a particular accumulation order, and some hardware returns results a few units off even when the exact result is representable (for example −2.9999993 for −3.0 in an F32 accumulator). This was exposed by the larger shapes added in #8939. The spec owner has confirmed that correctly rounded results are not required.

  • Add a bounded comparison mode to the matrix oracle. Each element is checked against a reference computed in double, within (K + 2)·u·(Σ|a·b| + |acc|) plus the smallest normal, where u is the result type's unit roundoff.
  • Use it for F16 and F32 multiply results at Wave and ThreadGroup scope, and for F16/F32 MatVec and MatVecMulAdd results, including FP8 inputs.
  • Use sparse −1/0/1 patterns for F16-accumulator multiplies so the bound stays below 1 up to K = 256, and a single wrong term or swapped element still fails.
  • Integer multiplies, element-wise accumulate, outer product, transfers and conversions stay exact.
  • Add a host-side self-test covering the bound and every shape and pattern the device tests use.

Tested on WARP: no outcome changes. Dropping one term from the reference makes every bounded test fail.

The LinAlg float matrix multiply and MatVec tests compared results exactly.
Proposal 0035 does not require correctly rounded results or a particular
accumulation order, and some hardware returns results a few units off even
when the exact result is representable (for example -2.9999993 for -3.0 in
an F32 accumulator). The larger shapes added in microsoft#8939 exposed this. The spec owner has
confirmed that correctly rounded results are not required.

- Add a bounded comparison mode to the matrix oracle. Each element is checked
  against a reference computed in double, within
  (K + 2) * u * (sum |a*b| + |acc|) plus the smallest normal, where u is the
  result type's unit roundoff.
- Use it for F16 and F32 multiply results at Wave and ThreadGroup scope, and
  for F16/F32 MatVec and MatVecMulAdd results, including FP8 inputs.
- Use sparse -1/0/1 patterns for F16-accumulator multiplies so the bound
  stays below 1 up to K = 256 and a single wrong term still fails.
- Integer multiplies, element-wise accumulate, outer product, transfers and
  conversions stay exact.
- Add a host-side self-test for the bound and every pattern the device
  tests use.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f05f926c-8544-4ea3-87aa-307088e1622a

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

1 participant