From b1d7dc0707406da69d94f3915fa48f39020b93ab Mon Sep 17 00:00:00 2001 From: winmad Date: Tue, 7 Feb 2023 22:30:00 -0800 Subject: 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 Co-authored-by: Lifan Wu --- tests/autodiff-dstdlib/dstdlib-dot.slang | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/autodiff-dstdlib/dstdlib-dot.slang (limited to 'tests/autodiff-dstdlib/dstdlib-dot.slang') diff --git a/tests/autodiff-dstdlib/dstdlib-dot.slang b/tests/autodiff-dstdlib/dstdlib-dot.slang new file mode 100644 index 000000000..4a4e2a78b --- /dev/null +++ b/tests/autodiff-dstdlib/dstdlib-dot.slang @@ -0,0 +1,29 @@ +//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 +RWStructuredBuffer outputBuffer; + +typedef DifferentialPair dpfloat3; + +[BackwardDifferentiable] +float diffDot(float3 x, float3 y) +{ + return dot(x, y); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + { + dpfloat3 dpx = dpfloat3(float3(-0.5, 0.7, 0.8), float3(0.0, 0.0, 0.0)); + dpfloat3 dpy = dpfloat3(float3(0.0, 0.0, 1.0), float3(0.0, 0.0, 0.0)); + __bwd_diff(diffDot)(dpx, dpy, 1.0); + outputBuffer[0] = dpx.d[0]; // Expect: 0.000000 + outputBuffer[1] = dpx.d[1]; // Expect: 0.000000 + outputBuffer[2] = dpx.d[2]; // Expect: 1.000000 + outputBuffer[3] = dpy.d[0]; // Expect: -0.500000 + outputBuffer[4] = dpy.d[1]; // Expect: 0.700000 + outputBuffer[5] = dpy.d[2]; // Expect: 0.800000 + } +} -- cgit v1.2.3