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.2 KiB49 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
10[ForwardDifferentiable]
11void g(float x, float y, inout float z)
12{
13    float m = x + y;
14    float n = x - y;
15    z += m * n + 2 * x * y;
16}
17
18[ForwardDifferentiable]
19void h(float x, float y, inout float z)
20{
21    float m = x + y;
22    float n = x - y;
23    z = z + m * n + 2 * x * y;
24}
25
26
27[numthreads(1, 1, 1)]
28void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
29{
30    float x = 2.0;
31    float y = 3.5;
32    float z = 1.0;
33    float dx = 1.0;
34    float dy = 0.5;
35    float dz = 2.5;
36
37    dpfloat dpz = dpfloat(z, dz);
38
39    __fwd_diff(h)(dpfloat(x, dx), dpfloat(y, dy), dpz);
40
41    outputBuffer[0] = dpz.d; // Expect: 12.0
42    outputBuffer[1] = dpz.p; // Expect: 6.75
43
44    __fwd_diff(g)(dpfloat(x, dx), dpfloat(y, dy), dpz);
45
46    outputBuffer[2] = dpz.d; // Expect: 21.5
47    outputBuffer[3] = dpz.p; // Expect: 12.5
48
49}