From cbc1eff56057f199183bb7c17d8a360326512367 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 1 Nov 2022 08:46:57 -0700 Subject: Make `DifferentialPair` able to nest. (#2477) --- tests/autodiff/high-order-forward-diff.slang | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/autodiff/high-order-forward-diff.slang (limited to 'tests/autodiff/high-order-forward-diff.slang') 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 outputBuffer; + +[ForwardDifferentiable] +float f(float x) +{ + return x * x; +} + +[ForwardDifferentiable] +float df(float x) +{ + return __fwd_diff(f)(DifferentialPair(x, 1.0)).d(); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + outputBuffer[0] = __fwd_diff(df)(DifferentialPair(1.0, 1.0)).d(); // Expect: 2.0 +} -- cgit v1.2.3