Skip to content

Commit d40bb08

Browse files
committed
address comments
1 parent 660e58b commit d40bb08

4 files changed

Lines changed: 30 additions & 33 deletions

File tree

include/dxc/DXIL/DxilConstants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ const unsigned kMinWaveSize = 4;
155155
const unsigned kMaxWaveSize = 128;
156156
const unsigned kDefaultMaxVectorLength = 4;
157157
const unsigned kSM69MaxVectorLength = 1024;
158+
const unsigned kLinAlgThreadGroupMatrixMaxK = 1024;
159+
const unsigned kLinAlgWaveThreadMatrixMaxK = 128;
160+
const unsigned kLinAlgMatrixMinK = 4;
158161

159162
const float kMaxMipLodBias = 15.99f;
160163
const float kMinMipLodBias = -16.0f;

lib/DxilValidation/DxilValidation.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -984,25 +984,25 @@ static void ValidateLinAlgOpParameters(CallInst *CI,
984984
if (isa<UndefValue>(Arg))
985985
ValCtx.EmitInstrError(CI, ValidationRule::InstrNoReadingUninitialized);
986986

987-
// If we have a LinAlg Matrix validate it
987+
// If we have a LinAlg Matrix, validate that we have correct metadata.
988988
if (!dxilutil::IsHLSLLinAlgMatrixType(Ty))
989989
continue;
990-
991-
// Metadata is malformed if we don't have metadata
992-
if (ValCtx.TargetTypeMap.find(Ty) == ValCtx.TargetTypeMap.end()) {
990+
if (ValCtx.LinAlgTargetTypeMap.find(Ty) ==
991+
ValCtx.LinAlgTargetTypeMap.end()) {
993992
ValCtx.EmitInstrError(CI, ValidationRule::MetaWellFormed);
994993
continue;
995994
}
996995
}
997996
}
998997

