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.3 KiB46 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-cuda -compute -shaderobj -output-using-type
3//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-vk -compute -shaderobj -output-using-type
4//TEST:SIMPLE(filecheck=CHECK):-stage compute -entry computeMain -target hlsl
5
6//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0], stride=4):out,name=outputBuffer
7RWStructuredBuffer<float> outputBuffer;
8
9typedef DifferentialPair<float> dpfloat;
10typedef float.Differential dfloat;
11
12// CHECK-NOT: void mySqr{{.*}}(
13
14// Test that calls to a ForceInline function stil get correct custom derivative.
15[BackwardDerivative(bwd_mySqr)]
16[ForceInline]
17void mySqr(float x, out float y)
18{
19    y = x * x;
20}
21
22void bwd_mySqr(inout DifferentialPair<float> dpx, in float.Differential dy)
23{
24    dpx = DifferentialPair<float>(dpx.p, 1001.0);
25}
26
27[Differentiable]
28void myF(float x, out float y)
29{
30    mySqr(x, y);
31}
32
33[numthreads(1, 1, 1)]
34void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
35{
36    {
37        dpfloat dpa = dpfloat(2.0, 1.0);
38        __bwd_diff(myF)(dpa, 1.0);
39        // BUFFER: 1001.0
40        outputBuffer[0] = dpa.d;
41
42        float o;
43        myF(1.0, o);
44        outputBuffer[1] = o;
45    }
46}