Skip to content

Conversation

llvm-beanz
Copy link
Collaborator

@llvm-beanz llvm-beanz commented Aug 6, 2025

This PR removes the row and element accessors in favor of a more general means of accessing per-thread vectors. This change allows initializing a matrix from per-thread vectors as well as splitting it out into constituent vectors.

The vectors represent rows in A matrices, and columns in B matrices. Since the layout of Accumulator matrices vary by vendor, this method may only be used to construct A or B matrices.

Resolves #575, resolves #596

@llvm-beanz llvm-beanz marked this pull request as draft August 6, 2025 13:42
This PR removes the row and element accessors in favor of a more general
means of accessing per-thread vectors. This change allows initializing a
matrix from per-thread vectors as well as splitting it out into
constituent vectors.

The vectors represent rows in A matrices, and columns in B matrices.
Since the layout of Accumulator matrices vary by vendor, this method may
only be used to construct A or B matrices.

Resolves microsoft#575
@llvm-beanz llvm-beanz force-pushed the cbieneman/linalg-matrix-accessors branch from 98bc052 to 61123b6 Compare August 6, 2025 13:49
@llvm-beanz llvm-beanz marked this pull request as ready for review August 6, 2025 13:49
Copy link

@nhaehnle nhaehnle left a comment

Choose a reason for hiding this comment

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

I like the general direction, and it's much better than being able to directly query or set elements by (row, col).

In addition to my earlier comments, I do think it could still be valuable to expose a more general mechanism for per-element operations on matrices, a sort of map operation, perhaps one that provides row/col information to the lambda/functor/whatever.

If map is an issue due to general HLSL concerns, an alternative could be extending element-wise operations to matrices similar to what's done for vectors. Plus, a way to generate "iota" matrices where the value of each element is its row or its column number.

@llvm-beanz
Copy link
Collaborator Author

I like the general direction, and it's much better than being able to directly query or set elements by (row, col).

In addition to my earlier comments, I do think it could still be valuable to expose a more general mechanism for per-element operations on matrices, a sort of map operation, perhaps one that provides row/col information to the lambda/functor/whatever.

I've been slightly trying to avoid adding lambdas or function pointers to HLSL for this feature since that is a much bigger problem space. I was hoping to support a limited set of functionality through the ApplyUnaryOperation function.

We do have lambdas working in HLSL in Clang (although they need to be inlined to be valid DXIL). We could consider bringing that in for HLSL 202x and supporting it in DXC, but if we can instead have a reduced (but useful) functionality of pre-selected operations and extend the feature with lambdas in the future that is probably idea.

If map is an issue due to general HLSL concerns, an alternative could be extending element-wise operations to matrices similar to what's done for vectors. Plus, a way to generate "iota" matrices where the value of each element is its row or its column number.

I had consciously decided not to do this because it complicates the overload story, but maybe that's the wrong decision.

The main updates here are adding a linalg::AccumulatorLayout() query
and documenting the uniformity requirements of the APIs.
@llvm-beanz llvm-beanz merged commit e464840 into microsoft:main Aug 29, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this to Triaged in HLSL Triage Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Triaged
Development

Successfully merging this pull request may close these issues.

[0035] Add query for whether Accumulator is an A or B matrix [0035] Revisit Row/Col accessors
6 participants