Skip to content

[HLSL] Add Wave matrix arithmetic coverage for LinAlg - #8774

Open
Jack Elliott (JoeCitizen) wants to merge 2 commits into
microsoft:mainfrom
JoeCitizen:linalg-hlk-wave-matrix-arith
Open

[HLSL] Add Wave matrix arithmetic coverage for LinAlg#8774
Jack Elliott (JoeCitizen) wants to merge 2 commits into
microsoft:mainfrom
JoeCitizen:linalg-hlk-wave-matrix-arith

Conversation

@JoeCitizen

Copy link
Copy Markdown
Collaborator

Proposal 0035 specifies Wave-scope matrix multiply and accumulate. Existing coverage was square F16 only, so row, column and indexing defects were not distinguishable.

These six tests exercise non-uniform rectangular F16 products, mixed F16 to F32 accumulation, B-use accumulation and capability-gated I32, at the exact wave size both matrix construction and the multiply advertise. Expected products come from checked signed 64-bit host arithmetic, self-tested against a hand-derived 2x3 by 3x2 case so the oracle cannot silently mirror the implementation.

MatrixQueryAccumulatorLayout is made observable by selecting a distinct arithmetic path per layout, and the output is poison-initialised so a shader that stores nothing cannot read back as a valid layout. WARP reports the B layout unconditionally, so the A path is compiled and host-oracled here but not executed.

Copilot AI balanced review requested due to automatic review settings August 13, 2026 20:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds broader LinAlg wave-matrix arithmetic coverage with exact CPU-oracle validation.

Changes:

  • Adds rectangular, mixed-type, integer, and B-use arithmetic tests.
  • Adds checked integer matrix-product oracle helpers.
  • Makes accumulator-layout behavior observable and poison-initialized.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tools/clang/unittests/HLSLExec/LinAlgTests.cpp Outdated
Exercise non-uniform rectangular F16 products, mixed F16-to-F32 accumulation, B-use accumulation, and capability-gated I32 at the exact wave size supported by both matrix construction and WaveMatrixMultiply. The rectangular integer-valued patterns distinguish row, column, and indexing defects while keeping every result bit-exact.

Derive expected products with checked signed 64-bit host arithmetic and self-test the oracle against the hand-derived 2x3 by 3x2 products [58, 64, 139, 154] and accumulated values [59, 63, 141, 152]. Make MatrixQueryAccumulatorLayout observable by selecting either the 2+3 A path or 2+7 B path and publishing the queried layout from lane zero only.

The existing F16 arithmetic baselines remain unchanged.

Assisted-by: GitHub Copilot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 83725f5d-8e98-4c1d-91ee-ad47629e007b
Copilot AI review requested due to automatic review settings August 13, 2026 21:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@damyanp Damyan Pepper (damyanp) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGT-my superficial review. This will need to be looked at by someone with some more domain knowledge.

Comment thread tools/clang/unittests/HLSLExec/LinAlgTests.cpp Outdated
Comment thread tools/clang/unittests/HLSLExec/LinAlgTests.cpp Outdated
Comment thread tools/clang/unittests/HLSLExec/LinAlgTests.cpp Outdated
Comment thread tools/clang/unittests/HLSLExec/LinAlgTests.cpp Outdated
Damyan and Chris both pushed back on the checked arithmetic added here, and
on inspection it can go entirely rather than be refactored.

Every value it guards is authored by the test. The dimensions are literals of
at most M=16, N=16, K=32; MatrixBufferLayout carries literal stride and offset
values; nothing reaches these helpers from a driver. The largest integer
literal anywhere in the file is 65504, so the widest accumulation the oracle
can actually perform is around 1.4e11 against an int64 range of 9.2e18. The
overflow branches were unreachable, and an overflow would have meant a bug in
the test rather than a driver failing conformance.

checkedAddInt64 and checkedMultiplyInt64 are removed along with the self-test
assertions that only existed to exercise them. multiplyIntegerMatrices now
returns its result directly instead of an optional, and reads as ordinary
arithmetic. Its dimension and size preconditions are already established by
isWaveMultiplyCaseValid, which every caller passes through, so checking them
again here was the cascade Chris objected to.

The compound conditions in encodeLogicalMatrixBuffer and
isWaveMultiplyCaseValid are split so each test has one readable outcome.

Removing these also resolves a collision that neither pull request shows on
its own: microsoft#8775 defines the same two helpers in the same namespace, in a
different region of the file, so the two would have merged without conflict
and left main with a duplicate definition.

Verified with the full HLSLExec LinAlg selection on WARP, compared per test
rather than by totals: 45 total, 40 passed, 4 failed, 1 skipped, identical to
the parent commit.

Assisted-by: GitHub Copilot
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 83725f5d-8e98-4c1d-91ee-ad47629e007b
Copilot AI review requested due to automatic review settings August 14, 2026 22:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

tools/clang/unittests/HLSLExec/LinAlgTests.cpp:4333

  • isWaveMultiplyCaseValid accepts any encodable I32 operands, but this unchecked multiply/add can overflow signed int64_t (for example, summing three INT32_MAX * INT32_MAX terms), invoking undefined behavior before result encoding can reject it. Detect both multiplication and addition overflow and make the oracle fail explicitly so it cannot generate a silently incorrect expected result.
      for (MatrixDim Inner = 0; Inner < K; ++Inner)
        Sum += MatrixA[static_cast<size_t>(Row) * K + Inner] *
               MatrixB[static_cast<size_t>(Inner) * N + Column];

@damyanp Damyan Pepper (damyanp) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest updates LGTM, thanks! Deferring to someone with domain expertise to review the test content.

@JoeCitizen
Jack Elliott (JoeCitizen) enabled auto-merge (squash) August 15, 2026 00:38
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.

4 participants