summaryrefslogtreecommitdiff
path: root/tests/autodiff/reverse-nested-calls.slang
diff options
context:
space:
mode:
Diffstat (limited to 'tests/autodiff/reverse-nested-calls.slang')
-rw-r--r--tests/autodiff/reverse-nested-calls.slang29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-nested-calls.slang b/tests/autodiff/reverse-nested-calls.slang
new file mode 100644
index 000000000..2b55efd60
--- /dev/null
+++ b/tests/autodiff/reverse-nested-calls.slang
@@ -0,0 +1,29 @@
+//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], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+typedef DifferentialPair<float> dpfloat;
+typedef float.Differential dfloat;
+
+[BackwardDifferentiable]
+float g(float y)
+{
+ return 4.0f * y;
+}
+
+[BackwardDifferentiable]
+float f(float x)
+{
+ return 3.0f * g(2.0f * x);
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ dpfloat dpa = dpfloat(1.0, 0.0);
+
+ __bwd_diff(f)(dpa, 1.0f);
+ outputBuffer[0] = dpa.d; // Expect: 24.0
+}