Skip to content

Commit 28e49e8

Browse files
authored
Add WaveActiveBitXor tests (llvm#971)
This PR adds tests for WaveActiveBitXor. WaveActiveBitXor only accepts uint and uint64 types. The PR also adds a control flow test, since this operation is convergent. Fixes llvm#896
1 parent e9581da commit 28e49e8

3 files changed

Lines changed: 576 additions & 0 deletions

File tree

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#--- source.hlsl
2+
StructuredBuffer<uint> In : register(t0);
3+
4+
RWStructuredBuffer<uint> Out1 : register(u1); // branch A
5+
RWStructuredBuffer<uint> Out2 : register(u2); // branch B
6+
RWStructuredBuffer<uint> Out3 : register(u3); // reconverged
7+
RWStructuredBuffer<uint> Out4 : register(u4); // loop
8+
RWStructuredBuffer<uint> Out5 : register(u5); // divergent loop
9+
10+
[numthreads(4,1,1)]
11+
void main(uint3 TID : SV_GroupThreadID) {
12+
uint V = In[TID.x];
13+
14+
// divergent branch
15+
if (TID.x < 2)
16+
Out1[TID.x] = WaveActiveBitXor(V);
17+
else
18+
Out2[TID.x] = WaveActiveBitXor(V);
19+
20+
// reconverged wave op
21+
Out3[TID.x] = WaveActiveBitXor(V);
22+
23+
// loop case
24+
uint R = V;
25+
for (uint i = 0; i < 2; i++)
26+
R = WaveActiveBitXor(R);
27+
28+
Out4[TID.x] = R;
29+
30+
// divergent loop: each thread iterates TID.x times
31+
// thread 0: 0 iters, thread 1: 1 iter, thread 2: 2 iters, thread 3: 3 iters
32+
uint R2 = V;
33+
for (uint j = 0; j < TID.x; j++)
34+
R2 = WaveActiveBitXor(R2);
35+
36+
Out5[TID.x] = R2;
37+
}
38+
39+
#--- pipeline.yaml
40+
41+
---
42+
Shaders:
43+
- Stage: Compute
44+
Entry: main
45+
DispatchSize: [1, 1, 1]
46+
47+
Buffers:
48+
49+
- Name: In
50+
Format: UInt32
51+
Stride: 4
52+
Data: [ 0x11, 0x12, 0x14, 0x18 ]
53+
- Name: Out1
54+
Format: UInt32
55+
Stride: 4
56+
FillSize: 16
57+
- Name: Out2
58+
Format: UInt32
59+
Stride: 4
60+
FillSize: 16
61+
- Name: Out3
62+
Format: UInt32
63+
Stride: 4
64+
FillSize: 16
65+
- Name: Out4
66+
Format: UInt32
67+
Stride: 4
68+
FillSize: 16
69+
- Name: Out5
70+
Format: UInt32
71+
Stride: 4
72+
FillSize: 16
73+
- Name: ExpectedOut1
74+
Format: UInt32
75+
Stride: 4
76+
Data: [ 0x3, 0x3, 0x0, 0x0 ]
77+
- Name: ExpectedOut2
78+
Format: UInt32
79+
Stride: 4
80+
Data: [ 0x0, 0x0, 0xc, 0xc ]
81+
- Name: ExpectedOut3
82+
Format: UInt32
83+
Stride: 4
84+
Data: [ 0xf, 0xf, 0xf, 0xf ]
85+
- Name: ExpectedOut4
86+
Format: UInt32
87+
Stride: 4
88+
Data: [ 0x0, 0x0, 0x0, 0x0 ]
89+
- Name: ExpectedOut5
90+
Format: UInt32
91+
Stride: 4
92+
Data: [ 0x11, 0x1e, 0x0, 0x0 ]
93+
94+
Results:
95+
- Result: ExpectedOut1
96+
Rule: BufferExact
97+
Actual: Out1
98+
Expected: ExpectedOut1
99+
- Result: ExpectedOut2
100+
Rule: BufferExact
101+
Actual: Out2
102+
Expected: ExpectedOut2
103+
- Result: ExpectedOut3
104+
Rule: BufferExact
105+
Actual: Out3
106+
Expected: ExpectedOut3
107+
- Result: ExpectedOut4
108+
Rule: BufferExact
109+
Actual: Out4
110+
Expected: ExpectedOut4
111+
- Result: ExpectedOut5
112+
Rule: BufferExact
113+
Actual: Out5
114+
Expected: ExpectedOut5
115+
116+
117+
DescriptorSets:
118+
- Resources:
119+
- Name: In
120+
Kind: StructuredBuffer
121+
DirectXBinding:
122+
Register: 0
123+
Space: 0
124+
VulkanBinding:
125+
Binding: 0
126+
- Name: Out1
127+
Kind: RWStructuredBuffer
128+
DirectXBinding:
129+
Register: 1
130+
Space: 0
131+
VulkanBinding:
132+
Binding: 1
133+
- Name: Out2
134+
Kind: RWStructuredBuffer
135+
DirectXBinding:
136+
Register: 2
137+
Space: 0
138+
VulkanBinding:
139+
Binding: 2
140+
- Name: Out3
141+
Kind: RWStructuredBuffer
142+
DirectXBinding:
143+
Register: 3
144+
Space: 0
145+
VulkanBinding:
146+
Binding: 3
147+
- Name: Out4
148+
Kind: RWStructuredBuffer
149+
DirectXBinding:
150+
Register: 4
151+
Space: 0
152+
VulkanBinding:
153+
Binding: 4
154+
- Name: Out5
155+
Kind: RWStructuredBuffer
156+
DirectXBinding:
157+
Register: 5
158+
Space: 0
159+
VulkanBinding:
160+
Binding: 5
161+
...
162+
#--- end
163+
164+
# Bug: https://github.com/llvm/llvm-project/issues/188323
165+
# XFAIL: Vulkan && Clang
166+
167+
# Bug: https://github.com/llvm/offload-test-suite/issues/1022
168+
# XFAIL: WARP
169+
170+
# RUN: split-file %s %t
171+
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
172+
# RUN: %offloader %t/pipeline.yaml %t.o
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#--- source.hlsl
2+
StructuredBuffer<uint4> In : register(t0);
3+
4+
RWStructuredBuffer<uint> Out1 : register(u1);
5+
RWStructuredBuffer<uint2> Out2 : register(u2);
6+
RWStructuredBuffer<uint3> Out3 : register(u3);
7+
RWStructuredBuffer<uint4> Out4 : register(u4);
8+
RWStructuredBuffer<uint4> Out5 : register(u5);
9+
10+
11+
[numthreads(4,1,1)]
12+
void main(uint3 TID : SV_GroupThreadID) {
13+
uint4 V = In[TID.x];
14+
15+
Out1[TID.x] = WaveActiveBitXor(V.x);
16+
17+
// 3 thread case
18+
if (TID.x != 1)
19+
Out1[TID.x + 4] = WaveActiveBitXor(V.x);
20+
21+
Out2[TID.x] = WaveActiveBitXor(V.xy);
22+
23+
uint3 R3 = WaveActiveBitXor(V.xyz);
24+
Out3[TID.x].xyz = R3;
25+
26+
Out4[TID.x] = WaveActiveBitXor(V);
27+
28+
// constant folding
29+
Out5[TID.x] = WaveActiveBitXor(uint4(1,2,3,4));
30+
31+
if (TID.x != 1)
32+
Out5[TID.x + 4] = WaveActiveBitXor(uint4(1,2,3,4));
33+
if (TID.x % 2)
34+
Out5[TID.x + 4 * 2] = WaveActiveBitXor(uint4(1,2,3,4));
35+
if (TID.x == 1)
36+
Out5[TID.x + 4 * 3] = WaveActiveBitXor(uint4(1,2,3,4));
37+
38+
}
39+
40+
#--- pipeline.yaml
41+
42+
---
43+
Shaders:
44+
- Stage: Compute
45+
Entry: main
46+
DispatchSize: [1,1,1]
47+
48+
Buffers:
49+
- Name: In
50+
Format: UInt32
51+
Stride: 16
52+
Data: [
53+
0x11, 0x2, 0x4, 0x8,
54+
0x10, 0x20, 0x40, 0x80,
55+
0x100, 0x200, 0x400, 0x800,
56+
0x1000, 0x2000, 0x4000, 0x8000
57+
]
58+
59+
- Name: Out1
60+
Format: UInt32
61+
Stride: 4
62+
FillSize: 32
63+
- Name: Out2
64+
Format: UInt32
65+
Stride: 8
66+
FillSize: 32
67+
- Name: Out3
68+
Format: UInt32
69+
Stride: 12
70+
FillSize: 48
71+
- Name: Out4
72+
Format: UInt32
73+
Stride: 16
74+
FillSize: 64
75+
- Name: Out5
76+
Format: UInt32
77+
Stride: 16
78+
FillSize: 256
79+
80+
- Name: ExpectedOut1
81+
Format: UInt32
82+
Stride: 4
83+
Data: [ 0x1101, 0x1101, 0x1101, 0x1101, 0x1111, 0x0, 0x1111, 0x1111 ]
84+
- Name: ExpectedOut2
85+
Format: UInt32
86+
Stride: 8
87+
Data: [
88+
0x1101, 0x2222,
89+
0x1101, 0x2222,
90+
0x1101, 0x2222,
91+
0x1101, 0x2222
92+
]
93+
- Name: ExpectedOut3
94+
Format: UInt32
95+
Stride: 12
96+
Data: [
97+
0x1101, 0x2222, 0x4444,
98+
0x1101, 0x2222, 0x4444,
99+
0x1101, 0x2222, 0x4444,
100+
0x1101, 0x2222, 0x4444
101+
]
102+
- Name: ExpectedOut4
103+
Format: UInt32
104+
Stride: 16
105+
Data: [
106+
0x1101, 0x2222, 0x4444, 0x8888,
107+
0x1101, 0x2222, 0x4444, 0x8888,
108+
0x1101, 0x2222, 0x4444, 0x8888,
109+
0x1101, 0x2222, 0x4444, 0x8888
110+
]
111+
- Name: ExpectedOut5
112+
Format: UInt32
113+
Stride: 16
114+
Data: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
115+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
116+
0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0,
117+
0x1, 0x2, 0x3, 0x4, 0x1, 0x2, 0x3, 0x4,
118+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
119+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
120+
0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4,
121+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
122+
]
123+
124+
Results:
125+
- Result: ExpectedOut1
126+
Rule: BufferExact
127+
Actual: Out1
128+
Expected: ExpectedOut1
129+
- Result: ExpectedOut2
130+
Rule: BufferExact
131+
Actual: Out2
132+
Expected: ExpectedOut2
133+
- Result: ExpectedOut3
134+
Rule: BufferExact
135+
Actual: Out3
136+
Expected: ExpectedOut3
137+
- Result: ExpectedOut4
138+
Rule: BufferExact
139+
Actual: Out4
140+
Expected: ExpectedOut4
141+
- Result: ExpectedOut5
142+
Rule: BufferExact
143+
Actual: Out5
144+
Expected: ExpectedOut5
145+
146+
DescriptorSets:
147+
- Resources:
148+
- Name: In
149+
Kind: StructuredBuffer
150+
DirectXBinding:
151+
Register: 0
152+
Space: 0
153+
VulkanBinding:
154+
Binding: 0
155+
- Name: Out1
156+
Kind: RWStructuredBuffer
157+
DirectXBinding:
158+
Register: 1
159+
Space: 0
160+
VulkanBinding:
161+
Binding: 1
162+
- Name: Out2
163+
Kind: RWStructuredBuffer
164+
DirectXBinding:
165+
Register: 2
166+
Space: 0
167+
VulkanBinding:
168+
Binding: 2
169+
- Name: Out3
170+
Kind: RWStructuredBuffer
171+
DirectXBinding:
172+
Register: 3
173+
Space: 0
174+
VulkanBinding:
175+
Binding: 3
176+
- Name: Out4
177+
Kind: RWStructuredBuffer
178+
DirectXBinding:
179+
Register: 4
180+
Space: 0
181+
VulkanBinding:
182+
Binding: 4
183+
- Name: Out5
184+
Kind: RWStructuredBuffer
185+
DirectXBinding:
186+
Register: 5
187+
Space: 0
188+
VulkanBinding:
189+
Binding: 5
190+
...
191+
#--- end
192+
193+
# Bug https://github.com/llvm/offload-test-suite/issues/1058
194+
# XFAIL: QC && DirectX
195+
196+
# Bug https://github.com/llvm/offload-test-suite/issues/1058
197+
# XFAIL: QC && Clang && Vulkan
198+
199+
# RUN: split-file %s %t
200+
# RUN: %dxc_target -T cs_6_5 -fvk-use-dx-layout -Fo %t.o %t/source.hlsl
201+
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)