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
869 B32 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8[BackwardDifferentiable]
9bool conditionFunc(no_diff float a, inout float x)
10{
11    x = x * a;
12    return x > 100.f;
13}
14
15[BackwardDifferentiable]
16float outerFunc(no_diff float a, float x)
17{
18    if (conditionFunc(a, x))
19        return x;
20    else
21        return -x;
22}
23
24[numthreads(1, 1, 1)]
25void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
26{
27    float a = 10.0;
28    DifferentialPair<float> dpx = DifferentialPair<float>(4.f, 1.f);
29    __bwd_diff(outerFunc)(a, dpx, 1.0);
30
31    outputBuffer[0] = dpx.d;
32}