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
2.0 KiB59 linesraw
1//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute -output-using-type
4//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
5
6//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer
7RWStructuredBuffer<float> outputBuffer;
8
9typedef DifferentialPair<float> dpfloat;
10typedef DifferentialPair<float2> dpfloat2;
11typedef DifferentialPair<float3> dpfloat3;
12
13[BackwardDifferentiable]
14float diffAbs(float x)
15{
16    return abs(x);
17}
18
19[BackwardDifferentiable]
20float3 diffAbs(float3 x)
21{
22    return abs(x);
23}
24
25[numthreads(1, 1, 1)]
26void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
27{
28    {
29        dpfloat dpx = dpfloat(-3.0, 2.0);
30        dpfloat res = __fwd_diff(diffAbs)(dpx);
31        outputBuffer[0] = res.p;               // Expect: 3.000000
32        outputBuffer[1] = res.d;               // Expect: -2.000000
33    }
34
35    {
36        dpfloat3 dpx = dpfloat3(float3(2.f, -3.f, -1.f), float3(-2.f, 3.f, -1.f));
37        dpfloat3 res = __fwd_diff(diffAbs)(dpx);
38        outputBuffer[2] = res.p[0];            // Expect: 2.000000
39        outputBuffer[3] = res.d[0];            // Expect: -2.000000
40        outputBuffer[4] = res.p[1];            // Expect: 3.000000
41        outputBuffer[5] = res.d[1];            // Expect: -3.000000
42        outputBuffer[6] = res.p[2];            // Expect: 1.000000
43        outputBuffer[7] = res.d[2];            // Expect: 1.000000
44    }
45
46    {
47        dpfloat dpx = dpfloat(-3.0, 0.0);
48        __bwd_diff(diffAbs)(dpx, 2.0);
49        outputBuffer[8] = dpx.d; // Expect: -2.000000
50    }
51
52    {
53        dpfloat3 dpx = dpfloat3(float3(2.f, -3.f, -1.f), float3(0.f, 0.f, 0.f));
54        __bwd_diff(diffAbs)(dpx, float3(1.f, 1.f, 1.f));        
55        outputBuffer[9] = dpx.d[0];  // Expect: 1.000000
56        outputBuffer[10] = dpx.d[1]; // Expect: -1.000000
57        outputBuffer[11] = dpx.d[2]; // Expect: -1.000000
58    }
59}