diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2022-12-12 17:33:44 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-12 14:33:44 -0800 |
| commit | 9d048351d283f8df2a68aca52b3573dcbb8cdb9b (patch) | |
| tree | 71b869fd3d460193a1dccc77b9c0b6e3511ab53b /tests | |
| parent | c2dc1a86ed2f5e160749fe9f99b70db6c3e4d7a6 (diff) | |
Added support for nested calls (#2562)
* Added initial support for nested calls
* removed comments
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/reverse-nested-calls.slang | 29 | ||||
| -rw-r--r-- | tests/autodiff/reverse-nested-calls.slang.expected.txt | 6 | ||||
| -rw-r--r-- | tests/autodiff/reverse-struct-types.slang | 23 | ||||
| -rw-r--r-- | tests/autodiff/reverse-struct-types.slang.expected.txt | 2 |
4 files changed, 37 insertions, 23 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 +} diff --git a/tests/autodiff/reverse-nested-calls.slang.expected.txt b/tests/autodiff/reverse-nested-calls.slang.expected.txt new file mode 100644 index 000000000..0a39c4da6 --- /dev/null +++ b/tests/autodiff/reverse-nested-calls.slang.expected.txt @@ -0,0 +1,6 @@ +type: float +24.000000 +0.000000 +0.000000 +0.000000 +0.000000 diff --git a/tests/autodiff/reverse-struct-types.slang b/tests/autodiff/reverse-struct-types.slang index 699e50480..d2b52a008 100644 --- a/tests/autodiff/reverse-struct-types.slang +++ b/tests/autodiff/reverse-struct-types.slang @@ -9,27 +9,6 @@ struct A : IDifferentiable { float x; float y; - - [__unsafeForceInlineEarly] - static Differential dzero() - { - Differential b = {0.0, float.dzero()}; - return b; - } - - [__unsafeForceInlineEarly] - static Differential dadd(Differential a, Differential b) - { - Differential o = {a.x + b.x, 0.0}; - return o; - } - - [__unsafeForceInlineEarly] - static Differential dmul(This a, Differential b) - { - Differential o = {a.x * b.x, 0.0}; - return o; - } }; typedef DifferentialPair<A> dpA; @@ -56,7 +35,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) A.Differential dout = {1.0, 1.0}; __bwd_diff(f)(dpa, dout); - outputBuffer[0] = dpa.d.x; // Expect: 10 + outputBuffer[0] = dpa.d.x; // Expect: 7 outputBuffer[1] = dpa.d.y; // Expect: 0 } } diff --git a/tests/autodiff/reverse-struct-types.slang.expected.txt b/tests/autodiff/reverse-struct-types.slang.expected.txt index 82bc8f733..b94f4fec6 100644 --- a/tests/autodiff/reverse-struct-types.slang.expected.txt +++ b/tests/autodiff/reverse-struct-types.slang.expected.txt @@ -1,5 +1,5 @@ type: float -5.000000 +7.000000 0.000000 0.000000 0.000000 |
