blob: 9ef69ea346a92a2d3511fdc6d485cce73324da2e (
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
34
35
36
37
38
39
40
|
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;
typedef DifferentialPair<float> dpfloat;
typedef DifferentialPair<float2> dpfloat2;
typedef DifferentialPair<float3> dpfloat3;
[ForwardDifferentiable]
float diffSqrt(float x)
{
return sqrt(x);
}
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
{
dpfloat dpx = dpfloat(2.0, 1.0);
dpfloat res = __fwd_diff(diffSqrt)(dpx);
outputBuffer[0] = res.p; // Expect: 1.414214
outputBuffer[1] = res.d; // Expect: 0.353553
}
{
dpfloat dpx = dpfloat(100.0, -3.0);
dpfloat res = __fwd_diff(diffSqrt)(dpx);
outputBuffer[2] = res.p; // Expect: 10.000000
outputBuffer[3] = res.d; // Expect: -0.150000
}
{
dpfloat dpx = dpfloat(0.0, 1.0);
dpfloat res = __fwd_diff(diffSqrt)(dpx);
outputBuffer[4] = res.p; // Expect: 0.000000
outputBuffer[5] = res.d; // Expect: 0.000000
}
}
|