diff options
| author | winmad <winmad.wlf@gmail.com> | 2023-02-07 22:30:00 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-07 22:30:00 -0800 |
| commit | b1d7dc0707406da69d94f3915fa48f39020b93ab (patch) | |
| tree | bb571884616aaf79fa663aec1eb8fcf92f5138cc /tests/autodiff-dstdlib/dstdlib-abs.slang | |
| parent | 4be623c52a6518eb86756a0369706c1d6670f6bb (diff) | |
Add backward derivatives for functions in diff.meta.slang (#2633)
* WIP: start adding backward derivatives
* Overhaul `transposeParameterBlock` to support `inout` params.
* Small bug fixes.
* Bug fix on differentiable intrinsic specialization.
* Fixes.
* Run autodiff tests on CPU.
* Clean up.
* Overhaul `transposeParameterBlock` to support `inout` params.
* Small bug fixes.
* Bug fix on differentiable intrinsic specialization.
* Fixes.
* Run autodiff tests on CPU.
* Clean up.
* More bug fixes.,
* WIP: working on detach
* Arithmetic simplifications and more IR clean up logic.
* WIP: adding detach and abs
* Fix detach and abs
* Fix.
* Add IR transform pass for cleaner code emit.
* Fix test cases.
* Fix type system logic for reference type.
* Add backward derivatives for functions that already have forward derivatives
* Fix changes
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Co-authored-by: Lifan Wu <lifanw@nvidia.com>
Diffstat (limited to 'tests/autodiff-dstdlib/dstdlib-abs.slang')
| -rw-r--r-- | tests/autodiff-dstdlib/dstdlib-abs.slang | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/tests/autodiff-dstdlib/dstdlib-abs.slang b/tests/autodiff-dstdlib/dstdlib-abs.slang index 0da2de4c7..b7988f573 100644 --- a/tests/autodiff-dstdlib/dstdlib-abs.slang +++ b/tests/autodiff-dstdlib/dstdlib-abs.slang @@ -1,21 +1,21 @@ //TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type //TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type -//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<float> outputBuffer; typedef DifferentialPair<float> dpfloat; typedef DifferentialPair<float2> dpfloat2; typedef DifferentialPair<float3> dpfloat3; -[ForwardDifferentiable] +[BackwardDifferentiable] float diffAbs(float x) { return abs(x); } -[ForwardDifferentiable] -float3 diffAbs3(float3 x) +[BackwardDifferentiable] +float3 diffAbs(float3 x) { return abs(x); } @@ -32,12 +32,26 @@ void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) { dpfloat3 dpx = dpfloat3(float3(2.f, -3.f, -1.f), float3(-2.f, 3.f, -1.f)); - dpfloat3 res = __fwd_diff(diffAbs3)(dpx); + dpfloat3 res = __fwd_diff(diffAbs)(dpx); outputBuffer[2] = res.p[0]; // Expect: 2.000000 outputBuffer[3] = res.d[0]; // Expect: -2.000000 outputBuffer[4] = res.p[1]; // Expect: 3.000000 outputBuffer[5] = res.d[1]; // Expect: -3.000000 - outputBuffer[6] = res.p[2]; // Expect: 1.000000 - outputBuffer[7] = res.d[2]; // Expect: 1.000000 + outputBuffer[6] = res.p[2]; // Expect: 1.000000 + outputBuffer[7] = res.d[2]; // Expect: 1.000000 + } + + { + dpfloat dpx = dpfloat(-3.0, 0.0); + __bwd_diff(diffAbs)(dpx, 2.0); + outputBuffer[8] = dpx.d; // Expect: -2.000000 + } + + { + dpfloat3 dpx = dpfloat3(float3(2.f, -3.f, -1.f), float3(0.f, 0.f, 0.f)); + __bwd_diff(diffAbs)(dpx, float3(1.f, 1.f, 1.f)); + outputBuffer[9] = dpx.d[0]; // Expect: 1.000000 + outputBuffer[10] = dpx.d[1]; // Expect: -1.000000 + outputBuffer[11] = dpx.d[2]; // Expect: -1.000000 } } |
