Skip to content

Commit 8b04ac1

Browse files
authored
Add dot tests (#318)
Closes #124. Adds tests for `dot` testing 16 bit int types, half, 32 bit types, 64 bit int types, and double (only supports scalar double not vector). Didn't use the [HLK test inputs](https://github.com/microsoft/DirectXShaderCompiler/blob/57177f77a4dc6996400ac97a0d618799c82374e8/tools/clang/unittests/HLSLExec/ShaderOpArithTable.xml#L4766) because it was testing 9 inputs for each of vector sizes 2-4, and the tests were mostly for nans, infs, and denorms.
1 parent 2750884 commit 8b04ac1

File tree

5 files changed

+640
-0
lines changed

5 files changed

+640
-0
lines changed

test/Feature/HLSLLib/dot.32.test

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
#--- source.hlsl
2+
StructuredBuffer<float4> X0 : register(t0);
3+
StructuredBuffer<float4> Y0 : register(t1);
4+
StructuredBuffer<int4> X1 : register(t2);
5+
StructuredBuffer<int4> Y1 : register(t3);
6+
StructuredBuffer<uint4> X2 : register(t4);
7+
StructuredBuffer<uint4> Y2 : register(t5);
8+
9+
RWStructuredBuffer<float> Out0 : register(u6);
10+
RWStructuredBuffer<int> Out1 : register(u7);
11+
RWStructuredBuffer<uint> Out2 : register(u8);
12+
13+
14+
[numthreads(1,1,1)]
15+
void main() {
16+
// float
17+
Out0[0] = dot(X0[0].x, Y0[0].x);
18+
Out0[1] = dot(float(1.125), float(7.29));
19+
20+
Out0[2] = dot(X0[0].xy, Y0[0].xy);
21+
Out0[3] = dot(float2(1.125, -2.5), float2(7.29, 3.14));
22+
23+
Out0[4] = dot(X0[0].xyz, Y0[0].xyz);
24+
Out0[5] = dot(float3(1.125, -2.5, -4.75), float3(7.29, 3.14, -1.1));
25+
26+
Out0[6] = dot(X0[0], Y0[0]);
27+
Out0[7] = dot(float4(1.125, -2.5, -4.75, 6.625), float4(7.29, 3.14, -1.1, -3.5));
28+
29+
// int
30+
Out1[0] = dot(X1[0].x, Y1[0].x);
31+
Out1[1] = dot(int(100), int(25));
32+
33+
Out1[2] = dot(X1[0].xy, Y1[0].xy);
34+
Out1[3] = dot(int2(100, -52), int2(25, 43));
35+
36+
Out1[4] = dot(X1[0].xyz, Y1[0].xyz);
37+
Out1[5] = dot(int3(100, -52, -210), int3(25, 43, -16));
38+
39+
Out1[6] = dot(X1[0], Y1[0]);
40+
Out1[7] = dot(int4(100, -52, -210, 75), int4(25, 43, -16, -62));
41+
42+
// uint
43+
Out2[0] = dot(X2[0].x, Y2[0].x);
44+
Out2[1] = dot(uint(100), uint(25));
45+
46+
Out2[2] = dot(X2[0].xy, Y2[0].xy);
47+
Out2[3] = dot(uint2(100, 52), uint2(25, 43));
48+
49+
Out2[4] = dot(X2[0].xyz, Y2[0].xyz);
50+
Out2[5] = dot(uint3(100, 52, 210), uint3(25, 43, 16));
51+
52+
Out2[6] = dot(X2[0], Y2[0]);
53+
Out2[7] = dot(uint4(100, 52, 210, 75), uint4(25, 43, 16, 62));
54+
}
55+
//--- pipeline.yaml
56+
57+
---
58+
Shaders:
59+
- Stage: Compute
60+
Entry: main
61+
DispatchSize: [1, 1, 1]
62+
Buffers:
63+
- Name: X0
64+
Format: Float32
65+
Stride: 16
66+
Data: [ 1.125, -2.5, -4.75, 6.625 ]
67+
- Name: Y0
68+
Format: Float32
69+
Stride: 16
70+
Data: [ 7.29, 3.14, -1.1, -3.5 ]
71+
- Name: X1
72+
Format: Int32
73+
Stride: 16
74+
Data: [ 100, -52, -210, 75 ]
75+
- Name: Y1
76+
Format: Int32
77+
Stride: 16
78+
Data: [ 25, 43, -16, -62 ]
79+
- Name: X2
80+
Format: UInt32
81+
Stride: 16
82+
Data: [ 100, 52, 210, 75 ]
83+
- Name: Y2
84+
Format: UInt32
85+
Stride: 16
86+
Data: [ 25, 43, 16, 62 ]
87+
- Name: Out0
88+
Format: Float32
89+
Stride: 4
90+
ZeroInitSize: 32
91+
- Name: ExpectedOut0
92+
Format: Float32
93+
Stride: 4
94+
Data: [ 8.20125, 8.20125, 0.35125, 0.35125, 5.57625, 5.57625, -17.61125, -17.61125 ]
95+
- Name: Out1
96+
Format: Int32
97+
Stride: 4
98+
ZeroInitSize: 32
99+
- Name: ExpectedOut1
100+
Format: Int32
101+
Stride: 4
102+
Data: [ 2500, 2500, 264, 264, 3624, 3624, -1026, -1026 ]
103+
- Name: Out2
104+
Format: UInt32
105+
Stride: 4
106+
ZeroInitSize: 32
107+
- Name: ExpectedOut2
108+
Format: UInt32
109+
Stride: 4
110+
Data: [ 2500, 2500, 4736, 4736, 8096, 8096, 12746, 12746 ]
111+
Results:
112+
- Result: Test0
113+
Rule: BufferFloatEpsilon
114+
Epsilon: 0.008
115+
Actual: Out0
116+
Expected: ExpectedOut0
117+
- Result: Test1
118+
Rule: BufferExact
119+
Actual: Out1
120+
Expected: ExpectedOut1
121+
- Result: Test2
122+
Rule: BufferExact
123+
Actual: Out2
124+
Expected: ExpectedOut2
125+
DescriptorSets:
126+
- Resources:
127+
- Name: X0
128+
Kind: StructuredBuffer
129+
DirectXBinding:
130+
Register: 0
131+
Space: 0
132+
VulkanBinding:
133+
Binding: 0
134+
- Name: Y0
135+
Kind: StructuredBuffer
136+
DirectXBinding:
137+
Register: 1
138+
Space: 0
139+
VulkanBinding:
140+
Binding: 1
141+
- Name: X1
142+
Kind: StructuredBuffer
143+
DirectXBinding:
144+
Register: 2
145+
Space: 0
146+
VulkanBinding:
147+
Binding: 2
148+
- Name: Y1
149+
Kind: StructuredBuffer
150+
DirectXBinding:
151+
Register: 3
152+
Space: 0
153+
VulkanBinding:
154+
Binding: 3
155+
- Name: X2
156+
Kind: StructuredBuffer
157+
DirectXBinding:
158+
Register: 4
159+
Space: 0
160+
VulkanBinding:
161+
Binding: 4
162+
- Name: Y2
163+
Kind: StructuredBuffer
164+
DirectXBinding:
165+
Register: 5
166+
Space: 0
167+
VulkanBinding:
168+
Binding: 5
169+
- Name: Out0
170+
Kind: RWStructuredBuffer
171+
DirectXBinding:
172+
Register: 6
173+
Space: 0
174+
VulkanBinding:
175+
Binding: 6
176+
- Name: Out1
177+
Kind: RWStructuredBuffer
178+
DirectXBinding:
179+
Register: 7
180+
Space: 0
181+
VulkanBinding:
182+
Binding: 7
183+
- Name: Out2
184+
Kind: RWStructuredBuffer
185+
DirectXBinding:
186+
Register: 8
187+
Space: 0
188+
VulkanBinding:
189+
Binding: 8
190+
#--- end
191+
192+
# https://github.com/llvm/llvm-project/issues/149561
193+
# XFAIL: Clang-Vulkan
194+
195+
# RUN: split-file %s %t
196+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
197+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/HLSLLib/dot.fp16.test

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#--- source.hlsl
2+
StructuredBuffer<half4> X : register(t0);
3+
StructuredBuffer<half4> Y : register(t1);
4+
5+
RWStructuredBuffer<half> Out : register(u2);
6+
7+
8+
[numthreads(1,1,1)]
9+
void main() {
10+
Out[0] = dot(X[0].x, Y[0].x);
11+
Out[1] = dot(half(1.125), half(7.29));
12+
13+
Out[2] = dot(X[0].xy, Y[0].xy);
14+
Out[3] = dot(half2(1.125, -2.5), half2(7.29, 3.14));
15+
16+
Out[4] = dot(X[0].xyz, Y[0].xyz);
17+
Out[5] = dot(half3(1.125, -2.5, -4.75), half3(7.29, 3.14, -1.1));
18+
19+
Out[6] = dot(X[0], Y[0]);
20+
Out[7] = dot(half4(1.125, -2.5, -4.75, 6.625), half4(7.29, 3.14, -1.1, -3.5));
21+
}
22+
//--- pipeline.yaml
23+
24+
---
25+
Shaders:
26+
- Stage: Compute
27+
Entry: main
28+
DispatchSize: [1, 1, 1]
29+
Buffers:
30+
- Name: X
31+
Format: Float16
32+
Stride: 8
33+
Data: [ 0x3c80, 0xc100, 0xc4c0, 0x46a0 ]
34+
# [ 1.125, -2.5, -4.75, 6.625 ]
35+
- Name: Y
36+
Format: Float16
37+
Stride: 8
38+
Data: [ 0x474a, 0x4247, 0xbc66, 0xc300 ]
39+
# [ 7.29, 3.14, -1.1, -3.5 ]
40+
- Name: Out
41+
Format: Float16
42+
Stride: 2
43+
ZeroInitSize: 16
44+
- Name: ExpectedOut
45+
Format: Float16
46+
Stride: 2
47+
Data: [ 0x481a, 0x481a, 0x359f, 0x359f, 0x4594, 0x4594, 0xcc67, 0xcc67 ]
48+
# [ 8.20125, 8.20125, 0.35125, 0.35125, 5.57625, 5.57625, -17.61125, -17.61125 ]
49+
Results:
50+
- Result: Test1
51+
Rule: BufferFloatEpsilon
52+
Epsilon: 0.008
53+
Actual: Out
54+
Expected: ExpectedOut
55+
DescriptorSets:
56+
- Resources:
57+
- Name: X
58+
Kind: StructuredBuffer
59+
DirectXBinding:
60+
Register: 0
61+
Space: 0
62+
VulkanBinding:
63+
Binding: 0
64+
- Name: Y
65+
Kind: StructuredBuffer
66+
DirectXBinding:
67+
Register: 1
68+
Space: 0
69+
VulkanBinding:
70+
Binding: 1
71+
- Name: Out
72+
Kind: RWStructuredBuffer
73+
DirectXBinding:
74+
Register: 2
75+
Space: 0
76+
VulkanBinding:
77+
Binding: 2
78+
#--- end
79+
80+
# https://github.com/llvm/llvm-project/issues/149561
81+
# XFAIL: Clang-Vulkan
82+
83+
# REQUIRES: Half
84+
# RUN: split-file %s %t
85+
# RUN: %dxc_target -enable-16bit-types -T cs_6_5 -Fo %t.o %t/source.hlsl
86+
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/HLSLLib/dot.fp64.test

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#--- source.hlsl
2+
StructuredBuffer<double> X : register(t0);
3+
StructuredBuffer<double> Y : register(t1);
4+
5+
RWStructuredBuffer<double> Out : register(u2);
6+
7+
8+
[numthreads(1,1,1)]
9+
void main() {
10+
Out[0] = dot(X[0], Y[0]);
11+
Out[1] = dot(double(1.125), double(7.29));
12+
13+
Out[2] = dot(X[1], Y[1]);
14+
Out[3] = dot(double(-2.5), double(3.14));
15+
16+
Out[4] = dot(X[2], Y[2]);
17+
Out[5] = dot(double(-4.75), double(-1.1));
18+
19+
Out[6] = dot(X[3], Y[3]);
20+
Out[7] = dot(double(6.625), double(-3.5));
21+
}
22+
//--- pipeline.yaml
23+
24+
---
25+
Shaders:
26+
- Stage: Compute
27+
Entry: main
28+
DispatchSize: [1, 1, 1]
29+
Buffers:
30+
- Name: X
31+
Format: Float64
32+
Stride: 8
33+
Data: [ 1.125, -2.5, -4.75, 6.625 ]
34+
- Name: Y
35+
Format: Float64
36+
Stride: 8
37+
Data: [ 7.29, 3.14, -1.1, -3.5 ]
38+
- Name: Out
39+
Format: Float64
40+
Stride: 8
41+
ZeroInitSize: 64
42+
- Name: ExpectedOut
43+
Format: Float64
44+
Stride: 8
45+
Data: [ 8.20125, 8.20125, -7.85, -7.85, 5.225, 5.225, -23.1875, -23.1875 ]
46+
Results:
47+
- Result: Test0
48+
Rule: BufferFloatEpsilon
49+
Epsilon: 0.008
50+
Actual: Out
51+
Expected: ExpectedOut
52+
DescriptorSets:
53+
- Resources:
54+
- Name: X
55+
Kind: StructuredBuffer
56+
DirectXBinding:
57+
Register: 0
58+
Space: 0
59+
VulkanBinding:
60+
Binding: 0
61+
- Name: Y
62+
Kind: StructuredBuffer
63+
DirectXBinding:
64+
Register: 1
65+
Space: 0
66+
VulkanBinding:
67+
Binding: 1
68+
- Name: Out
69+
Kind: RWStructuredBuffer
70+
DirectXBinding:
71+
Register: 2
72+
Space: 0
73+
VulkanBinding:
74+
Binding: 2
75+
#--- end
76+
77+
# https://github.com/llvm/llvm-project/issues/149561
78+
# XFAIL: Clang-Vulkan
79+
80+
# REQUIRES: Double
81+
# RUN: split-file %s %t
82+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
83+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)