yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Harsh Aggarwal (NVIDIA)Fix 7723 - Add autodiff tests (#7919)d10732742

master
1.4 KiB43 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute  -output-using-type
2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
3//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
4//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
5
6//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
7RWStructuredBuffer<float> outputBuffer;
8
9[ForwardDifferentiable]
10float3x3 g(float3x3 x, float3x3 y)
11{
12    float3x3 a = x + y;
13    float3x3 b = x - y;
14    return a * b + 2 * x * y;
15}
16
17[ForwardDifferentiable]
18float h(float2x2 x, float2x2 y)
19{
20    let t = mul(x, y);
21    return t[0][0] + t[0][1] + t[1][0] + t[1][1];
22}
23
24[numthreads(1, 1, 1)]
25void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
26{
27    float3x3 a = float3x3(2.0);
28    float3x3 b = float3x3(1.5);
29    float3x3 da = float3x3(1.0);
30
31    outputBuffer[0] = __fwd_diff(g)(
32                          diffPair(a, da),
33                          diffPair(b, da)).d._11; // Expect: 8
34
35    float2x2 l = float2x2(1.0, 2.0, 3.0, 4.0);
36    float2x2 r = float2x2(10.0, 11.0, 12.0, 13.0);
37    float2x2 d = float2x2(1.0, 0.0, 1.0, 1.0);
38    
39    //float2x2 epsilon = d * 0.001f;
40    //outputBuffer[1] = (h(l + epsilon, r + epsilon) - h(l - epsilon, r - epsilon)) / (epsilon[0][0] * 2.0));
41
42    outputBuffer[1] = __fwd_diff(h)(diffPair(l, d), diffPair(r, d)).d; // Expect 83.0
43}