999-
static void ValidateLinAlgOpReturn(CallInst *CI, ValidationContext &ValCtx) {
998+
static void ValidateLinAlgOpReturnMatrix(CallInst *CI,
999+
ValidationContext &ValCtx) {
10001000
Type *Ty = CI->getType();
10011001
assert(dxilutil::IsHLSLLinAlgMatrixType(Ty) && "CI must return a matrix");
10021002

10031003
// Metadata is malformed if we don't have metadata
1004-
auto it = ValCtx.TargetTypeMap.find(Ty);
1005-
if (it == ValCtx.TargetTypeMap.end()) {
1004+
auto it = ValCtx.LinAlgTargetTypeMap.find(Ty);
1005+
if (it == ValCtx.LinAlgTargetTypeMap.end()) {
10061006
ValCtx.EmitInstrError(CI, ValidationRule::MetaWellFormed);
10071007
return;
10081008
}
@@ -1012,9 +1012,11 @@ static void ValidateLinAlgOpReturn(CallInst *CI, ValidationContext &ValCtx) {
10121012
// Validate the K dim is in bounds. Which dim is K depends on use.
10131013
// This validation isn't applied to an accumulator matrix
10141014
if (LATT.Use != DXIL::MatrixUse::Accumulator) {
1015-
unsigned MinK = 4;
1015+
unsigned MinK = DXIL::kLinAlgMatrixMinK;
10161016
unsigned K = (LATT.Use == DXIL::MatrixUse::A) ? LATT.N : LATT.M;
1017-
unsigned MaxK = (LATT.Scope == DXIL::MatrixScope::ThreadGroup) ? 1024 : 128;
1017+
unsigned MaxK = (LATT.Scope == DXIL::MatrixScope::ThreadGroup)
1018+
? DXIL::kLinAlgThreadGroupMatrixMaxK
1019+
: DXIL::kLinAlgWaveThreadMatrixMaxK;
10181020
if (K < MinK || K > MaxK)
10191021
ValCtx.EmitInstrFormatError(
10201022
CI, ValidationRule::InstrLinAlgIllegalKDim,
@@ -2250,7 +2252,7 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
22502252
case DXIL::OpCode::LinAlgMatrixAccumulate:
22512253
case DXIL::OpCode::LinAlgMatrixMultiplyAccumulate:
22522254
case DXIL::OpCode::LinAlgMatrixOuterProduct: {
2253-
ValidateLinAlgOpReturn(CI, ValCtx);
2255+
ValidateLinAlgOpReturnMatrix(CI, ValCtx);
22542256
ValidateLinAlgOpParameters(CI, ValCtx);
22552257
break;
22562258
}

lib/DxilValidation/DxilValidationUtils.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,35 @@ EntryStatus::EntryStatus(DxilEntryProps &entryProps)
4141
entryProps.sig.PatchConstOrPrimSignature.GetElements().size(), 0);
4242
}
4343

44-
static std::optional<std::tuple<Type *, LinAlgTargetType>>
45-
TryMakeLinAlgTargetType(MDTuple *MDT) {
44+
static void
45+
TryAddLinAlgTargetType(MDTuple *MDT,
46+
std::unordered_map<Type *, LinAlgTargetType> &Map) {
4647
if (!MDT || MDT->getNumOperands() != 6)
47-
return std::nullopt;
48+
return;
4849

4950
ConstantAsMetadata *ConstMD0 =
5051
dyn_cast<ConstantAsMetadata>(MDT->getOperand(0).get());
5152
if (!ConstMD0)
52-
return std::nullopt;
53+
return;
5354

5455
Type *Ty = ConstMD0->getValue()->getType();
55-
ConstantInt *Ints[5];
56+
uint64_t Ints[5];
5657

5758
for (size_t I = 0; I < 5; ++I) {
5859
ConstantAsMetadata *ConstMDI =
5960
dyn_cast<ConstantAsMetadata>(MDT->getOperand(I + 1).get());
6061
if (!ConstMDI)
61-
return std::nullopt;
62+
return;
6263
ConstantInt *CI = dyn_cast<ConstantInt>(ConstMDI->getValue());
6364
if (!CI)
64-
return std::nullopt;
65-
Ints[I] = CI;
65+
return;
66+
Ints[I] = CI->getLimitedValue();
6667
}
6768

68-
LinAlgTargetType LATT;
69-
LATT.Type = static_cast<DXIL::ComponentType>(Ints[0]->getLimitedValue());
70-
LATT.M = Ints[1]->getLimitedValue();
71-
LATT.N = Ints[2]->getLimitedValue();
72-
LATT.Use = static_cast<DXIL::MatrixUse>(Ints[3]->getLimitedValue());
73-
LATT.Scope = static_cast<DXIL::MatrixScope>(Ints[4]->getLimitedValue());
74-
75-
return {{Ty, LATT}};
69+
Map.try_emplace(
70+
Ty, LinAlgTargetType{static_cast<DXIL::ComponentType>(Ints[0]), Ints[1],
71+
Ints[2], static_cast<DXIL::MatrixUse>(Ints[3]),
72+
static_cast<DXIL::MatrixScope>(Ints[4])});
7673
}
7774

7875
ValidationContext::ValidationContext(Module &llvmModule, Module *DebugModule,
@@ -132,11 +129,7 @@ ValidationContext::ValidationContext(Module &llvmModule, Module *DebugModule,
132129
if (NMD) {
133130
for (llvm::MDNode *MDN : NMD->operands()) {
134131
MDTuple *MDT = dyn_cast<MDTuple>(MDN);
135-
std::optional<std::tuple<Type *, LinAlgTargetType>> LATTOpt =
136-
TryMakeLinAlgTargetType(MDT);
137-
if (!LATTOpt)
138-
continue;
139-
TargetTypeMap.try_emplace(std::get<0>(*LATTOpt), std::get<1>(*LATTOpt));
132+
TryAddLinAlgTargetType(MDT, LinAlgTargetTypeMap);
140133
}
141134
}
142135
}

lib/DxilValidation/DxilValidationUtils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Value;
3636
class GlobalVariable;
3737
class Instruction;
3838
class Type;
39-
class MDTuple;
4039
} // namespace llvm
4140

4241
namespace hlsl {
@@ -89,7 +88,7 @@ struct ValidationContext {
8988
std::unordered_map<Value *, DxilResourceProperties> ResPropMap;
9089
std::unordered_map<Function *, std::vector<Function *>> PatchConstantFuncMap;
9190
std::unordered_map<Function *, std::unique_ptr<EntryStatus>> entryStatusMap;
92-
std::unordered_map<Type *, LinAlgTargetType> TargetTypeMap;
91+
std::unordered_map<Type *, LinAlgTargetType> LinAlgTargetTypeMap;
9392
bool isLibProfile;
9493
const unsigned kDxilControlFlowHintMDKind;
9594
const unsigned kDxilPreciseMDKind;

0 commit comments

Comments
 (0)