summaryrefslogtreecommitdiffstats
path: root/tests/autodiff-dstdlib/dstdlib-log.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-log.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-log.slang')
-rw-r--r--tests/autodiff-dstdlib/dstdlib-log.slang37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/autodiff-dstdlib/dstdlib-log.slang b/tests/autodiff-dstdlib/dstdlib-log.slang
new file mode 100644
index 000000000..6961d2f09
--- /dev/null
+++ b/tests/autodiff-dstdlib/dstdlib-log.slang
@@ -0,0 +1,37 @@
+//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], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+typedef DifferentialPair<float> dpfloat;
+typedef DifferentialPair<float2> dpfloat2;
+
+[BackwardDifferentiable]
+float diffLog(float x)
+{
+ return log(x);
+}
+
+[BackwardDifferentiable]
+float2 diffLog(float2 x)
+{
+ return log(x);
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ {
+ dpfloat dpa = dpfloat(10.0, 0.0);
+ __bwd_diff(diffLog)(dpa, 3.0);
+ outputBuffer[0] = dpa.d; // Expect: 0.300000
+ }
+
+ {
+ dpfloat2 dpx = dpfloat2(float2(2.0, 5.0), float2(0.0, 0.0));
+ __bwd_diff(diffLog)(dpx, float2(1.0, 1.0));
+ outputBuffer[1] = dpx.d[0]; // Expect: 0.500000
+ outputBuffer[2] = dpx.d[1]; // Expect: 0.200000
+ }
+}