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.5 KiB68 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 DifferentialPair<float3> dpfloat3;
10
11[ForwardDifferentiable]
12float f(float x)
13{
14    return x * x + x * x * x;
15}
16
17[ForwardDifferentiable]
18float f2(float x)
19{
20    return f(x);
21}
22
23float g(float x)
24{
25    return x * x + x * x * x;
26}
27
28[ForwardDifferentiable]
29float g2(float x)
30{
31    return no_diff(g(x));
32}
33
34struct A
35{
36    float o;
37
38    [ForwardDifferentiable]
39    [NoDiffThis]
40    float doSomethingDifferentiable(float b)
41    {
42        return o + b;
43    }
44
45    float doSomethingNotDifferentiable(float b)
46    {
47        return o * b;
48    }
49}
50
51[ForwardDifferentiable]
52float h2(A a, float k)
53{
54    float v = k * k;
55    return no_diff(a.doSomethingNotDifferentiable(k)) + v;
56}
57
58[numthreads(1, 1, 1)]
59void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
60{
61     {
62         outputBuffer[0] = f2(1.0); // Expect: 2.0
63         outputBuffer[1] = __fwd_diff(f2)(dpfloat(1.0, 1.0)).d; // Expect: 5.0
64         outputBuffer[2] = __fwd_diff(f2)(dpfloat(1.0, 1.0)).p; // Expect: 2.0
65         outputBuffer[3] = __fwd_diff(g2)(dpfloat(1.0, 1.0)).d; // Expect: 0.0
66         outputBuffer[4] = __fwd_diff(h2)({1.0}, DifferentialPair<float>(1.0, 2.0)).d; // Expect: 4.0
67    }
68}