Skip to content

Add dot tests #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions test/Feature/HLSLLib/dot.32.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#--- source.hlsl
StructuredBuffer<float4> X0 : register(t0);
StructuredBuffer<float4> Y0 : register(t1);
StructuredBuffer<int4> X1 : register(t2);
StructuredBuffer<int4> Y1 : register(t3);
StructuredBuffer<uint4> X2 : register(t4);
StructuredBuffer<uint4> Y2 : register(t5);

RWStructuredBuffer<float> Out0 : register(u6);
RWStructuredBuffer<int> Out1 : register(u7);
RWStructuredBuffer<uint> Out2 : register(u8);


[numthreads(1,1,1)]
void main() {
// float
Out0[0] = dot(X0[0].x, Y0[0].x);
Out0[1] = dot(float(1.125), float(7.29));

Out0[2] = dot(X0[0].xy, Y0[0].xy);
Out0[3] = dot(float2(1.125, -2.5), float2(7.29, 3.14));

Out0[4] = dot(X0[0].xyz, Y0[0].xyz);
Out0[5] = dot(float3(1.125, -2.5, -4.75), float3(7.29, 3.14, -1.1));

Out0[6] = dot(X0[0], Y0[0]);
Out0[7] = dot(float4(1.125, -2.5, -4.75, 6.625), float4(7.29, 3.14, -1.1, -3.5));

// int
Out1[0] = dot(X1[0].x, Y1[0].x);
Out1[1] = dot(int(100), int(25));

Out1[2] = dot(X1[0].xy, Y1[0].xy);
Out1[3] = dot(int2(100, -52), int2(25, 43));

Out1[4] = dot(X1[0].xyz, Y1[0].xyz);
Out1[5] = dot(int3(100, -52, -210), int3(25, 43, -16));

Out1[6] = dot(X1[0], Y1[0]);
Out1[7] = dot(int4(100, -52, -210, 75), int4(25, 43, -16, -62));

// uint
Out2[0] = dot(X2[0].x, Y2[0].x);
Out2[1] = dot(uint(100), uint(25));

Out2[2] = dot(X2[0].xy, Y2[0].xy);
Out2[3] = dot(uint2(100, 52), uint2(25, 43));

Out2[4] = dot(X2[0].xyz, Y2[0].xyz);
Out2[5] = dot(uint3(100, 52, 210), uint3(25, 43, 16));

Out2[6] = dot(X2[0], Y2[0]);
Out2[7] = dot(uint4(100, 52, 210, 75), uint4(25, 43, 16, 62));
}
//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: X0
Format: Float32
Stride: 16
Data: [ 1.125, -2.5, -4.75, 6.625 ]
- Name: Y0
Format: Float32
Stride: 16
Data: [ 7.29, 3.14, -1.1, -3.5 ]
- Name: X1
Format: Int32
Stride: 16
Data: [ 100, -52, -210, 75 ]
- Name: Y1
Format: Int32
Stride: 16
Data: [ 25, 43, -16, -62 ]
- Name: X2
Format: UInt32
Stride: 16
Data: [ 100, 52, 210, 75 ]
- Name: Y2
Format: UInt32
Stride: 16
Data: [ 25, 43, 16, 62 ]
- Name: Out0
Format: Float32
Stride: 4
ZeroInitSize: 32
- Name: ExpectedOut0
Format: Float32
Stride: 4
Data: [ 8.20125, 8.20125, 0.35125, 0.35125, 5.57625, 5.57625, -17.61125, -17.61125 ]
- Name: Out1
Format: Int32
Stride: 4
ZeroInitSize: 32
- Name: ExpectedOut1
Format: Int32
Stride: 4
Data: [ 2500, 2500, 264, 264, 3624, 3624, -1026, -1026 ]
- Name: Out2
Format: UInt32
Stride: 4
ZeroInitSize: 32
- Name: ExpectedOut2
Format: UInt32
Stride: 4
Data: [ 2500, 2500, 4736, 4736, 8096, 8096, 12746, 12746 ]
Results:
- Result: Test0
Rule: BufferFloatEpsilon
Epsilon: 0.008
Actual: Out0
Expected: ExpectedOut0
- Result: Test1
Rule: BufferExact
Actual: Out1
Expected: ExpectedOut1
- Result: Test2
Rule: BufferExact
Actual: Out2
Expected: ExpectedOut2
DescriptorSets:
- Resources:
- Name: X0
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Y0
Kind: StructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: X1
Kind: StructuredBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
- Name: Y1
Kind: StructuredBuffer
DirectXBinding:
Register: 3
Space: 0
VulkanBinding:
Binding: 3
- Name: X2
Kind: StructuredBuffer
DirectXBinding:
Register: 4
Space: 0
VulkanBinding:
Binding: 4
- Name: Y2
Kind: StructuredBuffer
DirectXBinding:
Register: 5
Space: 0
VulkanBinding:
Binding: 5
- Name: Out0
Kind: RWStructuredBuffer
DirectXBinding:
Register: 6
Space: 0
VulkanBinding:
Binding: 6
- Name: Out1
Kind: RWStructuredBuffer
DirectXBinding:
Register: 7
Space: 0
VulkanBinding:
Binding: 7
- Name: Out2
Kind: RWStructuredBuffer
DirectXBinding:
Register: 8
Space: 0
VulkanBinding:
Binding: 8
#--- end

