diff options
Diffstat (limited to 'tests/autodiff')
| -rw-r--r-- | tests/autodiff/inout-custom-derivative.slang | 35 | ||||
| -rw-r--r-- | tests/autodiff/inout-custom-derivative.slang.expected.txt | 8 |
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/autodiff/inout-custom-derivative.slang b/tests/autodiff/inout-custom-derivative.slang new file mode 100644 index 000000000..76c9cb74f --- /dev/null +++ b/tests/autodiff/inout-custom-derivative.slang @@ -0,0 +1,35 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -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 + } +} diff --git a/tests/autodiff/inout-custom-derivative.slang.expected.txt b/tests/autodiff/inout-custom-derivative.slang.expected.txt new file mode 100644 index 000000000..07757c1f5 --- /dev/null +++ b/tests/autodiff/inout-custom-derivative.slang.expected.txt @@ -0,0 +1,8 @@ +type: float +9.000000 +36.000000 +0.000000 +0.000000 +0.000000 +0.000000 +0.000000 |
