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
2.0 KiB63 linesraw
1//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8typedef DifferentialPair<float> dpfloat;
9typedef DifferentialPair<float2> dpfloat2;
10typedef DifferentialPair<float3> dpfloat3;
11
12[BackwardDifferentiable]
13float diffDetach(float x)
14{
15    return detach(x);
16}
17
18[BackwardDifferentiable]
19float2 diffDetach(float2 x)
20{
21    return detach(x);
22}
23
24[BackwardDifferentiable]
25float3 diffDetach(float3 x)
26{
27    return detach(x);
28}
29
30[numthreads(1, 1, 1)]
31void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
32{
33    {
34        dpfloat dpx = dpfloat(-5.0, 1.0);
35        dpfloat res = __fwd_diff(diffDetach)(dpx);
36        outputBuffer[0] = res.p;               // Expect: -5.000000
37        outputBuffer[1] = res.d;               // Expect: 0.000000
38    }
39
40    {
41        dpfloat3 dpx = dpfloat3(float3(2.f, -3.f, -1.f), float3(-2.f, 3.f, -1.f));
42        dpfloat3 res = __fwd_diff(diffDetach)(dpx);
43        outputBuffer[2] = res.p[0];            // Expect: 2.000000
44        outputBuffer[3] = res.d[0];            // Expect: 0.000000
45        outputBuffer[4] = res.p[1];            // Expect: -3.000000
46        outputBuffer[5] = res.d[1];            // Expect: 0.000000
47        outputBuffer[6] = res.p[2];            // Expect: -1.000000
48        outputBuffer[7] = res.d[2];            // Expect: 0.000000
49    }
50
51    {
52        dpfloat dpx = dpfloat(-5.0, 1.0);
53        __bwd_diff(diffDetach)(dpx, 1.0);
54        outputBuffer[8] = dpx.d; // Expect: 0.000000
55    }
56
57    {
58        dpfloat2 dpx = dpfloat2(float2(1.0, -2.0), float2(1.0, 1.0));
59        __bwd_diff(diffDetach)(dpx, float2(2.0, -3.0));
60        outputBuffer[9] = dpx.d[0]; // Expect: 0.000000
61        outputBuffer[10] = dpx.d[1]; // Expect: 0.000000
62    }
63}