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.0 KiB41 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
5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8typedef DifferentialPair<float> dpfloat;
9typedef float.Differential dfloat;
10
11[BackwardDifferentiable]
12bool test_single_branch(float y, out float o)
13{
14    if (y > 0.5)
15    {
16        o = y * 2.0f;
17        return true;
18    }
19
20    o = y + 1.0f;
21
22    return false;    
23}
24
25[numthreads(1, 1, 1)]
26void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
27{
28    {
29        dpfloat dpa = dpfloat(1.0, 0.0);
30
31        __bwd_diff(test_single_branch)(dpa, 1.0f);
32        outputBuffer[0] = dpa.d; // Expect: 2.0
33    }
34
35    {
36        dpfloat dpa = dpfloat(0.4, 0.0);
37        
38        __bwd_diff(test_single_branch)(dpa, 1.0f);
39        outputBuffer[1] = dpa.d; // Expect: 1.0
40    }
41}