summaryrefslogtreecommitdiff
path: root/tests/autodiff/high-order-forward-diff.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-11-04 09:36:23 -0700
committerGitHub <noreply@github.com>2022-11-04 09:36:23 -0700
commitc6e6b7a9177bf4f7fc2f05da36c5952979006d78 (patch)
tree6db694b5b4bf94ce48678c73921676f9d305614d /tests/autodiff/high-order-forward-diff.slang
parent015bde8d5a46f32979c00dbb1feb4b3d80729c44 (diff)
Higher order differentiation. (#2487)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/autodiff/high-order-forward-diff.slang')
-rw-r--r--tests/autodiff/high-order-forward-diff.slang17
1 files changed, 13 insertions, 4 deletions
diff --git a/tests/autodiff/high-order-forward-diff.slang b/tests/autodiff/high-order-forward-diff.slang
index fde659227..94b4d2a0d 100644
--- a/tests/autodiff/high-order-forward-diff.slang
+++ b/tests/autodiff/high-order-forward-diff.slang
@@ -1,16 +1,22 @@
-//DTEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
-//DTEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+//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], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;
[ForwardDifferentiable]
-float f(float x)
+float mySqr(float x)
{
return x * x;
}
[ForwardDifferentiable]
+float f(float x)
+{
+ return mySqr(x * x);
+}
+
+[ForwardDifferentiable]
float df(float x)
{
return __fwd_diff(f)(DifferentialPair<float>(x, 1.0)).d();
@@ -19,5 +25,8 @@ float df(float x)
[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
+ // Given f(x) = x^4,
+ // f''(x) = 12 * x^2
+ // Expect f''(4) = 192
+ outputBuffer[0] = __fwd_diff(df)(DifferentialPair<float>(4.0, 1.0)).d();
}