Skip to content

[SM6.10] LinAlg Validation: MatrixLoadFromMemory - #8836

Open
Ashley Coleman (V-FEXrt) wants to merge 1 commit into
mainfrom
linalg-vali-matrixloadfrommemory
Open

[SM6.10] LinAlg Validation: MatrixLoadFromMemory#8836
Ashley Coleman (V-FEXrt) wants to merge 1 commit into
mainfrom
linalg-vali-matrixloadfrommemory

Conversation

@V-FEXrt

Copy link
Copy Markdown
Collaborator

Fixes #8499

Implements LinAlg MatrixLoadFromMemory validation rules


Stack created with GitHub Stacks CLIGive Feedback 💬

@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.

LGTM - although this also looks extremely similar to the MatrixStoreToMemory version.

Copilot AI balanced review requested due to automatic review settings September 1, 2026 21:35
@V-FEXrt
Ashley Coleman (V-FEXrt) force-pushed the linalg-vali-matrixloadfrommemory branch from 29da409 to 73b4d5d Compare September 1, 2026 21:35

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.

🟡 Changes recommended

Pointer handling can crash the validator, while bounds and alignment calculations use incorrect memory units.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds SM 6.10 validation for LinAlg matrix loads from groupshared memory.

Changes:

  • Validates matrix scope, storage type, capacity, offset, and stride.
  • Adds DXIL validation coverage.
  • Updates code-generation fixtures.
File summaries
File Description
lib/DxilValidation/DxilValidation.cpp Implements load validation rules.
tools/clang/test/LitDXILValidation/LinAlgMatrix/linalgmatrix-matrixloadfrommemory.ll Adds validator tests.
tools/clang/test/CodeGenDXIL/hlsl/linalg/builtins/matrixloadfrommemory/nominal.hlsl Updates scalar-array expectations.
tools/clang/test/CodeGenDXIL/hlsl/linalg/builtins/matrixloadfrommemory/vector-array.hlsl Updates vector-array expectations.
Review details

Suppressed comments (3)

lib/DxilValidation/DxilValidation.cpp:1643

  • This is not the memory footprint of the read: it ignores the GEP/start offset, runtime Offset, Stride, and row/column layout, and it also undercounts 64-bit matrices stored through i32 (for example, a 4x4 I64 matrix needs 32 i32 slots, not 16). As a result, the new test's “okay” load starts at element 128 of a 64-element global and is accepted. Compute the last byte/slot touched from the resolved base, storage element width, offset, stride, layout, and matrix dimensions, then compare that footprint with the global allocation.
  unsigned ElementsPerScalar = ComponentTypeElementsPerScalar(RetMat->Type);
  unsigned ExpectedScalarCount =
      (RetMat->N + ElementsPerScalar - 1) / ElementsPerScalar * RetMat->M;
  if (ExpectedScalarCount > GSScalarCount)

lib/DxilValidation/DxilValidation.cpp:1653

  • Offset is an element index, not a byte count: the public API names it StartIdx, and LinAlgTests.cpp:7896 divides OffsetBytes by the element size before passing it. Checking the raw index against 128 rejects valid offsets such as 32 for float (128 bytes). Convert the index to a byte offset using the memory pointee's allocation size before enforcing 128-byte alignment.
  if (ConstantInt *OffsetV = dyn_cast<ConstantInt>(Op.get_offset())) {
    unsigned Offset = OffsetV->getLimitedValue();
    if (Offset % 128 != 0)
      ValCtx.EmitInstrFormatError(CI, ValidationRule::InstrParamMultiple,
                                  {"Offset", "128", std::to_string(Offset)});

lib/DxilValidation/DxilValidation.cpp:1661

  • Like Offset, the groupshared Stride is expressed in memory elements (LinAlgTests.cpp:7897 passes StrideBytes / ElementBytes). Applying % 16 directly rejects a valid float stride of 4 elements (16 bytes), and is even more restrictive for vector arrays. Scale by the pointee allocation size before checking the 16-byte requirement.
  if (ConstantInt *StrideV = dyn_cast<ConstantInt>(Op.get_stride())) {
    unsigned Stride = StrideV->getLimitedValue();
    if (Stride % 16 != 0)
      ValCtx.EmitInstrFormatError(CI, ValidationRule::InstrParamMultiple,
                                  {"Stride", "16", std::to_string(Stride)});
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

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

Comment thread lib/DxilValidation/DxilValidation.cpp
Comment thread lib/DxilValidation/DxilValidation.cpp
Base automatically changed from linalg-vali-matrixaccumulatetomemory to main September 2, 2026 15:58
Fixes #8499

Implements LinAlg MatrixLoadFromMemory validation rules

@bob80905 Joshua Batista (bob80905) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

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.

LinAlg Validation: MatrixLoadFromMemory

4 participants