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
996 B36 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 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8typedef DifferentialPair<float> dpfloat;
9typedef float.Differential dfloat;
10
11[BackwardDerivative(bwd_f)]
12void f(float x, out float y)
13{
14    y = x * x;
15}
16
17void bwd_f(inout DifferentialPair<float> dpx, in float.Differential dy)
18{
19    dpx = DifferentialPair<float>(dpx.p, 2.0 * dpx.p * dy);
20}
21
22[numthreads(1, 1, 1)]
23void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
24{
25    {
26        float o;
27        f(3.0, o);
28
29        dpfloat dpa = dpfloat(2.0, 1.0);
30        dpfloat dpo = dpfloat(2.0, 1.0);
31        __bwd_diff(f)(dpa, o);
32
33        outputBuffer[0] = o; // Expect: 9
34        outputBuffer[1] = dpa.d; // Expect: 36
35    }
36}