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.2 KiB46 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
9typedef DifferentialPair<float> dpfloat;
10typedef float.Differential dfloat;
11
12[BackwardDifferentiable]
13float test_single_branch(float y)
14{
15    float o;
16    if (y > 0.5)
17    {
18        o = y * 2.0f;
19    }
20    else
21    {
22        o = y + 1.0f;
23    }
24
25    return o;
26}
27
28[numthreads(1, 1, 1)]
29void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
30{
31    {
32        dpfloat dpa = dpfloat(1.0, 0.0);
33
34        __bwd_diff(test_single_branch)(dpa, 1.0f);
35        outputBuffer[0] = dpa.d; // Expect: 2.0
36    }
37
38    {
39        dpfloat dpa = dpfloat(0.4, 0.0);
40        
41        __bwd_diff(test_single_branch)(dpa, 1.0f);
42        outputBuffer[1] = dpa.d; // Expect: 1.0
43    }
44}
45
46//CHK: (0): note: no checkpoint contexts to report