summaryrefslogtreecommitdiff
path: root/tests/autodiff-dstdlib/dstdlib-max.slang
diff options
context:
space:
mode:
authorwinmad <winmad.wlf@gmail.com>2023-02-07 22:30:00 -0800
committerGitHub <noreply@github.com>2023-02-07 22:30:00 -0800
commitb1d7dc0707406da69d94f3915fa48f39020b93ab (patch)
treebb571884616aaf79fa663aec1eb8fcf92f5138cc /tests/autodiff-dstdlib/dstdlib-max.slang
parent4be623c52a6518eb86756a0369706c1d6670f6bb (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-max.slang')
-rw-r--r--tests/autodiff-dstdlib/dstdlib-max.slang20
1 files changed, 15 insertions, 5 deletions
diff --git a/tests/autodiff-dstdlib/dstdlib-max.slang b/tests/autodiff-dstdlib/dstdlib-max.slang
index d28b17e06..026914c8c 100644
--- a/tests/autodiff-dstdlib/dstdlib-max.slang
+++ b/tests/autodiff-dstdlib/dstdlib-max.slang
@@ -1,20 +1,20 @@
//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], stride=4):out,name=outputBuffer
+//TEST_INPUT:ubuffer(data=[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;
-[ForwardDifferentiable]
+[BackwardDifferentiable]
float diffMax(float x, float y)
{
return max(x, y);
}
-[ForwardDifferentiable]
-float2 diffMax2(float2 x, float2 y)
+[BackwardDifferentiable]
+float2 diffMax(float2 x, float2 y)
{
return max(x, y);
}
@@ -33,10 +33,20 @@ void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
dpfloat2 dpx = dpfloat2(float2(-3.0, 4.0), float2(-1.0, -1.0));
dpfloat2 dpy = dpfloat2(float2(1.0, 2.0), float2(2.0, 2.0));
- dpfloat2 res = __fwd_diff(diffMax2)(dpx, dpy);
+ dpfloat2 res = __fwd_diff(diffMax)(dpx, dpy);
outputBuffer[2] = res.p[0]; // Expect: 1.000000
outputBuffer[3] = res.d[0]; // Expect: 2.000000
outputBuffer[4] = res.p[1]; // Expect: 4.000000
outputBuffer[5] = res.d[1]; // Expect: -1.000000
}
+
+ {
+ dpfloat2 dpx = dpfloat2(float2(2.0, 3.0), float2(0.0, 0.0));
+ dpfloat2 dpy = dpfloat2(float2(5.0, 1.0), float2(0.0, 0.0));
+ __bwd_diff(diffMax)(dpx, dpy, float2(1.0, 2.0));
+ outputBuffer[6] = dpx.d[0]; // Expect: 0.000000
+ outputBuffer[7] = dpx.d[1]; // Expect: 2.000000
+ outputBuffer[8] = dpy.d[0]; // Expect: 1.000000
+ outputBuffer[9] = dpy.d[1]; // Expect: 0.000000
+ }
}