blob: 3cd9bf5dd536d234252e29e0871e0df7848976be (
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
|
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;
typedef DifferentialPair<float> dpfloat;
typedef float.Differential dfloat;
[BackwardDerivative(bwd_f)]
void f(float x, out float y)
{
y = x * x;
}
void bwd_f(inout DifferentialPair<float> dpx, in float.Differential dy)
{
dpx = DifferentialPair<float>(dpx.p, 2.0 * dpx.p * dy);
}
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
{
float o;
f(3.0, o);
dpfloat dpa = dpfloat(2.0, 1.0);
dpfloat dpo = dpfloat(2.0, 1.0);
__bwd_diff(f)(dpa, o);
outputBuffer[0] = o; // Expect: 9
outputBuffer[1] = dpa.d; // Expect: 36
}
}
|