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
926 B33 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
5struct Buggy<let N : int>
6{
7    float m(float x) { return N * x; }
8
9    [BackwardDerivativeOf(m)]
10    void mDiff(inout DifferentialPair<float> x, float dResult)
11    {
12        updateDiff(x, N * dResult);
13    }
14}
15
16[Differentiable]
17float test(float x)
18{
19    Buggy<2> b;
20    return b.m(x);
21}
22
23//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
24RWStructuredBuffer<float> outputBuffer;
25
26[numthreads(1, 1, 1)]
27void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
28{
29    var a = diffPair(3.0);
30    __bwd_diff(test)(a, 1.0);
31    outputBuffer[dispatchThreadID.x] = a.d;
32    // CHECK: 2.0
33}