diff options
| author | Yong He <yonghe@outlook.com> | 2022-11-04 09:36:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-04 09:36:23 -0700 |
| commit | c6e6b7a9177bf4f7fc2f05da36c5952979006d78 (patch) | |
| tree | 6db694b5b4bf94ce48678c73921676f9d305614d /tests | |
| parent | 015bde8d5a46f32979c00dbb1feb4b3d80729c44 (diff) | |
Higher order differentiation. (#2487)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/generic-impl-jvp.slang | 6 | ||||
| -rw-r--r-- | tests/autodiff/getter-setter-multi.slang | 2 | ||||
| -rw-r--r-- | tests/autodiff/getter-setter.slang | 2 | ||||
| -rw-r--r-- | tests/autodiff/high-order-forward-diff.slang | 17 | ||||
| -rw-r--r-- | tests/autodiff/high-order-forward-diff.slang.expected.txt | 5 |
5 files changed, 23 insertions, 9 deletions
diff --git a/tests/autodiff/generic-impl-jvp.slang b/tests/autodiff/generic-impl-jvp.slang index 511e0b0d8..7f4c4313e 100644 --- a/tests/autodiff/generic-impl-jvp.slang +++ b/tests/autodiff/generic-impl-jvp.slang @@ -8,8 +8,8 @@ typedef float Real; typealias IDFloat = IFloat & IDifferentiable; -__generic<T, let N : int> -struct dvector +__generic<T : IDifferentiable, let N : int> +struct dvector : IDifferentiable { T values[N]; }; @@ -139,7 +139,7 @@ DifferentialPair<T> dot_jvp(dpvector<T, N> a, dpvector<T, N> b) } __generic<let N : int> -struct lineardvector +struct lineardvector : IDifferentiable { myvector<Real, N>.Differential val; diff --git a/tests/autodiff/getter-setter-multi.slang b/tests/autodiff/getter-setter-multi.slang index 3bf208e02..85b6a3c63 100644 --- a/tests/autodiff/getter-setter-multi.slang +++ b/tests/autodiff/getter-setter-multi.slang @@ -4,7 +4,7 @@ //TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<float> outputBuffer; -struct B +struct B : IDifferentiable { float3 z; float.Differential k[10]; diff --git a/tests/autodiff/getter-setter.slang b/tests/autodiff/getter-setter.slang index 5842654b5..a9e01b8c6 100644 --- a/tests/autodiff/getter-setter.slang +++ b/tests/autodiff/getter-setter.slang @@ -4,7 +4,7 @@ //TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<float> outputBuffer; -struct B +struct B : IDifferentiable { float z; }; 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(); } diff --git a/tests/autodiff/high-order-forward-diff.slang.expected.txt b/tests/autodiff/high-order-forward-diff.slang.expected.txt new file mode 100644 index 000000000..0f08247f0 --- /dev/null +++ b/tests/autodiff/high-order-forward-diff.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +192.000000 +0.000000 +0.000000 +0.000000 |
