summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/force-no-diff-this.slang
blob: ae1464ffb9327b64d5f70c0b57afc465a1477bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):

struct MyStruct<T> where T: __BuiltinFloatingPointType
{
    float a;
    __init(float a) { this.a = a;}

    [Differentiable]
    T eval(T x)
    {
        //CHECK: ([[# @LINE+1]]): warning 31159
        return exp(x * T(a) * T(a));
    }

    [Differentiable]
    [NoDiffThis]
    T eval1(T x)
    {
        //CHECK-NOT: ([[# @LINE+1]]): warning 31159
        return exp(x * T(a) * T(a));
    }
};

[Differentiable]
float evalFunc(float x)
{
    MyStruct<float> s = {x};
    return s.eval(x) + s.eval1(x);
}

RWStructuredBuffer<float> output;

[shader("compute")]
[numthreads(1,1,1)]
void computeMain(uint id : SV_DispatchThreadID)
{
    var x = diffPair(2.0f);
    bwd_diff(evalFunc)(x, 1.0f);

    output[0] = x.d;
}