Skip to content

Commit 3d3df3f

Browse files
authored
Update LongVector Execution tests to now use XML (#7393)
This change refactors the LongVector exec tests into their own files and swaps to use the XML and statically defined values for test input. 1. Update the LongVector exec tests to use the ShaderOpArithTable.xml TAEF table file for test entry points. This aligns with existing HLK tests. 2. Some light code cleanup. 3. Hard coded value sets in LongVectorTestData.h. Value sets give us a simple way to generate larger arrays from a smaller set of statically defined values. At a later point we can add logic to produce value sets at build time in this same header by consuming from a YAML file used in the offload test suite. 4. Move LongVector tests into their own LongVector.h, LongVector.tpp, and LongVector.cpp files. 5. Add an HLSLExecTestUtils.h file to hold some common logic to facilitate re-factoring the LongVector tests into their own files. This PR ended up growing larger than intended. Subsequent PRs will be smaller chunks. There are some additional refactoring and clean-up changes coming but I did not want to continue to add to this PR.
1 parent d73a9f5 commit 3d3df3f

15 files changed

Lines changed: 3891 additions & 2401 deletions

include/dxc/Test/HlslTestUtils.h

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
///////////////////////////////////////////////////////////////////////////////
1111

1212
// *** THIS FILE CANNOT TAKE ANY LLVM DEPENDENCIES *** //
13+
#ifndef HLSLTESTUTILS_H
14+
#define HLSLTESTUTILS_H
1315

1416
#include <algorithm>
1517
#include <atomic>
@@ -258,17 +260,29 @@ inline void LogErrorFmt(const wchar_t *fmt, ...) {
258260
WEX::Logging::Log::Error(buf.data());
259261
}
260262

261-
inline void LogErrorFmtThrow(const wchar_t *fmt, ...) {
263+
inline void LogErrorFmtThrow(const char *fileName, int line, const wchar_t *fmt,
264+
...) {
262265
va_list args;
263266
va_start(args, fmt);
264267
std::wstring buf(vFormatToWString(fmt, args));
265268
va_end(args);
266-
WEX::Logging::Log::Error(buf.data());
269+
270+
std::wstringstream wss;
271+
wss << L"Error in file: " << fileName << L" at line: " << line << L"\n"
272+
<< buf.data() << L"\n"
273+
<< buf;
274+
275+
WEX::Logging::Log::Error(wss.str().c_str());
267276

268277
// Throws an exception to abort the test.
269278
VERIFY_FAIL(L"Test error");
270279
}
271280

281+
// Macro to pass the file name and line number. Otherwise TAEF prints this file
282+
// and line number.
283+
#define LOG_ERROR_FMT_THROW(fmt, ...) \
284+
hlsl_test::LogErrorFmtThrow(__FILE__, __LINE__, fmt, __VA_ARGS__)
285+
272286
inline std::wstring
273287
GetPathToHlslDataFile(const wchar_t *relative,
274288
LPCWSTR paramName = HLSLDATAFILEPARAM,
@@ -553,6 +567,19 @@ inline bool CompareDoubleULP(
553567
return AbsoluteDiff <= (uint64_t)ULPTolerance;
554568
}
555569

570+
inline bool CompareDoubleEpsilon(const double &Src, const double &Ref,
571+
float Epsilon) {
572+
if (Src == Ref) {
573+
return true;
574+
}
575+
if (std::isnan(Src)) {
576+
return std::isnan(Ref);
577+
}
578+
// For FTZ or Preserve mode, we should get the expected number within
579+
// epsilon for any operations.
580+
return fabs(Src - Ref) < Epsilon;
581+
}
582+
556583
inline bool CompareFloatULP(
557584
const float &fsrc, const float &fref, int ULPTolerance,
558585
hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
@@ -604,12 +631,26 @@ inline bool CompareFloatRelativeEpsilon(
604631

605632
inline bool CompareHalfULP(const uint16_t &fsrc, const uint16_t &fref,
606633
float ULPTolerance) {
634+
// Treat +0 and -0 as equal
635+
if ((fsrc & ~FLOAT16_BIT_SIGN) == 0 && (fref & ~FLOAT16_BIT_SIGN) == 0)
636+
return true;
607637
if (fsrc == fref)
608638
return true;
609-
if (isnanFloat16(fsrc))
610-
return isnanFloat16(fref);
639+
640+
const bool nanRef = isnanFloat16(fref);
641+
const bool nanSrc = isnanFloat16(fsrc);
642+
if (nanRef || nanSrc)
643+
return nanRef && nanSrc;
644+
645+
// Map to monotonic ordering for correct ULP diff
646+
auto toOrdered = [](uint16_t h) -> int {
647+
return (h & FLOAT16_BIT_SIGN) ? (~h & 0xFFFF) : (h | 0x8000);
648+
};
649+
611650
// 16-bit floating point numbers must preserve denorms
612-
int diff = fsrc - fref;
651+
int i_fsrc = toOrdered(fsrc);
652+
int i_fref = toOrdered(fref);
653+
int diff = i_fsrc - i_fref;
613654
unsigned int uDiff = diff < 0 ? -diff : diff;
614655
return uDiff <= (unsigned int)ULPTolerance;
615656
}
@@ -773,3 +814,5 @@ inline UINT GetByteSizeForFormat(DXGI_FORMAT value) {
773814
}
774815
}
775816
#endif
817+
818+
#endif // HLSLTESTUTILS_H

tools/clang/unittests/HLSLExec/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
find_package(TAEF REQUIRED)
44
find_package(D3D12 REQUIRED) # Used for ExecutionTest.cpp.
55

6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
7+
68
add_clang_library(ExecHLSLTests SHARED
79
ExecutionTest.cpp
810
ShaderOpTest.cpp
11+
TableParameterHandler.cpp
12+
LongVectors.cpp
913
ExecHLSLTests.rc
1014
)
1115

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#include <windows.h>
22

3-
ShaderOpArithTable.xml DATASOURCE_XML "ShaderOpArithTable.xml"
3+
ShaderOpArithTable.xml DATASOURCE_XML "ShaderOpArithTable.xml"
4+
LongVectorOpTable.xml DATASOURCE_XML "LongVectorOpTable.xml"

0 commit comments

Comments
 (0)