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.1 KiB37 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -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    [MaxIters(30)]
15    for (int i = 1; i < iterations; i++)
16    {
17        term *= -1.0f * x * x / ((2 * i) * (2 * i + 1));
18        result += term;
19    }
20    return result;
21}
22
23// Check that the intermediate context of sin_series does not have an array for `i`.
24
25// CHECK: struct s_bwd_prop_sin_series_Intermediates
26// CHECK-NOT: int {{[A-Za-z0-9_]+}}[{{.*}}]
27// CHECK: }
28
29[numthreads(1, 1, 1)]
30void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
31{
32    var x = diffPair(float.getPi(), 1.0);
33
34    __bwd_diff(sin_series)(x, 30, 1.0f);
35
36    outputBuffer[0] = x.d; // -1.0
37}