Skip to content

Update LongVector Execution tests to now use XML #7393

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

Open
wants to merge 34 commits into
base: staging-sm6.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3fc0093
Update long vec execution tests to use xml and some other general
alsepkow Apr 24, 2025
c4d3de5
Forgot clang format
alsepkow Apr 28, 2025
a8ae0da
revert submodule changes
alsepkow Apr 29, 2025
da4efc5
Code review
alsepkow Apr 29, 2025
18135d6
Clang-format
alsepkow Apr 29, 2025
80d4ce1
const args
alsepkow Apr 29, 2025
482068a
WIP on trig. Accuracy issue and need some cleanup
alsepkow May 1, 2025
3849d62
Swapping
alsepkow May 2, 2025
70b675b
Remove doubles, not supported for trig functions
alsepkow May 3, 2025
51f3b2a
Wip, swap to look at coop vec stuff
alsepkow May 13, 2025
6d83f83
Trig tests passing
alsepkow May 14, 2025
7806a3c
Bug fixes and remove mod float64 as it is not supported
alsepkow May 14, 2025
643f39c
A few bug fixes. Comparing 0 and -0
alsepkow May 14, 2025
26737e9
Clang-format
alsepkow May 14, 2025
9ac2af4
LLVM ifdef include guards
alsepkow May 14, 2025
de485dc
A little code review. Const, fix the unneeded 0 comparison, new line
alsepkow May 19, 2025
0b275b4
Update template arg names. Need a better name than OpTypeT though
alsepkow May 20, 2025
6dbf265
More code review changes. Fix CompareHalfULP. Template arg names. Etc
alsepkow May 20, 2025
309aba6
Clang-format
alsepkow May 20, 2025
02ff216
Move RunShaderOp* functions to ShaderOpTest files
alsepkow May 21, 2025
c36a90b
Factor out TableParameterHandler
alsepkow May 21, 2025
7255a65
Forgot clang format, again again
alsepkow May 21, 2025
e93f1e9
Refactored all long vector tests into their own files. Still needs a …
alsepkow May 22, 2025
22350de
Clang-format
alsepkow May 22, 2025
411ec0f
fix includes
alsepkow May 22, 2025
3481634
Add a tpp
alsepkow May 22, 2025
43125c3
naming
alsepkow May 22, 2025
4e5feea
Formatting
alsepkow May 22, 2025
d950e67
clean up comment
alsepkow May 22, 2025
3ad7e9c
Comment 2
alsepkow May 22, 2025
294b113
Fix ComputeExpectedValues bugs I introduced during refactor
alsepkow May 22, 2025
c857d39
Keep formatter happy
alsepkow May 22, 2025
2afecfe
Change comment
alsepkow May 22, 2025
9732663
Code review. Update CompareHalfULP logic for nan values
alsepkow May 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions include/dxc/Test/HlslTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
///////////////////////////////////////////////////////////////////////////////

// *** THIS FILE CANNOT TAKE ANY LLVM DEPENDENCIES *** //
#ifndef HLSLTESTUTILS_H
#define HLSLTESTUTILS_H

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

