Skip to content

Commit 8627f00

Browse files
alsepkowCopilot
andcommitted
Address code review feedback
- Fix non-portable static_assert(false) to use sizeof(T)==0 idiom - Replace placeholder TestId GUID with f00df946-9877-4453-8844-b1f4c8977953 - Extend isFloatingPointType to cover SNorm/UNorm/F8 wrapper types - Rename ValidationConfig member to Validation to avoid type/member shadowing - Rename local variables in dispatchTest to avoid type shadowing (CurOp, OpConfig) - Add row-major assumption comment in doMatricesMatch - Add MATRIX_LAYOUT comment explaining 0=RowMajor, 1=ColMajor - Add TODO for non-square K dimension test coverage - Clarify pre-staged input set comments in LinearAlgebraTestData.h - Fix 'constuctor' typo in HLSLTestDataTypes.h Co-authored-by: Copilot <[email protected]>
1 parent 9350656 commit 8627f00

4 files changed

Lines changed: 31 additions & 23 deletions

File tree

tools/clang/unittests/HLSLExec/HLSLTestDataTypes.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace HLSLTestDataTypes {
1919

2020
// A helper struct because C++ bools are 1 byte and HLSL bools are 4 bytes.
21-
// Take int32_t as a constuctor argument and convert it to bool when needed.
21+
// Take int32_t as a constructor argument and convert it to bool when needed.
2222
// Comparisons cast to a bool because we only care if the bool representation is
2323
// true or false.
2424
struct HLSLBool_t {
@@ -498,7 +498,11 @@ struct F8E5M2_t {
498498

499499
template <typename T> constexpr bool isFloatingPointType() {
500500
return std::is_same_v<T, float> || std::is_same_v<T, double> ||
501-
std::is_same_v<T, HLSLHalf_t>;
501+
std::is_same_v<T, HLSLHalf_t> || std::is_same_v<T, SNormF16_t> ||
502+
std::is_same_v<T, UNormF16_t> || std::is_same_v<T, SNormF32_t> ||
503+
std::is_same_v<T, UNormF32_t> || std::is_same_v<T, SNormF64_t> ||
504+
std::is_same_v<T, UNormF64_t> || std::is_same_v<T, F8E4M3_t> ||
505+
std::is_same_v<T, F8E5M2_t>;
502506
}
503507

504508
enum class ValidationType {
@@ -521,17 +525,17 @@ struct ValidationConfig {
521525

522526
// Default validation: ULP for floating point, exact for integers.
523527
template <typename T> struct DefaultValidation {
524-
ValidationConfig ValidationConfig;
528+
ValidationConfig Validation;
525529

526530
DefaultValidation() {
527531
if constexpr (isFloatingPointType<T>())
528-
ValidationConfig = ValidationConfig::Ulp(1.0f);
532+
Validation = ValidationConfig::Ulp(1.0f);
529533
}
530534
};
531535

532536
// Strict validation: exact match by default.
533537
struct StrictValidation {
534-
ValidationConfig ValidationConfig;
538+
ValidationConfig Validation;
535539
};
536540

537541
//

tools/clang/unittests/HLSLExec/LinearAlgebra.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct DataType {
7070
};
7171

7272
template <typename T> const DataType &getDataType() {
73-
static_assert(false && "Unknown data type");
73+
static_assert(sizeof(T) == 0, "Unknown data type");
7474
}
7575

7676
#define DATA_TYPE(TYPE, HLSL_STRING, COMP_TYPE, HLSL_SIZE, IS_16BIT) \
@@ -118,6 +118,7 @@ bool doMatricesMatch(const std::vector<T> &Actual,
118118
for (size_t Index : MismatchedIndexes) {
119119
std::wstringstream Wss(L"");
120120
Wss << std::setprecision(15);
121+
// Assumes row-major layout for (row,col) decomposition.
121122
Wss << L"Mismatch at (" << Index / N << L"," << Index % N << L")";
122123
Wss << L" Actual:" << Actual[Index];
123124
Wss << L" Expected:" << Expected[Index];
@@ -162,7 +163,7 @@ std::string getCompilerOptionsString(const Operation &Op,
162163
if (KDim > 0)
163164
Options << " -DK_DIM=" << KDim;
164165

165-
Options << " -DMATRIX_LAYOUT=0";
166+
Options << " -DMATRIX_LAYOUT=0"; // 0 = RowMajor, 1 = ColMajor
166167

167168
return Options.str();
168169
}
@@ -416,26 +417,28 @@ template <typename T, OpType OP>
416417
void dispatchTest(ID3D12Device *D3DDevice, bool VerboseLogging) {
417418

418419
const std::vector<MatrixDims> Sizes = getMatrixSizesToTest();
419-
constexpr const Operation &Operation = getOperation(OP);
420-
Op<OP, T> Op;
420+
constexpr const Operation &CurOp = getOperation(OP);
421+
Op<OP, T> OpConfig;
421422

422423
for (const MatrixDims &Dims : Sizes) {
423424
const size_t Rows = Dims.Rows;
424425
const size_t Cols = Dims.Cols;
425-
const size_t KDim = (Operation.Arity >= 2) ? Cols : 0;
426+
// TODO: K dimension currently equals Cols for simplicity (square inner
427+
// dimension). Add non-square K sizes for better multiply coverage.
428+
const size_t KDim = (CurOp.Arity >= 2) ? Cols : 0;
426429

427430
// FillMatrix has special input handling (scalar, not a matrix).
428431
InputSets<T> Inputs;
429432
if constexpr (OP == OpType::FillMatrix)
430-
Inputs = ExpectedBuilder<OP, T>::buildInputs(Operation, Rows, Cols, KDim);
433+
Inputs = ExpectedBuilder<OP, T>::buildInputs(CurOp, Rows, Cols, KDim);
431434
else
432-
Inputs = buildTestInputs<T>(Operation, Rows, Cols, KDim);
435+
Inputs = buildTestInputs<T>(CurOp, Rows, Cols, KDim);
433436

434-
auto Expected =
435-
ExpectedBuilder<OP, T>::buildExpected(Op, Inputs, Rows, Cols, KDim);
437+
auto Expected = ExpectedBuilder<OP, T>::buildExpected(OpConfig, Inputs,
438+
Rows, Cols, KDim);
436439

437-
runAndVerify(D3DDevice, VerboseLogging, Operation, Inputs, Expected,
438-
Op.ValidationConfig, Rows, Cols, KDim);
440+
runAndVerify(D3DDevice, VerboseLogging, CurOp, Inputs, Expected,
441+
OpConfig.Validation, Rows, Cols, KDim);
439442
}
440443
}
441444

@@ -535,7 +538,7 @@ class DxilConf_SM610_LinearAlgebra : public LinAlgTestClassCommon {
535538
BEGIN_TEST_CLASS(DxilConf_SM610_LinearAlgebra)
536539
TEST_CLASS_PROPERTY("Kits.TestName",
537540
"D3D12 - Shader Model 6.10 - Linear Algebra Tests")
538-
TEST_CLASS_PROPERTY("Kits.TestId", "a1b2c3d4-e5f6-7890-abcd-ef1234567890")
541+
TEST_CLASS_PROPERTY("Kits.TestId", "f00df946-9877-4453-8844-b1f4c8977953")
539542
TEST_CLASS_PROPERTY("Kits.Description",
540543
"Validates SM 6.10 linear algebra matrix operations")
541544
TEST_CLASS_PROPERTY(

tools/clang/unittests/HLSLExec/LinearAlgebraTestData.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ INPUT_SET(InputSet::Fill, 42)
8686
INPUT_SET(InputSet::Identity, 1)
8787
END_INPUT_SETS()
8888

89-
// --- Additional scalar types ---
89+
// --- Additional scalar types (pre-staged for upcoming SM 6.10 ComponentTypes)
90+
// ---
9091

9192
BEGIN_INPUT_SETS(int8_t)
9293
INPUT_SET(InputSet::Seed, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)
@@ -124,7 +125,7 @@ INPUT_SET(InputSet::Fill, 42)
124125
INPUT_SET(InputSet::Identity, 1)
125126
END_INPUT_SETS()
126127

127-
// --- Normalized types (SNorm [-1,1], UNorm [0,1]) ---
128+
// --- Normalized types (pre-staged for SM 6.10 SNorm/UNorm ComponentTypes) ---
128129

129130
BEGIN_INPUT_SETS(SNormF16_t)
130131
INPUT_SET(InputSet::Seed, SNormF16_t(HLSLHalf_t(-0.9f)),
@@ -190,7 +191,7 @@ INPUT_SET(InputSet::Fill, UNormF64_t(0.5))
190191
INPUT_SET(InputSet::Identity, UNormF64_t(1.0))
191192
END_INPUT_SETS()
192193

193-
// --- FP8 types (packed 4 elements per scalar in HLSL) ---
194+
// --- FP8 types (pre-staged for SM 6.10 packed ComponentTypes) ---
194195

195196
BEGIN_INPUT_SETS(F8E4M3_t)
196197
INPUT_SET(InputSet::Seed, F8E4M3_t(1.0f), F8E4M3_t(1.5f), F8E4M3_t(2.0f),

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ template <typename T> struct ExpectedBuilder<OpType::Dot, T> {
11701170
AbsoluteEpsilon +=
11711171
computeAbsoluteEpsilon<T>((SumPos + SumNeg), ULPTolerance);
11721172

1173-
Op.ValidationConfig = ValidationConfig::Epsilon(AbsoluteEpsilon);
1173+
Op.Validation = ValidationConfig::Epsilon(AbsoluteEpsilon);
11741174

11751175
std::vector<T> Expected;
11761176
Expected.push_back(static_cast<T>(DotProduct));
@@ -1683,7 +1683,7 @@ void dispatchTest(ID3D12Device *D3DDevice, bool VerboseLogging,
16831683
auto Expected = ExpectedBuilder<OP, T>::buildExpected(Op, Inputs);
16841684

16851685
runAndVerify(D3DDevice, VerboseLogging, Operation, Inputs, Expected,
1686-
Op.ValidationConfig);
1686+
Op.Validation);
16871687
}
16881688
}
16891689

@@ -1708,7 +1708,7 @@ void dispatchWaveOpTest(ID3D12Device *D3DDevice, bool VerboseLogging,
17081708
auto Expected = ExpectedBuilder<OP, T>::buildExpected(Op, Inputs, WaveSize);
17091709

17101710
runAndVerify(D3DDevice, VerboseLogging, Operation, Inputs, Expected,
1711-
Op.ValidationConfig, AdditionalCompilerOptions);
1711+
Op.Validation, AdditionalCompilerOptions);
17121712
}
17131713
}
17141714

0 commit comments

Comments
 (0)