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.6 KiB48 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]
10[PreferRecompute]
11float get_thread_5_value(float v, uint group_thread_id)
12{
13    if(group_thread_id == 5)
14    {
15        s_shared = detach(v);
16        // CHECK: tests/autodiff/warn-on-prefer-recompute-side-effects.slang([[# @LINE-5]]): warning 42050: get_thread_5_value has [PreferRecompute] and may have side effects. side effects may execute multiple times. use [PreferRecompute(SideEffectBehavior.Allow)], or mark function with [__NoSideEffect]
17        // CHECK: float get_thread_5_value(float v, uint group_thread_id)
18        // CHECK:       ^~~~~~~~~~~~~~~~~~
19    }
20    GroupMemoryBarrierWithGroupSync();
21    return s_shared;
22}
23
24[BackwardDifferentiable]
25[PreferRecompute(SideEffectBehavior.Allow)] // Suppress warning here
26float get_thread_6_value(float v, uint group_thread_id)
27{
28    if (group_thread_id == 6)
29    {
30        s_shared = detach(v);
31        // CHECK-NOT: warning 42050
32
33    }
34    GroupMemoryBarrierWithGroupSync();
35    return s_shared;
36}
37
38[shader("compute")]
39[numthreads(128, 1, 1)]
40void computeMain(uint3 group_thread_id: SV_GroupThreadID, uint3 dispatch_thread_id: SV_DispatchThreadID)
41{
42    DifferentialPair<float> value = diffPair(3.f, 0.f);
43
44    bwd_diff(get_thread_5_value)(value, group_thread_id.x, 1.0f);
45    bwd_diff(get_thread_6_value)(value, group_thread_id.x, 1.0f);
46
47    outputBuffer[dispatch_thread_id.x] = value.d;
48}