inline void LogErrorFmtThrow(const wchar_t *fmt, ...) {
inline void LogErrorFmtThrow(const char *fileName, int line, const wchar_t *fmt,
...) {
va_list args;
va_start(args, fmt);
std::wstring buf(vFormatToWString(fmt, args));
va_end(args);
WEX::Logging::Log::Error(buf.data());

std::wstringstream wss;
wss << L"Error in file: " << fileName << L" at line: " << line << L"\n"
<< buf.data() << L"\n"
<< buf;

WEX::Logging::Log::Error(wss.str().c_str());

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

// Macro to pass the file name and line number. Otherwise TAEF prints this file
// and line number.
#define LOG_ERROR_FMT_THROW(fmt, ...) \
hlsl_test::LogErrorFmtThrow(__FILE__, __LINE__, fmt, __VA_ARGS__)

inline std::wstring
GetPathToHlslDataFile(const wchar_t *relative,
LPCWSTR paramName = HLSLDATAFILEPARAM,
Expand Down Expand Up @@ -553,6 +567,19 @@ inline bool CompareDoubleULP(
return AbsoluteDiff <= (uint64_t)ULPTolerance;
}

inline bool CompareDoubleEpsilon(const double &Src, const double &Ref,
float Epsilon) {
if (Src == Ref) {
return true;
}
if (std::isnan(Src)) {
return std::isnan(Ref);
}
// For FTZ or Preserve mode, we should get the expected number within
// epsilon for any operations.
return fabs(Src - Ref) < Epsilon;
}

inline bool CompareFloatULP(
const float &fsrc, const float &fref, int ULPTolerance,
hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
Expand Down Expand Up @@ -604,12 +631,26 @@ inline bool CompareFloatRelativeEpsilon(

inline bool CompareHalfULP(const uint16_t &fsrc, const uint16_t &fref,
float ULPTolerance) {
// Treat +0 and -0 as equal
if ((fsrc & ~FLOAT16_BIT_SIGN) == 0 && (fref & ~FLOAT16_BIT_SIGN) == 0)
return true;
if (fsrc == fref)
return true;
if (isnanFloat16(fsrc))
return isnanFloat16(fref);

const bool nanRef = isnanFloat16(fref);
const bool nanSrc = isnanFloat16(fsrc);
if (nanRef || nanSrc)
return nanRef && nanSrc;

// Map to monotonic ordering for correct ULP diff
auto toOrdered = [](uint16_t h) -> int {
return (h & FLOAT16_BIT_SIGN) ? (~h & 0xFFFF) : (h | 0x8000);
};

// 16-bit floating point numbers must preserve denorms
int diff = fsrc - fref;
int i_fsrc = toOrdered(fsrc);
int i_fref = toOrdered(fref);
int diff = i_fsrc - i_fref;
unsigned int uDiff = diff < 0 ? -diff : diff;
return uDiff <= (unsigned int)ULPTolerance;
}
Expand Down Expand Up @@ -773,3 +814,5 @@ inline UINT GetByteSizeForFormat(DXGI_FORMAT value) {
}
}
#endif

#endif // HLSLTESTUTILS_H
4 changes: 4 additions & 0 deletions tools/clang/unittests/HLSLExec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
find_package(TAEF REQUIRED)
find_package(D3D12 REQUIRED) # Used for ExecutionTest.cpp.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why we couldn't break things into multiple cpp files that we could copy over for the HLK test (like we do for ShaderOpTest.cpp). This ExecutionTest.cpp has gotten a bit out of hand!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look into doing that. Originally this code was more coupled with other helper code in ExecutionTest.cpp.

A few thoughts come to mind though:

  1. How much time to we want to spend trying to clean this up right now vs getting long vector exec tests in.
  2. We might do a refactoring/re-writing of a bunch of this in the not-too-distant future.
  3. "We'll do this later" often just turns into never 😔.

But I'll still take a closer look and see what I could easily break up. I think it will make reviews easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd need to factor out some of the ShaderOpTest* code starting on line 3531 with the ShaderOpTestResultStruct. Seems reasonable to put that into ShaderOpTest.h/cpp. And the TableParameter/TableParameterHandler stuff would need to be factored out. That could probably also go in its own appropriately named header/cpp file.

Both seem like reasonable updates I could make to help clean this file up a little. Think its worth doing that?


add_clang_library(ExecHLSLTests SHARED
ExecutionTest.cpp
ShaderOpTest.cpp
TableParameterHandler.cpp
LongVectors.cpp
ExecHLSLTests.rc
)

Expand Down
3 changes: 2 additions & 1 deletion tools/clang/unittests/HLSLExec/ExecHLSLTests.rc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <windows.h>

ShaderOpArithTable.xml DATASOURCE_XML "ShaderOpArithTable.xml"
ShaderOpArithTable.xml DATASOURCE_XML "ShaderOpArithTable.xml"
LongVectorOpTable.xml DATASOURCE_XML "LongVectorOpTable.xml"
Loading