Skip to content

Commit 2128c19

Browse files
authored
Add tests for concurrent writes to matrices (#654)
Adds new offload tests as mentioned should be done in llvm/llvm-project#174629 These tests are concurrently writing to a matrix in groupshared memory instead of directly in UAVs because the writing of matrices to UAVs is not currently implemented in Clang. The XFAIL on Clang with bug llvm/llvm-project#174629 can be removed after llvm/llvm-project#176216 is merged.
1 parent 0cc96f8 commit 2128c19

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#--- source.hlsl
2+
3+
// This tests that we can concurrently write to the components of a float4x4
4+
// as though it is an array. The large group size is used to force the write
5+
// to occur across multiple waves so that the datarace can be observed.
6+
7+
RWStructuredBuffer<float> In : register(u0);
8+
RWStructuredBuffer<float> Out : register(u1);
9+
10+
groupshared float4x4 SharedMat;
11+
12+
[numthreads(32, 4, 4)]
13+
void main(uint3 ThreadID : SV_GroupThreadID) {
14+
uint FlatIdx = ThreadID.y + ThreadID.z * 4;
15+
if (ThreadID.x == 0) {
16+
SharedMat[ThreadID.y][ThreadID.z] = In[FlatIdx];
17+
}
18+
GroupMemoryBarrierWithGroupSync();
19+
if (ThreadID.x == 0) {
20+
Out[FlatIdx] = SharedMat[ThreadID.y][ThreadID.z];
21+
}
22+
}
23+
//--- pipeline.yaml
24+
25+
---
26+
Shaders:
27+
- Stage: Compute
28+
Entry: main
29+
DispatchSize: [1, 1, 1]
30+
Buffers:
31+
- Name: In
32+
Format: Float32
33+
Data: [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ]
34+
- Name: Out
35+
Format: Float32
36+
FillSize: 64
37+
- Name: ExpectedOut
38+
Format: Float32
39+
Data: [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ]
40+
Results:
41+
- Result: Out
42+
Rule: BufferFloatULP
43+
ULPT: 0
44+
Actual: Out
45+
Expected: ExpectedOut
46+
DescriptorSets:
47+
- Resources:
48+
- Name: In
49+
Kind: RWStructuredBuffer
50+
DirectXBinding:
51+
Register: 0
52+
Space: 0
53+
VulkanBinding:
54+
Binding: 0
55+
- Name: Out
56+
Kind: RWStructuredBuffer
57+
DirectXBinding:
58+
Register: 1
59+
Space: 0
60+
VulkanBinding:
61+
Binding: 1
62+
...
63+
#--- end
64+
65+
# Bug https://github.com/llvm/llvm-project/issues/172577
66+
# XFAIL: Clang && Vulkan
67+
68+
# Bug https://github.com/llvm/offload-test-suite/issues/452
69+
# XFAIL: Metal
70+
71+
# RUN: split-file %s %t
72+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
73+
# RUN: %offloader %t/pipeline.yaml %t.o
74+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#--- source.hlsl
2+
3+
// This tests that we can concurrently write to the rows of a float4x4 as
4+
// though it is an array of four float4s. The large group size is used to force the
5+
// write to occur across multiple waves so that the datarace can be observed.
6+
7+
RWStructuredBuffer<float4> In : register(u0);
8+
RWStructuredBuffer<float4> Out : register(u1);
9+
10+
groupshared float4x4 SharedMat;
11+
12+
[numthreads(128, 4, 1)]
13+
void main(uint3 ThreadID : SV_GroupThreadID, uint FlatThreadID : SV_GroupIndex) {
14+
if (ThreadID.x == 0) {
15+
SharedMat[ThreadID.y] = In[ThreadID.y];
16+
}
17+
GroupMemoryBarrierWithGroupSync();
18+
if (ThreadID.x == 0) {
19+
Out[ThreadID.y] = SharedMat[ThreadID.y];
20+
}
21+
}
22+
//--- pipeline.yaml
23+
24+
---
25+
Shaders:
26+
- Stage: Compute
27+
Entry: main
28+
DispatchSize: [1, 1, 1]
29+
Buffers:
30+
- Name: In
31+
Format: Float32
32+
Stride: 16
33+
Data: [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ]
34+
- Name: Out
35+
Format: Float32
36+
Stride: 16
37+
FillSize: 64
38+
- Name: ExpectedOut
39+
Format: Float32
40+
Stride: 16
41+
Data: [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ]
42+
Results:
43+
- Result: Out
44+
Rule: BufferFloatULP
45+
ULPT: 0
46+
Actual: Out
47+
Expected: ExpectedOut
48+
DescriptorSets:
49+
- Resources:
50+
- Name: In
51+
Kind: RWStructuredBuffer
52+
DirectXBinding:
53+
Register: 0
54+
Space: 0
55+
VulkanBinding:
56+
Binding: 0
57+
- Name: Out
58+
Kind: RWStructuredBuffer
59+
DirectXBinding:
60+
Register: 1
61+
Space: 0
62+
VulkanBinding:
63+
Binding: 1
64+
...
65+
#--- end
66+
67+
# Bug https://github.com/llvm/llvm-project/issues/172577
68+
# XFAIL: Clang && Vulkan
69+
70+
# Bug https://github.com/llvm/offload-test-suite/issues/452
71+
# XFAIL: Metal
72+
73+
# RUN: split-file %s %t
74+
# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl
75+
# RUN: %offloader %t/pipeline.yaml %t.o
76+

0 commit comments

Comments
 (0)