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.1 KiB42 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], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8typedef DifferentialPair<float> dpfloat;
9
10struct A : IDifferentiable
11{
12    float p;
13    float3 q;
14}
15
16[ForwardDifferentiable]
17void g(A a, inout A aout)
18{
19    float t = a.p + a.q.y * a.q.x;
20    aout.p = aout.p + t;
21    aout.q = aout.q * t;
22}
23
24[numthreads(1, 1, 1)]
25void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
26{
27    float p = 1.0;
28    float3 q = float3(1.0, 2.0, 3.0);
29
30    float dp = 1.0;
31    float3 dq = float3(1.0, 0.5, 0.25);
32
33    DifferentialPair<A> dpa = DifferentialPair<A>({p, q}, {dp, dq});
34
35    __fwd_diff(g)(DifferentialPair<A>( { p, q }, { dp, dq }), dpa);
36
37    outputBuffer[0] = dpa.p.p; // Expect: 4.0
38    outputBuffer[1] = dpa.d.q.x; // Expect: 6.5
39    outputBuffer[2] = dpa.d.q.y; // Expect: 8.5
40    outputBuffer[3] = dpa.d.q.z; // Expect: 11.25
41
42}