Skip to content

Commit 19464d2

Browse files
authored
Adjust hyperbolic trig functions to use ULP rules (#342)
Unlike the standard trig functions which may be implemented as natural calculations or as hyperbolic aproximations, the hyperbolic functions are guaranteed to be hyperbolc aproximations and thus have consistent precision characteristics. These can all be guaranteed within 2 ULP, which gives a better match and will resolve the test failures on AMD GPUs. The `cosh.16` test is not updated in this PR because it is already using ULP rules and 2 ULP range specification. I've captured a spec issue to follow up on the very wide range requirements for `tanh` on NVIDIA GPUs: microsoft/hlsl-specs#601 This issue has also been observed by WGSL and is reflected in their spec: gpuweb/gpuweb#5199 Fixes #326
1 parent 4a31231 commit 19464d2

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

test/Feature/HLSLLib/cosh.32.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Buffers:
3838
# NaN, Inf, 1.0, 1.0, 1.0, 1.0, Inf, 1.543081, 1.543081,
3939
Results:
4040
- Result: Test1
41-
Rule: BufferFloatEpsilon
42-
Epsilon: 0.0008
41+
Rule: BufferFloatULP
42+
ULPT: 4
4343
Actual: Out
4444
Expected: ExpectedOut
4545
DescriptorSets:

test/Feature/HLSLLib/sinh.16.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Buffers:
3838
# NaN, -Inf, 0.0, 0.0, 0.0, 0.0, Inf, 1.175201, -1.175201,
3939
Results:
4040
- Result: Test1
41-
Rule: BufferFloatEpsilon
42-
Epsilon: 0.0008
41+
Rule: BufferFloatULP
42+
ULPT: 2
4343
Actual: Out
4444
Expected: ExpectedOut
4545
DescriptorSets:

test/Feature/HLSLLib/sinh.32.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Buffers:
3838
# NaN, -Inf, 0.0, 0.0, 0.0, 0.0, Inf, 1.175201, -1.175201,
3939
Results:
4040
- Result: Test1
41-
Rule: BufferFloatEpsilon
42-
Epsilon: 0.0008
41+
Rule: BufferFloatULP
42+
ULPT: 4
4343
Actual: Out
4444
Expected: ExpectedOut
4545
DescriptorSets:

test/Feature/HLSLLib/tanh.16.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Buffers:
3838
# -0.0, 0.0, 0.761594, -0.761594, -0.0, 0.0, 0.761594, -0.761594, -0.0, 0.0, 0.761594, -0.761594,
3939
Results:
4040
- Result: Test1
41-
Rule: BufferFloatEpsilon
42-
Epsilon: 0.0008
41+
Rule: BufferFloatULP
42+
ULPT: 5
4343
Actual: Out
4444
Expected: ExpectedOut
4545
DescriptorSets:

test/Feature/HLSLLib/tanh.32.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Buffers:
3636
Data: [ -0.0, 0.0, 0.761594, -0.761594, -0.0, 0.0, 0.761594, -0.761594, -0.0, 0.0, 0.761594, -0.761594]
3737
Results:
3838
- Result: Test1
39-
Rule: BufferFloatEpsilon
40-
Epsilon: 0.0008
39+
Rule: BufferFloatULP
40+
ULPT: 120 # Metal has an ULP range of 5, CUDA has 2, but NV drivers seem to have wider drift
4141
Actual: Out
4242
Expected: ExpectedOut
4343
DescriptorSets:
@@ -61,5 +61,5 @@ DescriptorSets:
6161

6262

6363
# RUN: split-file %s %t
64-
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
64+
# RUN: %dxc_target -T cs_6_5 -Gis -Fo %t.o %t/source.hlsl
6565
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)