Skip to content

Commit c8a39c7

Browse files
authored
Execution Tests: Update tolerances for half precision trig functions (#7992)
This PR adjusts the tolerances for half precision trig functions with DXIL vectors. The D3D spec only notes the tolerance range for fp32. That fp32 error tolerance is not sufficient for halfs. After some further discussion we opted to use 0.003 as the tolerance for most half precision trig ops. For trig ops with a range that approaches infinity in either direction, we instead use 2 ULP. Fixes #7936
1 parent 54e0745 commit c8a39c7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,12 +883,33 @@ CAST_OP(OpType::CastToFloat64, double, (CastToFloat64(A)));
883883
// specs. An example with this spec for sin and cos is available here:
884884
// https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm#22.10.20
885885

886-
struct TrigonometricValidation {
886+
template <typename T, OpType OP> struct TrigonometricValidation {
887887
ValidationConfig ValidationConfig = ValidationConfig::Epsilon(0.0008f);
888888
};
889889

890+
// Half precision trig functions have a larger tolerance due to their lower
891+
// precision. Note that the D3D spec
892+
// does not mention half precision trig functions.
893+
template <OpType OP> struct TrigonometricValidation<HLSLHalf_t, OP> {
894+
ValidationConfig ValidationConfig = ValidationConfig::Epsilon(0.003f);
895+
};
896+
897+
// For the half precision trig functions with an infinite range in either
898+
// direction we use 2 ULPs of tolerance instead.
899+
template <> struct TrigonometricValidation<HLSLHalf_t, OpType::Cosh> {
900+
ValidationConfig ValidationConfig = ValidationConfig::Ulp(2.0f);
901+
};
902+
903+
template <> struct TrigonometricValidation<HLSLHalf_t, OpType::Tan> {
904+
ValidationConfig ValidationConfig = ValidationConfig::Ulp(2.0f);
905+
};
906+
907+
template <> struct TrigonometricValidation<HLSLHalf_t, OpType::Sinh> {
908+
ValidationConfig ValidationConfig = ValidationConfig::Ulp(2.0f);
909+
};
910+
890911
#define TRIG_OP(OP, IMPL) \
891-
template <typename T> struct Op<OP, T, 1> : TrigonometricValidation { \
912+
template <typename T> struct Op<OP, T, 1> : TrigonometricValidation<T, OP> { \
892913
T operator()(T A) { return IMPL; } \
893914
}
894915

0 commit comments

Comments
 (0)