summaryrefslogtreecommitdiffstats
path: root/tests/autodiff/warn-on-shared-memory-access.slang
blob: 829191d0eda576d861764104541a1a52f0e6f971 (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
//TEST:SIMPLE(filecheck=CHECK): -target hlsl -line-directive-mode none
//TEST:SIMPLE(filecheck=CHECK): -target cuda -line-directive-mode none

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;

groupshared float s_shared;

[BackwardDifferentiable]
float get_thread_5_value(float v, uint group_thread_id)
{
    if(group_thread_id == 5)
    {
        // Using 'detach(v)' makes the error go away
        s_shared = v;
        // CHECK: tests/autodiff/warn-on-shared-memory-access.slang([[# @LINE-1]]): error 41024: derivative is lost during assignment to non-differentiable location, use 'detach()' to clarify intention.
        // CHECK: s_shared = v;
        // CHECK:          ^
    }
    GroupMemoryBarrierWithGroupSync();
    return s_shared;
}

[shader("compute")]
[numthreads(128, 1, 1)]
void computeMain(uint3 group_thread_id: SV_GroupThreadID, uint3 dispatch_thread_id: SV_DispatchThreadID)
{
    DifferentialPair<float> value = diffPair(3.f, 0.f);

    bwd_diff(get_thread_5_value)(value, group_thread_id.x, 1.0f);

    outputBuffer[dispatch_thread_id.x] = value.d;
}