-
Notifications
You must be signed in to change notification settings - Fork 888
[SM6.10] LinAlg Validation: MatrixAccumulateToDescriptor #8743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1213,6 +1213,87 @@ static void | |
| ValidateLinAlgMatrixAccumulateToDescriptor(CallInst *CI, | ||
| ValidationContext &ValCtx) { | ||
| ValidateLinAlgOpParameters(CI, ValCtx); | ||
|
|
||
| DxilInst_LinAlgMatrixAccumulateToDescriptor Op(CI); | ||
| Type *MatTy = Op.get_matrix()->getType(); | ||
|
|
||
| assert(dxilutil::IsHLSLLinAlgMatrixType(MatTy) && "Must be LinAlg type"); | ||
| auto MatIt = ValCtx.LinAlgTargetTypeMap.find(MatTy); | ||
| if (MatIt == ValCtx.LinAlgTargetTypeMap.end()) | ||
| return; | ||
| LinAlgTargetType MatLATT = MatIt->second; | ||
|
|
||
| ConstantInt *LayoutCI = dyn_cast<ConstantInt>(Op.get_layout()); | ||
| if (!LayoutCI) { | ||
| ValCtx.EmitInstrFormatError( | ||
| CI, ValidationRule::InstrOpConst, | ||
| {"Layout", "LinAlgMatrixAccumulateToDescriptor"}); | ||
| return; | ||
| } | ||
| auto Layout = static_cast<DXIL::MatrixLayout>(LayoutCI->getLimitedValue()); | ||
| bool LayoutIsRowColMajor = (Layout == DXIL::MatrixLayout::RowMajor || | ||
| Layout == DXIL::MatrixLayout::ColumnMajor); | ||
|
|
||
| // Thread Matrix must have layout OuterProductOptimal* | ||
| if (MatLATT.Scope == DXIL::MatrixScope::Thread && | ||
| (Layout != DXIL::MatrixLayout::OuterProductOptimal && | ||
| Layout != DXIL::MatrixLayout::OuterProductOptimalTranspose)) | ||
|
V-FEXrt marked this conversation as resolved.
|
||
| ValCtx.EmitInstrFormatError( | ||
| CI, ValidationRule::InstrLinAlgMatrixScopeReqLayout2, | ||
| {MatrixScopeToString(MatLATT.Scope), "OuterProductOptimal", | ||
| "OuterProductOptimalTranspose"}); | ||
|
|
||
| // Wave/ThreadGroup matrix must have layout RowMajor/ColMajor | ||
| if (MatLATT.Scope != DXIL::MatrixScope::Thread && !LayoutIsRowColMajor) | ||
| ValCtx.EmitInstrFormatError( | ||
| CI, ValidationRule::InstrLinAlgMatrixScopeReqLayout2, | ||
| {MatrixScopeToString(MatLATT.Scope), "RowMajor", "ColumnMajor"}); | ||
|
|
||
| // Stride must be an imm 0 if layout is not Row/Col Major | ||
| if (!LayoutIsRowColMajor) { | ||
| ConstantInt *StrideCI = dyn_cast<ConstantInt>(Op.get_stride()); | ||
| if (StrideCI) { | ||
| if (!StrideCI->isZero()) | ||
| ValCtx.EmitInstrFormatError( | ||
| CI, ValidationRule::InstrLinAlgMatrixLayoutReqStride, | ||
| {MatrixLayoutToString(Layout)}); | ||
| } else | ||
| ValCtx.EmitInstrFormatError( | ||
| CI, ValidationRule::InstrOpConst, | ||
| {"Stride", "LinAlgMatrixAccumulateToDescriptor"}); | ||
| } | ||
|
|
||
| // Matrix must have Accumulator use | ||
| if (MatLATT.Use != DXIL::MatrixUse::Accumulator) | ||
| ValCtx.EmitInstrFormatError( | ||
| CI, ValidationRule::InstrLinAlgMatrixUseMismatch, | ||
| {MatrixUseToString(MatLATT.Use), "Accumulator"}); | ||
|
|
||
| // handle must be a UAV Raw buffer (RWByteAddressBuffer) | ||
| DXIL::ComponentType ResCompTy; | ||
| DXIL::ResourceClass ResClass; | ||
| DXIL::ResourceKind ResKind = | ||
| GetResourceKindAndCompTy(Op.get_handle(), ResCompTy, ResClass, ValCtx); | ||
| if (ResClass != DXIL::ResourceClass::UAV || | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like in a previous PR, is an RWByteAddressBuffer the only resource type that would avoid this error emission? I would've hoped to somehow do a direct comparison and see if the resource is an RWBAB, but this might be the only way. Just hoping it isn't too lenient of a check.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like https://github.com/microsoft/DirectXShaderCompiler/blob/main/tools/clang/lib/Sema/SemaHLSL.cpp#L5283 also matches but I haven't seen/heard of ROVByteAddressBuffer before so maybe its not spellable? |
||
| ResKind != DXIL::ResourceKind::RawBuffer) | ||
| ValCtx.EmitInstrError( | ||
| CI, ValidationRule::InstrLinAlgMatrixLoadThreadRequiresRWBAB); | ||
|
|
||
| // Align must be an immediate constant that is a multiple of 128 greater than | ||
| // 0 | ||
| ConstantInt *AlignCI = dyn_cast<ConstantInt>(Op.get_align()); | ||
| if (AlignCI) { | ||
| unsigned Align = AlignCI->getLimitedValue(); | ||
| if (Align == 0) | ||
| ValCtx.EmitInstrFormatError(CI, ValidationRule::InstrParamMinimumValue, | ||
| {"Align", "0", std::to_string(Align)}); | ||
| if (Align % 128 != 0) | ||
| ValCtx.EmitInstrFormatError(CI, ValidationRule::InstrParamMultiple, | ||
| {"Align", "128", std::to_string(Align)}); | ||
| } else | ||
| ValCtx.EmitInstrFormatError( | ||
| CI, ValidationRule::InstrOpConst, | ||
| {"Align", "LinAlgMatrixAccumulateToDescriptor"}); | ||
| } | ||
|
|
||
| static void ValidateLinAlgMatrixAccumulateToMemory(CallInst *CI, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -438,12 +438,13 @@ class Matrix<ComponentTy, M, N, Use, MatrixScope::Thread> { | |
| return Result; | ||
| } | ||
|
|
||
| template <MatrixUseEnum UseLocal = Use> | ||
| template <uint Align = 128, MatrixUseEnum UseLocal = Use> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Chris B (@llvm-beanz) This is not in the spec atm but it seems necessary. Does that sound right to you?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. Looks right to me! |
||
| typename hlsl::enable_if<Use == MatrixUse::Accumulator && UseLocal == Use, | ||
| void>::type | ||
| InterlockedAccumulate(RWByteAddressBuffer Res, uint StartOffset) { | ||
| __builtin_LinAlg_MatrixAccumulateToDescriptor( | ||
| __handle, Res, StartOffset, 0, MatrixLayout::OuterProductOptimal, 0); | ||
| __handle, Res, StartOffset, 0, MatrixLayout::OuterProductOptimal, | ||
| Align); | ||
|
V-FEXrt marked this conversation as resolved.
|
||
| } | ||
| }; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.