Skip to content

Commit 22f4d28

Browse files
authored
Add tests for fma (#953)
1 parent 70ef868 commit 22f4d28

2 files changed

Lines changed: 247 additions & 0 deletions

File tree

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<double4> A : register(t0);
4+
StructuredBuffer<double4> B : register(t1);
5+
StructuredBuffer<double4> C : register(t2);
6+
7+
RWStructuredBuffer<double4> Out : register(u3);
8+
9+
[numthreads(1,1,1)]
10+
void main() {
11+
double3x2 r32 = fma(double3x2(A[0].xyz, A[1].xyz),
12+
double3x2(B[0].xyz, B[1].xyz),
13+
double3x2(C[0].xyz, C[1].xyz));
14+
15+
double2x4 r24 = fma(double2x4(A[2], A[3]),
16+
double2x4(B[2], B[3]),
17+
double2x4(C[2], C[3]));
18+
19+
double3x1 r31 = fma(double3x1(A[4].xyz),
20+
double3x1(B[4].xyz),
21+
double3x1(C[4].xyz));
22+
23+
double4x4 r44 = fma(double4x4(A[5], A[6], A[7], A[8]),
24+
double4x4(B[5], B[6], B[7], B[8]),
25+
double4x4(C[5], C[6], C[7], C[8]));
26+
27+
Out[0] = double4(r32[0], r32[1]);
28+
Out[1] = double4(r32[2], 0.0, 0.0);
29+
Out[2] = r24[0];
30+
Out[3] = r24[1];
31+
Out[4] = double4(r31[0][0], r31[1][0], r31[2][0], 0.0);
32+
Out[5] = r44[0];
33+
Out[6] = r44[1];
34+
Out[7] = r44[2];
35+
Out[8] = r44[3];
36+
}
37+
38+
//--- pipeline.yaml
39+
40+
---
41+
Shaders:
42+
- Stage: Compute
43+
Entry: main
44+
DispatchSize: [1, 1, 1]
45+
Buffers:
46+
- Name: A
47+
Format: Float64
48+
Stride: 32
49+
Data: [ 1.5, -2.5, 0.5, 0.0,
50+
-0.5, 2.0, 3.0, 0.0,
51+
0.25, -0.25, 10.4, -10.6,
52+
0.0, 10.0, -10.0, 10.5,
53+
1.25, -4.0, 2.5, 0.0,
54+
1.0, 2.0, 3.0, 4.0,
55+
-1.0, -2.0, -3.0, -4.0,
56+
0.5, 1.5, -0.5, -1.5,
57+
10.0, -10.0, 2.25, -2.25 ]
58+
- Name: B
59+
Format: Float64
60+
Stride: 32
61+
Data: [ 2.0, -1.0, 4.0, 0.0,
62+
4.0, -0.5, 1.5, 0.0,
63+
1.0, 1.0, 1.0, 1.0,
64+
1.0, 2.0, -1.0, 1.0,
65+
2.0, -0.5, 3.0, 0.0,
66+
2.0, -1.0, 0.5, 3.0,
67+
4.0, 0.5, -2.0, -1.0,
68+
1.0, 2.0, 3.0, 4.0,
69+
-0.5, 1.5, -1.0, 2.0 ]
70+
- Name: C
71+
Format: Float64
72+
Stride: 32
73+
Data: [ 0.25, 0.75, -1.5, 0.0,
74+
1.5, 1.0, -2.0, 0.0,
75+
0.0, 0.0, 0.0, 0.0,
76+
0.0, 0.5, 0.5, 0.0,
77+
0.5, 1.0, -1.5, 0.0,
78+
0.5, 1.0, -1.5, 0.0,
79+
-0.5, 2.0, 1.0, 3.0,
80+
1.5, -2.0, 0.5, -4.0,
81+
5.0, -5.0, 0.25, -0.25 ]
82+
- Name: Out
83+
Format: Float64
84+
Stride: 32
85+
FillSize: 288
86+
- Name: Expected
87+
Format: Float64
88+
Stride: 32
89+
Data: [ 3.25, 3.25, 0.5, -0.5,
90+
0.0, 2.5, 0.0, 0.0,
91+
0.25, -0.25, 10.4, -10.6,
92+
0.0, 20.5, 10.5, 10.5,
93+
3.0, 3.0, 6.0, 0.0,
94+
2.5, -1.0, 0.0, 12.0,
95+
-4.5, 1.0, 7.0, 7.0,
96+
2.0, 1.0, -1.0, -10.0,
97+
0.0, -20.0, -2.0, -4.75 ]
98+
Results:
99+
- Result: Result
100+
Rule: BufferFloatULP
101+
ULPT: 1
102+
Actual: Out
103+
Expected: Expected
104+
DescriptorSets:
105+
- Resources:
106+
- Name: A
107+
Kind: StructuredBuffer
108+
DirectXBinding:
109+
Register: 0
110+
Space: 0
111+
VulkanBinding:
112+
Binding: 0
113+
- Name: B
114+
Kind: StructuredBuffer
115+
DirectXBinding:
116+
Register: 1
117+
Space: 0
118+
VulkanBinding:
119+
Binding: 1
120+
- Name: C
121+
Kind: StructuredBuffer
122+
DirectXBinding:
123+
Register: 2
124+
Space: 0
125+
VulkanBinding:
126+
Binding: 2
127+
- Name: Out
128+
Kind: RWStructuredBuffer
129+
DirectXBinding:
130+
Register: 3
131+
Space: 0
132+
VulkanBinding:
133+
Binding: 3
134+
#--- end
135+
136+
# Bug https://github.com/llvm/offload-test-suite/issues/1000
137+
# XFAIL: arm64 && WARP
138+
139+
# REQUIRES: Double
140+
# RUN: split-file %s %t
141+
# RUN: %dxc_target -Gis -HV 202x -T cs_6_5 -Fo %t.o %t/source.hlsl
142+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/HLSLLib/fma.test

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#--- source.hlsl
2+
3+
StructuredBuffer<double4> A : register(t0);
4+
StructuredBuffer<double4> B : register(t1);
5+
StructuredBuffer<double4> C : register(t2);
6+
7+
RWStructuredBuffer<double4> Out : register(u3);
8+
9+
[numthreads(1,1,1)]
10+
void main() {
11+
Out[0] = fma(A[0], B[0], C[0]);
12+
Out[1] = double4(fma(A[1].xyz, B[1].xyz, C[1].xyz), fma(A[1].w, B[1].w, C[1].w));
13+
Out[2] = double4(fma(A[2].xy, B[2].xy, C[2].xy), fma(A[2].zw, B[2].zw, C[2].zw));
14+
Out[3] = fma(double4(1.0000000149011612l, -1.0000000149011612l, 1.0000000000000002l, 0.5l), double4(67108865.0l, 67108865.0l, -0.9999999999999998l, -8.0l), double4(-67108866.0l, 67108866.0l, 1.0l, 1.0l));
15+
}
16+
17+
//--- pipeline.yaml
18+
19+
---
20+
Shaders:
21+
- Stage: Compute
22+
Entry: main
23+
DispatchSize: [1, 1, 1]
24+
Buffers:
25+
- Name: A
26+
Format: Float64
27+
Stride: 32
28+
Data: [ 1.5, -2.0, 0.75, -3.25,
29+
2.5, -4.0, 1.25, 3.5,
30+
1.0000000149011612, -1.0000000149011612, 1.0000000000000002, 0.5 ]
31+
# last row: (1 + 2^-26), -(1 + 2^-26), (1 + 2^-52), 0.5
32+
- Name: B
33+
Format: Float64
34+
Stride: 32
35+
Data: [ 2.25, 4.5, -8.0, -2.0,
36+
-1.5, -2.0, 8.0, -2.0,
37+
67108865.0, 67108865.0, -0.9999999999999998, -8.0 ]
38+
# last row: (2^26 + 1), (2^26 + 1), -(1 - 2^-52), -8
39+
- Name: C
40+
Format: Float64
41+
Stride: 32
42+
Data: [ 0.125, 1.25, 2.5, -0.5,
43+
0.25, -1.5, -0.75, 0.5,
44+
-67108866.0, 67108866.0, 1.0, 1.0 ]
45+
# last row: -(2^26 + 2), (2^26 + 2), 1, 1
46+
- Name: Out
47+
Format: Float64
48+
Stride: 32
49+
FillSize: 128
50+
- Name: Expected
51+
Format: Float64
52+
Stride: 32
53+
Data: [ 3.5, -7.75, -3.5, 6.0,
54+
-3.5, 6.5, 9.25, -6.5,
55+
0x1.0000000000000p-26, -0x1.0000000000000p-26, 0x1.0000000000000p-104, -3.0,
56+
0x1.0000000000000p-26, -0x1.0000000000000p-26, 0x1.0000000000000p-104, -3.0 ]
57+
# last two rows: 2^-26, -(2^-26), 2^-104, -3
58+
Results:
59+
- Result: Result
60+
Rule: BufferFloatULP
61+
ULPT: 1
62+
Actual: Out
63+
Expected: Expected
64+
DescriptorSets:
65+
- Resources:
66+
- Name: A
67+
Kind: StructuredBuffer
68+
DirectXBinding:
69+
Register: 0
70+
Space: 0
71+
VulkanBinding:
72+
Binding: 0
73+
- Name: B
74+
Kind: StructuredBuffer
75+
DirectXBinding:
76+
Register: 1
77+
Space: 0
78+
VulkanBinding:
79+
Binding: 1
80+
- Name: C
81+
Kind: StructuredBuffer
82+
DirectXBinding:
83+
Register: 2
84+
Space: 0
85+
VulkanBinding:
86+
Binding: 2
87+
- Name: Out
88+
Kind: RWStructuredBuffer
89+
DirectXBinding:
90+
Register: 3
91+
Space: 0
92+
VulkanBinding:
93+
Binding: 3
94+
#--- end
95+
96+
# Bug https://github.com/microsoft/DirectXShaderCompiler/issues/8330
97+
# XFAIL: arm64 && WARP
98+
99+
# Bug https://github.com/llvm/offload-test-suite/issues/1026
100+
# XFAIL: Intel && Vulkan && DXC
101+
102+
# REQUIRES: Double
103+
# RUN: split-file %s %t
104+
# RUN: %dxc_target -Gis -HV 202x -T cs_6_5 -Fo %t.o %t/source.hlsl
105+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)