[SM6.10] Add LinAng Matrix attributes and two new attributed matrix types#8125
[SM6.10] Add LinAng Matrix attributes and two new attributed matrix types#8125hekota wants to merge 23 commits intomicrosoft:mainfrom
Conversation
| __builtin_LinAlg_Matrix [[__LinAlg_Matrix_Attributes(ComponentType::I32, 4, 5, MatrixUse::B, MatrixScope::ThreadGroup)]] mat8; | ||
|
|
||
| // expected-error@+1 {{cannot initialize a variable of type '__builtin_LinAlg_Matrix' with an lvalue of type '__builtin_LinAlg_Matrix [[__LinAlg_Matrix_Attributes(ComponentType::I32, 4, 5, MatrixUse::B, MatrixScope::ThreadGroup)]]'}} | ||
| __builtin_LinAlg_Matrix naked_mat = mat8; |
There was a problem hiding this comment.
Should it be illegal to declare this type without attributes? Is that the reason for TMP?
There was a problem hiding this comment.
We could make it illegal by intercepting every place where a type can be used and adding a special check and error if it is the __builtin_LinAlgMatrix without attributes. Or we can do nothing because the naked typed cannot be used for anything anyway. The __builtin prefix means users should not be using these directly.
|
|
||
| // Check that the value is a valid range. | ||
| int64_t Value = APVal.getLimitedValue(); | ||
| if (Value < 0) { |
There was a problem hiding this comment.
Should we enforce any maximum?
There was a problem hiding this comment.
The spec has maximums for the K dimension but no specified maximum the M or N dimensions:
| Matrix Scope | Scalar element dimensions |
| ------------ | ------------------------- |
| Thread | [4,128] |
| Wave | [4,128] |
| ThreadGroup | [1,1024] |
The "scalar element" refers to the dimensions being 4x that number if the data type is an 8-bit type represented in packed data types.
…://github.com/microsoft/DirectXShaderCompiler into linalg-matrix-attributes-and-types
V-FEXrt
left a comment
There was a problem hiding this comment.
LGTM but I did a very rush job on the review. Wanted to mark my general approval before being out the next couple days
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
llvm-beanz
left a comment
There was a problem hiding this comment.
There's a lot of boilerplate here, but it all looks pretty reasonable to me.
| #ifdef __hlsl_dx_compiler | ||
| #define SIZE_TYPE int | ||
| #else | ||
| #define SIZE_TYPE uint | ||
| #endif |
There was a problem hiding this comment.
I don't expect that this header will be portable to clang, so for the purposes of DXC we can simplify this to just:
| #ifdef __hlsl_dx_compiler | |
| #define SIZE_TYPE int | |
| #else | |
| #define SIZE_TYPE uint | |
| #endif | |
| #define SIZE_TYPE int |
We should probably file an issue to decide what to do about size types generally in HLSL. I don't love that DXC decided size types were signed 32-bit integers, but we may want Clang to match that for at least some language modes (cc @tex3d & @bogner for visibility about Clang and language spec issues).
|
|
||
| // Check that the value is a valid range. | ||
| int64_t Value = APVal.getLimitedValue(); | ||
| if (Value < 0) { |
There was a problem hiding this comment.
The spec has maximums for the K dimension but no specified maximum the M or N dimensions:
| Matrix Scope | Scalar element dimensions |
| ------------ | ------------------------- |
| Thread | [4,128] |
| Wave | [4,128] |
| ThreadGroup | [1,1024] |
The "scalar element" refers to the dimensions being 4x that number if the data type is an 8-bit type represented in packed data types.
…ectly in error reporting
…iler into linalg-matrix-attributes-and-types
pow2clk
left a comment
There was a problem hiding this comment.
I just implemented almost this exact change, so I had many thoughts. Nothing is really blocking, but some things you may want to consider
|
|
||
| #endif // SM 6.9 check and HV version check | ||
|
|
||
| #if ((__SHADER_TARGET_MAJOR > 6) || \ |
There was a problem hiding this comment.
Personally I'd like this to not be in the same file as the coopvec header code. Imo that's going to cause a lot of confusion.
Maybe we rename the old file to coopvec.h and note it as a breaking change in the next release? If that doesn't work we should create a new file for the new code
| template <ComponentEnum ComponentTy, SIZE_TYPE M, SIZE_TYPE N, | ||
| MatrixUseEnum Use, MatrixScopeEnum Scope> | ||
| class Matrix { | ||
| int TestField; |
There was a problem hiding this comment.
| int TestField; |
| Node\w* | RWNode\w* | EmptyNode\w* | | ||
| AnyNodeOutput\w* | NodeOutputRecord\w* | GroupShared\w* | | ||
| VkBufferPointer | ||
| VkBufferPointer | LinAlgMatrix |
There was a problem hiding this comment.
| VkBufferPointer | LinAlgMatrix | |
| VkBufferPointer | LinAlgMatrix |
Adds new type attribute
__LinAlg_Matrix_Attributesthat can be attached to__builtin_LinAlg_Matrixbuilt-in matrix handle type to specify the matrix component type, dimensions, use and scope. Includes enabling C11++ -style attributes on types in DXC.Adds two new AST types that are used to capture the information from the attribute:
AttributedLinAlgMatrixTypetype is used when the attribute specifies concrete matrix parametersDependentAttributedLinAlgMatrixTypeis for cases where the type attributes arguments are dependent on template instantiationThe
AttributedLinAlgMatrixTypeis linked toLinAlgMatrixtype alias used ingen_intrin_main.txtfor built-in function APIs.This change also adds the outline of the LinAlg
Matrixtemplate class todx/linalg.h, including the enumeration types used as arguments to the new attribute and as template parameters ofMatrix.Note that the
ComponentTypeenum indx/linalg.his defined using values matching the existing internalComponentTypeenum that was added in SM 6.9 for cooperative vectors. This is different from the current LinAlg spec. The issue to update the spec is microsoft/hlsl-specs#779.Fixes #8122