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 KiB50 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 x;
13
14    [ForwardDifferentiable]
15    float getVal(float y){ return x * x + y * y; }
16
17    [ForwardDifferentiable]
18    [NoDiffThis]
19    float getVal2(float y) { return x * x + y * y; }
20
21    [ForwardDifferentiable]
22    static float f(A obj, float y)
23    {
24        return obj.getVal(y);
25    }
26
27    [ForwardDifferentiable]
28    static float f2(A obj, float y)
29    {
30        return obj.getVal2(y);
31    }
32}
33
34
35[numthreads(1, 1, 1)]
36void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
37{
38    A a;
39    a.x = 2.0;
40    A.Differential ad;
41    ad.x = 1.0;
42
43    let rs = __fwd_diff(A.f)(DifferentialPair<A>(a, ad), dpfloat(3.0, 1.0));
44    outputBuffer[0] = rs.p; // Expect: 13.0
45    outputBuffer[1] = rs.d; // Expect: 10.0
46
47    let rs2 = __fwd_diff(A.f2)(DifferentialPair<A>(a, ad), dpfloat(3.0, 1.0));
48    outputBuffer[2] = rs2.p; // Expect: 13.0
49    outputBuffer[3] = rs2.d; // Expect: 6.0
50}