yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Harsh Aggarwal (NVIDIA)Enable CUDA Test Enablement - Batch 1: Autodiff Tests (1-16) (#8139)c3df36043

master
1.1 KiB33 linesraw
1//TEST:SIMPLE(filecheck=CHECK): -target hlsl -line-directive-mode none
2//TEST:SIMPLE(filecheck=CHECK): -target cuda -line-directive-mode none
3
4//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
5RWStructuredBuffer<float> outputBuffer;
6
7groupshared float s_shared;
8
9[BackwardDifferentiable]
10float get_thread_5_value(float v, uint group_thread_id)
11{
12    if(group_thread_id == 5)
13    {
14        // Using 'detach(v)' makes the error go away
15        s_shared = v;
16        // 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.
17        // CHECK: s_shared = v;
18        // CHECK:          ^
19    }
20    GroupMemoryBarrierWithGroupSync();
21    return s_shared;
22}
23
24[shader("compute")]
25[numthreads(128, 1, 1)]
26void computeMain(uint3 group_thread_id: SV_GroupThreadID, uint3 dispatch_thread_id: SV_DispatchThreadID)
27{
28    DifferentialPair<float> value = diffPair(3.f, 0.f);
29
30    bwd_diff(get_thread_5_value)(value, group_thread_id.x, 1.0f);
31
32    outputBuffer[dispatch_thread_id.x] = value.d;
33}