# https://github.com/llvm/llvm-project/issues/149561
# XFAIL: Clang-Vulkan

# RUN: split-file %s %t
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
86 changes: 86 additions & 0 deletions test/Feature/HLSLLib/dot.fp16.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#--- source.hlsl
StructuredBuffer<half4> X : register(t0);
StructuredBuffer<half4> Y : register(t1);

RWStructuredBuffer<half> Out : register(u2);


[numthreads(1,1,1)]
void main() {
Out[0] = dot(X[0].x, Y[0].x);
Out[1] = dot(half(1.125), half(7.29));

Out[2] = dot(X[0].xy, Y[0].xy);
Out[3] = dot(half2(1.125, -2.5), half2(7.29, 3.14));

Out[4] = dot(X[0].xyz, Y[0].xyz);
Out[5] = dot(half3(1.125, -2.5, -4.75), half3(7.29, 3.14, -1.1));

Out[6] = dot(X[0], Y[0]);
Out[7] = dot(half4(1.125, -2.5, -4.75, 6.625), half4(7.29, 3.14, -1.1, -3.5));
}
//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: X
Format: Float16
Stride: 8
Data: [ 0x3c80, 0xc100, 0xc4c0, 0x46a0 ]
# [ 1.125, -2.5, -4.75, 6.625 ]
- Name: Y
Format: Float16
Stride: 8
Data: [ 0x474a, 0x4247, 0xbc66, 0xc300 ]
# [ 7.29, 3.14, -1.1, -3.5 ]
- Name: Out
Format: Float16
Stride: 2
ZeroInitSize: 16
- Name: ExpectedOut
Format: Float16
Stride: 2
Data: [ 0x481a, 0x481a, 0x359f, 0x359f, 0x4594, 0x4594, 0xcc67, 0xcc67 ]
# [ 8.20125, 8.20125, 0.35125, 0.35125, 5.57625, 5.57625, -17.61125, -17.61125 ]
Results:
- Result: Test1
Rule: BufferFloatEpsilon
Epsilon: 0.008
Actual: Out
Expected: ExpectedOut
DescriptorSets:
- Resources:
- Name: X
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Y
Kind: StructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: Out
Kind: RWStructuredBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
#--- end

# https://github.com/llvm/llvm-project/issues/149561
# XFAIL: Clang-Vulkan

# REQUIRES: Half
# RUN: split-file %s %t
# RUN: %dxc_target -enable-16bit-types -T cs_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
83 changes: 83 additions & 0 deletions test/Feature/HLSLLib/dot.fp64.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#--- source.hlsl
StructuredBuffer<double> X : register(t0);
StructuredBuffer<double> Y : register(t1);

RWStructuredBuffer<double> Out : register(u2);


[numthreads(1,1,1)]
void main() {
Out[0] = dot(X[0], Y[0]);
Out[1] = dot(double(1.125), double(7.29));

Out[2] = dot(X[1], Y[1]);
Out[3] = dot(double(-2.5), double(3.14));

Out[4] = dot(X[2], Y[2]);
Out[5] = dot(double(-4.75), double(-1.1));

Out[6] = dot(X[3], Y[3]);
Out[7] = dot(double(6.625), double(-3.5));
}
//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: X
Format: Float64
Stride: 8
Data: [ 1.125, -2.5, -4.75, 6.625 ]
- Name: Y
Format: Float64
Stride: 8
Data: [ 7.29, 3.14, -1.1, -3.5 ]
- Name: Out
Format: Float64
Stride: 8
ZeroInitSize: 64
- Name: ExpectedOut
Format: Float64
Stride: 8
Data: [ 8.20125, 8.20125, -7.85, -7.85, 5.225, 5.225, -23.1875, -23.1875 ]
Results:
- Result: Test0
Rule: BufferFloatEpsilon
Epsilon: 0.008
Actual: Out
Expected: ExpectedOut
DescriptorSets:
- Resources:
- Name: X
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Y
Kind: StructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: Out
Kind: RWStructuredBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
#--- end

# https://github.com/llvm/llvm-project/issues/149561
# XFAIL: Clang-Vulkan

# REQUIRES: Double
# RUN: split-file %s %t
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
Loading
Loading