summaryrefslogtreecommitdiff
path: root/tests/autodiff/high-order-forward-diff.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-11-01 08:46:57 -0700
committerGitHub <noreply@github.com>2022-11-01 08:46:57 -0700
commitcbc1eff56057f199183bb7c17d8a360326512367 (patch)
tree487865e928cd2ceecbb509f0bfd06aa8d9584411 /tests/autodiff/high-order-forward-diff.slang
parentb707a07b1de3535cb0a8ccb6fe2ed4afa4a016d1 (diff)
Make `DifferentialPair` able to nest. (#2477)
Diffstat (limited to 'tests/autodiff/high-order-forward-diff.slang')
-rw-r--r--tests/autodiff/high-order-forward-diff.slang23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/autodiff/high-order-forward-diff.slang b/tests/autodiff/high-order-forward-diff.slang
new file mode 100644
index 000000000..fde659227
--- /dev/null
+++ b/tests/autodiff/high-order-forward-diff.slang
@@ -0,0 +1,23 @@
+//DTEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+//DTEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+[ForwardDifferentiable]
+float f(float x)
+{
+ return x * x;
+}
+
+[ForwardDifferentiable]
+float df(float x)
+{
+ return __fwd_diff(f)(DifferentialPair<float>(x, 1.0)).d();
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ outputBuffer[0] = __fwd_diff(df)(DifferentialPair<float>(1.0, 1.0)).d(); // Expect: 2.0
+}