yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
2.2 KiB84 linesraw
1//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -dx12 -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -shaderobj -output-using-type
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8typedef DifferentialPair<float> dpfloat;
9
10[BackwardDifferentiable]
11float diffAsinh(float x)
12{
13    return asinh(x);
14}
15
16[BackwardDifferentiable]
17float diffAcosh(float x)
18{
19    return acosh(x);
20}
21
22[BackwardDifferentiable]
23float diffAtanh(float x)
24{
25    return atanh(x);
26}
27
28[numthreads(1, 1, 1)]
29[shader("compute")]
30void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
31{
32    var index = 0U;
33
34    let sinhValue = 2;
35    {
36        // Expected: 1 / sqrt(x^2 + 1) = 1 / sqrt(4 + 1) = 0.447214
37        // CHECK: 0.447214
38        dpfloat dpx = dpfloat(sinhValue, 1.0);
39        dpfloat res = __fwd_diff(diffAsinh)(dpx);
40        outputBuffer[index++] = res.d;
41    }
42    {
43        // Check backward mode agrees with forward
44        // CHECK: 0.447214
45        dpfloat dpx = diffPair(sinhValue);
46        __bwd_diff(diffAsinh)(dpx, 1.0);
47        outputBuffer[index++] = dpx.d;
48    }
49
50    let coshValue = 4;
51    {
52        // Expected: 1 / sqrt(x^2 + 1) = 1 / sqrt(16 - 1) = 0.258199
53        // CHECK: 0.258199
54        dpfloat dpx = dpfloat(coshValue, 1.0);
55        dpfloat res = __fwd_diff(diffAcosh)(dpx);
56        outputBuffer[index++] = res.d;
57    }
58    {
59        // Check backward mode agrees with forward
60        // CHECK: 0.258199
61        dpfloat dpx = diffPair(coshValue);
62        __bwd_diff(diffAcosh)(dpx, 1.0);
63        outputBuffer[index++] = dpx.d;
64    }
65
66
67    let tanhValue = 0.5;
68    {
69        // Expected: 1 / (1 - x^2) = 1 / (1 - 0.25) = 1.333...
70        // CHECK: 1.3333
71        dpfloat dpx = dpfloat(tanhValue, 1.0);
72        dpfloat res = __fwd_diff(diffAtanh)(dpx);
73        outputBuffer[index++] = res.d;
74    }
75    {
76        // Check backward mode agrees with forward
77        // CHECK: 1.3333
78        dpfloat dpx = diffPair(tanhValue);
79        __bwd_diff(diffAtanh)(dpx, 1.0);
80        outputBuffer[index++] = dpx.d;
81    }
82}
83
84