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.6 KiB79 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
3//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
4//TEST:SIMPLE(filecheck=CHK):-target glsl -stage compute -entry computeMain -report-checkpoint-intermediates
5
6//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
7RWStructuredBuffer<float> outputBuffer;
8
9[BackwardDifferentiable]
10bool doWork(float x, out float y)
11{
12    bool retVal = false;
13    y = 0;
14    for (;;)
15    {
16        if (x == 0.0)
17            break;
18
19        bool exited = (x == 1.0);
20
21        y += x;
22
23        if (!exited)
24        {
25            if (x < 1.0)
26            {
27                float b = x * 2.0f;
28                y += b;
29                exited = true;
30            }
31        }
32        retVal = true;
33        break;
34    }
35    return retVal;
36}
37
38[BackwardDifferentiable]
39bool doWork2(float x, out float y)
40{
41    y = 0;
42
43    if (x == 0.0) return false;
44
45    [ForceUnroll]
46    for (int i = 0; i < 2; ++i)
47    {
48        if (x > 0.0)
49        {
50            y += x;
51
52            if (x == 1.0) break;
53
54            y += x;
55        }
56        else
57        {
58            y += x;
59        }
60    }
61    return true;
62}
63
64[numthreads(1, 1, 1)]
65void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
66{
67    {
68        var dpx = diffPair(0.5f, 1.0f);
69        __bwd_diff(doWork)(dpx, 1.0f);
70        outputBuffer[0] = dpx.d;
71    }
72    {
73        var dpx = diffPair(0.5f, 0.0f);
74        __bwd_diff(doWork2)(dpx, 1.0);
75        outputBuffer[1] = dpx.d;
76    }
77}
78
79//CHK: (0): note: no checkpoint contexts to report