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 KiB36 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
8[ForwardDifferentiable]
9float mySqr(float x)
10{
11    return x * x;
12}
13
14[ForwardDifferentiable]
15float f(float x)
16{
17    return mySqr(x * x);
18}
19
20[numthreads(1, 1, 1)]
21void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
22{
23    // Given f(x) = x^4,
24    // f''(x) = 12 * x^2
25    // Expect f''(4) = 192
26    float.Differential t = 2;
27    outputBuffer[0] = __fwd_diff(__fwd_diff(f))(
28                          DifferentialPair<DifferentialPair<float>>(
29                              DifferentialPair<float>(4.0, 1.0), DifferentialPair<float>(1.0, 0.0))) .d.d;
30
31    // sin''(x) = cos'(x) = -sin(x).
32    // Expect sin''(Pi/2) = -1.
33    outputBuffer[1] = __fwd_diff(__fwd_diff(sin))(
34                          DifferentialPair<DifferentialPair<float>>(
35                              DifferentialPair<float>(float.getPi()/2, 1.0), DifferentialPair<float>(1.0, 0.0))).d.d; 
36}