[SM6.10] LinAlg Validation: MatrixMultiply MatrixMultiplyAccumulate - #8779
[SM6.10] LinAlg Validation: MatrixMultiply MatrixMultiplyAccumulate#8779Ashley Coleman (V-FEXrt) wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds more detailed DXIL validation for LinAlg matrix multiply / multiply-accumulate operations, along with new/updated validation rules and regression tests.
Changes:
- Add new validation rules for matrix scope consistency and matrix dimension compatibility.
- Implement additional semantic checks in DXIL validation for
LinAlgMatrixMultiplyandLinAlgMatrixMultiplyAccumulate. - Add new Lit validation tests and update existing CodeGen/Lit IR tests to reflect new behavior and shapes.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/hct/hctdb.py | Registers new validator rule strings used by DXIL validation. |
| lib/DxilValidation/DxilValidation.cpp | Adds the actual validation logic for matrix use/scope and dimension matching. |
| docs/DXIL.rst | Documents the new validation rule IDs and their messages. |
| tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-matrixmultiply.ll | New regression test coverage for multiply validation errors. |
| tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-matrixmultiplyaccumulate.ll | New regression test coverage for multiply-accumulate validation errors. |
| tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-cs.ll | Updates existing Lit DXIL validation IR to new matrix shapes/types. |
| tools/clang/test/CodeGenDXIL/hlsl/linalg/builtins/matrixmatrixmultiply/nominal.hlsl | Updates CodeGen coverage for matrix-multiply builtin invocation. |
| tools/clang/test/CodeGenDXIL/hlsl/linalg/builtins/matrixmatrixmultiplyaccumulate/nominal.hlsl | Updates CodeGen coverage for matrix-multiply-accumulate builtin invocation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| ; CHECK-NEXT: Function: main: error: A matrix scope 'Thread' does not match expected scope Wave or ThreadGroup. | ||
| ; CHECK-NEXT: note: at {{.*}} @dx.op.linAlgMatrixMultiplyAccumulate.mC8M8N8U2S2.mC8M8N8U0S0.mC8M8N8U1S2.mC8M8N8U2S2 | ||
| ; CHECK-NEXT: Function: main: error: Matrix scope must be the same for all matrices. A 'Thread', B 'ThreadGroup', C 'ThreadGroup', Return 'ThreadGroup'. | ||
| ; CHECK-NEXT: note: at {{.*}} @dx.op.linAlgMatrixMultiplyAccumulate.mC8M8N8U2S2.mC8M8N8U0S0.mC8M8N8U1S2.mC8M8N8U2S2 | ||
| %23 = call %dx.types.LinAlgMatrixC8M8N8U2S2 @dx.op.linAlgMatrixMultiplyAccumulate.mC8M8N8U2S2.mC8M8N8U0S0.mC8M8N8U1S2.mC8M8N8U2S2(i32 -2147483637, %dx.types.LinAlgMatrixC8M8N8U0S0 %9, %dx.types.LinAlgMatrixC8M8N8U1S2 %22, %dx.types.LinAlgMatrixC8M8N8U2S2 %7) ; LinAlgMatrixMultiplyAccumulate(matrixA,matrixB,matrixC) | ||
|
|
||
| ; CHECK-NEXT: Function: main: error: B matrix scope 'Thread' does not match expected scope Wave or ThreadGroup. | ||
| ; CHECK-NEXT: note: at {{.*}} @dx.op.linAlgMatrixMultiplyAccumulate.mC8M8N8U2S2.mC8M8N8U0S2.mC8M8N8U1S0.mC8M8N8U2S2 | ||
| ; CHECK-NEXT: Function: main: error: Matrix scope must be the same for all matrices. A 'ThreadGroup', B 'Thread', C 'ThreadGroup', Return 'ThreadGroup'. | ||
| ; CHECK-NEXT: note: at {{.*}} @dx.op.linAlgMatrixMultiplyAccumulate.mC8M8N8U2S2.mC8M8N8U0S2.mC8M8N8U1S0.mC8M8N8U2S2 |
There was a problem hiding this comment.
Long runs of CHECK-NEXT's here are used in leu of the implicit check-not flag to exlcude unexpected errors
without the run of check-next's newly generated errors (which would be unexpected) would still pass.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Suppressed comments (2)
utils/hct/hctdb.py:8730
- The two new messages are slightly ambiguous/inconsistent: (1) the “K dim” rule prints full matrix dimensions in
%0/%1(per tests), not the K dimension itself, and (2) the result-dimension message is missing a trailing period (unlike many other rules). Consider either updating the text to explicitly say it’s comparingMxKvsKxN(or changing%0/%1to be the K values only), and make punctuation consistent across the new messages (this will require updating the lit checks accordingly).
"Instr.LinAlgMatrixMatrixKDimMustMatch",
"K dim of A matrix '%0' must match K dim of B matrix '%1'. %2 != %3.",
)
self.add_valrule(
"Instr.LinAlgMatrixMatrixResDimMustMatch",
"%0 matrix dimension '%1' must match A.MxB.N '%2'",
lib/DxilValidation/DxilValidation.cpp:1466
ValidateLinAlgMatrixMultiplyandValidateLinAlgMatrixMultiplyAccumulateintroduce large, structurally similar blocks for (a) Use checks, (b) scope allowed-set checks, (c) scope equality checks, and (d) K/result dimension checks. This duplication increases the chance of the two validators drifting over time (e.g., one adds a new constraint/message and the other doesn’t). Consider extracting shared helpers (e.g., “validate matrix use for role”, “validate allowed scopes”, “validate all scopes equal”, “validate K/res dims”) so both ops reuse identical logic and formatting.
DxilInst_LinAlgMatrixMultiply Op(CI);
std::optional<LinAlgTargetType> RetMat =
GetCheckedLATT(CI->getType(), ValCtx);
if (!RetMat)
return;
std::optional<LinAlgTargetType> AMat =
GetCheckedLATT(Op.get_matrixA()->getType(), ValCtx);
if (!AMat)
return;
std::optional<LinAlgTargetType> BMat =
GetCheckedLATT(Op.get_matrixB()->getType(), ValCtx);
if (!BMat)
return;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Suppressed comments (3)
lib/DxilValidation/DxilValidation.cpp:1478
- The new validation logic for
ValidateLinAlgMatrixMultiplyandValidateLinAlgMatrixMultiplyAccumulateis largely duplicated (use checks, allowed-scope checks, “all scopes match” checks, K-dim checks, andA.M x B.Nresult-dimension checks). This duplication increases the chance of future drift and inconsistent diagnostics. Consider extracting small helpers (e.g., “validate expected MatrixUse for operand label”, “validate scope is in allowed set”, and “validate all scopes equal with N operands”) so both validators share the same implementation for common rules.
DxilInst_LinAlgMatrixMultiply Op(CI);
std::optional<LinAlgTargetType> RetMat =
GetCheckedLATT(CI->getType(), ValCtx);
if (!RetMat)
return;
std::optional<LinAlgTargetType> AMat =
GetCheckedLATT(Op.get_matrixA()->getType(), ValCtx);
if (!AMat)
return;
std::optional<LinAlgTargetType> BMat =
GetCheckedLATT(Op.get_matrixB()->getType(), ValCtx);
if (!BMat)
return;
// A is an A matrix
if (AMat->Use != DXIL::MatrixUse::A)
ValCtx.EmitInstrFormatError(CI,
ValidationRule::InstrLinAlgMatrixUseMismatch,
{"A", MatrixUseToString(AMat->Use), "A"});
// B is a B matrix
if (BMat->Use != DXIL::MatrixUse::B)
ValCtx.EmitInstrFormatError(CI,
ValidationRule::InstrLinAlgMatrixUseMismatch,
{"B", MatrixUseToString(BMat->Use), "B"});
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-matrixmultiply.ll:54
- The new lit tests rely heavily on
CHECK-NEXT, which makes them fragile if the validator starts emitting additional notes/errors (or changes emission order) for the same instruction. Where strict adjacency is not essential, preferCHECK:for each line (orCHECK-DAGfor sets of errors that don’t require ordering) to keep the tests stable as validation evolves.
; CHECK-NEXT: Function: main: error: A matrix scope 'Thread' does not match expected scope Wave or ThreadGroup.
; CHECK-NEXT: note: at {{.*}} @dx.op.linAlgMatrixMultiply.mC8M8N8U2S2.mC8M8N8U0S0.mC8M8N8U1S2
; CHECK-NEXT: Function: main: error: Matrix scope must be the same for all matrices. A 'Thread', B 'ThreadGroup', Return 'ThreadGroup'.
; CHECK-NEXT: note: at {{.*}} @dx.op.linAlgMatrixMultiply.mC8M8N8U2S2.mC8M8N8U0S0.mC8M8N8U1S2
utils/hct/hctdb.py:8726
- The new diagnostic text uses the shorthand “K dim”, which is slightly ambiguous and less consistent with other messages that use “dimension” explicitly. Consider changing this to “K dimension” (and similarly updating the documented string in
docs/DXIL.rst) to improve clarity for users reading validator output.
"Instr.LinAlgMatrixMatrixKDimMustMatch",
"K dim of A matrix '%0' must match K dim of B matrix '%1'. %2 != %3.",
)
Fixes #8500
Fixes #8502
Implements validation rules for MatrixMultiply and MatrixMultiplyAccumulate