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
949 B36 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-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 float.Differential dfloat;
9
10struct Params
11{
12    float vv;
13}
14
15[Differentiable]
16float3 f(float3 x, uint2 v, Params p)
17{
18    v.x = 1 + int(p.vv);
19
20    x.y = x.x * x.x;
21    return x;
22}
23
24[numthreads(1, 1, 1)]
25void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
26{
27    {
28        var dpa = diffPair(float3(4.0, 2.0, 3.0));
29        Params p;
30        p.vv = 0.0;
31        __bwd_diff(f)(dpa, uint2(1,2), p, float3(1.0,1.0,1.0));
32
33        // CHECK: 9.0
34        outputBuffer[0] = dpa.d.x; // Expect: 9.0
35    }
36}