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.3 KiB43 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=CHECK): -target hlsl -profile cs_5_0 -entry computeMain -line-directive-mode none
5
6//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
7RWStructuredBuffer<float> outputBuffer;
8
9[BackwardDifferentiable]
10float sin_series(float x, int iterations)
11{
12    float result = x;
13    float term = x;
14    int i = 1;
15    [MaxIters(30)]
16    do
17    {
18        term *= -1.0f * x * x / ((2 * i) * (2 * i + 1));
19        i += 2;
20        i++;
21        result += term;
22        i -= 2;
23    } while (i < iterations);
24    return result;
25}
26
27// Check that the intermediate context of sin_series does not have an array for `i`.
28// This test inparticular checks that can identify induction variables with
29// more than one operation applied to them during the loop
30
31// CHECK: struct s_bwd_prop_sin_series_Intermediates
32// CHECK-NOT: int {{[A-Za-z0-9_]+}}[{{.*}}]
33// CHECK: }
34
35[numthreads(1, 1, 1)]
36void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
37{
38    var x = diffPair(float.getPi(), 1.0);
39
40    __bwd_diff(sin_series)(x, 30, 1.0f);
41
42    outputBuffer[0] = x.d; // -1.0
43}